Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-11 01:19:06 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-06-16 19:52:12 +0300
commit2b4b05727db923d901f90571be94c64f0e1f5fdd (patch)
tree4ac9145eff1fffe9070a793168f883ca1144ff5f
parentf22d80ad7587ee55cb2d07320ea46dbe7d6156a8 (diff)
Spec the failure cases for PreferencesController#update
cherry-picked
-rw-r--r--app/controllers/profiles/preferences_controller.rb13
-rw-r--r--spec/controllers/profiles/preferences_controller_spec.rb20
2 files changed, 27 insertions, 6 deletions
diff --git a/app/controllers/profiles/preferences_controller.rb b/app/controllers/profiles/preferences_controller.rb
index e43a247f725..538b09ca54d 100644
--- a/app/controllers/profiles/preferences_controller.rb
+++ b/app/controllers/profiles/preferences_controller.rb
@@ -5,10 +5,15 @@ class Profiles::PreferencesController < Profiles::ApplicationController
end
def update
- if @user.update_attributes(preferences_params)
- flash[:notice] = 'Preferences saved.'
- else
- # TODO (rspeicher): There's no validation on these values, so can it fail?
+ begin
+ if @user.update_attributes(preferences_params)
+ flash[:notice] = 'Preferences saved.'
+ else
+ flash[:alert] = 'Failed to save preferences.'
+ end
+ rescue ArgumentError => e
+ # Raised when `dashboard` is given an invalid value.
+ flash[:alert] = "Failed to save preferences (#{e.message})."
end
respond_to do |format|
diff --git a/spec/controllers/profiles/preferences_controller_spec.rb b/spec/controllers/profiles/preferences_controller_spec.rb
index 646aa0320b2..1f0943c93d8 100644
--- a/spec/controllers/profiles/preferences_controller_spec.rb
+++ b/spec/controllers/profiles/preferences_controller_spec.rb
@@ -51,8 +51,24 @@ describe Profiles::PreferencesController do
end
end
- context 'on unsuccessful update' do
- # TODO (rspeicher): Can this happen?
+ context 'on failed update' do
+ it 'sets the flash' do
+ expect(user).to receive(:update_attributes).and_return(false)
+
+ go
+
+ expect(flash[:alert]).to eq('Failed to save preferences.')
+ end
+ end
+
+ context 'on invalid dashboard setting' do
+ it 'sets the flash' do
+ prefs = {dashboard: 'invalid'}
+
+ go params: prefs
+
+ expect(flash[:alert]).to match(/\AFailed to save preferences \(.+\)\.\z/)
+ end
end
context 'as js' do