Skip to content

Commit

Permalink
[ci] Improve test coverage for EventFindSubscription.
Browse files Browse the repository at this point in the history
I add a test to consider what happens when a user is both a maintainer
and a commentor for a comment event.
  • Loading branch information
Evan Rolfe committed Oct 10, 2017
1 parent e9d9064 commit 7a5d21f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/api/spec/models/event_find_subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@
let!(:maintainer) { create(:group) }
end

context 'with a user who is a maintainer and a commenter' do
context 'and the user has a maintainer and commenter subscriptions, which are both enabled' do
let!(:maintainer) { create(:confirmed_user) }
let!(:project) { create(:project, maintainer: [maintainer]) }
let!(:comment) { create(:comment_project, commentable: project, body: "Hey @#{maintainer.login} hows it going?") }

let!(:subscription_maintainer) do
create(:event_subscription_comment_for_project_without_subscriber, receiver_role: 'maintainer', subscriber: maintainer)
end
let!(:subscription_commenter) do
create(:event_subscription_comment_for_project_without_subscriber, receiver_role: 'commenter', subscriber: maintainer)
end

it 'returns a subscription for that user/group' do
result_subscription = subject.find { |subscription| subscription.subscriber == maintainer }

# It doesn't matter if the maintainer or commenter subscription is returned
expect(result_subscription.id).not_to be_nil
expect(result_subscription.eventtype).to eq(subscription_maintainer.eventtype)
expect(result_subscription.channel).to eq(subscription_maintainer.channel)
end

it 'only returns one subscription' do
result_subscriptions = subject.select { |subscription| subscription.subscriber == maintainer }

expect(result_subscriptions.length).to eq(1)
end
end
end

context 'with a maintainer group who has no email set and has a user as a member' do
let!(:group) { create(:group, email: nil) }
let!(:user) { create(:confirmed_user) }
Expand Down

0 comments on commit 7a5d21f

Please sign in to comment.