FIX: update user preferences was failing if custom_fields is blank string

This commit is contained in:
Neil Lalonde 2014-09-17 13:09:39 -04:00
parent d472b4e10a
commit d6a562658a
2 changed files with 13 additions and 1 deletions

View file

@ -66,7 +66,7 @@ class UserUpdater
user_profile.send("#{attribute}=", attributes[attribute]) user_profile.send("#{attribute}=", attributes[attribute])
end end
if fields = attributes[:custom_fields] if fields = attributes[:custom_fields] and fields.present?
user.custom_fields = fields user.custom_fields = fields
end end

View file

@ -91,5 +91,17 @@ describe UserUpdater do
expect(user.reload.user_profile.website).to eq 'http://example.com' expect(user.reload.user_profile.website).to eq 'http://example.com'
end end
end end
context 'when custom_fields is empty string' do
it "update is successful" do
user = Fabricate(:user)
user.custom_fields = {'import_username' => 'my_old_username'}
user.save
updater = described_class.new(acting_user, user)
updater.update(website: 'example.com', custom_fields: '')
user.reload.custom_fields.should == {'import_username' => 'my_old_username'}
end
end
end end
end end