@@ -33,7 +33,7 class UserPreference < ActiveRecord::Base | |||||
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def [](attr_name) |
|
35 | def [](attr_name) | |
36 |
if attribute |
|
36 | if has_attribute? attr_name | |
37 | super |
|
37 | super | |
38 | else |
|
38 | else | |
39 | others ? others[attr_name] : nil |
|
39 | others ? others[attr_name] : nil | |
@@ -41,7 +41,7 class UserPreference < ActiveRecord::Base | |||||
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def []=(attr_name, value) |
|
43 | def []=(attr_name, value) | |
44 |
if attribute |
|
44 | if has_attribute? attr_name | |
45 | super |
|
45 | super | |
46 | else |
|
46 | else | |
47 | h = (read_attribute(:others) || {}).dup |
|
47 | h = (read_attribute(:others) || {}).dup |
@@ -55,6 +55,11 class UserPreferenceTest < ActiveSupport::TestCase | |||||
55 | assert_kind_of Hash, up.others |
|
55 | assert_kind_of Hash, up.others | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
|
58 | def test_others_should_be_blank_after_initialization | |||
|
59 | pref = User.new.pref | |||
|
60 | assert_equal({}, pref.others) | |||
|
61 | end | |||
|
62 | ||||
58 | def test_reading_value_from_nil_others_hash |
|
63 | def test_reading_value_from_nil_others_hash | |
59 | up = UserPreference.new(:user => User.new) |
|
64 | up = UserPreference.new(:user => User.new) | |
60 | up.others = nil |
|
65 | up.others = nil |
General Comments 0
You need to be logged in to leave comments.
Login now