summaryrefslogtreecommitdiff
path: root/spec/controllers
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-02-13 18:36:47 +0000
committerDouwe Maan <douwe@gitlab.com>2017-02-13 18:36:47 +0000
commit5e9666880376b3f53edb95cba77b5642d3cc1810 (patch)
treec41d0997dbfa7211d3f66ffd0cf3cc2b88d7221e /spec/controllers
parentb35378a938e22f745b6c6ea32b53cb50f9b6c627 (diff)
parent9493791d1212f484217e74757550353a5ef07dcf (diff)
downloadgitlab-ce-5e9666880376b3f53edb95cba77b5642d3cc1810.tar.gz
Merge branch 'option-to-be-notified-of-own-activity' into 'master'
Add option to receive email notifications about your own activity See merge request !8836
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/profiles/notifications_controller_spec.rb45
1 files changed, 45 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..58caf7999cf
--- /dev/null
+++ b/spec/controllers/profiles/notifications_controller_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe Profiles::NotificationsController do
+ let(:user) do
+ 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
+
+ describe 'GET show' do
+ it 'renders' do
+ sign_in(user)
+
+ get :show
+
+ expect(response).to render_template :show
+ end
+ end
+
+ describe 'POST update' do
+ it 'updates only permitted attributes' do
+ sign_in(user)
+
+ put :update, user: { notification_email: 'new@example.com', notified_of_own_activity: true, admin: true }
+
+ user.reload
+ expect(user.notification_email).to eq('new@example.com')
+ expect(user.notified_of_own_activity).to eq(true)
+ 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
+ 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
+end