diff options
author | Richard Macklin <richard.github@nrm.com> | 2017-01-27 01:31:42 -0800 |
---|---|---|
committer | Richard Macklin <richard.github@nrm.com> | 2017-02-01 11:17:36 -0800 |
commit | 67cec150cc5a991846a45dffdd699efbb1b65187 (patch) | |
tree | 65eccedb42b86f4c7452526323e9f4cbee714a28 /spec/controllers/profiles | |
parent | e27416300fc71e84b5bc901ef7f9e9143b8b940e (diff) | |
download | gitlab-ce-67cec150cc5a991846a45dffdd699efbb1b65187.tar.gz |
Add controller spec for Profiles::NotificationsController
Diffstat (limited to 'spec/controllers/profiles')
-rw-r--r-- | spec/controllers/profiles/notifications_controller_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/controllers/profiles/notifications_controller_spec.rb b/spec/controllers/profiles/notifications_controller_spec.rb new file mode 100644 index 00000000000..55acc445e43 --- /dev/null +++ b/spec/controllers/profiles/notifications_controller_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe Profiles::NotificationsController do + describe 'GET show' do + it 'renders' do + user = create_user + sign_in(user) + + get :show + expect(response).to render_template :show + end + end + + describe 'POST update' do + it 'updates only permitted attributes' do + user = create_user + sign_in(user) + + put :update, user: { notification_email: 'new@example.com', admin: true } + + user.reload + expect(user.notification_email).to eq('new@example.com') + expect(user.admin).to eq(false) + expect(controller).to set_flash[:notice].to('Notification settings saved') + end + + it 'shows an error message if the params are invalid' do + user = create_user + sign_in(user) + + put :update, user: { notification_email: '' } + + expect(user.reload.notification_email).to eq('original@example.com') + expect(controller).to set_flash[:alert].to('Failed to save new settings') + end + end + + def create_user + create(:user) do |user| + user.emails.create(email: 'original@example.com') + user.emails.create(email: 'new@example.com') + user.update(notification_email: 'original@example.com') + user.save! + end + end +end |