Browse Source

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
tags/2.2.0
Jean-Philippe Lang 11 years ago
parent
commit
838025372d
2 changed files with 16 additions and 1 deletions
  1. 1
    1
      app/models/user_preference.rb
  2. 15
    0
      test/unit/user_preference_test.rb

+ 1
- 1
app/models/user_preference.rb View 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

+ 15
- 0
test/unit/user_preference_test.rb View 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

Loading…
Cancel
Save