From d6a562658a461ec7355677d73c63a57ed8609549 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 17 Sep 2014 13:09:39 -0400 Subject: [PATCH] FIX: update user preferences was failing if custom_fields is blank string --- app/services/user_updater.rb | 2 +- spec/services/user_updater_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index 19a771b6ea4..af05e6e3962 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -66,7 +66,7 @@ class UserUpdater user_profile.send("#{attribute}=", attributes[attribute]) end - if fields = attributes[:custom_fields] + if fields = attributes[:custom_fields] and fields.present? user.custom_fields = fields end diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rb index 02ad0fec06e..8ecbbc6491d 100644 --- a/spec/services/user_updater_spec.rb +++ b/spec/services/user_updater_spec.rb @@ -91,5 +91,17 @@ describe UserUpdater do 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