Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-02-12 17:58:39 +0300
committerRémy Coutable <remy@rymai.me>2016-03-15 19:25:37 +0300
commit0444fa560acd07255960284f19b1de6499cd5910 (patch)
tree005ce576bbe661242ee58c1e1ddebd9e665bd9ff /spec/services/notification_service_spec.rb
parent178c80a561fa10a157bae6e5d4682b232ae727c7 (diff)
Original implementation to allow users to subscribe to labels
1. Allow subscribing (the current user) to a label - Refactor the `Subscription` coffeescript class - The main change is that it accepts a container, and conducts all DOM queries within its scope. We need this because the labels page has multiple instances of `Subscription` on the same page. 2. Creating an issue or MR with labels notifies users subscribed to those labels - Label `has_many` subscribers through subscriptions. 3. Adding a label to an issue or MR notifies users subscribed to those labels - This only applies to subscribers of the label that has just been added, not all labels for the issue.
Diffstat (limited to 'spec/services/notification_service_spec.rb')
-rw-r--r--spec/services/notification_service_spec.rb87
1 files changed, 75 insertions, 12 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index 2d0b5df4224..35afa768057 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -224,6 +224,16 @@ describe NotificationService, services: true do
should_not_email(issue.assignee)
end
+
+ it "should email subscribers of the issue's labels" do
+ subscriber, non_subscriber = create_list(:user, 2)
+ label = create(:label, issues: [issue])
+ label.toggle_subscription(subscriber)
+ 2.times { label.toggle_subscription(non_subscriber) }
+ notification.new_issue(issue, @u_disabled)
+ should_email(subscriber)
+ should_not_email(non_subscriber)
+ end
end
describe :reassigned_issue do
@@ -326,6 +336,32 @@ describe NotificationService, services: true do
should_not_email(@u_participating)
end
end
+
+ describe :relabel_issue do
+ it "sends email to subscribers of the given labels" do
+ subscriber, non_subscriber = create_list(:user, 2)
+ label = create(:label, issues: [issue])
+ label.toggle_subscription(subscriber)
+ 2.times { label.toggle_subscription(non_subscriber) }
+ notification.relabeled_issue(issue, [label], @u_disabled)
+ should_email(subscriber)
+ should_not_email(non_subscriber)
+ end
+
+ it "doesn't send email to anyone but subscribers of the given labels" do
+ label = create(:label, issues: [issue])
+ notification.relabeled_issue(issue, [label], @u_disabled)
+
+ should_not_email(issue.assignee)
+ should_not_email(issue.author)
+ should_not_email(@u_watcher)
+ should_not_email(@u_participant_mentioned)
+ should_not_email(@subscriber)
+ should_not_email(@watcher_and_subscriber)
+ should_not_email(@unsubscriber)
+ should_not_email(@u_participating)
+ end
+ end
end
describe 'Merge Requests' do
@@ -349,6 +385,17 @@ describe NotificationService, services: true do
should_not_email(@u_participating)
should_not_email(@u_disabled)
end
+
+ it "should email subscribers of the MR's labels" do
+ subscriber, non_subscriber = create_list(:user, 2)
+ label = create(:label)
+ merge_request.labels << label
+ label.toggle_subscription(subscriber)
+ 2.times { label.toggle_subscription(non_subscriber) }
+ notification.new_merge_request(merge_request, @u_disabled)
+ should_email(subscriber)
+ should_not_email(non_subscriber)
+ end
end
describe :reassigned_merge_request do
@@ -410,6 +457,34 @@ describe NotificationService, services: true do
should_not_email(@u_disabled)
end
end
+
+ describe :relabel_merge_request do
+ it "sends email to subscribers of the given labels" do
+ subscriber, non_subscriber = create_list(:user, 2)
+ label = create(:label)
+ merge_request.labels << label
+ label.toggle_subscription(subscriber)
+ 2.times { label.toggle_subscription(non_subscriber) }
+ notification.relabeled_merge_request(merge_request, [label], @u_disabled)
+ should_email(subscriber)
+ should_not_email(non_subscriber)
+ end
+
+ it "doesn't send email to anyone but subscribers of the given labels" do
+ label = create(:label)
+ merge_request.labels << label
+ notification.relabeled_merge_request(merge_request, [label], @u_disabled)
+
+ should_not_email(merge_request.assignee)
+ should_not_email(merge_request.author)
+ should_not_email(@u_watcher)
+ should_not_email(@u_participant_mentioned)
+ should_not_email(@subscriber)
+ should_not_email(@watcher_and_subscriber)
+ should_not_email(@unsubscriber)
+ should_not_email(@u_participating)
+ end
+ end
end
describe 'Projects' do
@@ -467,16 +542,4 @@ describe NotificationService, services: true do
# Make the watcher a subscriber to detect dupes
issuable.subscriptions.create(user: @watcher_and_subscriber, subscribed: true)
end
-
- def sent_to_user?(user)
- ActionMailer::Base.deliveries.map(&:to).flatten.count(user.email) == 1
- end
-
- def should_email(user)
- expect(sent_to_user?(user)).to be_truthy
- end
-
- def should_not_email(user)
- expect(sent_to_user?(user)).to be_falsey
- end
end