diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-06-13 10:54:31 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-06-13 10:54:31 +0300 |
commit | 10ea97505f134ec4b43c93071a02d1498f2e5fc3 (patch) | |
tree | 54f4d8c072412d26f983c9d6f10acb799eb8785b /spec/lib | |
parent | 738f55a0376f86a7e52fb4b76f3e22bd5da514c2 (diff) | |
parent | cef127e10778a21756c00c4226592f32f15a6c1f (diff) |
Merge branch '61157-reviewer-roulette-shouldn-t-include-the-author-as-a-possibility' into 'master'
Review roulette excludes mr_author
Closes #61157
See merge request gitlab-org/gitlab-ce!28886
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/danger/helper_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/danger/roulette_spec.rb | 43 |
2 files changed, 53 insertions, 0 deletions
diff --git a/spec/lib/gitlab/danger/helper_spec.rb b/spec/lib/gitlab/danger/helper_spec.rb index f7642182a17..22e52901758 100644 --- a/spec/lib/gitlab/danger/helper_spec.rb +++ b/spec/lib/gitlab/danger/helper_spec.rb @@ -202,4 +202,14 @@ describe Gitlab::Danger::Helper do it { is_expected.to eq(expected_label) } end end + + describe '#new_teammates' do + it 'returns an array of Teammate' do + usernames = %w[filipa iamphil] + + teammates = helper.new_teammates(usernames) + + expect(teammates.map(&:username)).to eq(usernames) + end + end end diff --git a/spec/lib/gitlab/danger/roulette_spec.rb b/spec/lib/gitlab/danger/roulette_spec.rb index 40dce0c5378..121c5d8ecd9 100644 --- a/spec/lib/gitlab/danger/roulette_spec.rb +++ b/spec/lib/gitlab/danger/roulette_spec.rb @@ -98,4 +98,47 @@ describe Gitlab::Danger::Roulette do is_expected.to contain_exactly(ce_teammate_matcher) end end + + describe '#spin_for_person' do + let(:person1) { Gitlab::Danger::Teammate.new('username' => 'rymai') } + let(:person2) { Gitlab::Danger::Teammate.new('username' => 'godfat') } + let(:author) { Gitlab::Danger::Teammate.new('username' => 'filipa') } + let(:ooo) { Gitlab::Danger::Teammate.new('username' => 'jacopo-beschi') } + + before do + stub_person_message(person1, 'making GitLab magic') + stub_person_message(person2, 'making GitLab magic') + stub_person_message(ooo, 'OOO till 15th') + # we don't stub Filipa, as she is the author and + # we should not fire request checking for her + + allow(subject).to receive_message_chain(:gitlab, :mr_author).and_return(author.username) + end + + it 'returns a random person' do + persons = [person1, person2] + + selected = subject.spin_for_person(persons, random: Random.new) + + expect(selected.username).to be_in(persons.map(&:username)) + end + + it 'excludes OOO persons' do + expect(subject.spin_for_person([ooo], random: Random.new)).to be_nil + end + + it 'excludes mr.author' do + expect(subject.spin_for_person([author], random: Random.new)).to be_nil + end + + private + + def stub_person_message(person, message) + body = { message: message }.to_json + + WebMock + .stub_request(:get, "https://gitlab.com/api/v4/users/#{person.username}/status") + .to_return(body: body) + end + end end |