Commit e08dddfb authored by Stan Hu's avatar Stan Hu

Merge branch 'pl-rubocop-inline-association-design-management' into 'master'

Fix cop FactoryBot/InlineAssociation for designs_management factories

See merge request gitlab-org/gitlab!45766
parents 2e7870be b47d0a6b
......@@ -6,9 +6,6 @@ FactoryBot/InlineAssociation:
- 'ee/spec/factories/merge_request_blocks.rb'
- 'ee/spec/factories/vulnerabilities/feedback.rb'
- 'spec/factories/atlassian_identities.rb'
- 'spec/factories/design_management/design_at_version.rb'
- 'spec/factories/design_management/designs.rb'
- 'spec/factories/design_management/versions.rb'
- 'spec/factories/events.rb'
- 'spec/factories/git_wiki_commit_details.rb'
- 'spec/factories/gitaly/commit.rb'
......
......@@ -38,7 +38,7 @@ module Resolvers
# that the DesignAtVersion as found by its ID does in fact belong
# to this issue.
def consistent?(dav)
issue.nil? || (dav&.design&.issue_id == issue.id)
issue.nil? || (dav.present? && dav.design&.issue_id == issue.id)
end
def issue
......
......@@ -43,10 +43,7 @@ module DesignManagement
validates :sha, presence: true
validates :sha, uniqueness: { case_sensitive: false, scope: :issue_id }
validates :author, presence: true
# We are not validating the issue object as it incurs an extra query to fetch
# the record from the DB. Instead, we rely on the foreign key constraint to
# ensure referential integrity.
validates :issue_id, presence: true, unless: :importing?
validates :issue, presence: true, unless: :importing?
sha_attribute :sha
......
......@@ -9,13 +9,13 @@ FactoryBot.define do
version { nil }
transient do
issue { design&.issue || version&.issue || create(:issue) }
issue { design&.issue || version&.issue || association(:issue) }
end
initialize_with do
attrs = attributes.dup
attrs[:design] ||= create(:design, issue: issue)
attrs[:version] ||= create(:design_version, issue: issue)
attrs[:design] ||= association(:design, issue: issue)
attrs[:version] ||= association(:design_version, issue: issue)
new(attrs)
end
......
......@@ -2,8 +2,8 @@
FactoryBot.define do
factory :design, class: 'DesignManagement::Design' do
issue { create(:issue) }
project { issue&.project || create(:project) }
issue { association(:issue) }
project { issue&.project || association(:project) }
sequence(:filename) { |n| "homescreen-#{n}.jpg" }
transient do
......
......@@ -3,8 +3,8 @@
FactoryBot.define do
factory :design_version, class: 'DesignManagement::Version' do
sha
issue { designs.first&.issue || create(:issue) }
author { issue&.author || create(:user) }
issue { designs.first&.issue || association(:issue) }
author { issue&.author || association(:user) }
transient do
designs_count { 1 }
......
......@@ -185,7 +185,7 @@ RSpec.describe DesignManagement::DesignAtVersion do
end
describe 'validations' do
subject(:design_at_version) { build(:design_at_version) }
subject(:design_at_version) { build_stubbed(:design_at_version) }
it { is_expected.to be_valid }
......
......@@ -31,7 +31,7 @@ RSpec.describe DesignManagement::Version do
it { is_expected.to validate_presence_of(:author) }
it { is_expected.to validate_presence_of(:sha) }
it { is_expected.to validate_presence_of(:designs) }
it { is_expected.to validate_presence_of(:issue_id) }
it { is_expected.to validate_presence_of(:issue) }
it { is_expected.to validate_uniqueness_of(:sha).scoped_to(:issue_id).case_insensitive }
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