From 614b4fbe4c43b90f939a411986c5d3168b1b5c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 8 Sep 2023 13:52:54 +0200 Subject: [PATCH] Add and apply FactoryBot/AssociationStyle rule This rule was added in rubocop-factory_bot 2.23.0. We were following it sometimes, and sometimes we were not. --- .rubocop.yml | 3 +++ spec/factories/administration.rb | 6 ++--- spec/factories/budgets.rb | 14 ++++++------ spec/factories/classifications.rb | 22 +++++++++--------- spec/factories/comments.rb | 6 ++--- spec/factories/debates.rb | 6 ++--- spec/factories/files.rb | 16 +++++++------- spec/factories/machine_learning.rb | 2 +- spec/factories/milestones.rb | 6 ++--- spec/factories/notifications.rb | 8 +++---- spec/factories/polls.rb | 32 +++++++++++++-------------- spec/factories/proposals.rb | 10 ++++----- spec/factories/remote_translations.rb | 2 +- spec/factories/sdg.rb | 2 +- spec/factories/users.rb | 10 ++++----- spec/factories/votation_type.rb | 2 +- spec/factories/votes.rb | 4 ++-- 17 files changed, 77 insertions(+), 74 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e9772f8a8..73fad3b61 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -32,6 +32,9 @@ Capybara/SpecificActions: Capybara/VisibilityMatcher: Enabled: true +FactoryBot/AssociationStyle: + Enabled: true + FactoryBot/ConsistentParenthesesStyle: Enabled: true diff --git a/spec/factories/administration.rb b/spec/factories/administration.rb index 20e99b5a8..415e2c148 100644 --- a/spec/factories/administration.rb +++ b/spec/factories/administration.rb @@ -40,8 +40,8 @@ FactoryBot.define do end factory :banner_section, class: "Banner::Section" do - association :banner_id, factory: :banner - association :web_section + banner_id factory: :banner + web_section end factory :site_customization_page, class: "SiteCustomization::Page" do @@ -83,7 +83,7 @@ FactoryBot.define do end trait :budget_investment_map_location do - association :investment, factory: :budget_investment + investment factory: :budget_investment end end diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index 68bb26e8b..b1e4cd275 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -83,7 +83,7 @@ FactoryBot.define do sequence(:name) { |n| "Group #{n}" } trait :drafting_budget do - association :budget, factory: [:budget, :drafting] + budget factory: [:budget, :drafting] end end @@ -98,7 +98,7 @@ FactoryBot.define do group { association :budget_group, budget: budget || association(:budget) } trait :drafting_budget do - association :group, factory: [:budget_group, :drafting_budget] + group factory: [:budget_group, :drafting_budget] end trait :with_investment_with_milestone do @@ -113,7 +113,7 @@ FactoryBot.define do sequence(:title) { |n| "Budget Investment #{n} title" } heading { budget&.headings&.reload&.sample || association(:budget_heading, budget: budget) } - association :author, factory: :user + author factory: :user description { "Spend money on this" } price { 10 } unfeasibility_explanation { "" } @@ -251,7 +251,7 @@ FactoryBot.define do end factory :budget_ballot, class: "Budget::Ballot" do - association :user + user budget transient { investments { [] } } @@ -264,7 +264,7 @@ FactoryBot.define do end factory :budget_ballot_line, class: "Budget::Ballot::Line" do - association :investment, factory: :budget_investment + investment factory: :budget_investment transient { user { nil } } @@ -275,7 +275,7 @@ FactoryBot.define do factory :budget_reclassified_vote, class: "Budget::ReclassifiedVote" do user - association :investment, factory: :budget_investment + investment factory: :budget_investment reason { "unfeasible" } end @@ -284,7 +284,7 @@ FactoryBot.define do end factory :heading_content_block, class: "Budget::ContentBlock" do - association :heading, factory: :budget_heading + heading factory: :budget_heading locale { "en" } body { "Some heading contents" } end diff --git a/spec/factories/classifications.rb b/spec/factories/classifications.rb index c48c0e0f6..00b4b2d5b 100644 --- a/spec/factories/classifications.rb +++ b/spec/factories/classifications.rb @@ -21,14 +21,14 @@ FactoryBot.define do factory :tagging do context { "tags" } - association :taggable, factory: :proposal + taggable factory: :proposal tag end factory :topic do sequence(:title) { |n| "Topic title #{n}" } sequence(:description) { |n| "Description as comment #{n}" } - association :author, factory: :user + author factory: :user trait :with_community do community { create(:proposal).community } @@ -38,18 +38,18 @@ FactoryBot.define do end factory :related_content do - association :author, factory: :user - association :parent_relationable, factory: [:proposal, :debate].sample - association :child_relationable, factory: [:proposal, :debate].sample + author factory: :user + parent_relationable factory: [:proposal, :debate].sample + child_relationable factory: [:proposal, :debate].sample trait :proposals do - association :parent_relationable, factory: :proposal - association :child_relationable, factory: :proposal + parent_relationable factory: :proposal + child_relationable factory: :proposal end trait :budget_investments do - association :parent_relationable, factory: :budget_investment - association :child_relationable, factory: :budget_investment + parent_relationable factory: :budget_investment + child_relationable factory: :budget_investment end trait :from_machine_learning do @@ -58,7 +58,7 @@ FactoryBot.define do end factory :related_content_score do - association :user - association :related_content + user + related_content end end diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index f55581f88..467395ee5 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -1,13 +1,13 @@ FactoryBot.define do factory :comment do - association :commentable, factory: :debate + commentable factory: :debate user sequence(:body) { |n| "Comment body #{n}" } %i[budget_investment debate legislation_annotation legislation_question legislation_proposal poll proposal topic_with_community].each do |model| factory :"#{model}_comment" do - association :commentable, factory: model + commentable factory: model end end @@ -35,7 +35,7 @@ FactoryBot.define do trait :valuation do valuation { true } - association :commentable, factory: :budget_investment + commentable factory: :budget_investment before :create do |valuation| valuator = create(:valuator) valuation.author = valuator.user diff --git a/spec/factories/debates.rb b/spec/factories/debates.rb index 8484b95b9..da9e967e9 100644 --- a/spec/factories/debates.rb +++ b/spec/factories/debates.rb @@ -3,7 +3,7 @@ FactoryBot.define do sequence(:title) { |n| "Debate #{n} title" } description { "Debate description" } terms_of_service { "1" } - association :author, factory: :user + author factory: :user trait :hidden do hidden_at { Time.current } @@ -46,7 +46,7 @@ FactoryBot.define do end factory :flag do - association :flaggable, factory: :debate - association :user + flaggable factory: :debate + user end end diff --git a/spec/factories/files.rb b/spec/factories/files.rb index 04e84d1c8..7a488068e 100644 --- a/spec/factories/files.rb +++ b/spec/factories/files.rb @@ -2,36 +2,36 @@ FactoryBot.define do factory :image do attachment { Rack::Test::UploadedFile.new("spec/fixtures/files/clippy.jpg") } title { "Lorem ipsum dolor sit amet" } - association :user + user trait :proposal_image do - association :imageable, factory: :proposal + imageable factory: :proposal end trait :budget_image do - association :imageable, factory: :budget + imageable factory: :budget end trait :budget_investment_image do - association :imageable, factory: :budget_investment + imageable factory: :budget_investment end end factory :document do sequence(:title) { |n| "Document title #{n}" } - association :user + user attachment { Rack::Test::UploadedFile.new("spec/fixtures/files/empty.pdf") } trait :proposal_document do - association :documentable, factory: :proposal + documentable factory: :proposal end trait :budget_investment_document do - association :documentable, factory: :budget_investment + documentable factory: :budget_investment end trait :poll_question_document do - association :documentable, factory: :poll_question + documentable factory: :poll_question end trait :admin do diff --git a/spec/factories/machine_learning.rb b/spec/factories/machine_learning.rb index 97f6de434..652f4729f 100644 --- a/spec/factories/machine_learning.rb +++ b/spec/factories/machine_learning.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :machine_learning_job do - association :user + user script { "script.py" } started_at { Time.current } finished_at { nil } diff --git a/spec/factories/milestones.rb b/spec/factories/milestones.rb index 9c6bfba2a..9332fdaec 100644 --- a/spec/factories/milestones.rb +++ b/spec/factories/milestones.rb @@ -5,8 +5,8 @@ FactoryBot.define do end factory :milestone do - association :milestoneable, factory: :budget_investment - association :status, factory: :milestone_status + milestoneable factory: :budget_investment + status factory: :milestone_status sequence(:title) { |n| "Milestone #{n} title" } description { "Milestone description" } publication_date { Date.current } @@ -25,7 +25,7 @@ FactoryBot.define do end factory :progress_bar do - association :progressable, factory: :budget_investment + progressable factory: :budget_investment percentage { rand(0..100) } kind { :primary } diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb index b0d8eaecc..741fef308 100644 --- a/spec/factories/notifications.rb +++ b/spec/factories/notifications.rb @@ -1,22 +1,22 @@ FactoryBot.define do factory :notification do user - association :notifiable, factory: :proposal + notifiable factory: :proposal trait :read do read_at { Time.current } end trait :for_proposal_notification do - association :notifiable, factory: :proposal_notification + notifiable factory: :proposal_notification end trait :for_comment do - association :notifiable, factory: :comment + notifiable factory: :comment end trait :for_poll_question do - association :notifiable, factory: :poll_question + notifiable factory: :poll_question end end diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index 0819457b9..84bdb9961 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -31,7 +31,7 @@ FactoryBot.define do end trait :for_budget do - association :budget + budget end trait :with_image do @@ -49,7 +49,7 @@ FactoryBot.define do factory :poll_question, class: "Poll::Question" do poll - association :author, factory: :user + author factory: :user sequence(:title) { |n| "Question title #{n}" } trait :yes_no do @@ -124,11 +124,11 @@ FactoryBot.define do factory :poll_booth_assignment, class: "Poll::BoothAssignment" do poll - association :booth, factory: :poll_booth + booth factory: :poll_booth end factory :poll_officer_assignment, class: "Poll::OfficerAssignment" do - association :officer, factory: :poll_officer + officer factory: :poll_officer date { Date.current } transient { poll { association(:poll) } } @@ -144,8 +144,8 @@ FactoryBot.define do end factory :poll_shift, class: "Poll::Shift" do - association :booth, factory: :poll_booth - association :officer, factory: :poll_officer + booth factory: :poll_booth + officer factory: :poll_officer date { Date.current } trait :vote_collection_task do @@ -158,7 +158,7 @@ FactoryBot.define do end factory :poll_voter, class: "Poll::Voter" do - association :user, :level_two + user factory: [:user, :level_two] from_web transient { budget { nil } } @@ -196,20 +196,20 @@ FactoryBot.define do end factory :poll_answer, class: "Poll::Answer" do - association :question, factory: [:poll_question, :yes_no] - association :author, factory: [:user, :level_two] + question factory: [:poll_question, :yes_no] + author factory: [:user, :level_two] answer { question.question_answers.sample.title } end factory :poll_partial_result, class: "Poll::PartialResult" do - association :question, factory: [:poll_question, :yes_no] - association :author, factory: :user + question factory: [:poll_question, :yes_no] + author factory: :user origin { "web" } answer { question.question_answers.sample.title } end factory :poll_recount, class: "Poll::Recount" do - association :author, factory: :user + author factory: :user origin { "web" } trait :from_booth do @@ -224,19 +224,19 @@ FactoryBot.define do end factory :poll_ballot_sheet, class: "Poll::BallotSheet" do - association :poll - association :officer_assignment, factory: :poll_officer_assignment + poll + officer_assignment factory: :poll_officer_assignment data { "1234;9876;5678\n1000;2000;3000;9999" } end factory :poll_ballot, class: "Poll::Ballot" do - association :ballot_sheet, factory: :poll_ballot_sheet + ballot_sheet factory: :poll_ballot_sheet data { "1,2,3" } end factory :officing_residence, class: "Officing::Residence" do user - association :officer, factory: :poll_officer + officer factory: :poll_officer document_number document_type { "1" } year_of_birth { "1980" } diff --git a/spec/factories/proposals.rb b/spec/factories/proposals.rb index 02ad9145d..052f67f3b 100644 --- a/spec/factories/proposals.rb +++ b/spec/factories/proposals.rb @@ -8,7 +8,7 @@ FactoryBot.define do terms_of_service { "1" } published_at { Time.current } - association :author, factory: :user + author factory: :user trait :hidden do hidden_at { Time.current } @@ -96,7 +96,7 @@ FactoryBot.define do sequence(:title) { |n| "Thank you for supporting my proposal #{n}" } sequence(:body) { |n| "Please let others know so we can make it happen #{n}" } proposal - association :author, factory: :user + author factory: :user trait :moderated do moderated { true } @@ -116,8 +116,8 @@ FactoryBot.define do end factory :signature_sheet do - association :signable, factory: :proposal - association :author, factory: :user + signable factory: :proposal + author factory: :user required_fields_to_verify { "123A, 456B, 789C" } trait :with_title do @@ -133,7 +133,7 @@ FactoryBot.define do factory :activity do user action { "hide" } - association :actionable, factory: :proposal + actionable factory: :proposal end factory :dashboard_action, class: "Dashboard::Action" do diff --git a/spec/factories/remote_translations.rb b/spec/factories/remote_translations.rb index 59aacb379..2bd68f18c 100644 --- a/spec/factories/remote_translations.rb +++ b/spec/factories/remote_translations.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :remote_translation do - association :remote_translatable, factory: :debate + remote_translatable factory: :debate end end diff --git a/spec/factories/sdg.rb b/spec/factories/sdg.rb index 7a0b9efbd..69fc4a056 100644 --- a/spec/factories/sdg.rb +++ b/spec/factories/sdg.rb @@ -24,7 +24,7 @@ FactoryBot.define do SDG::Related::RELATABLE_TYPES.map { |relatable_type| relatable_type.downcase.gsub("::", "_") } .each do |relatable| trait :"#{relatable}_review" do - association :relatable, factory: relatable + relatable factory: relatable end end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 7f72aba71..d9b8789c5 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -126,21 +126,21 @@ FactoryBot.define do end factory :follow do - association :user + user trait :followed_proposal do - association :followable, factory: :proposal + followable factory: :proposal end trait :followed_investment do - association :followable, factory: :budget_investment + followable factory: :budget_investment end end factory :direct_message do title { "Hey" } body { "How are You doing?" } - association :sender, factory: :user - association :receiver, factory: :user + sender factory: :user + receiver factory: :user end end diff --git a/spec/factories/votation_type.rb b/spec/factories/votation_type.rb index dfee71b8d..5a9e77e7d 100644 --- a/spec/factories/votation_type.rb +++ b/spec/factories/votation_type.rb @@ -9,6 +9,6 @@ FactoryBot.define do max_votes { 3 } end - association :questionable, factory: :poll_question + questionable factory: :poll_question end end diff --git a/spec/factories/votes.rb b/spec/factories/votes.rb index a2c5d0df4..cb3b94059 100644 --- a/spec/factories/votes.rb +++ b/spec/factories/votes.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :vote do - association :votable, factory: :debate - association :voter, factory: :user + votable factory: :debate + voter factory: :user vote_flag { true } after(:create) do |vote, _| vote.votable.update_cached_votes