diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-07 12:41:48 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-07-07 17:14:21 +0100 |
commit | 808642775a850bf4f3ec41ced030f3f60a374085 (patch) | |
tree | cf39b4e5f56984211701124d053aab65766dee91 /spec | |
parent | 3c89a788c795fba2b050a0af0d8261e302d8cded (diff) | |
download | gitlab-ce-pending-delete-project-notifications.tar.gz |
Exclude projects pending delete from notificationspending-delete-project-notifications
If the Sidekiq job fails for some reason, a project can be 'stuck'
pending deletion. The project can't be viewed, so it shouldn't be
available through the notification settings association as this will
throw an exception when we try to show the link.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/notification_settings.rb | 8 | ||||
-rw-r--r-- | spec/models/notification_setting_spec.rb | 17 |
2 files changed, 25 insertions, 0 deletions
diff --git a/spec/factories/notification_settings.rb b/spec/factories/notification_settings.rb new file mode 100644 index 00000000000..b5e96d18b8f --- /dev/null +++ b/spec/factories/notification_settings.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :notification_setting do + source factory: :empty_project + user + level 3 + events [] + end +end diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb index df336a6effe..3ae2149d56a 100644 --- a/spec/models/notification_setting_spec.rb +++ b/spec/models/notification_setting_spec.rb @@ -38,4 +38,21 @@ RSpec.describe NotificationSetting, type: :model do end end end + + describe '#for_projects' do + let(:user) { create(:user) } + + before do + 1.upto(4) do |i| + setting = create(:notification_setting, user: user) + + setting.project.update_attributes(pending_delete: true) if i % 2 == 0 + end + end + + it 'excludes projects pending delete' do + expect(user.notification_settings.for_projects).to all(have_attributes(project: an_instance_of(Project))) + expect(user.notification_settings.for_projects.map(&:project)).to all(have_attributes(pending_delete: false)) + end + end end |