diff options
author | Stan Hu <stanhu@gmail.com> | 2017-03-17 06:18:57 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-03-17 06:18:57 +0300 |
commit | 7cad597f6c8ba794c6852e23d718ed7827da35c6 (patch) | |
tree | a81a2f320f35a546b5a6d7a1b54015877d53c0ff /spec/controllers/profiles | |
parent | 4bf4612cfbe73845391375bf721592426d7b4181 (diff) |
Revert "Merge branch '8836-mr-revert' into 'master'
This reverts commit 68e40bd49fde7b790bb31b9ac85a249bedd817d2, reversing
changes made to 2d1f823b4c8b60cee525384cb52e547d2be8925a.
Diffstat (limited to 'spec/controllers/profiles')
-rw-r--r-- | spec/controllers/profiles/notifications_controller_spec.rb | 45 |
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 |