Skip to content

Instantly share code, notes, and snippets.

@PriteshJain
Last active January 3, 2016 02:59
Show Gist options
  • Save PriteshJain/8398859 to your computer and use it in GitHub Desktop.
Save PriteshJain/8398859 to your computer and use it in GitHub Desktop.
rails#11776 AR::Store attributes inaccessible after destruction of object
gem 'activerecord', '=4.0.0' #Works Fine
# gem 'activerecord' , '=4.0.1' #CAUSES ActiveModel::MissingAttributeError: missing attribute: group_id
# gem 'activerecord', '=4.0.2' #CAUSES ActiveModel::MissingAttributeError: missing attribute: group_id
require 'active_record'
# require 'sqlite3'
require 'mysql2'
require 'minitest/autorun'
require 'logger'
# == Connection/configuration stuff
puts "#{ActiveRecord::VERSION::STRING}"
# ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'rails_11776', username: 'root')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS users')
# == Schema definition
ActiveRecord::Schema.define do
create_table :users do |t|
t.text :settings
t.string :email
end
end
# == Models
class User < ActiveRecord::Base
# store :settings, coder: JSON
store_accessor :settings, :newsletter_enabled
# and a User has an email attribute
end
# == Test case
class BugTest < MiniTest::Unit::TestCase
def setup
@user = User.create(email: '[email protected]',newsletter_enabled: true)
end
# passes
def test_destructions
puts @user.newsletter_enabled.inspect
@user.destroy
puts "Destroyed"
puts @user.newsletter_enabled.inspect
end
end
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment