Commit 25caf20c authored by Felipe Artur's avatar Felipe Artur

Move merge service specs to EE module

parent 01932584
......@@ -26,4 +26,56 @@ describe MergeRequests::MergeService do
end
end
end
describe '#hooks_validation_pass?' do
shared_examples 'hook validations are skipped when push rules unlicensed' do
subject { service.hooks_validation_pass?(merge_request) }
before do
stub_licensed_features(push_rules: false)
end
it { is_expected.to be_truthy }
end
let(:service) { described_class.new(project, user, commit_message: 'Awesome message') }
it 'returns true when valid' do
expect(service.hooks_validation_pass?(merge_request)).to be_truthy
end
context 'commit message validation' do
before do
allow(project).to receive(:push_rule) { build(:push_rule, commit_message_regex: 'unmatched pattern .*') }
end
it_behaves_like 'hook validations are skipped when push rules unlicensed'
it 'returns false and saves error when invalid' do
expect(service.hooks_validation_pass?(merge_request)).to be_falsey
expect(merge_request.merge_error).not_to be_empty
end
end
context 'authors email validation' do
before do
allow(project).to receive(:push_rule) { build(:push_rule, author_email_regex: '.*@unmatchedemaildomain.com') }
end
it_behaves_like 'hook validations are skipped when push rules unlicensed'
it 'returns false and saves error when invalid' do
expect(service.hooks_validation_pass?(merge_request)).to be_falsey
expect(merge_request.merge_error).not_to be_empty
end
end
context 'fast forward merge request' do
it 'returns true when fast forward is enabled' do
allow(project).to receive(:merge_requests_ff_only_enabled) { true }
expect(service.hooks_validation_pass?(merge_request)).to be_truthy
end
end
end
end
......@@ -306,56 +306,4 @@ describe MergeRequests::MergeService do
end
end
end
describe '#hooks_validation_pass?' do
shared_examples 'hook validations are skipped when push rules unlicensed' do
subject { service.hooks_validation_pass?(merge_request) }
before do
stub_licensed_features(push_rules: false)
end
it { is_expected.to be_truthy }
end
let(:service) { described_class.new(project, user, commit_message: 'Awesome message') }
it 'returns true when valid' do
expect(service.hooks_validation_pass?(merge_request)).to be_truthy
end
context 'commit message validation' do
before do
allow(project).to receive(:push_rule) { build(:push_rule, commit_message_regex: 'unmatched pattern .*') }
end
it_behaves_like 'hook validations are skipped when push rules unlicensed'
it 'returns false and saves error when invalid' do
expect(service.hooks_validation_pass?(merge_request)).to be_falsey
expect(merge_request.merge_error).not_to be_empty
end
end
context 'authors email validation' do
before do
allow(project).to receive(:push_rule) { build(:push_rule, author_email_regex: '.*@unmatchedemaildomain.com') }
end
it_behaves_like 'hook validations are skipped when push rules unlicensed'
it 'returns false and saves error when invalid' do
expect(service.hooks_validation_pass?(merge_request)).to be_falsey
expect(merge_request.merge_error).not_to be_empty
end
end
context 'fast forward merge request' do
it 'returns true when fast forward is enabled' do
allow(project).to receive(:merge_requests_ff_only_enabled) { true }
expect(service.hooks_validation_pass?(merge_request)).to be_truthy
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