From bf43b4c33fe323448a714854327fdabdcb3c7a14 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 10 Oct 2013 10:32:52 +0200 Subject: `stored_attributes` need to be specific to a subclass. Currently they are all stored globally in the same `Hash`. This commit forces the creation of a per-class variable if necessary. The behavior was exposed through the following test-case: ``` 1) Failure: StoreTest#test_all_stored_attributes_are_returned [/Users/senny/Projects/rails/activerecord/test/cases/store_test.rb:151]: --- expected +++ actual @@ -1 +1 @@ -[:color, :homepage, :favorite_food] +[:resolution, :color, :homepage, :favorite_food] ``` --- activerecord/test/cases/store_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test/cases/store_test.rb') diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index c2c56abacd..0c9f7ccd55 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -150,4 +150,16 @@ class StoreTest < ActiveRecord::TestCase test "all stored attributes are returned" do assert_equal [:color, :homepage, :favorite_food], Admin::User.stored_attributes[:settings] end + + test "stored_attributes are tracked per class" do + first_model = Class.new(ActiveRecord::Base) do + store_accessor :data, :color + end + second_model = Class.new(ActiveRecord::Base) do + store_accessor :data, :width, :height + end + + assert_equal [:color], first_model.stored_attributes[:data] + assert_equal [:width, :height], second_model.stored_attributes[:data] + end end -- cgit v1.2.3