diff options
Diffstat (limited to 'spec/services/user_preferences/update_service_spec.rb')
-rw-r--r-- | spec/services/user_preferences/update_service_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/services/user_preferences/update_service_spec.rb b/spec/services/user_preferences/update_service_spec.rb new file mode 100644 index 00000000000..59089a4a7af --- /dev/null +++ b/spec/services/user_preferences/update_service_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe UserPreferences::UpdateService do + let(:user) { create(:user) } + let(:params) { { view_diffs_file_by_file: false } } + + describe '#execute' do + subject(:service) { described_class.new(user, params) } + + context 'successfully updating the record' do + it 'updates the preference and returns a success' do + result = service.execute + + expect(result.status).to eq(:success) + expect(result.payload[:preferences].view_diffs_file_by_file).to eq(params[:view_diffs_file_by_file]) + end + end + + context 'unsuccessfully updating the record' do + before do + allow(user.user_preference).to receive(:update).and_return(false) + end + + it 'returns an error' do + result = service.execute + + expect(result.status).to eq(:error) + end + end + end +end |