summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/notification_settings_controller_spec.rb69
1 files changed, 55 insertions, 14 deletions
diff --git a/spec/controllers/notification_settings_controller_spec.rb b/spec/controllers/notification_settings_controller_spec.rb
index 15d155833b4..ad48b9e9087 100644
--- a/spec/controllers/notification_settings_controller_spec.rb
+++ b/spec/controllers/notification_settings_controller_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe NotificationSettingsController do
let(:project) { create(:empty_project) }
+ let(:group) { create(:group, :internal) }
let(:user) { create(:user) }
before do
@@ -20,33 +21,73 @@ describe NotificationSettingsController do
end
context 'when authorized' do
+ let(:custom_events) do
+ events = {}
+
+ NotificationSetting::EMAIL_EVENTS.each do |event|
+ events[event.to_s] = true
+ end
+
+ events
+ end
+
before do
sign_in(user)
end
- it 'returns success' do
- post :create,
- project: { id: project.id },
- notification_setting: { level: :participating }
+ context 'for projects' do
+ let(:notification_setting) { user.notification_settings_for(project) }
- expect(response.status).to eq 200
- end
+ it 'creates notification setting' do
+ post :create,
+ project: { id: project.id },
+ notification_setting: { level: :participating }
- context 'and setting custom notification setting' do
- let(:custom_events) do
- events = {}
+ expect(response.status).to eq 200
+ expect(notification_setting.level).to eq("participating")
+ expect(notification_setting.user_id).to eq(user.id)
+ expect(notification_setting.source_id).to eq(project.id)
+ expect(notification_setting.source_type).to eq("Project")
+ end
- NotificationSetting::EMAIL_EVENTS.each do |event|
- events[event] = "true"
+ context 'with custom settings' do
+ it 'creates notification setting' do
+ post :create,
+ project: { id: project.id },
+ notification_setting: { level: :custom }.merge(custom_events)
+
+ expect(response.status).to eq 200
+ expect(notification_setting.level).to eq("custom")
+ expect(notification_setting.events).to eq(custom_events)
end
end
+ end
- it 'returns success' do
+ context 'for groups' do
+ let(:notification_setting) { user.notification_settings_for(group) }
+
+ it 'creates notification setting' do
post :create,
- project: { id: project.id },
- notification_setting: { level: :participating, events: custom_events }
+ namespace: { id: group.id },
+ notification_setting: { level: :watch }
expect(response.status).to eq 200
+ expect(notification_setting.level).to eq("watch")
+ expect(notification_setting.user_id).to eq(user.id)
+ expect(notification_setting.source_id).to eq(group.id)
+ expect(notification_setting.source_type).to eq("Namespace")
+ end
+
+ context 'with custom settings' do
+ it 'creates notification setting' do
+ post :create,
+ namespace: { id: group.id },
+ notification_setting: { level: :custom }.merge(custom_events)
+
+ expect(response.status).to eq 200
+ expect(notification_setting.level).to eq("custom")
+ expect(notification_setting.events).to eq(custom_events)
+ end
end
end
end