Last active
January 3, 2016 02:59
-
-
Save PriteshJain/8398859 to your computer and use it in GitHub Desktop.
rails#11776 AR::Store attributes inaccessible after destruction of object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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