summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-09-22 06:16:53 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-09-22 06:16:53 +0000
commit838025372dc34096464cf19cdd39a1a587e4f176 (patch)
treed8103a18bfc90585c75f3bb9f76890c4abeae44a
parent5328c4adcb6c34978652b5245b0de0b98903a6d1 (diff)
downloadredmine-838025372dc34096464cf19cdd39a1a587e4f176.tar.gz
redmine-838025372dc34096464cf19cdd39a1a587e4f176.zip
Potential can't dup NilClass error in UserPreference (#11905).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10438 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/user_preference.rb2
-rw-r--r--test/unit/user_preference_test.rb15
2 files changed, 16 insertions, 1 deletions
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index da99061a1..3c46712f9 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -44,7 +44,7 @@ class UserPreference < ActiveRecord::Base
if attribute_present? attr_name
super
else
- h = read_attribute(:others).dup || {}
+ h = (read_attribute(:others) || {}).dup
h.update(attr_name => value)
write_attribute(:others, h)
value
diff --git a/test/unit/user_preference_test.rb b/test/unit/user_preference_test.rb
index 61dea0f59..9f49458eb 100644
--- a/test/unit/user_preference_test.rb
+++ b/test/unit/user_preference_test.rb
@@ -54,4 +54,19 @@ class UserPreferenceTest < ActiveSupport::TestCase
assert up.save
assert_kind_of Hash, up.others
end
+
+ def test_reading_value_from_nil_others_hash
+ up = UserPreference.new(:user => User.new)
+ up.others = nil
+ assert_nil up.others
+ assert_nil up[:foo]
+ end
+
+ def test_writing_value_to_nil_others_hash
+ up = UserPreference.new(:user => User.new)
+ up.others = nil
+ assert_nil up.others
+ up[:foo] = 'bar'
+ assert_equal 'bar', up[:foo]
+ end
end