diff options
author | micael.bergeron <micael.bergeron@solutionstlm.com> | 2017-08-29 09:46:40 -0400 |
---|---|---|
committer | micael.bergeron <micael.bergeron@solutionstlm.com> | 2017-09-06 09:00:57 -0400 |
commit | 65bcd141c883b1efd9518ff5f588e1dcb1d80f64 (patch) | |
tree | 21507da44c611c2a8cfeb0b64e4163374b6f2451 /spec | |
parent | 4130552b421f1b83e60f03715000efe56461fc6b (diff) | |
download | gitlab-ce-65bcd141c883b1efd9518ff5f588e1dcb1d80f64.tar.gz |
add controller spec
also fix some code styling issues
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/merge_requests_controller_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/note_spec.rb | 21 |
3 files changed, 25 insertions, 24 deletions
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index bb67db268fa..6775012bab5 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -56,6 +56,28 @@ describe Projects::MergeRequestsController do expect(response).to be_success end + + context "loads notes" do + let(:first_contributor) { create(:user) } + let(:contributor) { create(:user) } + let(:merge_request) { create(:merge_request, author: first_contributor, target_project: project, source_project: project) } + let(:contributor_merge_request) { create(:merge_request, :merged, author: contributor, target_project: project, source_project: project) } + # the order here is important + # as the controller reloads these from DB, references doesn't correspond after + let!(:first_contributor_note) { create(:note, author: first_contributor, noteable: merge_request, project: project) } + let!(:contributor_note) { create(:note, author: contributor, noteable: merge_request, project: project) } + let!(:owner_note) { create(:note, author: user, noteable: merge_request, project: project) } + + it "with special_role FIRST_TIME_CONTRIBUTOR" do + go(format: :html) + + notes = assigns(:notes) + expect(notes).to match(a_collection_containing_exactly(an_object_having_attributes(special_role: Note::SpecialRole::FIRST_TIME_CONTRIBUTOR), + an_object_having_attributes(special_role: nil), + an_object_having_attributes(special_role: nil) + )) + end + end end describe 'as json' do diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 098d33e46c5..fb5fb7daaab 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -501,7 +501,7 @@ describe Issuable do project.add_guest(contributor) project.add_guest(first_time_contributor) end - + let(:merged_mr) { create(:merge_request, :merged, author: contributor, target_project: project, source_project: project) } let(:open_mr) { create(:merge_request, author: first_time_contributor, target_project: project, source_project: project) } let(:merged_mr_other_project) { create(:merge_request, :merged, author: first_time_contributor, target_project: other_project, source_project: other_project) } @@ -515,13 +515,13 @@ describe Issuable do it "is false for OWNER" do mr = create(:merge_request, author: owner, target_project: project, source_project: project) - + expect(mr).not_to be_first_contribution end it "is false for REPORTER" do mr = create(:merge_request, author: reporter, target_project: project, source_project: project) - + expect(mr).not_to be_first_contribution end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 09caa2c9991..b214074fdce 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -696,25 +696,4 @@ describe Note do note.destroy! end end - - describe '#specialize!' do - let(:note) { build(:note) } - let(:role) { Note::SpecialRole::FIRST_TIME_CONTRIBUTOR } - - it 'should set special role without a block' do - expect { note.specialize!(role) }.to change { note.special_role }.from(nil).to(role) - end - - it 'should set special role with a truthy block' do - tautology = -> (*) { true } - - expect { note.specialize!(role, &tautology) }.to change { note.special_role }.from(nil).to(role) - end - - it 'should not set special role with a falsey block' do - contradiction = -> (*) { false } - - expect { note.specialize!(role, &contradiction) }.not_to change { note.special_role } - end - end end |