]> source.dussan.org Git - redmine.git/commitdiff
Potential can't dup NilClass error in UserPreference (#11905).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 22 Sep 2012 06:16:53 +0000 (06:16 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 22 Sep 2012 06:16:53 +0000 (06:16 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10438 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/user_preference.rb
test/unit/user_preference_test.rb

index da99061a11fe998f032e79807f755da048c03454..3c46712f9f14f7f553a371f333c589bcdc5f39eb 100644 (file)
@@ -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
index 61dea0f59634c44ff8a651fe30209255c7fe4aef..9f49458eba2d9a60ae9b2b7b15a01de0c43d2122 100644 (file)
@@ -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