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.
This commit is contained in:
parent
d707e2a49f
commit
37a335e60e
3 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in a new issue