Commit 3f029144 authored by Rémy Coutable's avatar Rémy Coutable

Complete and improve specs

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 1db9f826
...@@ -334,9 +334,9 @@ class ProjectsController < Projects::ApplicationController ...@@ -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,13 +298,18 @@ describe Projects::MergeRequestsController do ...@@ -298,13 +298,18 @@ 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
let(:merge_request) { create(:merge_request_with_diff_notes, source_project: project, author: user) }
context 'when enabled' do
before do before do
project.update_column(:only_allow_merge_if_all_discussions_are_resolved, allowed) project.update_column(:only_allow_merge_if_all_discussions_are_resolved, true)
end end
context "when the only_allow_merge_if_all_discussions_are_resolved? is true" do context 'with unresolved discussion' do
let(:allowed) { true } before do
expect(merge_request).not_to be_discussions_resolved
end
it 'returns :failed' do it 'returns :failed' do
merge_with_sha merge_with_sha
...@@ -313,10 +318,44 @@ describe Projects::MergeRequestsController do ...@@ -313,10 +318,44 @@ describe Projects::MergeRequestsController do
end end
end end
context "when the only_allow_merge_if_all_discussions_are_resolved? is false" do context 'with all discussions resolved' do
let(:allowed) { false } before do
merge_request.discussions.each { |d| d.resolve!(user) }
expect(merge_request).to be_discussions_resolved
end
it 'returns :failed' do it 'returns :success' do
merge_with_sha
expect(assigns(:status)).to eq(:success)
end
end
end
context 'when disabled' do
before do
project.update_column(:only_allow_merge_if_all_discussions_are_resolved, false)
end
context 'with unresolved discussion' do
before do
expect(merge_request).not_to be_discussions_resolved
end
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 merge_with_sha
expect(assigns(:status)).to eq(:success) expect(assigns(:status)).to eq(:success)
...@@ -325,6 +364,7 @@ describe Projects::MergeRequestsController do ...@@ -325,6 +364,7 @@ describe Projects::MergeRequestsController do
end end
end end
end end
end
describe "DELETE destroy" do describe "DELETE destroy" do
it "denies access to users unless they're admin or project owner" do it "denies access to users unless they're admin or project owner" do
......
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)
end
it 'allows MR to be merged' do context 'with unresolved discussions' do
it 'does not allow to merge' do
visit_merge_request(merge_request) visit_merge_request(merge_request)
expect(page).to have_button 'Accept Merge Request' expect(page).not_to have_button 'Accept Merge Request'
expect(page).to have_content('This merge request has unresolved discussions')
end end
end end
context 'when only_allow_merge_if_all_discussions_are_resolved is true' do context 'with all discussions resolved' do
let(:allowed) { true }
context "when discussions are 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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 is true' do context 'when project.only_allow_merge_if_all_discussions_are_resolved == true' do
let(:allowed) { true } let(:project) { create(:project, only_allow_merge_if_all_discussions_are_resolved: true) }
context 'when discussions are resolved' do context 'with all discussions 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment