summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-06-14 10:17:00 -0300
committerFelipe Artur <felipefac@gmail.com>2016-06-14 10:17:00 -0300
commitbef15a0f91ee82815bc1a79e2608201fcd83c2ca (patch)
tree8e2c05bf5a9bd0170a9a8a73664fda7529be103a /spec
parent220708fa6ebca4ece1be0af4bb72933a4d72cc76 (diff)
downloadgitlab-ce-bef15a0f91ee82815bc1a79e2608201fcd83c2ca.tar.gz
Refactor custom notifications controller code and add specs
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/notification_settings_controller_spec.rb19
-rw-r--r--spec/models/notification_setting_spec.rb25
2 files changed, 44 insertions, 0 deletions
diff --git a/spec/controllers/projects/notification_settings_controller_spec.rb b/spec/controllers/projects/notification_settings_controller_spec.rb
index c5d17d97ec9..a726f70a64a 100644
--- a/spec/controllers/projects/notification_settings_controller_spec.rb
+++ b/spec/controllers/projects/notification_settings_controller_spec.rb
@@ -33,6 +33,25 @@ describe Projects::NotificationSettingsController do
expect(response.status).to eq 200
end
+
+ context 'and setting custom notification setting' do
+ let(:custom_events) do
+ events = {}
+
+ NotificationSetting::EMAIL_EVENTS.each do |event|
+ events[event] = "true"
+ end
+ end
+
+ it 'returns success' do
+ put :update,
+ namespace_id: project.namespace.to_param,
+ project_id: project.to_param,
+ notification_setting: { level: :participating, events: custom_events }
+
+ expect(response.status).to eq 200
+ end
+ end
end
context 'not authorized' do
diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb
index 4e24e89b008..df336a6effe 100644
--- a/spec/models/notification_setting_spec.rb
+++ b/spec/models/notification_setting_spec.rb
@@ -12,5 +12,30 @@ RSpec.describe NotificationSetting, type: :model do
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:level) }
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to([:source_id, :source_type]).with_message(/already exists in source/) }
+
+ context "events" do
+ let(:user) { create(:user) }
+ let(:notification_setting) { NotificationSetting.new(source_id: 1, source_type: 'Project', user_id: user.id) }
+
+ before do
+ notification_setting.level = "custom"
+ notification_setting.new_note = "true"
+ notification_setting.new_issue = 1
+ notification_setting.close_issue = "1"
+ notification_setting.merge_merge_request = "t"
+ notification_setting.close_merge_request = "nil"
+ notification_setting.reopen_merge_request = "false"
+ notification_setting.save
+ end
+
+ it "parses boolean before saving" do
+ expect(notification_setting.new_note).to eq(true)
+ expect(notification_setting.new_issue).to eq(true)
+ expect(notification_setting.close_issue).to eq(true)
+ expect(notification_setting.merge_merge_request).to eq(true)
+ expect(notification_setting.close_merge_request).to eq(false)
+ expect(notification_setting.reopen_merge_request).to eq(false)
+ end
+ end
end
end