Skip to content

Commit

Permalink
FIX: update user preferences was failing if custom_fields is blank st…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
nlalonde committed Sep 17, 2014
1 parent d472b4e commit d6a5626
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/services/user_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def update(attributes = {})
user_profile.send("#{attribute}=", attributes[attribute])
end

if fields = attributes[:custom_fields]
if fields = attributes[:custom_fields] and fields.present?

This comment has been minimized.

Copy link
@eviltrout

eviltrout Sep 22, 2014

Contributor

Very minor but we're supposed to use && instead of and in ruby code

user.custom_fields = fields
end

Expand Down
12 changes: 12 additions & 0 deletions spec/services/user_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,17 @@
expect(user.reload.user_profile.website).to eq 'http://example.com'
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

1 comment on commit d6a5626

@nlalonde
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Fixed

Please sign in to comment.