From 61be48a6c6e34dcf1c648a2d45afe4b3369346ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jun 2019 01:34:55 +0200 Subject: [PATCH 1/4] Remove unused and obsolete rubocop rules These rules are now defined under `Style/`. However, we don't really use them, so they add noise to the rubocop configuration file without solving any issues we actually have. --- .rubocop.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5854c404b..b0de35f5e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -48,9 +48,6 @@ Performance/FixedSize: Performance/FlatMap: Enabled: true -Performance/LstripRstrip: - Enabled: true - Performance/RangeInclude: Enabled: true @@ -63,18 +60,12 @@ Performance/RedundantMatch: Performance/RedundantMerge: Enabled: true -Performance/RedundantSortBy: - Enabled: true - Performance/RegexpMatch: Enabled: true Performance/ReverseEach: Enabled: true -Performance/Sample: - Enabled: true - Performance/Size: Enabled: true From 444fc524f7d5c7dec59e8e28f346130a793da10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jun 2019 01:44:44 +0200 Subject: [PATCH 2/4] Use the AttributeDefinedStatically rubocop rule Factory bot has stopped supporting dynamic attributes, and we'll have to change all factories before upgrading. In order to apply the rubocop rule, we need to bump rubocop-rspec to its latest version. --- .rubocop.yml | 6 ------ .rubocop_basic.yml | 3 +++ Gemfile | 4 ++-- Gemfile.lock | 24 +++++++++++++----------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b0de35f5e..fb10526c8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -351,12 +351,6 @@ RSpec/VerifiedDoubles: RSpec/VoidExpect: Enabled: true -FactoryBot/StaticAttributeDefinedDynamically: - Enabled: true - -FactoryBot/DynamicAttributeDefinedStatically: - Enabled: false - Security/Eval: Enabled: true diff --git a/.rubocop_basic.yml b/.rubocop_basic.yml index 1d9d41b45..90005227a 100644 --- a/.rubocop_basic.yml +++ b/.rubocop_basic.yml @@ -20,6 +20,9 @@ Capybara/FeatureMethods: - scenario - xscenario +FactoryBot/AttributeDefinedStatically: + Enabled: true + Layout/IndentationConsistency: EnforcedStyle: rails diff --git a/Gemfile b/Gemfile index 6e8cf5c24..79990e628 100644 --- a/Gemfile +++ b/Gemfile @@ -96,8 +96,8 @@ group :development do gem "capistrano3-delayed-job", "~> 1.7.3" gem "erb_lint", require: false gem "mdl", "~> 0.5.0", require: false - gem "rubocop", "~> 0.54.0", require: false - gem "rubocop-rspec", "~> 1.26.0", require: false + gem "rubocop", "~> 0.60.0", require: false + gem "rubocop-rspec", "~> 1.33.0", require: false gem "rvm1-capistrano3", "~> 1.4.0", require: false gem "scss_lint", "~> 0.55.0", require: false gem "web-console", "~> 3.3.0" diff --git a/Gemfile.lock b/Gemfile.lock index 582f12578..f49a1b035 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -270,6 +270,7 @@ GEM railties (>= 3.1, < 6.0) invisible_captcha (0.10.0) rails (>= 3.2.0) + jaro_winkler (1.5.2) jquery-fileupload-rails (0.4.7) actionpack (>= 3.1) railties (>= 3.1) @@ -370,10 +371,10 @@ GEM cocaine (~> 0.5.5) mime-types mimemagic (~> 0.3.0) - parallel (1.12.1) + parallel (1.17.0) paranoia (2.4.1) activerecord (>= 4.0, < 5.3) - parser (2.5.1.2) + parser (2.6.3.0) ast (~> 2.4.0) pg (0.21.0) pg_search (2.0.1) @@ -447,16 +448,17 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.54.0) + rubocop (0.60.0) + jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.5) + parser (>= 2.5, != 2.5.1.1) powerpack (~> 0.1) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - rubocop-rspec (1.26.0) - rubocop (>= 0.53.0) - ruby-progressbar (1.10.0) + unicode-display_width (~> 1.4.0) + rubocop-rspec (1.33.0) + rubocop (>= 0.60.0) + ruby-progressbar (1.10.1) rubyzip (1.2.2) rvm1-capistrano3 (1.4.0) capistrano (~> 3.0) @@ -536,7 +538,7 @@ GEM thread_safe (~> 0.1) uglifier (4.1.19) execjs (>= 0.3.0, < 3) - unicode-display_width (1.4.0) + unicode-display_width (1.4.1) unicorn (5.4.1) kgio (~> 2.6) raindrops (~> 0.7) @@ -634,8 +636,8 @@ DEPENDENCIES rinku (~> 2.0.2) rollbar (~> 2.18.0) rspec-rails (~> 3.8) - rubocop (~> 0.54.0) - rubocop-rspec (~> 1.26.0) + rubocop (~> 0.60.0) + rubocop-rspec (~> 1.33.0) rvm1-capistrano3 (~> 1.4.0) sass-rails (~> 5.0, >= 5.0.4) savon (~> 2.12.0) From fc1a89e966e2b0631983f5aed4536ca292935086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jun 2019 01:49:08 +0200 Subject: [PATCH 3/4] Use dynamic attributes in factories Static attributes are deprecated since factory bot 4.11; we haven't upgraded yet but now we're ready to do so: https://thoughtbot.com/blog/deprecating-static-attributes-in-factory_bot-4-11 --- spec/factories/administration.rb | 46 ++++----- spec/factories/budgets.rb | 118 +++++++++++----------- spec/factories/classifications.rb | 6 +- spec/factories/comments.rb | 2 +- spec/factories/debates.rb | 4 +- spec/factories/emails.rb | 2 +- spec/factories/files.rb | 12 +-- spec/factories/legislations.rb | 158 +++++++++++++++--------------- spec/factories/milestones.rb | 6 +- spec/factories/notifications.rb | 10 +- spec/factories/organizations.rb | 2 +- spec/factories/polls.rb | 46 ++++----- spec/factories/proposals.rb | 50 +++++----- spec/factories/users.rb | 34 +++---- spec/factories/verifications.rb | 38 +++---- spec/factories/votation_type.rb | 82 ++++++++-------- spec/factories/votes.rb | 2 +- 17 files changed, 309 insertions(+), 309 deletions(-) diff --git a/spec/factories/administration.rb b/spec/factories/administration.rb index 24704dfaa..e11b73ac2 100644 --- a/spec/factories/administration.rb +++ b/spec/factories/administration.rb @@ -10,7 +10,7 @@ FactoryBot.define do sequence(:census_code) { |n| n.to_s } trait :in_census do - census_code "01" + census_code { "01" } end end @@ -20,12 +20,12 @@ FactoryBot.define do target_url {["/proposals", "/debates" ].sample} post_started_at { Time.current - 7.days } post_ended_at { Time.current + 7.days } - background_color "#FF0000" - font_color "#FFFFFF" + background_color { "#FF0000" } + font_color { "#FFFFFF" } end factory :web_section do - name "homepage" + name { "homepage" } end factory :banner_section, class: "Banner::Section" do @@ -34,33 +34,33 @@ FactoryBot.define do end factory :site_customization_page, class: "SiteCustomization::Page" do - slug "example-page" - title "Example page" - subtitle "About an example" - content "This page is about..." - more_info_flag false - print_content_flag false - status "draft" + slug { "example-page" } + title { "Example page" } + subtitle { "About an example" } + content { "This page is about..." } + more_info_flag { false } + print_content_flag { false } + status { "draft" } trait :published do - status "published" + status { "published" } end trait :display_in_more_info do - more_info_flag true + more_info_flag { true } end end factory :site_customization_content_block, class: "SiteCustomization::ContentBlock" do - name "top_links" - locale "en" - body "Some top links content" + name { "top_links" } + locale { "en" } + body { "Some top links content" } end factory :map_location do - latitude 51.48 - longitude 0.0 - zoom 10 + latitude { 51.48 } + longitude { 0.0 } + zoom { 10 } trait :proposal_map_location do proposal @@ -78,7 +78,7 @@ FactoryBot.define do sequence(:link_url) { |n| "Link url #{n}" } trait :header do - header true + header { true } sequence(:button_text) { |n| "Button text #{n}" } sequence(:button_url) { |n| "Button url #{n}" } sequence(:alignment) { |n| "background" } @@ -93,8 +93,8 @@ FactoryBot.define do end factory :i18n_content, class: "I18nContent" do - key "debates.index.section_footer.description" - value_es "Texto en español" - value_en "Text in english" + key { "debates.index.section_footer.description" } + value_es { "Texto en español" } + value_en { "Text in english" } end end diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index 11645104f..d6141366d 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -1,59 +1,59 @@ FactoryBot.define do factory :budget do sequence(:name) { |n| "#{Faker::Lorem.word} #{n}" } - currency_symbol "€" - phase "accepting" - description_drafting "This budget is drafting" - description_informing "This budget is informing" - description_accepting "This budget is accepting" - description_reviewing "This budget is reviewing" - description_selecting "This budget is selecting" - description_valuating "This budget is valuating" - description_publishing_prices "This budget is publishing prices" - description_balloting "This budget is balloting" - description_reviewing_ballots "This budget is reviewing ballots" - description_finished "This budget is finished" + currency_symbol { "€" } + phase { "accepting" } + description_drafting { "This budget is drafting" } + description_informing { "This budget is informing" } + description_accepting { "This budget is accepting" } + description_reviewing { "This budget is reviewing" } + description_selecting { "This budget is selecting" } + description_valuating { "This budget is valuating" } + description_publishing_prices { "This budget is publishing prices" } + description_balloting { "This budget is balloting" } + description_reviewing_ballots { "This budget is reviewing ballots" } + description_finished { "This budget is finished" } trait :drafting do - phase "drafting" + phase { "drafting" } end trait :informing do - phase "informing" + phase { "informing" } end trait :accepting do - phase "accepting" + phase { "accepting" } end trait :reviewing do - phase "reviewing" + phase { "reviewing" } end trait :selecting do - phase "selecting" + phase { "selecting" } end trait :valuating do - phase "valuating" + phase { "valuating" } end trait :publishing_prices do - phase "publishing_prices" + phase { "publishing_prices" } end trait :balloting do - phase "balloting" + phase { "balloting" } end trait :reviewing_ballots do - phase "reviewing_ballots" + phase { "reviewing_ballots" } end trait :finished do - phase "finished" - results_enabled true - stats_enabled true + phase { "finished" } + results_enabled { true } + stats_enabled { true } end end @@ -68,12 +68,12 @@ FactoryBot.define do factory :budget_heading, class: "Budget::Heading" do sequence(:name) { |n| "Heading #{n}" } - price 1000000 - population 1234 - latitude "40.416775" - longitude "-3.703790" + price { 1000000 } + population { 1234 } + latitude { "40.416775" } + longitude { "-3.703790" } - transient { budget nil } + transient { budget { nil } } group { association :budget_group, budget: budget || association(:budget) } trait :drafting_budget do @@ -85,64 +85,64 @@ FactoryBot.define do sequence(:title) { |n| "Budget Investment #{n} title" } heading { association :budget_heading, budget: budget } association :author, factory: :user - description "Spend money on this" - price 10 - unfeasibility_explanation "" - skip_map "1" - terms_of_service "1" - incompatible false + description { "Spend money on this" } + price { 10 } + unfeasibility_explanation { "" } + skip_map { "1" } + terms_of_service { "1" } + incompatible { false } trait :with_confidence_score do before(:save) { |i| i.calculate_confidence_score } end trait :feasible do - feasibility "feasible" + feasibility { "feasible" } end trait :unfeasible do - feasibility "unfeasible" - unfeasibility_explanation "set to unfeasible on creation" + feasibility { "unfeasible" } + unfeasibility_explanation { "set to unfeasible on creation" } end trait :undecided do - feasibility "undecided" + feasibility { "undecided" } end trait :finished do - valuation_finished true + valuation_finished { true } end trait :selected do - selected true - feasibility "feasible" - valuation_finished true + selected { true } + feasibility { "feasible" } + valuation_finished { true } end trait :winner do selected - winner true + winner { true } end trait :visible_to_valuators do - visible_to_valuators true + visible_to_valuators { true } end trait :incompatible do selected - incompatible true + incompatible { true } end trait :selected_with_price do selected - price 1000 - price_explanation "Because of reasons" + price { 1000 } + price_explanation { "Because of reasons" } end trait :unselected do - selected false - feasibility "feasible" - valuation_finished true + selected { false } + feasibility { "feasible" } + valuation_finished { true } end trait :hidden do @@ -174,12 +174,12 @@ FactoryBot.define do factory :budget_phase, class: "Budget::Phase" do budget - kind :balloting - summary Faker::Lorem.sentence(3) - description Faker::Lorem.sentence(10) + kind { :balloting } + summary { Faker::Lorem.sentence(3) } + description { Faker::Lorem.sentence(10) } starts_at { Date.yesterday } ends_at { Date.tomorrow } - enabled true + enabled { true } end factory :budget_ballot, class: "Budget::Ballot" do @@ -190,7 +190,7 @@ FactoryBot.define do factory :budget_ballot_line, class: "Budget::Ballot::Line" do association :investment, factory: :budget_investment - transient { user nil } + transient { user { nil } } ballot do association :budget_ballot, budget: investment.budget.reload, user: user || association(:user) @@ -200,7 +200,7 @@ FactoryBot.define do factory :budget_reclassified_vote, class: "Budget::ReclassifiedVote" do user association :investment, factory: :budget_investment - reason "unfeasible" + reason { "unfeasible" } end factory :valuator_group, class: ValuatorGroup do @@ -209,7 +209,7 @@ FactoryBot.define do factory :heading_content_block, class: "Budget::ContentBlock" do association :heading, factory: :budget_heading - locale "en" - body "Some heading contents" + locale { "en" } + body { "Some heading contents" } end end diff --git a/spec/factories/classifications.rb b/spec/factories/classifications.rb index e8721a50c..5703bd3ff 100644 --- a/spec/factories/classifications.rb +++ b/spec/factories/classifications.rb @@ -3,16 +3,16 @@ FactoryBot.define do sequence(:name) { |n| "Tag #{n} name" } trait :category do - kind "category" + kind { "category" } end trait :milestone do - kind "milestone" + kind { "milestone" } end end factory :tagging, class: "ActsAsTaggableOn::Tagging" do - context "tags" + context { "tags" } association :taggable, factory: :proposal tag end diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 8795f2e3d..368579902 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -27,7 +27,7 @@ FactoryBot.define do end trait :valuation do - valuation true + valuation { true } association :commentable, factory: :budget_investment before :create do |valuation| valuator = create(:valuator) diff --git a/spec/factories/debates.rb b/spec/factories/debates.rb index 41ca081c0..671c0235b 100644 --- a/spec/factories/debates.rb +++ b/spec/factories/debates.rb @@ -1,8 +1,8 @@ FactoryBot.define do factory :debate do sequence(:title) { |n| "Debate #{n} title" } - description "Debate description" - terms_of_service "1" + description { "Debate description" } + terms_of_service { "1" } association :author, factory: :user trait :hidden do diff --git a/spec/factories/emails.rb b/spec/factories/emails.rb index 2d40d46bf..3ed748737 100644 --- a/spec/factories/emails.rb +++ b/spec/factories/emails.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :newsletter do sequence(:subject) { |n| "Subject #{n}" } - segment_recipient UserSegments::SEGMENTS.sample + segment_recipient { UserSegments::SEGMENTS.sample } sequence(:from) { |n| "noreply#{n}@consul.dev" } sequence(:body) { |n| "Body #{n}" } end diff --git a/spec/factories/files.rb b/spec/factories/files.rb index 45d1d6e7e..2290ccab5 100644 --- a/spec/factories/files.rb +++ b/spec/factories/files.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :image do attachment { File.new("spec/fixtures/files/clippy.jpg") } - title "Lorem ipsum dolor sit amet" + title { "Lorem ipsum dolor sit amet" } association :user, factory: :user trait :proposal_image do @@ -31,7 +31,7 @@ FactoryBot.define do end trait :admin do - admin true + admin { true } end end @@ -39,18 +39,18 @@ FactoryBot.define do user trait :proposal do - resource_type "Proposal" + resource_type { "Proposal" } end trait :budget_investment do - resource_type "Budget::Investment" + resource_type { "Budget::Investment" } end trait :documents do - resource_relation "documents" + resource_relation { "documents" } attachment { File.new("spec/fixtures/files/empty.pdf") } end trait :image do - resource_relation "image" + resource_relation { "image" } attachment { File.new("spec/fixtures/files/clippy.jpg") } end initialize_with { new(attributes) } diff --git a/spec/factories/legislations.rb b/spec/factories/legislations.rb index b7014d18f..e25e5086d 100644 --- a/spec/factories/legislations.rb +++ b/spec/factories/legislations.rb @@ -1,8 +1,8 @@ FactoryBot.define do factory :legislation_process, class: "Legislation::Process" do - title "A collaborative legislation process" - description "Description of the process" - summary "Summary of the process" + title { "A collaborative legislation process" } + description { "Description of the process" } + summary { "Summary of the process" } start_date { Date.current - 5.days } end_date { Date.current + 5.days } @@ -16,13 +16,13 @@ FactoryBot.define do people_proposals_phase_start_date { Date.current } people_proposals_phase_end_date { Date.current + 2.days } result_publication_date { Date.current + 5.days } - debate_phase_enabled true - allegations_phase_enabled true - proposals_phase_enabled true - people_proposals_phase_enabled true - draft_publication_enabled true - result_publication_enabled true - published true + debate_phase_enabled { true } + allegations_phase_enabled { true } + proposals_phase_enabled { true } + people_proposals_phase_enabled { true } + draft_publication_enabled { true } + result_publication_enabled { true } + published { true } trait :past do start_date { Date.current - 12.days } @@ -40,7 +40,7 @@ FactoryBot.define do end_date { Date.current + 5.days } draft_start_date { Date.current - 2.days } draft_end_date { Date.current + 2.days } - draft_phase_enabled true + draft_phase_enabled { true } end trait :in_debate_phase do @@ -57,33 +57,33 @@ FactoryBot.define do trait :in_proposals_phase do proposals_phase_start_date { Date.current - 1.day } proposals_phase_end_date { Date.current + 2.days } - proposals_phase_enabled true + proposals_phase_enabled { true } end trait :upcoming_proposals_phase do proposals_phase_start_date { Date.current + 1.day } proposals_phase_end_date { Date.current + 2.days } - proposals_phase_enabled true + proposals_phase_enabled { true } end trait :in_people_proposals_phase do people_proposals_phase_start_date { Date.current - 1.day } people_proposals_phase_end_date { Date.current + 2.days } - people_proposals_phase_enabled true + people_proposals_phase_enabled { true } end trait :upcoming_people_proposals_phase do people_proposals_phase_start_date { Date.current + 1.day } people_proposals_phase_end_date { Date.current + 2.days } - people_proposals_phase_enabled true + people_proposals_phase_enabled { true } end trait :published do - published true + published { true } end trait :not_published do - published false + published { false } end trait :open do @@ -94,23 +94,23 @@ FactoryBot.define do trait :empty do start_date { Date.current - 5.days } end_date { Date.current + 5.days } - debate_start_date nil - debate_end_date nil - draft_publication_date nil - allegations_start_date nil - allegations_end_date nil - proposals_phase_start_date nil - proposals_phase_end_date nil - people_proposals_phase_start_date nil - people_proposals_phase_end_date nil - result_publication_date nil - debate_phase_enabled false - allegations_phase_enabled false - proposals_phase_enabled false - people_proposals_phase_enabled false - draft_publication_enabled false - result_publication_enabled false - published true + debate_start_date { nil } + debate_end_date { nil } + draft_publication_date { nil } + allegations_start_date { nil } + allegations_end_date { nil } + proposals_phase_start_date { nil } + proposals_phase_end_date { nil } + people_proposals_phase_start_date { nil } + people_proposals_phase_end_date { nil } + result_publication_date { nil } + debate_phase_enabled { false } + allegations_phase_enabled { false } + proposals_phase_enabled { false } + people_proposals_phase_enabled { false } + draft_publication_enabled { false } + result_publication_enabled { false } + published { true } end trait :with_milestone_tags do @@ -120,11 +120,11 @@ FactoryBot.define do factory :legislation_draft_version, class: "Legislation::DraftVersion" do process factory: :legislation_process - title "Version 1" - changelog "What changed in this version" - status "draft" - final_version false - body <<-LOREM_IPSUM + title { "Version 1" } + changelog { "What changed in this version" } + status { "draft" } + final_version { false } + body { <<-LOREM_IPSUM } Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id. @@ -139,29 +139,29 @@ Lorem salutandi eu mea, eam in soleat iriure assentior. Tamquam lobortis id qui. LOREM_IPSUM trait :published do - status "published" + status { "published" } end trait :final_version do - final_version true + final_version { true } end end factory :legislation_annotation, class: "Legislation::Annotation" do draft_version factory: :legislation_draft_version author factory: :user - quote "ipsum" - text "a comment" - ranges [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}] - range_start "/p[1]" - range_start_offset 6 - range_end "/p[1]" - range_end_offset 11 + quote { "ipsum" } + text { "a comment" } + ranges { [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}] } + range_start { "/p[1]" } + range_start_offset { 6 } + range_end { "/p[1]" } + range_end_offset { 11 } end factory :legislation_question, class: "Legislation::Question" do process factory: :legislation_process - title "Question text" + title { "Question text" } author factory: :user end @@ -178,55 +178,55 @@ LOREM_IPSUM factory :legislation_proposal, class: "Legislation::Proposal" do sequence(:title) { |n| "Proposal #{n} for a legislation" } - summary "This law should include..." - terms_of_service "1" + summary { "This law should include..." } + terms_of_service { "1" } process factory: :legislation_process author factory: :user end factory :debate_comment, class: "Comment" do - commentable_id "10" - commentable_type Legislation::Question - body "This is a comment" - user_id "1" - cached_votes_down "0" - cached_votes_total "0" - cached_votes_up "0" - confidence_score "0" + commentable_id { "10" } + commentable_type { Legislation::Question } + body { "This is a comment" } + user_id { "1" } + cached_votes_down { "0" } + cached_votes_total { "0" } + cached_votes_up { "0" } + confidence_score { "0" } end factory :text_comment, class: "Comment" do - commentable_id "10" - commentable_type Legislation::Annotation - body "This is a comment" - user_id "1" - cached_votes_down "0" - cached_votes_total "0" - cached_votes_up "0" - confidence_score "0" - ancestry nil + commentable_id { "10" } + commentable_type { Legislation::Annotation } + body { "This is a comment" } + user_id { "1" } + cached_votes_down { "0" } + cached_votes_total { "0" } + cached_votes_up { "0" } + confidence_score { "0" } + ancestry { nil } end factory :legislation_people_proposal, class: "Legislation::PeopleProposal" do sequence(:title) { |n| "People and group #{n} for a legislation" } - summary "This law should be implemented by..." - terms_of_service "1" + summary { "This law should be implemented by..." } + terms_of_service { "1" } process factory: :legislation_process author factory: :user - validated false + validated { false } trait :with_contact_info do - email "proposal@test.com" - website "https://proposal.io" - phone "666666666" - facebook "facebook.id" - twitter "TwitterId" - youtube "youtubechannelid" - instagram "instagramid" + email { "proposal@test.com" } + website { "https://proposal.io" } + phone { "666666666" } + facebook { "facebook.id" } + twitter { "TwitterId" } + youtube { "youtubechannelid" } + instagram { "instagramid" } end trait :validated do - validated true + validated { true } end end end diff --git a/spec/factories/milestones.rb b/spec/factories/milestones.rb index 0e4071d15..9d2aebceb 100644 --- a/spec/factories/milestones.rb +++ b/spec/factories/milestones.rb @@ -8,17 +8,17 @@ FactoryBot.define do association :milestoneable, factory: :budget_investment association :status, factory: :milestone_status sequence(:title) { |n| "Milestone #{n} title" } - description "Milestone description" + description { "Milestone description" } publication_date { Date.current } end factory :progress_bar do association :progressable, factory: :budget_investment percentage { rand(0..100) } - kind :primary + kind { :primary } trait(:secondary) do - kind :secondary + kind { :secondary } sequence(:title) { |n| "Progress bar #{n} title" } end end diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb index b43aa7660..b79b478c4 100644 --- a/spec/factories/notifications.rb +++ b/spec/factories/notifications.rb @@ -11,13 +11,13 @@ FactoryBot.define do factory :admin_notification do title { |n| "Admin Notification title #{n}" } body { |n| "Admin Notification body #{n}" } - link nil - segment_recipient UserSegments::SEGMENTS.sample - recipients_count nil - sent_at nil + link { nil } + segment_recipient { UserSegments::SEGMENTS.sample } + recipients_count { nil } + sent_at { nil } trait :sent do - recipients_count 1 + recipients_count { 1 } sent_at { Time.current } end end diff --git a/spec/factories/organizations.rb b/spec/factories/organizations.rb index 5ac105520..a45cfb2a1 100644 --- a/spec/factories/organizations.rb +++ b/spec/factories/organizations.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :organization do user - responsible_name "Johnny Utah" + responsible_name { "Johnny Utah" } sequence(:name) { |n| "org#{n}" } trait :verified do diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index e9b525d00..b41d22641 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :poll do sequence(:name) { |n| "Poll #{SecureRandom.hex}" } - slug "this-is-a-slug" + slug { "this-is-a-slug" } starts_at { 1.month.ago } ends_at { 1.month.from_now } @@ -23,7 +23,7 @@ FactoryBot.define do end trait :published do - published true + published { true } end end @@ -112,8 +112,8 @@ FactoryBot.define do factory :poll_answer_video, class: "Poll::Question::Answer::Video" do association :answer, factory: :poll_question_answer - title "Sample video title" - url "https://youtu.be/nhuNb0XtRhQ" + title { "Sample video title" } + url { "https://youtu.be/nhuNb0XtRhQ" } end factory :poll_booth, class: "Poll::Booth" do @@ -132,7 +132,7 @@ FactoryBot.define do date { Date.current } trait :final do - final true + final { true } end end @@ -142,11 +142,11 @@ FactoryBot.define do date { Date.current } trait :vote_collection_task do - task 0 + task { 0 } end trait :recount_scrutiny_task do - task 1 + task { 1 } end end @@ -154,16 +154,16 @@ FactoryBot.define do association :user, :level_two from_web - transient { budget nil } + transient { budget { nil } } poll { budget&.poll || association(:poll, budget: budget) } trait :from_web do - origin "web" - token SecureRandom.hex(32) + origin { "web" } + token { SecureRandom.hex(32) } end trait :from_booth do - origin "booth" + origin { "booth" } booth_assignment do association :poll_booth_assignment, poll: poll @@ -177,13 +177,13 @@ FactoryBot.define do end trait :valid_document do - document_type "1" - document_number "12345678Z" + document_type { "1" } + document_number { "12345678Z" } end trait :invalid_document do - document_type "1" - document_number "99999999A" + document_type { "1" } + document_number { "99999999A" } end end @@ -196,18 +196,18 @@ FactoryBot.define do factory :poll_partial_result, class: "Poll::PartialResult" do association :question, factory: [:poll_question, :with_answers] association :author, factory: :user - origin "web" + origin { "web" } answer { question.question_answers.sample.title } end factory :poll_recount, class: "Poll::Recount" do association :author, factory: :user - origin "web" + origin { "web" } trait :from_booth do - origin "booth" + origin { "booth" } - transient { poll nil } + transient { poll { nil } } booth_assignment do association :poll_booth_assignment, poll: poll @@ -218,20 +218,20 @@ FactoryBot.define do factory :poll_ballot_sheet, class: "Poll::BallotSheet" do association :poll association :officer_assignment, factory: :poll_officer_assignment - data "1234;9876;5678\n1000;2000;3000;9999" + data { "1234;9876;5678\n1000;2000;3000;9999" } end factory :poll_ballot, class: "Poll::Ballot" do association :ballot_sheet, factory: :poll_ballot_sheet - data "1,2,3" + data { "1,2,3" } end factory :officing_residence, class: "Officing::Residence" do user association :officer, factory: :poll_officer document_number - document_type "1" - year_of_birth "1980" + document_type { "1" } + year_of_birth { "1980" } trait :invalid do year_of_birth { Time.current.year } diff --git a/spec/factories/proposals.rb b/spec/factories/proposals.rb index 963a4bc6a..93b1cd54a 100644 --- a/spec/factories/proposals.rb +++ b/spec/factories/proposals.rb @@ -2,11 +2,11 @@ FactoryBot.define do factory :proposal do sequence(:title) { |n| "Proposal #{n} title" } sequence(:summary) { |n| "In summary, what we want is... #{n}" } - description "Proposal description" - video_url "https://youtu.be/nhuNb0XtRhQ" - responsible_name "John Snow" - terms_of_service "1" - skip_map "1" + description { "Proposal description" } + video_url { "https://youtu.be/nhuNb0XtRhQ" } + responsible_name { "John Snow" } + terms_of_service { "1" } + skip_map { "1" } published_at { Time.current } association :author, factory: :user @@ -34,7 +34,7 @@ FactoryBot.define do end trait :selected do - selected true + selected { true } end trait :with_hot_score do @@ -57,13 +57,13 @@ FactoryBot.define do end trait :draft do - published_at nil + published_at { nil } end trait :retired do retired_at { Time.current } - retired_reason "unfeasible" - retired_explanation "Retired explanation" + retired_reason { "unfeasible" } + retired_explanation { "Retired explanation" } end trait :published do @@ -82,7 +82,7 @@ FactoryBot.define do association :author, factory: :user trait :moderated do - moderated true + moderated { true } end trait :ignored do @@ -101,7 +101,7 @@ FactoryBot.define do factory :signature_sheet do association :signable, factory: :proposal association :author, factory: :user - required_fields_to_verify "123A, 456B, 789C" + required_fields_to_verify { "123A, 456B, 789C" } end factory :signature do @@ -111,24 +111,24 @@ FactoryBot.define do factory :activity do user - action "hide" + action { "hide" } association :actionable, factory: :proposal end factory :dashboard_action, class: "Dashboard::Action" do title { Faker::Lorem.sentence[0..79] } description { Faker::Lorem.sentence } - link nil - request_to_administrators true - day_offset 0 - required_supports 0 - order 0 - active true - hidden_at nil - action_type "proposed_action" + link { nil } + request_to_administrators { true } + day_offset { 0 } + required_supports { 0 } + order { 0 } + active { true } + hidden_at { nil } + action_type { "proposed_action" } trait :admin_request do - request_to_administrators true + request_to_administrators { true } end trait :external_link do @@ -136,11 +136,11 @@ FactoryBot.define do end trait :inactive do - active false + active { false } end trait :active do - active true + active { true } end trait :deleted do @@ -148,11 +148,11 @@ FactoryBot.define do end trait :proposed_action do - action_type "proposed_action" + action_type { "proposed_action" } end trait :resource do - action_type "resource" + action_type { "resource" } end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 4b5d790ba..998f1df1e 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -3,11 +3,11 @@ FactoryBot.define do sequence(:username) { |n| "Manuela#{n}" } sequence(:email) { |n| "manuela#{n}@consul.dev" } - password "judgmentday" - terms_of_service "1" + password { "judgmentday" } + terms_of_service { "1" } confirmed_at { Time.current } date_of_birth { 20.years.ago } - public_activity true + public_activity { true } trait :incomplete_verification do after :create do |user| @@ -17,19 +17,19 @@ FactoryBot.define do trait :level_two do residence_verified_at { Time.current } - unconfirmed_phone "611111111" - confirmed_phone "611111111" - sms_confirmation_code "1234" - document_type "1" + unconfirmed_phone { "611111111" } + confirmed_phone { "611111111" } + sms_confirmation_code { "1234" } + document_type { "1" } document_number - date_of_birth Date.new(1980, 12, 31) - gender "female" + date_of_birth { Date.new(1980, 12, 31) } + gender { "female" } geozone end trait :level_three do verified_at { Time.current } - document_type "1" + document_type { "1" } document_number end @@ -47,16 +47,16 @@ FactoryBot.define do end trait :in_census do - document_number "12345678Z" - document_type "1" + document_number { "12345678Z" } + document_type { "1" } verified_at { Time.current } end end factory :identity do - user nil - provider "Twitter" - uid "MyString" + user { nil } + provider { "Twitter" } + uid { "MyString" } end factory :administrator do @@ -96,8 +96,8 @@ FactoryBot.define do end factory :direct_message do - title "Hey" - body "How are You doing?" + title { "Hey" } + body { "How are You doing?" } association :sender, factory: :user association :receiver, factory: :user end diff --git a/spec/factories/verifications.rb b/spec/factories/verifications.rb index 4878e46a7..97e083a0e 100644 --- a/spec/factories/verifications.rb +++ b/spec/factories/verifications.rb @@ -1,9 +1,9 @@ FactoryBot.define do factory :local_census_record, class: "LocalCensusRecord" do sequence(:document_number) { |n| "DOC_NUMBER#{n}" } - document_type 1 - date_of_birth Date.new(1970, 1, 31) - postal_code "28002" + document_type { 1 } + date_of_birth { Date.new(1970, 1, 31) } + postal_code { "28002" } end factory :local_census_records_import, class: "LocalCensusRecords::Import" do file { @@ -17,50 +17,50 @@ FactoryBot.define do factory :verification_residence, class: Verification::Residence do user document_number - document_type "1" + document_type { "1" } date_of_birth { Time.zone.local(1980, 12, 31).to_date } - postal_code "28013" - terms_of_service "1" + postal_code { "28013" } + terms_of_service { "1" } trait :invalid do - postal_code "28001" + postal_code { "28001" } end end factory :failed_census_call do user document_number - document_type 1 - date_of_birth Date.new(1900, 1, 1) - postal_code "28000" + document_type { 1 } + date_of_birth { Date.new(1900, 1, 1) } + postal_code { "28000" } end factory :verification_sms, class: Verification::Sms do - phone "699999999" + phone { "699999999" } end factory :verification_letter, class: Verification::Letter do user - email "user@consul.dev" - password "1234" - verification_code "5555" + email { "user@consul.dev" } + password { "1234" } + verification_code { "5555" } end factory :lock do user - tries 0 + tries { 0 } locked_until { Time.current } end factory :verified_user do document_number - document_type "dni" + document_type { "dni" } end factory :verification_document, class: Verification::Management::Document do document_number - document_type "1" - date_of_birth Date.new(1980, 12, 31) - postal_code "28013" + document_type { "1" } + date_of_birth { Date.new(1980, 12, 31) } + postal_code { "28013" } end end diff --git a/spec/factories/votation_type.rb b/spec/factories/votation_type.rb index fc391409f..bea74e3fe 100644 --- a/spec/factories/votation_type.rb +++ b/spec/factories/votation_type.rb @@ -1,76 +1,76 @@ FactoryBot.define do factory :votation_type do factory :votation_type_unique do - enum_type "unique" - open_answer false - prioritized false + enum_type { "unique" } + open_answer { false } + prioritized { false } end factory :votation_type_multiple do - enum_type "multiple" - open_answer false - prioritized false - max_votes 5 + enum_type { "multiple" } + open_answer { false } + prioritized { false } + max_votes { 5 } end factory :votation_type_prioritized do - enum_type "prioritized" - open_answer false - prioritized true - max_votes 5 - prioritization_type "borda" + enum_type { "prioritized" } + open_answer { false } + prioritized { true } + max_votes { 5 } + prioritization_type { "borda" } end factory :votation_type_positive_open do - enum_type "positive_open" - open_answer true - prioritized false - max_votes 5 + enum_type { "positive_open" } + open_answer { true } + prioritized { false } + max_votes { 5 } end factory :votation_type_positive_negative_open do - enum_type "positive_negative_open" - open_answer true - prioritized false - max_votes 5 - prioritization_type "borda" + enum_type { "positive_negative_open" } + open_answer { true } + prioritized { false } + max_votes { 5 } + prioritization_type { "borda" } end factory :votation_type_answer_couples_open do - enum_type "answer_couples_open" - open_answer true - prioritized false - max_votes 5 + enum_type { "answer_couples_open" } + open_answer { true } + prioritized { false } + max_votes { 5 } end factory :votation_type_answer_couples_closed do - enum_type "answer_couples_open" - open_answer false - prioritized false - max_votes 5 + enum_type { "answer_couples_open" } + open_answer { false } + prioritized { false } + max_votes { 5 } end factory :votation_type_answer_set_open do - enum_type "answer_set_open" - open_answer true - prioritized false - max_votes 3 - max_groups_answers 5 + enum_type { "answer_set_open" } + open_answer { true } + prioritized { false } + max_votes { 3 } + max_groups_answers { 5 } end factory :votation_type_answer_set_closed do - enum_type "answer_set_open" - open_answer false - prioritized false - max_votes 3 - max_groups_answers 5 + enum_type { "answer_set_open" } + open_answer { false } + prioritized { false } + max_votes { 3 } + max_groups_answers { 5 } end trait :open do - open_answer true + open_answer { true } end trait :prioritized do - prioritized true + prioritized { true } end end diff --git a/spec/factories/votes.rb b/spec/factories/votes.rb index 39bf23812..a2c5d0df4 100644 --- a/spec/factories/votes.rb +++ b/spec/factories/votes.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :vote do association :votable, factory: :debate association :voter, factory: :user - vote_flag true + vote_flag { true } after(:create) do |vote, _| vote.votable.update_cached_votes end From c2869f48870d86930aa669472f26726c79c31305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 22 Jun 2019 22:19:23 +0200 Subject: [PATCH 4/4] Move `Rails/RelativeDateConstant` to basic cops The reason for this rule is similar to dynamic factories: we want dynamic dates to be evaluted relative to the current time, and not relative to the moment the application was loaded. --- .rubocop.yml | 3 --- .rubocop_basic.yml | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index fb10526c8..91b73e7f7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -159,9 +159,6 @@ Rails/ReadWriteAttribute: Rails/RedundantReceiverInWithOptions: Enabled: true -Rails/RelativeDateConstant: - Enabled: true - Rails/RequestReferer: Enabled: true diff --git a/.rubocop_basic.yml b/.rubocop_basic.yml index 90005227a..bc737cd77 100644 --- a/.rubocop_basic.yml +++ b/.rubocop_basic.yml @@ -59,6 +59,9 @@ Rails/ApplicationRecord: Rails/HttpPositionalArguments: Enabled: true +Rails/RelativeDateConstant: + Enabled: true + RSpec/NotToNot: Enabled: true