summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-05-21 14:07:37 -0700
committerStan Hu <stanhu@gmail.com>2019-05-21 23:19:07 -0700
commit37a335e60edd4f4c8b61fd2f9ffe0f1d27e3bfb8 (patch)
tree1e1d0aad5fdfe0ba1a9cecae6c402313b7be5c54
parentd707e2a49f2efe4670b5ebe62fb61554640ca7e9 (diff)
downloadgitlab-ce-37a335e60edd4f4c8b61fd2f9ffe0f1d27e3bfb8.tar.gz
Fix remaining failures in shoulda-matcher
Starting with Rails 5, belongs_to now adds a presence validation to the association, and so as of shoulda-matchers 4.0.0 the belong_to matcher follows suit and tests that this validation is there by setting the association to nil and asserting that there are validation errors. This exposed an error with the `validate_branches` method: we need to check the source and target project exist.
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--spec/models/deployment_spec.rb4
-rw-r--r--spec/models/environment_spec.rb2
3 files changed, 5 insertions, 3 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index df162e4844c..311ba1ce6bd 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -581,6 +581,8 @@ class MergeRequest < ApplicationRecord
end
def validate_branches
+ return unless target_project && source_project
+
if target_project == source_project && target_branch == source_branch
errors.add :branch_conflict, "You can't use same project/branch for source and target"
return
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb
index f51322e1404..1dceef3fc00 100644
--- a/spec/models/deployment_spec.rb
+++ b/spec/models/deployment_spec.rb
@@ -5,8 +5,8 @@ require 'spec_helper'
describe Deployment do
subject { build(:deployment) }
- it { is_expected.to belong_to(:project) }
- it { is_expected.to belong_to(:environment) }
+ it { is_expected.to belong_to(:project).required }
+ it { is_expected.to belong_to(:environment).required }
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:deployable) }
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 17246f238e0..7233d2454c6 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -6,7 +6,7 @@ describe Environment do
let(:project) { create(:project, :stubbed_repository) }
subject(:environment) { create(:environment, project: project) }
- it { is_expected.to belong_to(:project) }
+ it { is_expected.to belong_to(:project).required }
it { is_expected.to have_many(:deployments) }
it { is_expected.to delegate_method(:stop_action).to(:last_deployment) }