Commit 2b4b0572 authored by Robert Speicher's avatar Robert Speicher

Spec the failure cases for PreferencesController#update

cherry-picked
parent f22d80ad
...@@ -5,10 +5,15 @@ class Profiles::PreferencesController < Profiles::ApplicationController ...@@ -5,10 +5,15 @@ class Profiles::PreferencesController < Profiles::ApplicationController
end end
def update def update
begin
if @user.update_attributes(preferences_params) if @user.update_attributes(preferences_params)
flash[:notice] = 'Preferences saved.' flash[:notice] = 'Preferences saved.'
else else
# TODO (rspeicher): There's no validation on these values, so can it fail? 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 end
respond_to do |format| respond_to do |format|
......
...@@ -51,8 +51,24 @@ describe Profiles::PreferencesController do ...@@ -51,8 +51,24 @@ describe Profiles::PreferencesController do
end end
end end
context 'on unsuccessful update' do context 'on failed update' do
# TODO (rspeicher): Can this happen? 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 end
context 'as js' do context 'as js' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment