Complete and improve specs
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
1db9f826c1
commit
3f02914460
4 changed files with 105 additions and 56 deletions
|
@ -334,9 +334,9 @@ class ProjectsController < Projects::ApplicationController
|
||||||
:issues_tracker_id, :default_branch,
|
:issues_tracker_id, :default_branch,
|
||||||
:visibility_level, :import_url, :last_activity_at, :namespace_id, :avatar,
|
:visibility_level, :import_url, :last_activity_at, :namespace_id, :avatar,
|
||||||
:build_allow_git_fetch, :build_timeout_in_minutes, :build_coverage_regex,
|
:build_allow_git_fetch, :build_timeout_in_minutes, :build_coverage_regex,
|
||||||
:public_builds, :only_allow_merge_if_build_succeeds,
|
:public_builds, :only_allow_merge_if_build_succeeds, :request_access_enabled,
|
||||||
:only_allow_merge_if_all_discussions_are_resolved,
|
:only_allow_merge_if_all_discussions_are_resolved,
|
||||||
:request_access_enabled, :lfs_enabled, project_feature_attributes
|
:lfs_enabled, project_feature_attributes
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -298,28 +298,68 @@ describe Projects::MergeRequestsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when project project has unresolved discussion' do
|
describe 'only_allow_merge_if_all_discussions_are_resolved? setting' do
|
||||||
before do
|
let(:merge_request) { create(:merge_request_with_diff_notes, source_project: project, author: user) }
|
||||||
project.update_column(:only_allow_merge_if_all_discussions_are_resolved, allowed)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the only_allow_merge_if_all_discussions_are_resolved? is true" do
|
context 'when enabled' do
|
||||||
let(:allowed) { true }
|
before do
|
||||||
|
project.update_column(:only_allow_merge_if_all_discussions_are_resolved, true)
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns :failed' do
|
context 'with unresolved discussion' do
|
||||||
merge_with_sha
|
before do
|
||||||
|
expect(merge_request).not_to be_discussions_resolved
|
||||||
|
end
|
||||||
|
|
||||||
expect(assigns(:status)).to eq(:failed)
|
it 'returns :failed' do
|
||||||
|
merge_with_sha
|
||||||
|
|
||||||
|
expect(assigns(:status)).to eq(:failed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with all discussions resolved' do
|
||||||
|
before do
|
||||||
|
merge_request.discussions.each { |d| d.resolve!(user) }
|
||||||
|
expect(merge_request).to be_discussions_resolved
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns :success' do
|
||||||
|
merge_with_sha
|
||||||
|
|
||||||
|
expect(assigns(:status)).to eq(:success)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the only_allow_merge_if_all_discussions_are_resolved? is false" do
|
context 'when disabled' do
|
||||||
let(:allowed) { false }
|
before do
|
||||||
|
project.update_column(:only_allow_merge_if_all_discussions_are_resolved, false)
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns :failed' do
|
context 'with unresolved discussion' do
|
||||||
merge_with_sha
|
before do
|
||||||
|
expect(merge_request).not_to be_discussions_resolved
|
||||||
|
end
|
||||||
|
|
||||||
expect(assigns(:status)).to eq(:success)
|
it 'returns :success' do
|
||||||
|
merge_with_sha
|
||||||
|
|
||||||
|
expect(assigns(:status)).to eq(:success)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with all discussions resolved' do
|
||||||
|
before do
|
||||||
|
merge_request.discussions.each { |d| d.resolve!(user) }
|
||||||
|
expect(merge_request).to be_discussions_resolved
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns :success' do
|
||||||
|
merge_with_sha
|
||||||
|
|
||||||
|
expect(assigns(:status)).to eq(:success)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
feature 'Check if mergeable with unresolved discussions', js: true, feature: true do
|
feature 'Check if mergeable with unresolved discussions', js: true, feature: true do
|
||||||
let!(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let!(:project) { create(:project, :public, only_allow_merge_if_all_discussions_are_resolved: allowed) }
|
let(:project) { create(:project) }
|
||||||
let!(:merge_request) { create(:merge_request_with_diff_notes, source_project: project, author: user, title: "Bug NS-04" ) }
|
let!(:merge_request) { create(:merge_request_with_diff_notes, source_project: project, author: user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_as user
|
login_as user
|
||||||
project.team << [user, :master]
|
project.team << [user, :master]
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when only_allow_merge_if_all_discussions_are_resolved is false' do
|
context 'when project.only_allow_merge_if_all_discussions_are_resolved == true' do
|
||||||
let(:allowed) { false }
|
before do
|
||||||
|
project.update_column(:only_allow_merge_if_all_discussions_are_resolved, true)
|
||||||
it 'allows MR to be merged' do
|
|
||||||
visit_merge_request(merge_request)
|
|
||||||
|
|
||||||
expect(page).to have_button 'Accept Merge Request'
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context 'when only_allow_merge_if_all_discussions_are_resolved is true' do
|
context 'with unresolved discussions' do
|
||||||
let(:allowed) { true }
|
it 'does not allow to merge' do
|
||||||
|
visit_merge_request(merge_request)
|
||||||
|
|
||||||
context "when discussions are resolved" do
|
expect(page).not_to have_button 'Accept Merge Request'
|
||||||
|
expect(page).to have_content('This merge request has unresolved discussions')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with all discussions resolved' do
|
||||||
before do
|
before do
|
||||||
merge_request.discussions.each { |d| d.resolve!(user) }
|
merge_request.discussions.each { |d| d.resolve!(user) }
|
||||||
end
|
end
|
||||||
|
@ -35,14 +35,30 @@ feature 'Check if mergeable with unresolved discussions', js: true, feature: tru
|
||||||
expect(page).to have_button 'Accept Merge Request'
|
expect(page).to have_button 'Accept Merge Request'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when discussions are unresolved" do
|
context 'when project.only_allow_merge_if_all_discussions_are_resolved == false' do
|
||||||
|
before do
|
||||||
|
project.update_column(:only_allow_merge_if_all_discussions_are_resolved, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with unresolved discussions' do
|
||||||
it 'does not allow to merge' do
|
it 'does not allow to merge' do
|
||||||
visit_merge_request(merge_request)
|
visit_merge_request(merge_request)
|
||||||
|
|
||||||
expect(page).not_to have_button 'Accept Merge Request'
|
expect(page).to have_button 'Accept Merge Request'
|
||||||
expect(page).to have_content('This merge request has unresolved discussions')
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with all discussions resolved' do
|
||||||
|
before do
|
||||||
|
merge_request.discussions.each { |d| d.resolve!(user) }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'allows MR to be merged' do
|
||||||
|
visit_merge_request(merge_request)
|
||||||
|
|
||||||
|
expect(page).to have_button 'Accept Merge Request'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -825,11 +825,8 @@ describe MergeRequest, models: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when failed' do
|
context 'when failed' do
|
||||||
before { allow(subject).to receive(:broken?) { false } }
|
context 'when #mergeable_ci_state? is false' do
|
||||||
|
|
||||||
context 'when project settings restrict to merge only if build succeeds and build failed' do
|
|
||||||
before do
|
before do
|
||||||
project.only_allow_merge_if_build_succeeds = true
|
|
||||||
allow(subject).to receive(:mergeable_ci_state?) { false }
|
allow(subject).to receive(:mergeable_ci_state?) { false }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -838,9 +835,8 @@ describe MergeRequest, models: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when project settings restrict to merge only when all the discussions are resolved" do
|
context 'when #mergeable_discussions_state? is false' do
|
||||||
before do
|
before do
|
||||||
project.only_allow_merge_if_all_discussions_are_resolved = true
|
|
||||||
allow(subject).to receive(:mergeable_discussions_state?) { false }
|
allow(subject).to receive(:mergeable_discussions_state?) { false }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -899,45 +895,42 @@ describe MergeRequest, models: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#mergeable_discussions_state?' do
|
describe '#mergeable_discussions_state?' do
|
||||||
let!(:user) { create(:user) }
|
let(:merge_request) { create(:merge_request_with_diff_notes, source_project: project) }
|
||||||
let!(:project) { create(:project, only_allow_merge_if_all_discussions_are_resolved: allowed) }
|
|
||||||
|
|
||||||
subject { create(:merge_request_with_diff_notes, source_project: project) }
|
context 'when project.only_allow_merge_if_all_discussions_are_resolved == true' do
|
||||||
|
let(:project) { create(:project, only_allow_merge_if_all_discussions_are_resolved: true) }
|
||||||
|
|
||||||
context 'when is true' do
|
context 'with all discussions resolved' do
|
||||||
let(:allowed) { true }
|
|
||||||
|
|
||||||
context 'when discussions are resolved' do
|
|
||||||
before do
|
before do
|
||||||
subject.discussions.each { |d| d.resolve!(user) }
|
merge_request.discussions.each { |d| d.resolve!(merge_request.author) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(subject.mergeable_discussions_state?).to be_truthy
|
expect(merge_request.mergeable_discussions_state?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when discussions are unresolved' do
|
context 'with unresolved discussions' do
|
||||||
before do
|
before do
|
||||||
subject.discussions.map(&:unresolve!)
|
merge_request.discussions.each(&:unresolve!)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false' do
|
it 'returns false' do
|
||||||
expect(subject.mergeable_discussions_state?).to be_falsey
|
expect(merge_request.mergeable_discussions_state?).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when is false' do
|
context 'when project.only_allow_merge_if_all_discussions_are_resolved == false' do
|
||||||
let(:allowed) { false }
|
let(:project) { create(:project, only_allow_merge_if_all_discussions_are_resolved: false) }
|
||||||
|
|
||||||
context 'when discussions are unresolved' do
|
context 'with unresolved discussions' do
|
||||||
before do
|
before do
|
||||||
subject.discussions.map(&:unresolve!)
|
merge_request.discussions.each(&:unresolve!)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(subject.mergeable_discussions_state?).to be_truthy
|
expect(merge_request.mergeable_discussions_state?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue