Skip to content

Commit

Permalink
Fix: reviewers also get private notifications (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrixr authored Aug 15, 2019
1 parent 260b3e7 commit 39dabad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/message_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def public_subscribers_to(klass, id)
end

# A private subscriber is defined as :
# > A supervisor who has answered the private thread
# > A supervisor or reviewer who has answered the private thread
def private_subscribers_to(klass, id)
User.supervisors
User.staff
.joins(messages: [:subscriptions])
.where(messages: { is_private: true })
.where(subscriptions: { "#{klass}_id": id })
Expand Down
21 changes: 21 additions & 0 deletions spec/models/concerns/message_subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@
end
end

context "should subscribe a reviewer for subsequent messages if he/she posted something in the private thread" do
let!(:other_reviewer) { create :user, :reviewer }

before { User.current_user = other_reviewer }

it do
# The unrelated supervisor receives the first message of the thread
expect(message).to receive(:add_subscription).with('read', reviewer.id)
expect(message).to receive(:add_subscription).with('unread', other_reviewer.id)
message.save

# The supervisor answers on the the private thread
create :message, sender: other_reviewer, offer: message.offer, is_private: true

# The supervisor receives subsequent message of the thread
expect(message2).to receive(:add_subscription).with('read', reviewer.id) # sender
expect(message2).to receive(:add_subscription).with('unread', other_reviewer.id)
message2.save
end
end

context "should subscribe a supervisor for subsequent messages if he/she posted something in the public thread" do
let!(:supervisor) { create :user, :supervisor }

Expand Down

0 comments on commit 39dabad

Please sign in to comment.