From 2e870336ceb003691341da5c56a4dd08f84327ce Mon Sep 17 00:00:00 2001 From: Daniel Martin <53006+etdsoft@users.noreply.github.com> Date: Tue, 9 May 2023 10:24:52 +0200 Subject: [PATCH 1/4] Fix Boards Factory - associate with the right project Before this PR, a Board created via the factory could end up associated with a Node in a different project. We used create(:project) inside the node association which was independent from the board's own :project association. By using an after-build callback we can ensure that the node belongs to the same project already setup via the :project association. We guard this assignment to allow the caller to specify a different node (e.g. a host in the project). --- spec/factories/boards.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/factories/boards.rb b/spec/factories/boards.rb index 925dc3360..4bf5abf41 100644 --- a/spec/factories/boards.rb +++ b/spec/factories/boards.rb @@ -1,8 +1,10 @@ FactoryBot.define do factory :board do sequence(:name){ |n| "Board-#{n}" } - node { create(:project).methodology_library } - association :project + + after(:build) do |board| + board.node = board.project.methodology_library unless board.node.present? + end end end From e1e8ef8d910442fa66b2615649d474bf93f26d40 Mon Sep 17 00:00:00 2001 From: Daniel Martin <53006+etdsoft@users.noreply.github.com> Date: Tue, 9 May 2023 10:30:51 +0200 Subject: [PATCH 2/4] Rubocop'ing --- spec/factories/boards.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/boards.rb b/spec/factories/boards.rb index 4bf5abf41..edcc070c5 100644 --- a/spec/factories/boards.rb +++ b/spec/factories/boards.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :board do - sequence(:name){ |n| "Board-#{n}" } + sequence(:name) { |n| "Board-#{n}" } association :project after(:build) do |board| From aed3b9a402e03bb38a405994dd051b20fe7d0fdf Mon Sep 17 00:00:00 2001 From: Daniel Martin <53006+etdsoft@users.noreply.github.com> Date: Tue, 9 May 2023 11:21:02 +0200 Subject: [PATCH 3/4] Tweak Card spec --- spec/models/card_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/card_spec.rb b/spec/models/card_spec.rb index 7a6ea3b8b..7783e6475 100644 --- a/spec/models/card_spec.rb +++ b/spec/models/card_spec.rb @@ -20,7 +20,7 @@ describe 'on create' do it 'subscribes new assignees' do - new_card = build(:card, assignee_ids: create_list(:user, 2).map(&:id)) + new_card = build(:card, assignee_ids: create_list(:user, 2).map(&:id), list: @parent) expect { new_card.save }.to change { Subscription.count }.by(2) From ce02e850eb5a180d2ee8c30fc6be2cef537a439c Mon Sep 17 00:00:00 2001 From: Daniel Martin <53006+etdsoft@users.noreply.github.com> Date: Tue, 9 May 2023 11:37:27 +0200 Subject: [PATCH 4/4] More Rubocop :love: --- spec/models/card_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/card_spec.rb b/spec/models/card_spec.rb index 7783e6475..2ac325d7e 100644 --- a/spec/models/card_spec.rb +++ b/spec/models/card_spec.rb @@ -2,7 +2,7 @@ describe Card do it { should belong_to(:list).touch(true) } - it { should have_and_belong_to_many(:assignees).class_name("User") } + it { should have_and_belong_to_many(:assignees).class_name('User') } it { should have_many(:comments).dependent(:destroy) } it { should validate_length_of(:description).is_at_most(DB_MAX_TEXT_LENGTH) }