From 9d74f06d24df0ff87140060745e852f03eb0a4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jul 2023 21:20:29 +0200 Subject: [PATCH 01/35] Simplify loading resources in DraftVersionsController We were using `prepend: true`, but it doesn't seem to be necessary. We were also loading the draft versions twice in the index, so we can remove the line loading them a second time. --- .../admin/legislation/draft_versions_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 21704a70e..5cb6fc88e 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -1,11 +1,10 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseController include Translatable - load_and_authorize_resource :draft_version, class: "Legislation::DraftVersion", through: :process, prepend: true - load_and_authorize_resource :process, class: "Legislation::Process", prepend: true + load_and_authorize_resource :process, class: "Legislation::Process" + load_and_authorize_resource :draft_version, class: "Legislation::DraftVersion", through: :process def index - @draft_versions = @process.draft_versions end def create From 88f499d11433fcb519b02608fd58fa0355093620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jul 2023 21:39:41 +0200 Subject: [PATCH 02/35] Simplify passing parameters in FollowsController --- app/controllers/follows_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index 66fbb6a50..a9db098c0 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -4,13 +4,13 @@ class FollowsController < ApplicationController def create @follow.save! - flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice") + flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow)}.create.notice") render :refresh_follow_button end def destroy @follow.destroy! - flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.destroy.notice") + flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow)}.destroy.notice") render :refresh_follow_button end @@ -24,7 +24,7 @@ class FollowsController < ApplicationController [:followable_type, :followable_id] end - def followable_translation_key(followable) - followable.class.name.parameterize(separator: "_") + def followable_translation_key(follow) + follow.followable.class.name.parameterize(separator: "_") end end From 28a90f05f84d82296ef82af688d8cd495bf2872e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jul 2023 21:51:32 +0200 Subject: [PATCH 03/35] Make installation details code easier to follow --- app/controllers/installation_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/installation_controller.rb b/app/controllers/installation_controller.rb index 95fe9e5d0..da45177d3 100644 --- a/app/controllers/installation_controller.rb +++ b/app/controllers/installation_controller.rb @@ -14,6 +14,9 @@ class InstallationController < ApplicationController end def settings_feature_flags - Setting.where("key LIKE 'process.%'").each_with_object({}) { |x, n| n[x.key.remove("process.")] = x.value } + Setting.where("key LIKE 'process.%'") + .pluck(:key, :value) + .to_h + .transform_keys { |key| key.remove("process.") } end end From 0d35bddf9eedbe367d382863bccbcd73bf086175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jul 2023 21:59:57 +0200 Subject: [PATCH 04/35] Simplify finding the booth assignment for a voter --- app/controllers/officing/voters_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 26b1a7f53..da2210d13 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -19,7 +19,7 @@ class Officing::VotersController < Officing::BaseController poll: @poll, origin: "booth", officer: current_user.poll_officer, - booth_assignment: Poll::BoothAssignment.find_by(poll: @poll, booth: current_booth), + booth_assignment: current_booth.booth_assignments.find_by(poll: @poll), officer_assignment: officer_assignment(@poll)) @voter.save! end From 9491b20314721c29eec0189e142ed2721e742835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jul 2023 22:08:05 +0200 Subject: [PATCH 05/35] Extract method to get vote counts by votable type --- app/controllers/admin/stats_controller.rb | 6 +++--- app/controllers/stats_controller.rb | 8 ++++---- config/initializers/vote_extensions.rb | 4 ++++ spec/models/vote_spec.rb | 10 ++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index fc4377a1d..bd06d30fd 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -7,9 +7,9 @@ class Admin::StatsController < Admin::BaseController @proposals = Proposal.with_hidden.count @comments = Comment.not_valuations.with_hidden.count - @debate_votes = Vote.where(votable_type: "Debate").count - @proposal_votes = Vote.where(votable_type: "Proposal").count - @comment_votes = Vote.where(votable_type: "Comment").count + @debate_votes = Vote.count_for("Debate") + @proposal_votes = Vote.count_for("Proposal") + @comment_votes = Vote.count_for("Comment") @votes = Vote.count diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 62ff427ef..53b19a05e 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -11,10 +11,10 @@ class StatsController < ApplicationController @proposals = daily_cache("proposals") { Proposal.with_hidden.count } @comments = daily_cache("comments") { Comment.not_valuations.with_hidden.count } - @debate_votes = daily_cache("debate_votes") { Vote.where(votable_type: "Debate").count } - @proposal_votes = daily_cache("proposal_votes") { Vote.where(votable_type: "Proposal").count } - @comment_votes = daily_cache("comment_votes") { Vote.where(votable_type: "Comment").count } - @investment_votes = daily_cache("budget_investment_votes") { Vote.where(votable_type: "Budget::Investment").count } + @debate_votes = daily_cache("debate_votes") { Vote.count_for("Debate") } + @proposal_votes = daily_cache("proposal_votes") { Vote.count_for("Proposal") } + @comment_votes = daily_cache("comment_votes") { Vote.count_for("Comment") } + @investment_votes = daily_cache("budget_investment_votes") { Vote.count_for("Budget::Investment") } @votes = daily_cache("votes") { Vote.count } @verified_users = daily_cache("verified_users") { User.with_hidden.level_two_or_three_verified.count } diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 372c3789f..c70392250 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -8,6 +8,10 @@ ActsAsVotable::Vote.class_eval do where(votable: [Debate.public_for_api, Proposal.public_for_api, Comment.public_for_api]) end + def self.count_for(votable_type) + where(votable_type: votable_type).count + end + def value vote_flag end diff --git a/spec/models/vote_spec.rb b/spec/models/vote_spec.rb index c4f6919d8..f6bcee901 100644 --- a/spec/models/vote_spec.rb +++ b/spec/models/vote_spec.rb @@ -1,6 +1,16 @@ require "rails_helper" describe Vote do + describe ".count_for" do + it "returns the number of records for a votable type" do + 3.times { create(:vote, votable: create(:debate)) } + 2.times { create(:vote, votable: create(:proposal)) } + + expect(Vote.count_for("Debate")).to eq 3 + expect(Vote.count_for("Proposal")).to eq 2 + end + end + describe "#value" do it "returns vote flag" do vote = create(:vote, vote_flag: true) From 1d7a26940867a5ebf5b6eb2c6ef2bd020c2f0bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jul 2023 22:43:05 +0200 Subject: [PATCH 06/35] Use a transaction when registering a vote Otherwise it would be possible to increment the votes counter without actually introducing the vote. --- app/models/debate.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index 5333c08ad..0606d6630 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -107,8 +107,13 @@ class Debate < ApplicationRecord def register_vote(user, vote_value) if votable_by?(user) - Debate.increment_counter(:cached_anonymous_votes_total, id) if user.unverified? && !user.voted_for?(self) - vote_by(voter: user, vote: vote_value) + transaction do + if user.unverified? && !user.voted_for?(self) + Debate.increment_counter(:cached_anonymous_votes_total, id) + end + + vote_by(voter: user, vote: vote_value) + end end end From 62304b50e0fd2b913a799303b216a37bff2a2d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 2 Jul 2023 01:29:30 +0200 Subject: [PATCH 07/35] Remove non-existent action in management routes --- config/routes/management.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes/management.rb b/config/routes/management.rb index 9de4ef731..0ac65418a 100644 --- a/config/routes/management.rb +++ b/config/routes/management.rb @@ -38,7 +38,7 @@ namespace :management do get :print_investments end - resources :investments, only: [:index, :new, :create, :show, :destroy], controller: "budgets/investments" do + resources :investments, only: [:index, :new, :create, :show], controller: "budgets/investments" do get :print, on: :collection resources :votes, controller: "budgets/investments/votes", only: [:create, :destroy] From b8ed81c5b8b72b2a4561e19b38ef821dba189459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 2 Jul 2023 01:59:50 +0200 Subject: [PATCH 08/35] Simplify setting up admin component tests --- .../admin/allowed_table_actions_component_spec.rb | 3 +-- .../admin/budget_headings/headings_component_spec.rb | 2 +- .../admin/budget_phases/toggle_enabled_component_spec.rb | 2 +- spec/components/admin/budgets/actions_component_spec.rb | 3 +-- .../budgets/calculate_winners_button_component_spec.rb | 3 +-- spec/components/admin/budgets/links_component_spec.rb | 4 +--- .../admin/budgets/table_actions_component_spec.rb | 2 +- spec/components/admin/geozones/index_component_spec.rb | 2 +- .../admin/poll/officers/officers_component_spec.rb | 2 +- .../answers/documents/table_actions_component_spec.rb | 3 +-- .../questions/answers/table_actions_component_spec.rb | 4 +--- .../answers/videos/table_actions_component_spec.rb | 4 +--- .../admin/poll/questions/table_actions_component_spec.rb | 4 +--- .../admin/roles/table_actions_component_spec.rb | 2 +- spec/components/admin/table_actions_component_spec.rb | 2 +- spec/spec_helper.rb | 8 ++++++++ 16 files changed, 23 insertions(+), 27 deletions(-) diff --git a/spec/components/admin/allowed_table_actions_component_spec.rb b/spec/components/admin/allowed_table_actions_component_spec.rb index 6396be6b8..929ce0d72 100644 --- a/spec/components/admin/allowed_table_actions_component_spec.rb +++ b/spec/components/admin/allowed_table_actions_component_spec.rb @@ -1,8 +1,7 @@ require "rails_helper" -describe Admin::AllowedTableActionsComponent, controller: Admin::BaseController do +describe Admin::AllowedTableActionsComponent, :admin do before do - sign_in(create(:administrator).user) allow_any_instance_of(Admin::AllowedTableActionsComponent).to receive(:can?).and_return true end let(:record) { create(:banner, title: "Important!") } diff --git a/spec/components/admin/budget_headings/headings_component_spec.rb b/spec/components/admin/budget_headings/headings_component_spec.rb index e36c5ab4c..b425b216b 100644 --- a/spec/components/admin/budget_headings/headings_component_spec.rb +++ b/spec/components/admin/budget_headings/headings_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::BudgetHeadings::HeadingsComponent, controller: Admin::BaseController do +describe Admin::BudgetHeadings::HeadingsComponent, :admin do it "includes group name in the message when there are no headings" do group = create(:budget_group, name: "Whole planet") diff --git a/spec/components/admin/budget_phases/toggle_enabled_component_spec.rb b/spec/components/admin/budget_phases/toggle_enabled_component_spec.rb index 6786e1eb8..8b980bf5c 100644 --- a/spec/components/admin/budget_phases/toggle_enabled_component_spec.rb +++ b/spec/components/admin/budget_phases/toggle_enabled_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::BudgetPhases::ToggleEnabledComponent, controller: Admin::BaseController do +describe Admin::BudgetPhases::ToggleEnabledComponent, :admin do let(:phase) { create(:budget).phases.informing } let(:component) { Admin::BudgetPhases::ToggleEnabledComponent.new(phase) } diff --git a/spec/components/admin/budgets/actions_component_spec.rb b/spec/components/admin/budgets/actions_component_spec.rb index b67ac8c9d..e47845a80 100644 --- a/spec/components/admin/budgets/actions_component_spec.rb +++ b/spec/components/admin/budgets/actions_component_spec.rb @@ -1,8 +1,7 @@ require "rails_helper" -describe Admin::Budgets::ActionsComponent, controller: Admin::BaseController do +describe Admin::Budgets::ActionsComponent, :admin do include Rails.application.routes.url_helpers - before { sign_in(create(:administrator).user) } let(:budget) { create(:budget) } let(:component) { Admin::Budgets::ActionsComponent.new(budget) } diff --git a/spec/components/admin/budgets/calculate_winners_button_component_spec.rb b/spec/components/admin/budgets/calculate_winners_button_component_spec.rb index 1c26c1f16..e11975cdb 100644 --- a/spec/components/admin/budgets/calculate_winners_button_component_spec.rb +++ b/spec/components/admin/budgets/calculate_winners_button_component_spec.rb @@ -1,9 +1,8 @@ require "rails_helper" -describe Admin::Budgets::CalculateWinnersButtonComponent, controller: Admin::BaseController do +describe Admin::Budgets::CalculateWinnersButtonComponent, :admin do let(:budget) { create(:budget) } let(:component) { Admin::Budgets::CalculateWinnersButtonComponent.new(budget) } - before { sign_in(create(:administrator).user) } it "renders when reviewing ballots" do budget.update!(phase: "reviewing_ballots") diff --git a/spec/components/admin/budgets/links_component_spec.rb b/spec/components/admin/budgets/links_component_spec.rb index 997b1b6bd..14d25f889 100644 --- a/spec/components/admin/budgets/links_component_spec.rb +++ b/spec/components/admin/budgets/links_component_spec.rb @@ -1,8 +1,6 @@ require "rails_helper" -describe Admin::Budgets::LinksComponent, controller: Admin::BaseController do - before { sign_in(create(:administrator).user) } - +describe Admin::Budgets::LinksComponent, :admin do describe "see results link" do let(:budget) { create(:budget, :finished) } let(:component) { Admin::Budgets::LinksComponent.new(budget) } diff --git a/spec/components/admin/budgets/table_actions_component_spec.rb b/spec/components/admin/budgets/table_actions_component_spec.rb index 39dd13b43..0d994e5f5 100644 --- a/spec/components/admin/budgets/table_actions_component_spec.rb +++ b/spec/components/admin/budgets/table_actions_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::Budgets::TableActionsComponent, controller: Admin::BaseController do +describe Admin::Budgets::TableActionsComponent, :admin do let(:budget) { create(:budget) } let(:component) { Admin::Budgets::TableActionsComponent.new(budget) } diff --git a/spec/components/admin/geozones/index_component_spec.rb b/spec/components/admin/geozones/index_component_spec.rb index 6d3fe3dd4..dc5b7e1e9 100644 --- a/spec/components/admin/geozones/index_component_spec.rb +++ b/spec/components/admin/geozones/index_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::Geozones::IndexComponent, controller: Admin::BaseController do +describe Admin::Geozones::IndexComponent, :admin do describe "Coordinates description" do it "includes whether coordinates are defined or not" do geozones = [ diff --git a/spec/components/admin/poll/officers/officers_component_spec.rb b/spec/components/admin/poll/officers/officers_component_spec.rb index c2ed0f1a6..51246a02d 100644 --- a/spec/components/admin/poll/officers/officers_component_spec.rb +++ b/spec/components/admin/poll/officers/officers_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::Poll::Officers::OfficersComponent, controller: Admin::BaseController do +describe Admin::Poll::Officers::OfficersComponent, :admin do let(:existing_officer) { create(:poll_officer, name: "Old officer") } let(:new_officer) { build(:poll_officer, name: "New officer") } let(:officers) { [existing_officer, new_officer] } diff --git a/spec/components/admin/poll/questions/answers/documents/table_actions_component_spec.rb b/spec/components/admin/poll/questions/answers/documents/table_actions_component_spec.rb index 2d2261aea..218b46c41 100644 --- a/spec/components/admin/poll/questions/answers/documents/table_actions_component_spec.rb +++ b/spec/components/admin/poll/questions/answers/documents/table_actions_component_spec.rb @@ -1,7 +1,6 @@ require "rails_helper" -describe Admin::Poll::Questions::Answers::Documents::TableActionsComponent, controller: Admin::BaseController do - before { sign_in(create(:administrator).user) } +describe Admin::Poll::Questions::Answers::Documents::TableActionsComponent, :admin do let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) } let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) } diff --git a/spec/components/admin/poll/questions/answers/table_actions_component_spec.rb b/spec/components/admin/poll/questions/answers/table_actions_component_spec.rb index 4e6080a11..4b8243209 100644 --- a/spec/components/admin/poll/questions/answers/table_actions_component_spec.rb +++ b/spec/components/admin/poll/questions/answers/table_actions_component_spec.rb @@ -1,8 +1,6 @@ require "rails_helper" -describe Admin::Poll::Questions::Answers::TableActionsComponent, controller: Admin::BaseController do - before { sign_in(create(:administrator).user) } - +describe Admin::Poll::Questions::Answers::TableActionsComponent, :admin do it "displays the edit and destroy actions when the poll has not started" do answer = create(:poll_question_answer, poll: create(:poll, :future)) diff --git a/spec/components/admin/poll/questions/answers/videos/table_actions_component_spec.rb b/spec/components/admin/poll/questions/answers/videos/table_actions_component_spec.rb index e8449103d..199e83c7a 100644 --- a/spec/components/admin/poll/questions/answers/videos/table_actions_component_spec.rb +++ b/spec/components/admin/poll/questions/answers/videos/table_actions_component_spec.rb @@ -1,8 +1,6 @@ require "rails_helper" -describe Admin::Poll::Questions::Answers::Videos::TableActionsComponent, controller: Admin::BaseController do - before { sign_in(create(:administrator).user) } - +describe Admin::Poll::Questions::Answers::Videos::TableActionsComponent, :admin do it "displays the edit and destroy actions when the poll has not started" do video = create(:poll_answer_video, poll: create(:poll, :future)) diff --git a/spec/components/admin/poll/questions/table_actions_component_spec.rb b/spec/components/admin/poll/questions/table_actions_component_spec.rb index b1b84513b..3b1095d9c 100644 --- a/spec/components/admin/poll/questions/table_actions_component_spec.rb +++ b/spec/components/admin/poll/questions/table_actions_component_spec.rb @@ -1,8 +1,6 @@ require "rails_helper" -describe Admin::Poll::Questions::TableActionsComponent, controller: Admin::BaseController do - before { sign_in(create(:administrator).user) } - +describe Admin::Poll::Questions::TableActionsComponent, :admin do it "displays the edit and destroy actions when the poll has not started" do question = create(:poll_question, poll: create(:poll, :future)) diff --git a/spec/components/admin/roles/table_actions_component_spec.rb b/spec/components/admin/roles/table_actions_component_spec.rb index 445f790e1..b1e06d116 100644 --- a/spec/components/admin/roles/table_actions_component_spec.rb +++ b/spec/components/admin/roles/table_actions_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::Roles::TableActionsComponent, controller: Admin::BaseController do +describe Admin::Roles::TableActionsComponent, :admin do let(:user) { create(:user) } it "renders button to add the role for new records" do diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index cc5b554de..3951a2421 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::TableActionsComponent, controller: Admin::BaseController do +describe Admin::TableActionsComponent, :admin do let(:record) { create(:banner, title: "Important!") } it "renders edit and destroy actions by default" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7c941094e..edd1036f2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -94,6 +94,14 @@ RSpec.configure do |config| sign_in(nil) end + config.before(:each, :admin, type: :component) do + sign_in(create(:administrator).user) + end + + config.around(:each, :admin, type: :component) do |example| + with_controller_class(Admin::BaseController) { example.run } + end + config.around(:each, :controller, type: :component) do |example| with_controller_class(example.metadata[:controller]) { example.run } end From cebd6ddb3081a1275a9feff8ca70586275ad0e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jul 2023 18:30:28 +0200 Subject: [PATCH 09/35] Simplify code testing investment ids --- spec/models/poll/ballot_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/poll/ballot_spec.rb b/spec/models/poll/ballot_spec.rb index 54f292020..1cebae0a2 100644 --- a/spec/models/poll/ballot_spec.rb +++ b/spec/models/poll/ballot_spec.rb @@ -19,7 +19,7 @@ describe Poll::Ballot do poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) poll_ballot.verify - expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id] + expect(poll_ballot.ballot.investment_ids).to match_array [investment.id, investment2.id, investment3.id] end it "adds ballot lines if they are from valid headings" do @@ -32,7 +32,7 @@ describe Poll::Ballot do poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) poll_ballot.verify - expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id] + expect(poll_ballot.ballot.investment_ids).to match_array [investment.id, investment2.id, investment3.id] end it "adds ballot lines if they are from selectable" do @@ -43,7 +43,7 @@ describe Poll::Ballot do poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) poll_ballot.verify - expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id] + expect(poll_ballot.ballot.investment_ids).to match_array [investment.id, investment2.id, investment3.id] end end From bb79274ffea70ebc937dcdfdf8e19ea2fc589538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jul 2023 21:54:14 +0200 Subject: [PATCH 10/35] Simplify creating investments with the same heading --- spec/system/advanced_search_spec.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/system/advanced_search_spec.rb b/spec/system/advanced_search_spec.rb index cb95cfc6a..12517920d 100644 --- a/spec/system/advanced_search_spec.rb +++ b/spec/system/advanced_search_spec.rb @@ -197,9 +197,13 @@ describe "Advanced search" do Setting["feature.sdg"] = true Setting["sdg.process.budgets"] = true - create(:budget_investment, heading: heading, title: "Get Schwifty", sdg_goals: [SDG::Goal[7]], created_at: 1.minute.ago) - create(:budget_investment, heading: heading, title: "Hello Schwifty", sdg_goals: [SDG::Goal[7]], created_at: 2.days.ago) - create(:budget_investment, heading: heading, title: "Save the forest") + [ + { title: "Get Schwifty", sdg_goals: [SDG::Goal[7]], created_at: 1.minute.ago }, + { title: "Hello Schwifty", sdg_goals: [SDG::Goal[7]], created_at: 2.days.ago }, + { title: "Save the forest" } + ].each do |attributes| + create(:budget_investment, attributes.merge(heading: heading)) + end visit budget_investments_path(budget) From cd559e636195fa65d1968abf1191824b70bd3184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jul 2023 22:28:59 +0200 Subject: [PATCH 11/35] Simplify legislation variable names Since we're in the context of the legislation section, we don't need the `legislation_` prefix. --- .../comments/legislation_annotations_spec.rb | 246 +++++++++--------- .../comments/legislation_questions_spec.rb | 126 ++++----- 2 files changed, 186 insertions(+), 186 deletions(-) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index a9966442b..da9b5e7b0 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -2,17 +2,17 @@ require "rails_helper" describe "Commenting legislation questions" do let(:user) { create :user } - let(:legislation_annotation) { create :legislation_annotation, author: user } + let(:annotation) { create :legislation_annotation, author: user } it_behaves_like "flaggable", :legislation_annotation_comment scenario "Index" do - 3.times { create(:comment, commentable: legislation_annotation) } + 3.times { create(:comment, commentable: annotation) } comment = Comment.includes(:user).last - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) expect(page).to have_css(".comment", count: 4) @@ -24,12 +24,12 @@ describe "Commenting legislation questions" do end scenario "Show" do - href = legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) - parent_comment = create(:comment, commentable: legislation_annotation, body: "Parent") - create(:comment, commentable: legislation_annotation, parent: parent_comment, body: "First subcomment") - create(:comment, commentable: legislation_annotation, parent: parent_comment, body: "Last subcomment") + href = legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) + parent_comment = create(:comment, commentable: annotation, body: "Parent") + create(:comment, commentable: annotation, parent: parent_comment, body: "First subcomment") + create(:comment, commentable: annotation, parent: parent_comment, body: "Last subcomment") visit comment_path(parent_comment) @@ -38,7 +38,7 @@ describe "Commenting legislation questions" do expect(page).to have_content "First subcomment" expect(page).to have_content "Last subcomment" - expect(page).to have_link "Go back to #{legislation_annotation.title}", href: href + expect(page).to have_link "Go back to #{annotation.title}", href: href within ".comment", text: "Parent" do expect(page).to have_selector(".comment", count: 2) @@ -46,29 +46,29 @@ describe "Commenting legislation questions" do end scenario "Link to comment show" do - comment = create(:comment, commentable: legislation_annotation, user: user) + comment = create(:comment, commentable: annotation, user: user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) within "#comment_#{comment.id}" do expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T") click_link comment.created_at.strftime("%Y-%m-%d %T") end - expect(page).to have_link "Go back to #{legislation_annotation.title}" + expect(page).to have_link "Go back to #{annotation.title}" expect(page).to have_current_path(comment_path(comment)) end scenario "Collapsable comments" do - parent_comment = legislation_annotation.comments.first - child_comment = create(:comment, body: "First subcomment", commentable: legislation_annotation, parent: parent_comment) - grandchild_comment = create(:comment, body: "Last subcomment", commentable: legislation_annotation, parent: child_comment) + parent_comment = annotation.comments.first + child_comment = create(:comment, body: "First subcomment", commentable: annotation, parent: parent_comment) + grandchild_comment = create(:comment, body: "Last subcomment", commentable: annotation, parent: child_comment) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) @@ -101,16 +101,16 @@ describe "Commenting legislation questions" do end scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 100, + c1 = create(:comment, :with_confidence_score, commentable: annotation, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 10, + c2 = create(:comment, :with_confidence_score, commentable: annotation, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 1, + c3 = create(:comment, :with_confidence_score, commentable: annotation, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation, + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation, order: :most_voted) expect(c1.body).to appear_before(c2.body) @@ -132,30 +132,30 @@ describe "Commenting legislation questions" do end scenario "Creation date works differently in roots and in child comments, even when sorting by confidence_score" do - old_root = create(:comment, commentable: legislation_annotation, created_at: Time.current - 10) - new_root = create(:comment, commentable: legislation_annotation, created_at: Time.current) - old_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current - 10) - new_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current) + old_root = create(:comment, commentable: annotation, created_at: Time.current - 10) + new_root = create(:comment, commentable: annotation, created_at: Time.current) + old_child = create(:comment, commentable: annotation, parent_id: new_root.id, created_at: Time.current - 10) + new_child = create(:comment, commentable: annotation, parent_id: new_root.id, created_at: Time.current) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation, + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation, order: :most_voted) expect(new_root.body).to appear_before(old_root.body) expect(old_child.body).to appear_before(new_child.body) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation, + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation, order: :newest) expect(new_root.body).to appear_before(old_root.body) expect(new_child.body).to appear_before(old_child.body) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation, + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation, order: :oldest) expect(old_root.body).to appear_before(new_root.body) @@ -163,12 +163,12 @@ describe "Commenting legislation questions" do end scenario "Turns links into html links" do - legislation_annotation = create :legislation_annotation, author: user - legislation_annotation.comments << create(:comment, body: "Built with http://rubyonrails.org/") + annotation = create :legislation_annotation, author: user + annotation.comments << create(:comment, body: "Built with http://rubyonrails.org/") - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) within all(".comment").first do expect(page).to have_content "Built with http://rubyonrails.org/" @@ -179,12 +179,12 @@ describe "Commenting legislation questions" do end scenario "Sanitizes comment body for security" do - create :comment, commentable: legislation_annotation, + create :comment, commentable: annotation, body: " click me http://www.url.com" - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) within all(".comment").first do expect(page).to have_content "click me http://www.url.com" @@ -195,11 +195,11 @@ describe "Commenting legislation questions" do scenario "Paginated comments" do per_page = 10 - (per_page + 2).times { create(:comment, commentable: legislation_annotation) } + (per_page + 2).times { create(:comment, commentable: annotation) } - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) expect(page).to have_css(".comment", count: per_page) within("ul.pagination") do @@ -215,10 +215,10 @@ describe "Commenting legislation questions" do describe "Not logged user" do scenario "can not see comments forms" do - create(:comment, commentable: legislation_annotation) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + create(:comment, commentable: annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) expect(page).to have_content "You must sign in or sign up to leave a comment" within("#comments") do @@ -230,9 +230,9 @@ describe "Commenting legislation questions" do scenario "Create" do login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" @@ -245,9 +245,9 @@ describe "Commenting legislation questions" do scenario "Errors on create" do login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) click_button "Publish comment" @@ -276,13 +276,13 @@ describe "Commenting legislation questions" do scenario "Reply" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") - legislation_annotation = create(:legislation_annotation, author: citizen) - comment = legislation_annotation.comments.first + annotation = create(:legislation_annotation, author: citizen) + comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) click_link "Reply" @@ -300,13 +300,13 @@ describe "Commenting legislation questions" do scenario "Reply update parent comment responses count" do manuela = create(:user, :level_two, username: "Manuela") - legislation_annotation = create(:legislation_annotation) - comment = legislation_annotation.comments.first + annotation = create(:legislation_annotation) + comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) within ".comment", text: comment.body do click_link "Reply" @@ -319,14 +319,14 @@ describe "Commenting legislation questions" do scenario "Reply show parent comments responses when hidden" do manuela = create(:user, :level_two, username: "Manuela") - legislation_annotation = create(:legislation_annotation) - comment = legislation_annotation.comments.first - create(:comment, commentable: legislation_annotation, parent: comment) + annotation = create(:legislation_annotation) + comment = annotation.comments.first + create(:comment, commentable: annotation, parent: comment) login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) within ".comment", text: comment.body do click_link text: "1 response (collapse)" @@ -339,12 +339,12 @@ describe "Commenting legislation questions" do end scenario "Errors on reply" do - comment = legislation_annotation.comments.first + comment = annotation.comments.first login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) click_link "Reply" @@ -355,28 +355,28 @@ describe "Commenting legislation questions" do end scenario "N replies" do - parent = create(:comment, commentable: legislation_annotation) + parent = create(:comment, commentable: annotation) 7.times do - create(:comment, commentable: legislation_annotation, parent: parent) + create(:comment, commentable: annotation, parent: parent) parent = parent.children.first end - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") end scenario "Erasing a comment's author" do - legislation_annotation = create(:legislation_annotation) - comment = create(:comment, commentable: legislation_annotation, body: "this should be visible") + annotation = create(:legislation_annotation) + comment = create(:comment, commentable: annotation, body: "this should be visible") comment.user.erase - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) within "#comment_#{comment.id}" do expect(page).to have_content("User deleted") @@ -385,12 +385,12 @@ describe "Commenting legislation questions" do end scenario "Submit button is disabled after clicking" do - legislation_annotation = create(:legislation_annotation) + annotation = create(:legislation_annotation) login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) fill_in "Leave your comment", with: "Testing submit button!" click_button "Publish comment" @@ -405,12 +405,12 @@ describe "Commenting legislation questions" do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) fill_in "Leave your comment", with: "I am moderating!" - check "comment-as-moderator-legislation_annotation_#{legislation_annotation.id}" + check "comment-as-moderator-legislation_annotation_#{annotation.id}" click_button "Publish comment" within "#comments" do @@ -425,13 +425,13 @@ describe "Commenting legislation questions" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") moderator = create(:moderator, user: manuela) - legislation_annotation = create(:legislation_annotation, author: citizen) - comment = legislation_annotation.comments.first + annotation = create(:legislation_annotation, author: citizen) + comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) click_link "Reply" @@ -455,9 +455,9 @@ describe "Commenting legislation questions" do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) expect(page).not_to have_content "Comment as administrator" end @@ -468,12 +468,12 @@ describe "Commenting legislation questions" do admin = create(:administrator) login_as(admin.user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) fill_in "Leave your comment", with: "I am your Admin!" - check "comment-as-administrator-legislation_annotation_#{legislation_annotation.id}" + check "comment-as-administrator-legislation_annotation_#{annotation.id}" click_button "Publish comment" within "#comments" do @@ -488,13 +488,13 @@ describe "Commenting legislation questions" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") admin = create(:administrator, user: manuela) - legislation_annotation = create(:legislation_annotation, author: citizen) - comment = legislation_annotation.comments.first + annotation = create(:legislation_annotation, author: citizen) + comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) click_link "Reply" @@ -515,9 +515,9 @@ describe "Commenting legislation questions" do end scenario "can not comment as a moderator", :admin do - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, - legislation_annotation.draft_version, - legislation_annotation) + visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, + annotation.draft_version, + annotation) expect(page).not_to have_content "Comment as moderator" end diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index a00f030f3..0d560e2ac 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "Commenting legislation questions" do let(:user) { create :user, :level_two } let(:process) { create :legislation_process, :in_debate_phase } - let(:legislation_question) { create :legislation_question, process: process } + let(:question) { create :legislation_question, process: process } context "Concerns" do it_behaves_like "notifiable in-app", :legislation_question @@ -11,10 +11,10 @@ describe "Commenting legislation questions" do end scenario "Index" do - 3.times { create(:comment, commentable: legislation_question) } + 3.times { create(:comment, commentable: question) } comment = Comment.includes(:user).last - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).to have_css(".comment", count: 3) @@ -26,10 +26,10 @@ describe "Commenting legislation questions" do end scenario "Show" do - href = legislation_process_question_path(legislation_question.process, legislation_question) - parent_comment = create(:comment, commentable: legislation_question, body: "Parent") - create(:comment, commentable: legislation_question, parent: parent_comment, body: "First subcomment") - create(:comment, commentable: legislation_question, parent: parent_comment, body: "Last subcomment") + href = legislation_process_question_path(question.process, question) + parent_comment = create(:comment, commentable: question, body: "Parent") + create(:comment, commentable: question, parent: parent_comment, body: "First subcomment") + create(:comment, commentable: question, parent: parent_comment, body: "Last subcomment") visit comment_path(parent_comment) @@ -38,7 +38,7 @@ describe "Commenting legislation questions" do expect(page).to have_content "First subcomment" expect(page).to have_content "Last subcomment" - expect(page).to have_link "Go back to #{legislation_question.title}", href: href + expect(page).to have_link "Go back to #{question.title}", href: href within ".comment", text: "Parent" do expect(page).to have_selector(".comment", count: 2) @@ -46,9 +46,9 @@ describe "Commenting legislation questions" do end scenario "Link to comment show" do - comment = create(:comment, commentable: legislation_question, user: user) + comment = create(:comment, commentable: question, user: user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) within "#comment_#{comment.id}" do expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T") @@ -56,16 +56,16 @@ describe "Commenting legislation questions" do click_link comment.created_at.strftime("%Y-%m-%d %T") - expect(page).to have_link "Go back to #{legislation_question.title}" + expect(page).to have_link "Go back to #{question.title}" expect(page).to have_current_path(comment_path(comment)) end scenario "Collapsable comments" do - parent_comment = create(:comment, body: "Main comment", commentable: legislation_question) - child_comment = create(:comment, body: "First subcomment", commentable: legislation_question, parent: parent_comment) - grandchild_comment = create(:comment, body: "Last subcomment", commentable: legislation_question, parent: child_comment) + parent_comment = create(:comment, body: "Main comment", commentable: question) + child_comment = create(:comment, body: "First subcomment", commentable: question, parent: parent_comment) + grandchild_comment = create(:comment, body: "Last subcomment", commentable: question, parent: child_comment) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) @@ -98,14 +98,14 @@ describe "Commenting legislation questions" do end scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 100, + c1 = create(:comment, :with_confidence_score, commentable: question, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 10, + c2 = create(:comment, :with_confidence_score, commentable: question, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 1, + c3 = create(:comment, :with_confidence_score, commentable: question, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) - visit legislation_process_question_path(legislation_question.process, legislation_question, order: :most_voted) + visit legislation_process_question_path(question.process, question, order: :most_voted) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) @@ -126,31 +126,31 @@ describe "Commenting legislation questions" do end scenario "Creation date works differently in roots and in child comments, even when sorting by confidence_score" do - old_root = create(:comment, commentable: legislation_question, created_at: Time.current - 10) - new_root = create(:comment, commentable: legislation_question, created_at: Time.current) - old_child = create(:comment, commentable: legislation_question, parent_id: new_root.id, created_at: Time.current - 10) - new_child = create(:comment, commentable: legislation_question, parent_id: new_root.id, created_at: Time.current) + old_root = create(:comment, commentable: question, created_at: Time.current - 10) + new_root = create(:comment, commentable: question, created_at: Time.current) + old_child = create(:comment, commentable: question, parent_id: new_root.id, created_at: Time.current - 10) + new_child = create(:comment, commentable: question, parent_id: new_root.id, created_at: Time.current) - visit legislation_process_question_path(legislation_question.process, legislation_question, order: :most_voted) + visit legislation_process_question_path(question.process, question, order: :most_voted) expect(new_root.body).to appear_before(old_root.body) expect(old_child.body).to appear_before(new_child.body) - visit legislation_process_question_path(legislation_question.process, legislation_question, order: :newest) + visit legislation_process_question_path(question.process, question, order: :newest) expect(new_root.body).to appear_before(old_root.body) expect(new_child.body).to appear_before(old_child.body) - visit legislation_process_question_path(legislation_question.process, legislation_question, order: :oldest) + visit legislation_process_question_path(question.process, question, order: :oldest) expect(old_root.body).to appear_before(new_root.body) expect(old_child.body).to appear_before(new_child.body) end scenario "Turns links into html links" do - create :comment, commentable: legislation_question, body: "Built with http://rubyonrails.org/" + create :comment, commentable: question, body: "Built with http://rubyonrails.org/" - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) within first(".comment") do expect(page).to have_content "Built with http://rubyonrails.org/" @@ -161,10 +161,10 @@ describe "Commenting legislation questions" do end scenario "Sanitizes comment body for security" do - create :comment, commentable: legislation_question, + create :comment, commentable: question, body: " click me http://www.url.com" - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) within first(".comment") do expect(page).to have_content "click me http://www.url.com" @@ -175,9 +175,9 @@ describe "Commenting legislation questions" do scenario "Paginated comments" do per_page = 10 - (per_page + 2).times { create(:comment, commentable: legislation_question) } + (per_page + 2).times { create(:comment, commentable: question) } - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).to have_css(".comment", count: per_page) within("ul.pagination") do @@ -193,8 +193,8 @@ describe "Commenting legislation questions" do describe "Not logged user" do scenario "can not see comments forms" do - create(:comment, commentable: legislation_question) - visit legislation_process_question_path(legislation_question.process, legislation_question) + create(:comment, commentable: question) + visit legislation_process_question_path(question.process, question) expect(page).to have_content "You must sign in or sign up to leave a comment" within("#comments") do @@ -206,7 +206,7 @@ describe "Commenting legislation questions" do scenario "Create" do login_as(user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) fill_in "Leave your answer", with: "Have you thought about...?" click_button "Publish answer" @@ -219,7 +219,7 @@ describe "Commenting legislation questions" do scenario "Errors on create" do login_as(user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) click_button "Publish answer" @@ -230,7 +230,7 @@ describe "Commenting legislation questions" do unverified_user = create :user login_as(unverified_user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).to have_content "To participate verify your account" end @@ -239,7 +239,7 @@ describe "Commenting legislation questions" do process.update!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) login_as(user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).to have_content "Closed phase" end @@ -247,10 +247,10 @@ describe "Commenting legislation questions" do scenario "Reply" do citizen = create(:user, username: "Ana") manuela = create(:user, :level_two, username: "Manuela") - comment = create(:comment, commentable: legislation_question, user: citizen) + comment = create(:comment, commentable: question, user: citizen) login_as(manuela) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) click_link "Reply" @@ -268,10 +268,10 @@ describe "Commenting legislation questions" do scenario "Reply update parent comment responses count" do manuela = create(:user, :level_two, username: "Manuela") - comment = create(:comment, commentable: legislation_question) + comment = create(:comment, commentable: question) login_as(manuela) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) within ".comment", text: comment.body do click_link "Reply" @@ -284,11 +284,11 @@ describe "Commenting legislation questions" do scenario "Reply show parent comments responses when hidden" do manuela = create(:user, :level_two, username: "Manuela") - comment = create(:comment, commentable: legislation_question) - create(:comment, commentable: legislation_question, parent: comment) + comment = create(:comment, commentable: question) + create(:comment, commentable: question, parent: comment) login_as(manuela) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) within ".comment", text: comment.body do click_link text: "1 response (collapse)" @@ -301,10 +301,10 @@ describe "Commenting legislation questions" do end scenario "Errors on reply" do - comment = create(:comment, commentable: legislation_question, user: user) + comment = create(:comment, commentable: question, user: user) login_as(user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) click_link "Reply" @@ -315,22 +315,22 @@ describe "Commenting legislation questions" do end scenario "N replies" do - parent = create(:comment, commentable: legislation_question) + parent = create(:comment, commentable: question) 7.times do - create(:comment, commentable: legislation_question, parent: parent) + create(:comment, commentable: question, parent: parent) parent = parent.children.first end - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") end scenario "Erasing a comment's author" do - comment = create(:comment, commentable: legislation_question, body: "this should be visible") + comment = create(:comment, commentable: question, body: "this should be visible") comment.user.erase - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) within "#comment_#{comment.id}" do expect(page).to have_content("User deleted") expect(page).to have_content("this should be visible") @@ -339,7 +339,7 @@ describe "Commenting legislation questions" do scenario "Submit button is disabled after clicking" do login_as(user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) fill_in "Leave your answer", with: "Testing submit button!" click_button "Publish answer" @@ -354,10 +354,10 @@ describe "Commenting legislation questions" do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) fill_in "Leave your answer", with: "I am moderating!" - check "comment-as-moderator-legislation_question_#{legislation_question.id}" + check "comment-as-moderator-legislation_question_#{question.id}" click_button "Publish answer" within "#comments" do @@ -372,10 +372,10 @@ describe "Commenting legislation questions" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") moderator = create(:moderator, user: manuela) - comment = create(:comment, commentable: legislation_question, user: citizen) + comment = create(:comment, commentable: question, user: citizen) login_as(manuela) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) click_link "Reply" @@ -399,7 +399,7 @@ describe "Commenting legislation questions" do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).not_to have_content "Comment as administrator" end @@ -410,10 +410,10 @@ describe "Commenting legislation questions" do admin = create(:administrator) login_as(admin.user) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) fill_in "Leave your answer", with: "I am your Admin!" - check "comment-as-administrator-legislation_question_#{legislation_question.id}" + check "comment-as-administrator-legislation_question_#{question.id}" click_button "Publish answer" within "#comments" do @@ -428,10 +428,10 @@ describe "Commenting legislation questions" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") admin = create(:administrator, user: manuela) - comment = create(:comment, commentable: legislation_question, user: citizen) + comment = create(:comment, commentable: question, user: citizen) login_as(manuela) - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) click_link "Reply" @@ -452,7 +452,7 @@ describe "Commenting legislation questions" do end scenario "can not comment as a moderator", :admin do - visit legislation_process_question_path(legislation_question.process, legislation_question) + visit legislation_process_question_path(question.process, question) expect(page).not_to have_content "Comment as moderator" end From 316db607fed08e787a8ff249cea49e3e2ec5546a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jul 2023 22:46:54 +0200 Subject: [PATCH 12/35] Use polymorphic path in annotation tests Invoking legislation_process_draft_version_annotation_path makes the code harder to read. --- .../comments/legislation_annotations_spec.rb | 130 +++++------------- .../system/legislation/draft_versions_spec.rb | 2 +- 2 files changed, 33 insertions(+), 99 deletions(-) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index da9b5e7b0..8d34062e0 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -10,9 +10,7 @@ describe "Commenting legislation questions" do 3.times { create(:comment, commentable: annotation) } comment = Comment.includes(:user).last - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) expect(page).to have_css(".comment", count: 4) @@ -24,9 +22,7 @@ describe "Commenting legislation questions" do end scenario "Show" do - href = legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + href = polymorphic_path(annotation) parent_comment = create(:comment, commentable: annotation, body: "Parent") create(:comment, commentable: annotation, parent: parent_comment, body: "First subcomment") create(:comment, commentable: annotation, parent: parent_comment, body: "Last subcomment") @@ -48,9 +44,7 @@ describe "Commenting legislation questions" do scenario "Link to comment show" do comment = create(:comment, commentable: annotation, user: user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within "#comment_#{comment.id}" do expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T") @@ -66,9 +60,7 @@ describe "Commenting legislation questions" do child_comment = create(:comment, body: "First subcomment", commentable: annotation, parent: parent_comment) grandchild_comment = create(:comment, body: "Last subcomment", commentable: annotation, parent: child_comment) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) @@ -108,10 +100,7 @@ describe "Commenting legislation questions" do c3 = create(:comment, :with_confidence_score, commentable: annotation, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation, - order: :most_voted) + visit polymorphic_path(annotation, order: :most_voted) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) @@ -137,26 +126,17 @@ describe "Commenting legislation questions" do old_child = create(:comment, commentable: annotation, parent_id: new_root.id, created_at: Time.current - 10) new_child = create(:comment, commentable: annotation, parent_id: new_root.id, created_at: Time.current) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation, - order: :most_voted) + visit polymorphic_path(annotation, order: :most_voted) expect(new_root.body).to appear_before(old_root.body) expect(old_child.body).to appear_before(new_child.body) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation, - order: :newest) + visit polymorphic_path(annotation, order: :newest) expect(new_root.body).to appear_before(old_root.body) expect(new_child.body).to appear_before(old_child.body) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation, - order: :oldest) + visit polymorphic_path(annotation, order: :oldest) expect(old_root.body).to appear_before(new_root.body) expect(old_child.body).to appear_before(new_child.body) @@ -166,9 +146,7 @@ describe "Commenting legislation questions" do annotation = create :legislation_annotation, author: user annotation.comments << create(:comment, body: "Built with http://rubyonrails.org/") - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within all(".comment").first do expect(page).to have_content "Built with http://rubyonrails.org/" @@ -182,9 +160,7 @@ describe "Commenting legislation questions" do create :comment, commentable: annotation, body: " click me http://www.url.com" - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within all(".comment").first do expect(page).to have_content "click me http://www.url.com" @@ -197,9 +173,7 @@ describe "Commenting legislation questions" do per_page = 10 (per_page + 2).times { create(:comment, commentable: annotation) } - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) expect(page).to have_css(".comment", count: per_page) within("ul.pagination") do @@ -216,9 +190,7 @@ describe "Commenting legislation questions" do describe "Not logged user" do scenario "can not see comments forms" do create(:comment, commentable: annotation) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) expect(page).to have_content "You must sign in or sign up to leave a comment" within("#comments") do @@ -230,9 +202,7 @@ describe "Commenting legislation questions" do scenario "Create" do login_as(user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" @@ -245,9 +215,7 @@ describe "Commenting legislation questions" do scenario "Errors on create" do login_as(user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) click_button "Publish comment" @@ -264,7 +232,7 @@ describe "Commenting legislation questions" do login_as(user) - visit legislation_process_draft_version_annotation_path(version.process, version, annotation) + visit polymorphic_path(annotation) within "#comments" do expect(page).to have_content "Comments are closed" @@ -280,9 +248,7 @@ describe "Commenting legislation questions" do comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) click_link "Reply" @@ -304,9 +270,7 @@ describe "Commenting legislation questions" do comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within ".comment", text: comment.body do click_link "Reply" @@ -324,9 +288,7 @@ describe "Commenting legislation questions" do create(:comment, commentable: annotation, parent: comment) login_as(manuela) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within ".comment", text: comment.body do click_link text: "1 response (collapse)" @@ -342,9 +304,7 @@ describe "Commenting legislation questions" do comment = annotation.comments.first login_as(user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) click_link "Reply" @@ -362,9 +322,7 @@ describe "Commenting legislation questions" do parent = parent.children.first end - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") end @@ -374,9 +332,7 @@ describe "Commenting legislation questions" do comment = create(:comment, commentable: annotation, body: "this should be visible") comment.user.erase - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within "#comment_#{comment.id}" do expect(page).to have_content("User deleted") @@ -388,9 +344,7 @@ describe "Commenting legislation questions" do annotation = create(:legislation_annotation) login_as(user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) fill_in "Leave your comment", with: "Testing submit button!" click_button "Publish comment" @@ -405,9 +359,7 @@ describe "Commenting legislation questions" do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-legislation_annotation_#{annotation.id}" @@ -429,9 +381,7 @@ describe "Commenting legislation questions" do comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) click_link "Reply" @@ -455,9 +405,7 @@ describe "Commenting legislation questions" do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) expect(page).not_to have_content "Comment as administrator" end @@ -468,9 +416,7 @@ describe "Commenting legislation questions" do admin = create(:administrator) login_as(admin.user) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-legislation_annotation_#{annotation.id}" @@ -492,9 +438,7 @@ describe "Commenting legislation questions" do comment = annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) click_link "Reply" @@ -515,9 +459,7 @@ describe "Commenting legislation questions" do end scenario "can not comment as a moderator", :admin do - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) expect(page).not_to have_content "Comment as moderator" end @@ -537,9 +479,7 @@ describe "Commenting legislation questions" do create(:vote, voter: verified, votable: comment, vote_flag: true) create(:vote, voter: unverified, votable: comment, vote_flag: false) - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within("#comment_#{comment.id}_votes") do within(".in-favor") do @@ -555,9 +495,7 @@ describe "Commenting legislation questions" do end scenario "Create" do - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within("#comment_#{comment.id}_votes") do click_button "I agree" @@ -575,9 +513,7 @@ describe "Commenting legislation questions" do end scenario "Update" do - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within("#comment_#{comment.id}_votes") do click_button "I agree" @@ -601,9 +537,7 @@ describe "Commenting legislation questions" do end scenario "Trying to vote multiple times" do - visit legislation_process_draft_version_annotation_path(annotation.draft_version.process, - annotation.draft_version, - annotation) + visit polymorphic_path(annotation) within("#comment_#{comment.id}_votes") do click_button "I agree" diff --git a/spec/system/legislation/draft_versions_spec.rb b/spec/system/legislation/draft_versions_spec.rb index 962adc087..b306c0207 100644 --- a/spec/system/legislation/draft_versions_spec.rb +++ b/spec/system/legislation/draft_versions_spec.rb @@ -388,7 +388,7 @@ describe "Legislation Draft Versions" do annotation = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam", ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }]) - visit legislation_process_draft_version_annotation_path(draft_version.process, draft_version, annotation) + visit polymorphic_path(annotation) expect(page).not_to have_content "ipsum" expect(page).not_to have_content "my annotation" From 07e1f92dd511ecb2b82874528aa48e0fa6212230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jul 2023 23:26:38 +0200 Subject: [PATCH 13/35] Make moderation tests easier to read --- spec/system/admin/activity_spec.rb | 4 ++-- spec/system/admin/hidden_comments_spec.rb | 4 ++-- spec/system/moderation/budget_investments_spec.rb | 5 +++-- spec/system/moderation/users_spec.rb | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/spec/system/admin/activity_spec.rb b/spec/system/admin/activity_spec.rb index af1e3ffdd..e92270c2b 100644 --- a/spec/system/admin/activity_spec.rb +++ b/spec/system/admin/activity_spec.rb @@ -212,12 +212,12 @@ describe "Admin activity" do context "User" do scenario "Shows moderation activity on users" do - proposal = create(:proposal) + proposal = create(:proposal, author: create(:user, username: "Sam")) visit proposal_path(proposal) within("#proposal_#{proposal.id}") do - accept_confirm("Are you sure? This will hide the user \"#{proposal.author.name}\" and all their contents.") do + accept_confirm("Are you sure? This will hide the user \"Sam\" and all their contents.") do click_button "Block author" end diff --git a/spec/system/admin/hidden_comments_spec.rb b/spec/system/admin/hidden_comments_spec.rb index 36902e4d8..7f86f1bf1 100644 --- a/spec/system/admin/hidden_comments_spec.rb +++ b/spec/system/admin/hidden_comments_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" describe "Admin hidden comments", :admin do scenario "Do not show comments from blocked users" do - comment = create(:comment, :hidden, body: "SPAM from SPAMMER") + comment = create(:comment, :hidden, body: "SPAM from SPAMMER", author: create(:user, username: "Evil")) proposal = create(:proposal, author: comment.author) create(:comment, commentable: proposal, user: comment.author, body: "Good Proposal!") @@ -13,7 +13,7 @@ describe "Admin hidden comments", :admin do visit proposal_path(proposal) within("#proposal_#{proposal.id}") do - accept_confirm("Are you sure? This will hide the user \"#{proposal.author.name}\" and all their contents.") do + accept_confirm("Are you sure? This will hide the user \"Evil\" and all their contents.") do click_button "Block author" end end diff --git a/spec/system/moderation/budget_investments_spec.rb b/spec/system/moderation/budget_investments_spec.rb index bf8ec87d1..d4d7aa0e1 100644 --- a/spec/system/moderation/budget_investments_spec.rb +++ b/spec/system/moderation/budget_investments_spec.rb @@ -4,7 +4,8 @@ describe "Moderate budget investments" do let(:budget) { create(:budget) } let(:heading) { create(:budget_heading, budget: budget, price: 666666) } let(:mod) { create(:moderator) } - let!(:investment) { create(:budget_investment, heading: heading, author: create(:user)) } + let(:author) { create(:user, username: "Julia") } + let!(:investment) { create(:budget_investment, heading: heading, author: author) } scenario "Hiding an investment" do login_as(mod.user) @@ -23,7 +24,7 @@ describe "Moderate budget investments" do login_as(mod.user) visit budget_investment_path(budget, investment) - accept_confirm("Are you sure? This will hide the user \"#{investment.author.name}\" and all their contents.") do + accept_confirm("Are you sure? This will hide the user \"Julia\" and all their contents.") do click_button "Block author" end diff --git a/spec/system/moderation/users_spec.rb b/spec/system/moderation/users_spec.rb index ce9eed9ec..7ea01a603 100644 --- a/spec/system/moderation/users_spec.rb +++ b/spec/system/moderation/users_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" describe "Moderate users" do scenario "Hide" do - citizen = create(:user) + citizen = create(:user, username: "Mike") moderator = create(:moderator) debate1 = create(:debate, author: citizen) @@ -24,7 +24,7 @@ describe "Moderate users" do visit debate_path(debate1) within("#debate_#{debate1.id}") do - accept_confirm("Are you sure? This will hide the user \"#{debate1.author.name}\" and all their contents.") do + accept_confirm("Are you sure? This will hide the user \"Mike\" and all their contents.") do click_button "Block author" end end From 03fa5fc8d6a5817d8d90d8df06726212ccdb9f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jul 2023 23:33:19 +0200 Subject: [PATCH 14/35] Simplify long test titles --- spec/lib/remote_translations/microsoft/client_spec.rb | 4 ++-- spec/models/budget/investment_spec.rb | 4 ++-- spec/models/tenant_spec.rb | 2 +- spec/shared/system/nested_imageable.rb | 10 +++++----- spec/system/admin/poll/shifts_spec.rb | 2 +- spec/system/comments/budget_investments_spec.rb | 2 +- spec/system/comments/debates_spec.rb | 2 +- spec/system/comments/legislation_annotations_spec.rb | 2 +- spec/system/comments/legislation_questions_spec.rb | 2 +- spec/system/comments/polls_spec.rb | 2 +- spec/system/comments/proposals_spec.rb | 2 +- spec/system/comments/topics_spec.rb | 4 ++-- spec/system/management/document_verifications_spec.rb | 2 +- spec/system/users_auth_spec.rb | 4 ++-- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spec/lib/remote_translations/microsoft/client_spec.rb b/spec/lib/remote_translations/microsoft/client_spec.rb index 0b9b4c731..3a796f476 100644 --- a/spec/lib/remote_translations/microsoft/client_spec.rb +++ b/spec/lib/remote_translations/microsoft/client_spec.rb @@ -27,7 +27,7 @@ describe RemoteTranslations::Microsoft::Client do end context "when characters from request are greater than characters limit" do - it "response has the expected result when the request has 2 texts, where both less than CHARACTERS_LIMIT_PER_REQUEST" do + it "has the expected result when the request has two texts and both are smaller than the limit" do stub_const("RemoteTranslations::Microsoft::Client::CHARACTERS_LIMIT_PER_REQUEST", 20) text_en = Faker::Lorem.characters(number: 11) another_text_en = Faker::Lorem.characters(number: 11) @@ -49,7 +49,7 @@ describe RemoteTranslations::Microsoft::Client do expect(result).to eq([translated_text_es, another_translated_text_es]) end - it "response has the expected result when the request has 2 texts and both are greater than CHARACTERS_LIMIT_PER_REQUEST" do + it "has the expected result when the request has two texts and both are greater than the limit" do stub_const("RemoteTranslations::Microsoft::Client::CHARACTERS_LIMIT_PER_REQUEST", 20) start_text_en = Faker::Lorem.characters(number: 10) + " " end_text_en = Faker::Lorem.characters(number: 10) diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index 7dede4c03..d0a754158 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -1311,7 +1311,7 @@ describe Budget::Investment do end describe "check_for_reclassification" do - it "stores reclassfied votes and removes actual votes if an investment has been reclassified" do + it "removes votes and stores reclassfied votes if an investment has been reclassified" do investment = create(:budget_investment, :selected, heading: heading1) 3.times { create(:user, ballot_lines: [investment]) } @@ -1326,7 +1326,7 @@ describe Budget::Investment do expect(Budget::ReclassifiedVote.count).to eq(3) end - it "does not store reclassified votes nor remove actual votes if the investment has not been reclassifed" do + it "does not remove votes nor store reclassified votes if the investment has not been reclassifed" do investment = create(:budget_investment, :selected, heading: heading1) 3.times { create(:user, ballot_lines: [investment]) } diff --git a/spec/models/tenant_spec.rb b/spec/models/tenant_spec.rb index ba94f001a..1e7cda5a7 100644 --- a/spec/models/tenant_spec.rb +++ b/spec/models/tenant_spec.rb @@ -135,7 +135,7 @@ describe Tenant do expect { Tenant.resolve_host("www.consul.dev") }.to raise_exception(Apartment::TenantNotFound) end - it "raises an exception when accessing a hidden tenant with a domain and another tenant resolves to the same domain" do + it "raises an exception with a hidden tenant's domain when another tenant resolves to the same domain" do insert(:tenant, :domain, schema: "saturn.consul.dev", hidden_at: Time.current) insert(:tenant, schema: "saturn") diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index f82b66abb..be2588f31 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -33,7 +33,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p expect(page).not_to have_selector "#new_image_link" end - scenario "Should update nested image file name after choosing any file" do + scenario "Should update image file name after choosing any file" do do_login_for user, management: management visit send(path, arguments) @@ -43,7 +43,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p expect(page).to have_selector ".file-name", text: "clippy.jpg" end - scenario "Should update nested image file title with file name after choosing a file when no title defined" do + scenario "Should update image file title after choosing a file when no title is defined" do do_login_for user, management: management visit send(path, arguments) @@ -52,7 +52,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p expect_image_has_title("clippy.jpg") end - scenario "Should not update nested image file title with file name after choosing a file when title already defined" do + scenario "Should not update image file title after choosing a file when a title is already defined" do do_login_for user, management: management visit send(path, arguments) @@ -112,7 +112,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p expect(cached_attachment_field.value).to be_empty end - scenario "Should show nested image errors after invalid form submit" do + scenario "Should show image errors after invalid form submit" do do_login_for user, management: management visit send(path, arguments) @@ -137,7 +137,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p expect(page).to have_css "img[src$='clippy.jpg']" end - scenario "Should remove nested image after valid file upload and click on remove button" do + scenario "Should remove image after valid file upload and click on remove button" do do_login_for user, management: management visit send(path, arguments) diff --git a/spec/system/admin/poll/shifts_spec.rb b/spec/system/admin/poll/shifts_spec.rb index 1b92aa606..3effc075c 100644 --- a/spec/system/admin/poll/shifts_spec.rb +++ b/spec/system/admin/poll/shifts_spec.rb @@ -88,7 +88,7 @@ describe "Admin shifts", :admin do end end - scenario "Vote Collection Shift and Recount & Scrutiny Shift don't include already assigned dates to officer" do + scenario "Vote Collection Shift and Recount & Scrutiny Shift don't include already assigned dates" do poll = create(:poll) booth = create(:poll_booth, polls: [poll]) officer = create(:poll_officer) diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 6f7c6e55d..639db3a24 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -123,7 +123,7 @@ describe "Commenting Budget::Investments" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: investment, created_at: Time.current - 10) new_root = create(:comment, commentable: investment, created_at: Time.current) old_child = create(:comment, commentable: investment, parent_id: new_root.id, created_at: Time.current - 10) diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index d1021bd00..f56e52c35 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -139,7 +139,7 @@ describe "Commenting debates" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, even when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: debate, created_at: Time.current - 10) new_root = create(:comment, commentable: debate, created_at: Time.current) old_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.current - 10) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 8d34062e0..54ae77b22 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -120,7 +120,7 @@ describe "Commenting legislation questions" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, even when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: annotation, created_at: Time.current - 10) new_root = create(:comment, commentable: annotation, created_at: Time.current) old_child = create(:comment, commentable: annotation, parent_id: new_root.id, created_at: Time.current - 10) diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 0d560e2ac..83bda571d 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -125,7 +125,7 @@ describe "Commenting legislation questions" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, even when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: question, created_at: Time.current - 10) new_root = create(:comment, commentable: question, created_at: Time.current) old_child = create(:comment, commentable: question, parent_id: new_root.id, created_at: Time.current - 10) diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index 8179fd476..c4ffbd90f 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -117,7 +117,7 @@ describe "Commenting polls" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: poll, created_at: Time.current - 10) new_root = create(:comment, commentable: poll, created_at: Time.current) old_child = create(:comment, commentable: poll, parent_id: new_root.id, created_at: Time.current - 10) diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index 8b6f86fa8..4e229f3cb 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -119,7 +119,7 @@ describe "Commenting proposals" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: proposal, created_at: Time.current - 10) new_root = create(:comment, commentable: proposal, created_at: Time.current) old_child = create(:comment, commentable: proposal, parent_id: new_root.id, created_at: Time.current - 10) diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index caa5957cb..51484eec0 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -126,7 +126,7 @@ describe "Commenting topics from proposals" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do community = proposal.community topic = create(:topic, community: community) old_root = create(:comment, commentable: topic, created_at: Time.current - 10) @@ -673,7 +673,7 @@ describe "Commenting topics from budget investments" do expect(c2.body).to appear_before(c3.body) end - scenario "Creation date works differently in roots and in child comments, when sorting by confidence_score" do + scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do community = investment.community topic = create(:topic, community: community) old_root = create(:comment, commentable: topic, created_at: Time.current - 10) diff --git a/spec/system/management/document_verifications_spec.rb b/spec/system/management/document_verifications_spec.rb index 0549066cb..2403bcd8a 100644 --- a/spec/system/management/document_verifications_spec.rb +++ b/spec/system/management/document_verifications_spec.rb @@ -44,7 +44,7 @@ describe "DocumentVerifications" do expect(page).to have_content "This document is not registered" end - scenario "Verifying a user which does exists in the census but not in the db redirects allows sending an email" do + scenario "Verifying a user who exists in the census but not in the db allows sending an email" do login_as_manager visit management_document_verifications_path fill_in "document_verification_document_number", with: "12345678Z" diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index 9257a70e2..4fb0ed6e3 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -411,7 +411,7 @@ describe "Users" do expect(page).to have_field "Email", with: "manuelacarmena@example.com" end - scenario "Try to register with the email of an already existing user, when no email was provided by oauth" do + scenario "Try to register with an existing email, when no email was provided by oauth" do create(:user, username: "peter", email: "manuela@example.com") OmniAuth.config.add_mock(:twitter, twitter_hash) @@ -448,7 +448,7 @@ describe "Users" do expect(page).to have_field "Email", with: "somethingelse@example.com" end - scenario "Try to register with the email of an already existing user, when an unconfirmed email was provided by oauth" do + scenario "Try to register with an existing email, when an unconfirmed email was provided by oauth" do create(:user, username: "peter", email: "manuelacarmena@example.com") OmniAuth.config.add_mock(:twitter, twitter_hash_with_email) From 025f3ad2101f964eec557a2dd876050ff5f7e683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 01:26:10 +0200 Subject: [PATCH 15/35] Simplify variable names in remote translations tests --- spec/shared/system/remotely_translatable.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/shared/system/remotely_translatable.rb b/spec/shared/system/remotely_translatable.rb index 87eb15533..870bf5147 100644 --- a/spec/shared/system/remotely_translatable.rb +++ b/spec/shared/system/remotely_translatable.rb @@ -173,8 +173,8 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume describe "without delayed jobs" do scenario "the remote translation button should not be present" do - microsoft_translate_client_response = generate_response(resource) - expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(microsoft_translate_client_response) + response = generate_response(resource) + expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) visit path select "Español", from: "Language:" @@ -184,8 +184,8 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume end scenario "the remote translation has been translated and destoyed" do - microsoft_translate_client_response = generate_response(resource) - expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(microsoft_translate_client_response) + response = generate_response(resource) + expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) visit path select "Español", from: "Language:" @@ -197,8 +197,8 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume end scenario "request a translation of an already translated text" do - microsoft_translate_client_response = generate_response(resource) - expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(microsoft_translate_client_response) + response = generate_response(resource) + expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) in_browser(:one) do visit path From 016595fd80726caf4d777ec8b44c8397f2657c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 15:10:30 +0200 Subject: [PATCH 16/35] Simplify setting up poll geozones in test/dev data --- app/models/poll.rb | 5 +++++ db/dev_seeds/polls.rb | 3 +-- spec/models/abilities/common_spec.rb | 8 ++++---- spec/models/poll/poll_spec.rb | 10 ++++------ spec/system/admin/poll/questions_spec.rb | 2 +- spec/system/officing/voters_spec.rb | 6 +++--- spec/system/polls/polls_spec.rb | 11 ++++------- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 3d14971fc..866605117 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -181,6 +181,11 @@ class Poll < ApplicationRecord end end + def geozone_restricted_to=(geozones) + self.geozone_restricted = true + self.geozones = geozones + end + def generate_slug? slug.nil? end diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index 572d8cd9f..9fc1cfd69 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -20,8 +20,7 @@ section "Creating polls" do slug: I18n.t("seeds.polls.current_poll_geozone_restricted").parameterize, starts_at: 5.days.ago, ends_at: 5.days.from_now, - geozone_restricted: true, - geozones: Geozone.sample(3)) + geozone_restricted_to: Geozone.sample(3)) create_poll!(name: I18n.t("seeds.polls.recounting_poll"), slug: I18n.t("seeds.polls.recounting_poll").parameterize, diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index 81eb67e38..af7d7cb8c 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -35,11 +35,11 @@ describe Abilities::Common do let(:current_poll) { create(:poll) } let(:expired_poll) { create(:poll, :expired) } - let(:expired_poll_from_own_geozone) { create(:poll, :expired, geozone_restricted: true, geozones: [geozone]) } - let(:expired_poll_from_other_geozone) { create(:poll, :expired, geozone_restricted: true, geozones: [create(:geozone)]) } + let(:expired_poll_from_own_geozone) { create(:poll, :expired, geozone_restricted_to: [geozone]) } + let(:expired_poll_from_other_geozone) { create(:poll, :expired, geozone_restricted_to: [create(:geozone)]) } let(:poll) { create(:poll, geozone_restricted: false) } - let(:poll_from_own_geozone) { create(:poll, geozone_restricted: true, geozones: [geozone]) } - let(:poll_from_other_geozone) { create(:poll, geozone_restricted: true, geozones: [create(:geozone)]) } + let(:poll_from_own_geozone) { create(:poll, geozone_restricted_to: [geozone]) } + let(:poll_from_other_geozone) { create(:poll, geozone_restricted_to: [create(:geozone)]) } let(:poll_question_from_own_geozone) { create(:poll_question, poll: poll_from_own_geozone) } let(:poll_question_from_other_geozone) { create(:poll_question, poll: poll_from_other_geozone) } diff --git a/spec/models/poll/poll_spec.rb b/spec/models/poll/poll_spec.rb index 609227073..2eaac6859 100644 --- a/spec/models/poll/poll_spec.rb +++ b/spec/models/poll/poll_spec.rb @@ -195,10 +195,8 @@ describe Poll do let!(:current_poll) { create(:poll) } let!(:expired_poll) { create(:poll, :expired) } - let!(:current_restricted_poll) { create(:poll, geozone_restricted: true, geozones: [geozone]) } - let!(:expired_restricted_poll) do - create(:poll, :expired, geozone_restricted: true, geozones: [geozone]) - end + let!(:current_restricted_poll) { create(:poll, geozone_restricted_to: [geozone]) } + let!(:expired_restricted_poll) { create(:poll, :expired, geozone_restricted_to: [geozone]) } let!(:all_polls) { [current_poll, expired_poll, current_poll, expired_restricted_poll] } let(:non_current_polls) { [expired_poll, expired_restricted_poll] } @@ -490,8 +488,8 @@ describe Poll do poll1 = create(:poll, geozone_restricted: true) poll2 = create(:poll, geozone_restricted: true) poll3 = create(:poll) - poll_geozone_1 = create(:poll, geozone_restricted: true, geozones: [geozone]) - poll_geozone_2 = create(:poll, geozone_restricted: true, geozones: [geozone]) + poll_geozone_1 = create(:poll, geozone_restricted_to: [geozone]) + poll_geozone_2 = create(:poll, geozone_restricted_to: [geozone]) geozone_user = create(:user, :level_two, geozone: geozone) expect(Poll.sort_for_list).to eq [poll3, poll1, poll2, poll_geozone_1, poll_geozone_2] diff --git a/spec/system/admin/poll/questions_spec.rb b/spec/system/admin/poll/questions_spec.rb index d6f559fd7..b03f63d45 100644 --- a/spec/system/admin/poll/questions_spec.rb +++ b/spec/system/admin/poll/questions_spec.rb @@ -32,7 +32,7 @@ describe "Admin poll questions", :admin do scenario "Show" do geozone = create(:geozone) - poll = create(:poll, geozone_restricted: true, geozone_ids: [geozone.id]) + poll = create(:poll, geozone_restricted_to: [geozone]) question = create(:poll_question, poll: poll) visit admin_poll_path(poll) diff --git a/spec/system/officing/voters_spec.rb b/spec/system/officing/voters_spec.rb index 62216860c..4123602d9 100644 --- a/spec/system/officing/voters_spec.rb +++ b/spec/system/officing/voters_spec.rb @@ -35,7 +35,7 @@ describe "Voters" do end scenario "Cannot vote" do - unvotable_poll = create(:poll, geozone_restricted: true, geozones: [create(:geozone, census_code: "02")]) + unvotable_poll = create(:poll, geozone_restricted_to: [create(:geozone, census_code: "02")]) create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth) set_officing_booth(booth) @@ -96,7 +96,7 @@ describe "Voters" do end scenario "Display polls that the user can vote" do - votable_poll = create(:poll, geozone_restricted: true, geozones: [Geozone.first]) + votable_poll = create(:poll, geozone_restricted_to: [Geozone.first]) create(:poll_officer_assignment, officer: officer, poll: votable_poll, booth: booth) set_officing_booth(booth) @@ -108,7 +108,7 @@ describe "Voters" do end scenario "Display polls that the user cannot vote" do - unvotable_poll = create(:poll, geozone_restricted: true, geozones: [create(:geozone, census_code: "02")]) + unvotable_poll = create(:poll, geozone_restricted_to: [create(:geozone, census_code: "02")]) create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth) set_officing_booth(booth) diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb index 7128d421b..11e13f440 100644 --- a/spec/system/polls/polls_spec.rb +++ b/spec/system/polls/polls_spec.rb @@ -215,8 +215,7 @@ describe "Polls" do visit polls_path expect(page).not_to have_selector(".already-answer") - poll.update!(geozone_restricted: true) - poll.geozones << geozone + poll.update!(geozone_restricted_to: [geozone]) create(:poll_question, :yes_no, poll: poll) @@ -238,8 +237,7 @@ describe "Polls" do end scenario "Level 2 users answering" do - poll.update!(geozone_restricted: true) - poll.geozones << geozone + poll.update!(geozone_restricted_to: [geozone]) question = create(:poll_question, :yes_no, poll: poll) user = create(:user, :level_two, geozone: geozone) @@ -256,8 +254,7 @@ describe "Polls" do end scenario "Level 2 users changing answer" do - poll.update!(geozone_restricted: true) - poll.geozones << geozone + poll.update!(geozone_restricted_to: [geozone]) question = create(:poll_question, :yes_no, poll: poll) user = create(:user, :level_two, geozone: geozone) @@ -293,7 +290,7 @@ describe "Polls" do scenario "Polls with users same-geozone listed first" do create(:poll, geozone_restricted: true, name: "A Poll") create(:poll, name: "Not restricted") - create(:poll, geozone_restricted: true, geozones: [geozone], name: "Geozone Poll") + create(:poll, geozone_restricted_to: [geozone], name: "Geozone Poll") login_as(create(:user, :level_two, geozone: geozone)) visit polls_path(poll) From 332e3a296a3e78f6447ad3acd4fe1c16a8e91f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 01:53:35 +0200 Subject: [PATCH 17/35] Simplify expectations in related content tests --- spec/models/related_content_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spec/models/related_content_spec.rb b/spec/models/related_content_spec.rb index a41e5bd64..af8851f0b 100644 --- a/spec/models/related_content_spec.rb +++ b/spec/models/related_content_spec.rb @@ -65,11 +65,8 @@ describe RelatedContent do it "creates an opposite related_content" do expect { related_content.save }.to change { RelatedContent.count }.by(2) - expect(related_content.opposite_related_content.child_relationable_id).to eq(parent_relationable.id) - expect(related_content.opposite_related_content.child_relationable_type).to eq(parent_relationable.class.name) - expect(related_content.opposite_related_content.parent_relationable_id).to eq(child_relationable.id) - expect(related_content.opposite_related_content.parent_relationable_type).to eq(child_relationable.class.name) - expect(related_content.opposite_related_content.opposite_related_content.id).to eq(related_content.id) + expect(related_content.opposite_related_content.child_relationable).to eq(parent_relationable) + expect(related_content.opposite_related_content.parent_relationable).to eq(child_relationable) end end From 018ef2e4838cda78521144637cfa77b93ed9b088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 01:57:56 +0200 Subject: [PATCH 18/35] Simplify stubbing age responses in residence tests --- spec/models/officing/residence_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb index 96df02b1d..a9d842d85 100644 --- a/spec/models/officing/residence_spec.rb +++ b/spec/models/officing/residence_spec.rb @@ -130,13 +130,15 @@ describe Officing::Residence do describe "allowed age" do it "is not valid if user is under allowed age" do - allow_any_instance_of(Officing::Residence).to receive(:response_date_of_birth).and_return(15.years.ago) + allow(residence).to receive(:response_date_of_birth).and_return(15.years.ago) + expect(residence).not_to be_valid expect(residence.errors[:year_of_birth]).to include("You don't have the required age to participate") end it "is valid if user is above allowed age" do - allow_any_instance_of(Officing::Residence).to receive(:response_date_of_birth).and_return(16.years.ago) + allow(residence).to receive(:response_date_of_birth).and_return(16.years.ago) + expect(residence).to be_valid expect(residence.errors[:year_of_birth]).to be_empty end From cdc166e830b2050f45371fb11528f6dc8135e17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 14:43:42 +0200 Subject: [PATCH 19/35] Make it easier to distinguish counts and prices With so many similar numbers, the tests were hard to follow. Besides, we're now making these lines slightly shorter :). --- spec/models/budget/result_spec.rb | 76 +++++++++++++++---------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/spec/models/budget/result_spec.rb b/spec/models/budget/result_spec.rb index ade4de5e9..37b54729d 100644 --- a/spec/models/budget/result_spec.rb +++ b/spec/models/budget/result_spec.rb @@ -7,80 +7,80 @@ describe Budget::Result do context "When there are no winners" do it "assigns investments ordered by ballot lines until budget is met" do - create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500) - create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) - create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600) + create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 50) + create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 80) + create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 90) + create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 60) Budget::Result.new(budget, heading).calculate_winners - expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 600]) + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([90, 80, 60]) end it "selects cheaper investments when running out of budget" do - create(:budget_investment, :selected, heading: heading, price: 800, ballot_lines_count: 900) - create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 600) + create(:budget_investment, :selected, heading: heading, price: 800, ballot_lines_count: 90) + create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 80) + create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 60) Budget::Result.new(budget, heading).calculate_winners - expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 600]) + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([90, 60]) end it "excludes incompatible investments" do - create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) - create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700) - create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600) - create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500) + create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 90) + create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 80) + create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 70) + create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 60) + create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 50) Budget::Result.new(budget, heading).calculate_winners - expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 600]) + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([90, 80, 60]) end end context "When there are winners" do it "removes winners and recalculates" do - create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) - create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :winner, :incompatible, heading: heading, price: 500, ballot_lines_count: 700) - create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 600) - create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) + create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 90) + create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 80) + create(:budget_investment, :winner, :incompatible, heading: heading, price: 500, ballot_lines_count: 70) + create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 60) + create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 50) Budget::Result.new(budget, heading).calculate_winners - expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 600]) + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([90, 80, 60]) end end context "When a winner is flagged as incompatible" do it "recalculates winners leaving it out" do - wrong_win = create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 900) + wrong_win = create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 90) - create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 700) - create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 600) - create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) + create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 80) + create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 70) + create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 60) + create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 50) wrong_win.update!(incompatible: true) - expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([800, 700, 600]) + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([80, 70, 60]) end end context "When an incompatible is flagged as compatible again" do it "recalculates winners taking it in consideration" do - miss = create(:budget_investment, :incompatible, heading: heading, price: 200, ballot_lines_count: 900) + miss = create(:budget_investment, :incompatible, heading: heading, price: 200, ballot_lines_count: 90) - create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 700) - create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 600) - create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) + create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 80) + create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 70) + create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 60) + create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 50) miss.update!(incompatible: false) - expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 700]) + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([90, 80, 70]) end end @@ -88,14 +88,14 @@ describe Budget::Result do before { budget.update!(voting_style: "approval", hide_money: true) } it "does not take the price into account" do - create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500) - create(:budget_investment, :incompatible, heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :selected, heading: heading, price: 800, ballot_lines_count: 700) - create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600) + create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 50) + create(:budget_investment, :incompatible, heading: heading, price: 300, ballot_lines_count: 80) + create(:budget_investment, :selected, heading: heading, price: 800, ballot_lines_count: 70) + create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 60) Budget::Result.new(budget, heading).calculate_winners - expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([700, 600, 500]) + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([70, 60, 50]) end end end From 4b374151be3001b9e07c678cf839520607a435a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 15:42:55 +0200 Subject: [PATCH 20/35] Extract variable in GraphQL test --- spec/lib/graphql_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index de8b80c61..b0b33a638 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -10,7 +10,9 @@ end def hidden_field?(response, field_name) data_is_empty = response["data"].nil? - error_is_present = ((response["errors"].first["message"] =~ /Field '#{field_name}' doesn't exist on type '[[:alnum:]]*'/) == 0) + error_message = /Field '#{field_name}' doesn't exist on type '[[:alnum:]]*'/ + + error_is_present = ((response["errors"].first["message"] =~ error_message) == 0) data_is_empty && error_is_present end From 36c3ba6601256886f2b320532d249727398ecfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 15:53:06 +0200 Subject: [PATCH 21/35] Extract variable in manager authenticator method --- lib/manager_authenticator.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/manager_authenticator.rb b/lib/manager_authenticator.rb index d6976470e..fbe1ccab8 100644 --- a/lib/manager_authenticator.rb +++ b/lib/manager_authenticator.rb @@ -22,7 +22,9 @@ class ManagerAuthenticator def application_authorized? response = client.call(:get_applications_user_list, message: { ub: { user_key: @manager[:user_key] }}).body - parsed_response = parser.parse((response[:get_applications_user_list_response][:get_applications_user_list_return])) + user_list_return = response[:get_applications_user_list_response][:get_applications_user_list_return] + parsed_response = parser.parse(user_list_return) + aplication_value = parsed_response["APLICACIONES"]["APLICACION"] # aplication_value from UWEB can be an array of hashes or a hash aplication_value.include?("CLAVE_APLICACION" => application_key) || aplication_value["CLAVE_APLICACION"] == application_key From 8898c30f55402a71fa4eb95f7633c8b014518440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 16:21:39 +0200 Subject: [PATCH 22/35] Rename AvailableLocales.available_locales method I'm not sure whether we should rename the class instead. I'm renaming the method because renaming the class would require more changes. --- app/models/remote_translation.rb | 2 +- lib/remote_translations/microsoft/available_locales.rb | 4 ++-- .../remote_translations/microsoft/available_locales_spec.rb | 4 ++-- spec/models/remote_translation_spec.rb | 6 +++--- spec/shared/system/remotely_translatable.rb | 2 +- spec/spec_helper.rb | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/remote_translation.rb b/app/models/remote_translation.rb index 1ef0f893d..10dd58a92 100644 --- a/app/models/remote_translation.rb +++ b/app/models/remote_translation.rb @@ -4,7 +4,7 @@ class RemoteTranslation < ApplicationRecord validates :remote_translatable_id, presence: true validates :remote_translatable_type, presence: true validates :locale, presence: true - validates :locale, inclusion: { in: ->(_) { RemoteTranslations::Microsoft::AvailableLocales.available_locales }} + validates :locale, inclusion: { in: ->(_) { RemoteTranslations::Microsoft::AvailableLocales.locales }} validate :already_translated_resource after_create :enqueue_remote_translation diff --git a/lib/remote_translations/microsoft/available_locales.rb b/lib/remote_translations/microsoft/available_locales.rb index 2bc39d2e3..6ddcc8f7a 100644 --- a/lib/remote_translations/microsoft/available_locales.rb +++ b/lib/remote_translations/microsoft/available_locales.rb @@ -4,7 +4,7 @@ require "cgi" require "json" class RemoteTranslations::Microsoft::AvailableLocales - def self.available_locales + def self.locales daily_cache("locales") do remote_available_locales.map { |locale| remote_locale_to_app_locale(locale) } end @@ -15,7 +15,7 @@ class RemoteTranslations::Microsoft::AvailableLocales end def self.include_locale?(locale) - available_locales.include?(locale.to_s) + locales.include?(locale.to_s) end private diff --git a/spec/lib/remote_translations/microsoft/available_locales_spec.rb b/spec/lib/remote_translations/microsoft/available_locales_spec.rb index 421ef606a..1e24a8fb4 100644 --- a/spec/lib/remote_translations/microsoft/available_locales_spec.rb +++ b/spec/lib/remote_translations/microsoft/available_locales_spec.rb @@ -1,12 +1,12 @@ require "rails_helper" describe RemoteTranslations::Microsoft::AvailableLocales do - describe ".available_locales" do + describe ".locales" do it "includes locales with the same format as I18n.available_locales" do allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales) .and_return(%w[de en es fr pt zh-Hans]) - available_locales = RemoteTranslations::Microsoft::AvailableLocales.available_locales + available_locales = RemoteTranslations::Microsoft::AvailableLocales.locales expect(available_locales).to eq %w[de en es fr pt-BR zh-CN] end end diff --git a/spec/models/remote_translation_spec.rb b/spec/models/remote_translation_spec.rb index 8ce808ce5..c6ac6f6ad 100644 --- a/spec/models/remote_translation_spec.rb +++ b/spec/models/remote_translation_spec.rb @@ -39,18 +39,18 @@ describe RemoteTranslation, :remote_translations do it "checks available locales dynamically" do allow(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).and_return(["en"]) + .to receive(:locales).and_return(["en"]) expect(remote_translation).not_to be_valid allow(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).and_return(["es"]) + .to receive(:locales).and_return(["es"]) expect(remote_translation).to be_valid end it "is valid with a locale that uses a different name in the remote service" do - allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:available_locales).and_call_original + allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:locales).and_call_original allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales) .and_return(["pt"]) diff --git a/spec/shared/system/remotely_translatable.rb b/spec/shared/system/remotely_translatable.rb index 870bf5147..2912b1497 100644 --- a/spec/shared/system/remotely_translatable.rb +++ b/spec/shared/system/remotely_translatable.rb @@ -11,7 +11,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume Setting["feature.remote_translations"] = true available_locales_response = %w[de en es fr pt zh-Hans] expect(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).at_most(4).times + .to receive(:locales).at_most(4).times .and_return(available_locales_response) allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index edd1036f2..f47bafa8d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -145,7 +145,7 @@ RSpec.configure do |config| config.before(:each, :remote_translations) do allow(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).and_return(I18n.available_locales.map(&:to_s)) + .to receive(:locales).and_return(I18n.available_locales.map(&:to_s)) end config.around(:each, :with_frozen_time) do |example| From 243d55ec820f5f926b5acacfd2fed127802ed2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 16:34:43 +0200 Subject: [PATCH 23/35] Add method to get the archived proposals date limit --- app/models/proposal.rb | 6 +++--- app/models/setting.rb | 4 ++++ db/dev_seeds/proposals.rb | 5 ++--- spec/support/common_actions/proposals.rb | 5 ++--- spec/system/dashboard/dashboard_spec.rb | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 0382ad5e6..74f8864e8 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -72,8 +72,8 @@ class Proposal < ApplicationRecord scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_archival_date, -> { archived.sort_by_confidence_score } scope :sort_by_recommendations, -> { order(cached_votes_up: :desc) } - scope :archived, -> { where("proposals.created_at <= ?", Setting["months_to_archive_proposals"].to_i.months.ago) } - scope :not_archived, -> { where("proposals.created_at > ?", Setting["months_to_archive_proposals"].to_i.months.ago) } + scope :archived, -> { where("proposals.created_at <= ?", Setting.archived_proposals_date_limit) } + scope :not_archived, -> { where("proposals.created_at > ?", Setting.archived_proposals_date_limit) } scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago) } scope :retired, -> { where.not(retired_at: nil) } scope :not_retired, -> { where(retired_at: nil) } @@ -221,7 +221,7 @@ class Proposal < ApplicationRecord end def archived? - created_at <= Setting["months_to_archive_proposals"].to_i.months.ago + created_at <= Setting.archived_proposals_date_limit end def notifications diff --git a/app/models/setting.rb b/app/models/setting.rb index 452daeb23..fb2219066 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -229,5 +229,9 @@ class Setting < ApplicationRecord Setting["feature.remote_census"].present? && Setting["remote_census.request.postal_code"].present? end + + def archived_proposals_date_limit + Setting["months_to_archive_proposals"].to_i.months.ago + end end end diff --git a/db/dev_seeds/proposals.rb b/db/dev_seeds/proposals.rb index 61caf0773..6e48cc25d 100644 --- a/db/dev_seeds/proposals.rb +++ b/db/dev_seeds/proposals.rb @@ -49,7 +49,6 @@ section "Creating Archived Proposals" do 5.times do author = User.all.sample description = "

#{Faker::Lorem.paragraphs.join("

")}

" - months_to_archive_proposals = Setting["months_to_archive_proposals"] proposal = Proposal.create!(author: author, title: Faker::Lorem.sentence(word_count: 3).truncate(60), summary: Faker::Lorem.sentence(word_count: 3), @@ -58,8 +57,8 @@ section "Creating Archived Proposals" do tag_list: tags.sample(3).join(","), geozone: Geozone.all.sample, terms_of_service: "1", - created_at: months_to_archive_proposals.to_i.months.ago, - published_at: months_to_archive_proposals.to_i.months.ago) + created_at: Setting.archived_proposals_date_limit, + published_at: Setting.archived_proposals_date_limit) random_locales.map do |locale| Globalize.with_locale(locale) do proposal.title = "Archived proposal title for locale #{locale}" diff --git a/spec/support/common_actions/proposals.rb b/spec/support/common_actions/proposals.rb index 2ee198d14..3a30aa0f1 100644 --- a/spec/support/common_actions/proposals.rb +++ b/spec/support/common_actions/proposals.rb @@ -7,12 +7,11 @@ module Proposals end def create_archived_proposals - months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i [ create(:proposal, title: "This is an expired proposal", - created_at: months_to_archive_proposals.months.ago), + created_at: Setting.archived_proposals_date_limit), create(:proposal, title: "This is an oldest expired proposal", - created_at: (months_to_archive_proposals + 2).months.ago) + created_at: Setting.archived_proposals_date_limit - 2.months) ] end diff --git a/spec/system/dashboard/dashboard_spec.rb b/spec/system/dashboard/dashboard_spec.rb index 6eb79dbb2..bcd3ea8a1 100644 --- a/spec/system/dashboard/dashboard_spec.rb +++ b/spec/system/dashboard/dashboard_spec.rb @@ -313,7 +313,7 @@ describe "Proposal's dashboard" do scenario "Resource admin request button do not appear on archived proposals" do feature = create(:dashboard_action, :resource, :active) - archived = Setting["months_to_archive_proposals"].to_i.months.ago + archived = Setting.archived_proposals_date_limit archived_proposal = create(:proposal, created_at: archived) login_as(archived_proposal.author) From bff3331ba7c4dd271a345632cf6372abae0f3e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 16:38:25 +0200 Subject: [PATCH 24/35] Group related proposal scopes together --- app/models/proposal.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 74f8864e8..f8bba43c6 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -72,20 +72,22 @@ class Proposal < ApplicationRecord scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_archival_date, -> { archived.sort_by_confidence_score } scope :sort_by_recommendations, -> { order(cached_votes_up: :desc) } - scope :archived, -> { where("proposals.created_at <= ?", Setting.archived_proposals_date_limit) } - scope :not_archived, -> { where("proposals.created_at > ?", Setting.archived_proposals_date_limit) } - scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago) } - scope :retired, -> { where.not(retired_at: nil) } - scope :not_retired, -> { where(retired_at: nil) } - scope :successful, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success) } - scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) } - scope :public_for_api, -> { all } - scope :selected, -> { where(selected: true) } - scope :not_selected, -> { where(selected: false) } - scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) } - scope :published, -> { where.not(published_at: nil) } - scope :draft, -> { where(published_at: nil) } - scope :created_by, ->(author) { where(author: author) } + + scope :archived, -> { where("proposals.created_at <= ?", Setting.archived_proposals_date_limit) } + scope :not_archived, -> { where("proposals.created_at > ?", Setting.archived_proposals_date_limit) } + scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago) } + scope :retired, -> { where.not(retired_at: nil) } + scope :not_retired, -> { where(retired_at: nil) } + scope :successful, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success) } + scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) } + scope :public_for_api, -> { all } + scope :selected, -> { where(selected: true) } + scope :not_selected, -> { where(selected: false) } + scope :published, -> { where.not(published_at: nil) } + scope :draft, -> { where(published_at: nil) } + + scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) } + scope :created_by, ->(author) { where(author: author) } def publish update!(published_at: Time.current) From a2cc414887ab3a1525c462fa4931b3615f007c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 16:47:52 +0200 Subject: [PATCH 25/35] Remove unnecessary code in proposal scope The `id:` condition works with a list of proposals that might include nil items, so there's no need to compact it and manually get the IDs. Note this scope is probably inefficient, since it instantiates proposal objects (with the `find_voted_items` method) for something that could be done with a database query. We might change it in he future. --- app/models/proposal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index f8bba43c6..3ec643b4f 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -86,7 +86,7 @@ class Proposal < ApplicationRecord scope :published, -> { where.not(published_at: nil) } scope :draft, -> { where(published_at: nil) } - scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) } + scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal")) } scope :created_by, ->(author) { where(author: author) } def publish From 30767fa44e79a57bc4e448b089cf099f603aa085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 16:50:48 +0200 Subject: [PATCH 26/35] Use Ruby 1.9 hash notation in assignment scopes --- app/models/poll/officer_assignment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/poll/officer_assignment.rb b/app/models/poll/officer_assignment.rb index 19aae0efb..ffe4747b4 100644 --- a/app/models/poll/officer_assignment.rb +++ b/app/models/poll/officer_assignment.rb @@ -19,8 +19,8 @@ class Poll where("officer_id = ? AND poll_booth_assignments.poll_id = ?", officer_id, poll_id) end scope :by_officer, ->(officer) { where(officer_id: officer.id) } - scope :by_poll, ->(poll) { joins(:booth_assignment).where("poll_booth_assignments.poll_id" => poll.id) } - scope :by_booth, ->(booth) { joins(:booth_assignment).where("poll_booth_assignments.booth_id" => booth.id) } + scope :by_poll, ->(poll) { joins(:booth_assignment).where("poll_booth_assignments.poll_id": poll.id) } + scope :by_booth, ->(booth) { joins(:booth_assignment).where("poll_booth_assignments.booth_id": booth.id) } scope :by_date, ->(date) { where(date: date) } before_create :log_user_data From 58575374b1b8fdb104765810c0508443df82a086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 18:09:23 +0200 Subject: [PATCH 27/35] Simplify condition in direct upload validation --- app/models/direct_upload.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index c5e535906..e56138087 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -9,7 +9,7 @@ class DirectUpload validates :attachment, :resource_type, :resource_relation, :user, presence: true validate :parent_resource_attachment_validations, - if: -> { attachment.present? && resource_type.present? && resource_relation.present? && user.present? } + if: -> { [attachment, resource_type, resource_relation, user].all?(&:present?) } def initialize(attributes = {}) attributes.each do |name, value| From 8589adaf3e2d18389e221258365478223e58c222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 18:43:49 +0200 Subject: [PATCH 28/35] Simplify verification scopes The code was hard to read with so many nested conditions. --- app/models/concerns/verification.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/verification.rb b/app/models/concerns/verification.rb index a12d30784..d775d5e96 100644 --- a/app/models/concerns/verification.rb +++ b/app/models/concerns/verification.rb @@ -3,11 +3,16 @@ module Verification included do scope :residence_verified, -> { where.not(residence_verified_at: nil) } + scope :residence_unverified, -> { where(residence_verified_at: nil) } + scope :residence_and_phone_verified, -> { residence_verified.where.not(confirmed_phone: nil) } + scope :residence_or_phone_unverified, -> { residence_unverified.or(where(confirmed_phone: nil)) } + scope :phone_not_fully_confirmed, -> { where(unconfirmed_phone: nil).or(where(confirmed_phone: nil)) } + scope :level_three_verified, -> { where.not(verified_at: nil) } - scope :level_two_verified, -> { where("users.level_two_verified_at IS NOT NULL OR (users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL) AND verified_at IS NULL") } - scope :level_two_or_three_verified, -> { where("users.verified_at IS NOT NULL OR users.level_two_verified_at IS NOT NULL OR (users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL)") } - scope :unverified, -> { where("users.verified_at IS NULL AND (users.level_two_verified_at IS NULL AND (users.residence_verified_at IS NULL OR users.confirmed_phone IS NULL))") } - scope :incomplete_verification, -> { where("(users.residence_verified_at IS NULL AND users.failed_census_calls_count > ?) OR (users.residence_verified_at IS NOT NULL AND (users.unconfirmed_phone IS NULL OR users.confirmed_phone IS NULL))", 0) } + scope :level_two_verified, -> { where.not(level_two_verified_at: nil).or(residence_and_phone_verified.where(verified_at: nil)) } + scope :level_two_or_three_verified, -> { level_two_verified.or(level_three_verified) } + scope :unverified, -> { residence_or_phone_unverified.where(verified_at: nil, level_two_verified_at: nil) } + scope :incomplete_verification, -> { residence_unverified.where("failed_census_calls_count > ?", 0).or(residence_verified.phone_not_fully_confirmed) } end def skip_verification? From 2db45c4719311e507b69b9a728a1c5dbc2fd84ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 19:32:49 +0200 Subject: [PATCH 29/35] Group related investment filters together --- app/models/budget/investment.rb | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 61fe46bc3..0f5363295 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -135,21 +135,25 @@ class Budget budget = Budget.find_by_slug_or_id params[:budget_id] results = Investment.by_budget(budget) - results = results.where("cached_votes_up + physical_votes >= ?", - params[:min_total_supports]) if params[:min_total_supports].present? - results = results.where("cached_votes_up + physical_votes <= ?", - params[:max_total_supports]) if params[:max_total_supports].present? - results = results.where(group_id: params[:group_id]) if params[:group_id].present? - results = results.by_tag(params[:tag_name]) if params[:tag_name].present? - results = results.by_tag(params[:milestone_tag_name]) if params[:milestone_tag_name].present? - results = results.by_heading(params[:heading_id]) if params[:heading_id].present? - results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present? - results = results.by_valuator_group(params[:valuator_group_id]) if params[:valuator_group_id].present? - results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present? - results = results.search_by_title_or_id(params[:title_or_id].strip) if params[:title_or_id] - results = advanced_filters(params, results) if params[:advanced_filters].present? + if params[:min_total_supports].present? + results = results.where("cached_votes_up + physical_votes >= ?", params[:min_total_supports]) + end + if params[:max_total_supports].present? + results = results.where("cached_votes_up + physical_votes <= ?", params[:max_total_supports]) + end + results = results.where(group_id: params[:group_id]) if params[:group_id].present? + results = results.by_heading(params[:heading_id]) if params[:heading_id].present? + results = results.by_tag(params[:tag_name]) if params[:tag_name].present? + results = results.by_tag(params[:milestone_tag_name]) if params[:milestone_tag_name].present? + results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present? + results = results.by_valuator_group(params[:valuator_group_id]) if params[:valuator_group_id].present? + results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present? + + results = results.search_by_title_or_id(params[:title_or_id].strip) if params[:title_or_id] + results = advanced_filters(params, results) if params[:advanced_filters].present? results = results.send(current_filter) if current_filter.present? + results.includes(:heading, :group, :budget, administrator: :user, valuators: :user) end From c4dbd94e48881dbde6506f1e4fdf45013a1d2bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 20:05:42 +0200 Subject: [PATCH 30/35] Group related investment scopes together --- app/models/budget/investment.rb | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 0f5363295..3bea7972f 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -67,9 +67,8 @@ class Budget scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc, id: :desc) } scope :sort_by_ballots, -> { reorder(ballot_lines_count: :desc, id: :desc) } scope :sort_by_price, -> { reorder(price: :desc, confidence_score: :desc, id: :desc) } - - scope :sort_by_id, -> { order("id DESC") } - scope :sort_by_supports, -> { order("cached_votes_up DESC") } + scope :sort_by_id, -> { order("id DESC") } + scope :sort_by_supports, -> { order("cached_votes_up DESC") } scope :valuation_open, -> { where(valuation_finished: false) } scope :without_admin, -> { where(administrator_id: nil) } @@ -85,22 +84,23 @@ class Budget scope :unfeasible, -> { where(feasibility: "unfeasible") } scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") } scope :undecided, -> { where(feasibility: "undecided") } - scope :with_supports, -> { where("cached_votes_up > 0") } - scope :selected, -> { feasible.where(selected: true) } - scope :compatible, -> { where(incompatible: false) } - scope :incompatible, -> { where(incompatible: true) } - scope :winners, -> { selected.compatible.where(winner: true) } - scope :unselected, -> { not_unfeasible.where(selected: false) } - scope :last_week, -> { where("created_at >= ?", 7.days.ago) } - scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } - scope :sort_by_created_at, -> { reorder(created_at: :desc) } - scope :by_budget, ->(budget) { where(budget: budget) } - scope :by_group, ->(group_id) { where(group_id: group_id) } - scope :by_heading, ->(heading_id) { where(heading_id: heading_id) } - scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) } - scope :by_tag, ->(tag_name) { tagged_with(tag_name).distinct } - scope :visible_to_valuator, ->(valuator) { visible_to_valuators.where(id: valuator&.assigned_investment_ids) } + scope :with_supports, -> { where("cached_votes_up > 0") } + scope :selected, -> { feasible.where(selected: true) } + scope :compatible, -> { where(incompatible: false) } + scope :incompatible, -> { where(incompatible: true) } + scope :winners, -> { selected.compatible.where(winner: true) } + scope :unselected, -> { not_unfeasible.where(selected: false) } + scope :last_week, -> { where("created_at >= ?", 7.days.ago) } + scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } + scope :sort_by_created_at, -> { reorder(created_at: :desc) } + + scope :by_budget, ->(budget) { where(budget: budget) } + scope :by_group, ->(group_id) { where(group_id: group_id) } + scope :by_heading, ->(heading_id) { where(heading_id: heading_id) } + scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) } + scope :by_tag, ->(tag_name) { tagged_with(tag_name).distinct } + scope :visible_to_valuator, ->(valuator) { visible_to_valuators.where(id: valuator&.assigned_investment_ids) } scope :for_render, -> { includes(:heading) } From 9abc7cd41021480f76006772cb657855216ab362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 20:14:05 +0200 Subject: [PATCH 31/35] Simplify investment valuation scopes --- app/models/budget/investment.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 3bea7972f..d0fd4e1d1 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -71,12 +71,16 @@ class Budget scope :sort_by_supports, -> { order("cached_votes_up DESC") } scope :valuation_open, -> { where(valuation_finished: false) } + scope :with_admin, -> { where.not(administrator_id: nil) } scope :without_admin, -> { where(administrator_id: nil) } scope :without_valuator_group, -> { where(valuator_group_assignments_count: 0) } scope :without_valuator, -> { without_valuator_group.where(valuator_assignments_count: 0) } - scope :under_valuation, -> { valuation_open.valuating.where("administrator_id IS NOT ?", nil) } - scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) } - scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 OR valuator_group_assignments_count > 0") } + scope :under_valuation, -> { valuation_open.valuating.with_admin } + scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).with_admin } + scope :with_valuator_assignments, -> { where("valuator_assignments_count > 0") } + scope :with_group_assignments, -> { where("valuator_group_assignments_count > 0") } + scope :with_valuation_assignments, -> { with_valuator_assignments.or(with_group_assignments) } + scope :valuating, -> { valuation_open.with_valuation_assignments } scope :visible_to_valuators, -> { where(visible_to_valuators: true) } scope :valuation_finished, -> { where(valuation_finished: true) } scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") } From 2113c00db8a59140993ed0e5f22f5b5dc5fab4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 20:30:21 +0200 Subject: [PATCH 32/35] Simplify tests for total anonymous votes Since we added a `total_anonymous_votes` method, we might as well use it. --- spec/models/debate_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 68270198d..85e7a214a 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -170,7 +170,7 @@ describe Debate do it "does not increase anonymous votes counter " do user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111") - expect { debate.register_vote(user, "yes") }.not_to change { debate.reload.cached_anonymous_votes_total } + expect { debate.register_vote(user, "yes") }.not_to change { debate.reload.total_anonymous_votes } end end @@ -182,7 +182,7 @@ describe Debate do it "does not increase anonymous votes counter " do user = create(:user, verified_at: Time.current) - expect { debate.register_vote(user, "yes") }.not_to change { debate.reload.cached_anonymous_votes_total } + expect { debate.register_vote(user, "yes") }.not_to change { debate.reload.total_anonymous_votes } end end @@ -196,7 +196,7 @@ describe Debate do it "increases anonymous votes counter" do user = create(:user) - expect { debate.register_vote(user, "yes") }.to change { debate.reload.cached_anonymous_votes_total }.by(1) + expect { debate.register_vote(user, "yes") }.to change { debate.reload.total_anonymous_votes }.by(1) end end @@ -210,7 +210,7 @@ describe Debate do it "does not increase anonymous votes counter " do user = create(:user) - expect { debate.register_vote(user, "yes") }.not_to change { debate.reload.cached_anonymous_votes_total } + expect { debate.register_vote(user, "yes") }.not_to change { debate.reload.total_anonymous_votes } end end end From 3fe292dfe22a9fe67167a7de6af743997fdbedfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 20:59:35 +0200 Subject: [PATCH 33/35] Move relationable expectations to controller tests Having expectations related to database operations in system tests after the process running the browser has started might result in exceptions while running our test suite. --- .../related_contents_controller_spec.rb | 44 +++++++++++++++++++ spec/shared/system/relationable.rb | 10 +---- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/spec/controllers/related_contents_controller_spec.rb b/spec/controllers/related_contents_controller_spec.rb index 791276f1d..184299b81 100644 --- a/spec/controllers/related_contents_controller_spec.rb +++ b/spec/controllers/related_contents_controller_spec.rb @@ -10,4 +10,48 @@ describe RelatedContentsController do end.to raise_error ActiveRecord::RecordNotFound end end + + describe "#score_positive" do + it "increases the score of both the related content and its opposite" do + user = create(:user, :level_two) + related_content = create(:related_content, author: create(:user)) + opposite_content = related_content.opposite_related_content + + sign_in user + + put :score_positive, params: { id: related_content, format: :js } + + score = related_content.related_content_scores + .find_by(user: user, related_content: related_content) + .value + opposite_score = opposite_content.related_content_scores + .find_by(user: user, related_content: opposite_content) + .value + + expect(score).to eq(1) + expect(opposite_score).to eq(1) + end + end + + describe "#score_negative" do + it "decreases the score of both the related content and its opposite" do + user = create(:user, :level_two) + related_content = create(:related_content, author: create(:user)) + opposite_content = related_content.opposite_related_content + + sign_in user + + put :score_negative, params: { id: related_content, format: :js } + + score = related_content.related_content_scores + .find_by(user: user, related_content: related_content) + .value + opposite_score = opposite_content.related_content_scores + .find_by(user: user, related_content: opposite_content) + .value + + expect(score).to eq(-1) + expect(opposite_score).to eq(-1) + end + end end diff --git a/spec/shared/system/relationable.rb b/spec/shared/system/relationable.rb index 4b744fe35..c9faf9221 100644 --- a/spec/shared/system/relationable.rb +++ b/spec/shared/system/relationable.rb @@ -136,7 +136,7 @@ shared_examples "relationable" do |relationable_model_name| end scenario "related content can be scored positively" do - related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) + create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) login_as(user) visit polymorphic_path(relationable) @@ -147,13 +147,10 @@ shared_examples "relationable" do |relationable_model_name| expect(page).not_to have_link "Yes" expect(page).not_to have_link "No" end - - expect(related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.id).value).to eq(1) - expect(related_content.opposite_related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.opposite_related_content.id).value).to eq(1) end scenario "related content can be scored negatively" do - related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) + create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) login_as(user) visit polymorphic_path(relationable) @@ -164,9 +161,6 @@ shared_examples "relationable" do |relationable_model_name| expect(page).not_to have_link "Yes" expect(page).not_to have_link "No" end - - expect(related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.id).value).to eq(-1) - expect(related_content.opposite_related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.opposite_related_content.id).value).to eq(-1) end scenario "if related content has negative score it will be hidden" do From 75d2782061e96f44aed21040dbc1f12e47b26b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 21:12:40 +0200 Subject: [PATCH 34/35] Make investment votes abilities tests consistent Now both the tests to create and destroy use the `user.votes` association. --- spec/models/abilities/common_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index af7d7cb8c..92fab9aba 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -265,9 +265,9 @@ describe Abilities::Common do it { should be_able_to(:create, user.votes.build(votable: investment_in_selecting_budget)) } it { should_not be_able_to(:create, user.votes.build(votable: investment_in_accepting_budget)) } it { should_not be_able_to(:create, user.votes.build(votable: investment_in_balloting_budget)) } - it { should be_able_to(:destroy, create(:vote, voter: user, votable: investment_in_selecting_budget)) } - it { should_not be_able_to(:destroy, create(:vote, voter: user, votable: investment_in_accepting_budget)) } - it { should_not be_able_to(:destroy, create(:vote, voter: user, votable: investment_in_balloting_budget)) } + it { should be_able_to(:destroy, user.votes.create!(votable: investment_in_selecting_budget)) } + it { should_not be_able_to(:destroy, user.votes.create!(votable: investment_in_accepting_budget)) } + it { should_not be_able_to(:destroy, user.votes.create!(votable: investment_in_balloting_budget)) } it { should_not be_able_to(:destroy, investment_in_accepting_budget) } it { should_not be_able_to(:destroy, investment_in_reviewing_budget) } From a1439d07907b779598da8a8d7650730c33c828e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 21:37:59 +0200 Subject: [PATCH 35/35] Apply Layout/LineLength rubocop rule Note we're excluding a few files: * Configuration files that weren't generated by us * Migration files that weren't generated by us * The Gemfile, since it includes an important comment that must be on the same line as the gem declaration * The Budget::Stats class, since the heading statistics are a mess and having shorter lines would require a lot of refactoring --- .rubocop.yml | 9 +- app/components/admin/menu_component.rb | 6 +- .../budgets/investments/votes_component.rb | 5 +- .../relationable/related_list_component.rb | 4 +- app/components/sdg/filter_links_component.rb | 3 +- app/controllers/admin/api/stats_controller.rb | 3 +- .../budgets/ballot/lines_controller.rb | 4 +- .../budgets/investments_controller.rb | 9 +- .../concerns/admin/budget_headings_actions.rb | 3 +- .../concerns/commentable_actions.rb | 6 +- app/controllers/direct_uploads_controller.rb | 4 +- .../legislation/proposals_controller.rb | 3 +- .../budgets/investments_controller.rb | 5 +- .../document_verifications_controller.rb | 8 +- .../management/proposals_controller.rb | 4 +- .../management/users_controller.rb | 5 +- .../officing/residence_controller.rb | 3 +- .../officing/results_controller.rb | 20 +- app/controllers/proposals_controller.rb | 8 +- .../users/confirmations_controller.rb | 12 +- .../users/registrations_controller.rb | 14 +- .../verification/email_controller.rb | 3 +- app/graphql/types/query_type.rb | 11 +- app/helpers/admin_helper.rb | 5 +- app/helpers/comments_helper.rb | 12 +- app/helpers/communities_helper.rb | 12 +- app/helpers/mailer_helper.rb | 5 +- app/helpers/proposals_helper.rb | 3 +- app/mailers/mailer.rb | 8 +- app/models/abilities/administrator.rb | 8 +- app/models/abilities/common.rb | 8 +- app/models/abilities/moderator.rb | 5 +- app/models/banner.rb | 4 +- app/models/budget/ballot/line.rb | 3 +- app/models/budget/investment.rb | 7 +- app/models/concerns/filterable.rb | 6 +- app/models/concerns/globalizable.rb | 9 +- app/models/concerns/verification.rb | 13 +- app/models/debate.rb | 6 +- app/models/direct_upload.rb | 7 +- app/models/legislation/question.rb | 15 +- app/models/machine_learning.rb | 40 +++- app/models/organization.rb | 12 +- app/models/poll.rb | 3 +- app/models/poll/booth_assignment.rb | 4 +- app/models/poll/recount.rb | 4 +- app/models/progress_bar.rb | 5 +- app/models/proposal.rb | 14 +- app/models/proposal_notification.rb | 6 +- app/models/related_content.rb | 10 +- app/models/signature.rb | 4 +- app/models/verification/management/email.rb | 10 +- app/models/verification/residence.rb | 7 +- .../legislation/processes/summary.xlsx.axlsx | 39 +++- config/deploy.rb | 3 +- config/initializers/apartment.rb | 9 +- config/initializers/devise-security.rb | 6 +- config/routes/admin.rb | 9 +- db/dev_seeds/geozones.rb | 25 ++- ...0150820103351_create_inappropiate_flags.rb | 3 +- .../20171127171925_create_related_content.rb | 13 +- ...219184209_create_related_content_scores.rb | 6 +- ...or_task_to_dashboard_administrator_task.rb | 4 +- ...eate_legislation_people_proposals_table.rb | 5 +- .../20201117200945_create_sdg_relations.rb | 4 +- ...te_active_storage_tables.active_storage.rb | 4 +- lib/manager_authenticator.rb | 22 ++- .../permissions_list_component_spec.rb | 3 +- .../budget_headings/form_component_spec.rb | 3 +- .../admin/geozones/index_component_spec.rb | 4 +- .../pages/index_component_spec.rb | 3 +- .../budgets/budget_component_spec.rb | 3 +- .../related_list_selector_component_spec.rb | 3 +- spec/controllers/documents_controller_spec.rb | 3 +- .../moderation/users_controller_spec.rb | 3 +- spec/factories/administration.rb | 4 +- spec/helpers/signature_sheets_helper_spec.rb | 21 ++- spec/helpers/users_helper_spec.rb | 24 ++- spec/i18n_spec.rb | 8 +- spec/lib/document_parser_spec.rb | 10 +- spec/lib/graphql_spec.rb | 3 +- spec/lib/manager_authenticator_spec.rb | 28 ++- .../microsoft/client_spec.rb | 18 +- spec/models/abilities/administrator_spec.rb | 6 +- spec/models/abilities/common_spec.rb | 26 ++- spec/models/abilities/valuator_spec.rb | 12 +- spec/models/ahoy/data_source_spec.rb | 4 +- spec/models/budget/investment_spec.rb | 16 +- spec/models/budget/result_spec.rb | 4 +- spec/models/budget/stats_spec.rb | 5 +- spec/models/debate_spec.rb | 10 +- spec/models/direct_upload_spec.rb | 23 ++- spec/models/legislation/annotation_spec.rb | 173 +++++++++++------- spec/models/legislation/question_spec.rb | 8 +- spec/models/officing/residence_spec.rb | 6 +- spec/models/poll/ballot_spec.rb | 4 +- spec/models/poll/shift_spec.rb | 27 ++- spec/models/proposal_spec.rb | 19 +- spec/models/related_content_spec.rb | 36 +++- spec/models/sdg/local_target_spec.rb | 8 +- spec/models/sdg/relatable_spec.rb | 5 +- spec/models/signature_sheet_spec.rb | 21 ++- spec/models/signature_spec.rb | 15 +- spec/models/user_spec.rb | 10 +- .../verification/management/document_spec.rb | 28 ++- .../verification/management/email_spec.rb | 34 +++- spec/models/verification/residence_spec.rb | 8 +- spec/shared/models/acts_as_paranoid.rb | 7 +- spec/shared/system/mappable.rb | 15 +- spec/shared/system/relationable.rb | 20 +- spec/shared/system/remotely_translatable.rb | 13 +- spec/support/matchers/be_rendered.rb | 3 +- spec/system/admin/budgets_spec.rb | 4 +- spec/system/admin/hidden_users_spec.rb | 4 +- spec/system/admin/machine_learning_spec.rb | 4 +- spec/system/admin/poll/shifts_spec.rb | 31 +++- spec/system/admin/signature_sheets_spec.rb | 6 +- spec/system/admin/widgets/cards_spec.rb | 4 +- spec/system/advanced_search_spec.rb | 8 +- spec/system/budgets/ballots_spec.rb | 3 +- spec/system/budgets/investments_spec.rb | 57 +++++- spec/system/budgets/results_spec.rb | 22 ++- spec/system/budgets/votes_spec.rb | 3 +- .../comments/budget_investments_spec.rb | 27 ++- spec/system/comments/debates_spec.rb | 4 +- .../comments/legislation_annotations_spec.rb | 36 +++- .../comments/legislation_questions_spec.rb | 9 +- spec/system/comments/polls_spec.rb | 4 +- spec/system/comments/proposals_spec.rb | 9 +- spec/system/comments/topics_spec.rb | 8 +- spec/system/debates_spec.rb | 19 +- spec/system/emails_spec.rb | 5 +- .../system/legislation/draft_versions_spec.rb | 84 ++++++--- spec/system/legislation/processes_spec.rb | 24 ++- spec/system/legislation/summary_spec.rb | 16 +- .../management/email_verifications_spec.rb | 3 +- spec/system/management/managed_users_spec.rb | 3 +- spec/system/moderation/comments_spec.rb | 10 +- spec/system/moderation/debates_spec.rb | 10 +- .../moderation/proposal_notifications_spec.rb | 27 ++- spec/system/moderation/proposals_spec.rb | 10 +- spec/system/official_positions_spec.rb | 4 +- spec/system/officing/ballot_sheets_spec.rb | 3 +- spec/system/officing/results_spec.rb | 4 +- spec/system/officing/voters_spec.rb | 5 +- spec/system/officing_spec.rb | 12 +- spec/system/polls/polls_spec.rb | 3 +- spec/system/polls/voter_spec.rb | 11 +- spec/system/proposals_spec.rb | 4 +- spec/system/sdg/goals_spec.rb | 3 +- spec/system/tags/budget_investments_spec.rb | 7 +- spec/system/topics_spec.rb | 9 +- spec/system/users_auth_spec.rb | 31 +++- spec/system/verification/letter_spec.rb | 6 +- .../level_three_verification_spec.rb | 6 +- .../verification/verification_path_spec.rb | 5 +- 156 files changed, 1330 insertions(+), 503 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1652ce3e3..894ed16da 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -120,7 +120,14 @@ Layout/LineEndStringConcatenationIndentation: Layout/LineLength: Max: 110 - Severity: refactor + Exclude: + - "Gemfile" + - "config/environments/production.rb" + - "config/environments/staging.rb" + - "config/initializers/devise.rb" + - "config/initializers/backtrace_silencers.rb" + - "db/migrate/*create_delayed_jobs.rb" + - "app/models/budget/stats.rb" Layout/MultilineArrayBraceLayout: Enabled: true diff --git a/app/components/admin/menu_component.rb b/app/components/admin/menu_component.rb index 21ffbc74d..4c91e926b 100644 --- a/app/components/admin/menu_component.rb +++ b/app/components/admin/menu_component.rb @@ -183,7 +183,8 @@ class Admin::MenuComponent < ApplicationComponent [ t("admin.menu.poll_booth_assignments"), booth_assignments_admin_polls_path, - controller_name == "polls" && action_name == "booth_assignments" || controller_name == "booth_assignments" && action_name == "manage" + controller_name == "polls" && action_name == "booth_assignments" || + controller_name == "booth_assignments" && action_name == "manage" ] end @@ -255,7 +256,8 @@ class Admin::MenuComponent < ApplicationComponent banners_link, information_texts_link, documents_link, - class: ("is-active" if customization? && controller.class.module_parent != Admin::Poll::Questions::Answers) + class: ("is-active" if customization? && + controller.class.module_parent != Admin::Poll::Questions::Answers) ) end diff --git a/app/components/budgets/investments/votes_component.rb b/app/components/budgets/investments/votes_component.rb index 2a8877db2..df885ae1a 100644 --- a/app/components/budgets/investments/votes_component.rb +++ b/app/components/budgets/investments/votes_component.rb @@ -64,7 +64,10 @@ class Budgets::Investments::VotesComponent < ApplicationComponent t("votes.budget_investments.#{reason}", count: investment.group.max_votable_headings, verify_account: link_to_verify_account, - supported_headings: (current_user && current_user.headings_voted_within_group(investment.group).map(&:name).sort.to_sentence)) + supported_headings: (current_user && current_user.headings_voted_within_group(investment.group) + .map(&:name) + .sort + .to_sentence)) end end end diff --git a/app/components/relationable/related_list_component.rb b/app/components/relationable/related_list_component.rb index f9622ccf4..e84bcd04e 100644 --- a/app/components/relationable/related_list_component.rb +++ b/app/components/relationable/related_list_component.rb @@ -13,6 +13,8 @@ class Relationable::RelatedListComponent < ApplicationComponent private def related_contents - @related_contents ||= Kaminari.paginate_array(relationable.relationed_contents).page(params[:page]).per(5) + @related_contents ||= Kaminari.paginate_array(relationable.relationed_contents) + .page(params[:page]) + .per(5) end end diff --git a/app/components/sdg/filter_links_component.rb b/app/components/sdg/filter_links_component.rb index 56aaa88f0..0af424fdc 100644 --- a/app/components/sdg/filter_links_component.rb +++ b/app/components/sdg/filter_links_component.rb @@ -33,7 +33,8 @@ class SDG::FilterLinksComponent < ApplicationComponent def index_by(advanced_search) if related_model.name == "Legislation::Proposal" - legislation_process_proposals_path(params[:id], advanced_search: advanced_search, filter: params[:filter]) + legislation_process_proposals_path(params[:id], advanced_search: advanced_search, + filter: params[:filter]) else polymorphic_path(related_model, advanced_search: advanced_search) end diff --git a/app/controllers/admin/api/stats_controller.rb b/app/controllers/admin/api/stats_controller.rb index e13fe7ebf..c882e0e01 100644 --- a/app/controllers/admin/api/stats_controller.rb +++ b/app/controllers/admin/api/stats_controller.rb @@ -22,7 +22,8 @@ class Admin::Api::StatsController < Admin::Api::BaseController end if params[:user_supported_budgets].present? - ds.add "User supported budgets", Vote.where(votable_type: "Budget::Investment").group_by_day(:updated_at).count + ds.add "User supported budgets", + Vote.where(votable_type: "Budget::Investment").group_by_day(:updated_at).count end render json: ds.build end diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index dc7e8cfe3..3b4d1a45f 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -10,7 +10,9 @@ module Budgets authorize_resource :budget authorize_resource :ballot - load_and_authorize_resource :line, through: :ballot, find_by: :investment_id, class: "Budget::Ballot::Line" + load_and_authorize_resource :line, through: :ballot, + find_by: :investment_id, + class: "Budget::Ballot::Line" def create load_investment diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index c192827c4..81bff7ff9 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -28,7 +28,8 @@ module Budgets has_orders %w[most_voted newest oldest], only: :show has_orders ->(c) { c.instance_variable_get(:@budget).investments_orders }, only: :index - has_filters ->(c) { c.instance_variable_get(:@budget).investments_filters }, only: [:index, :show, :suggest] + has_filters ->(c) { c.instance_variable_get(:@budget).investments_filters }, + only: [:index, :show, :suggest] invisible_captcha only: [:create, :update], honeypot: :subtitle, scope: :budget_investment @@ -79,12 +80,14 @@ module Budgets def destroy @investment.destroy! - redirect_to user_path(current_user, filter: "budget_investments"), notice: t("flash.actions.destroy.budget_investment") + redirect_to user_path(current_user, filter: "budget_investments"), + notice: t("flash.actions.destroy.budget_investment") end def suggest @resource_path_method = :namespaced_budget_investment_path - @resource_relation = resource_model.where(budget: @budget).apply_filters_and_search(@budget, params, @current_filter) + @resource_relation = resource_model.where(budget: @budget) + .apply_filters_and_search(@budget, params, @current_filter) super end diff --git a/app/controllers/concerns/admin/budget_headings_actions.rb b/app/controllers/concerns/admin/budget_headings_actions.rb index 1a1db8314..6e611e891 100644 --- a/app/controllers/concerns/admin/budget_headings_actions.rb +++ b/app/controllers/concerns/admin/budget_headings_actions.rb @@ -59,7 +59,8 @@ module Admin::BudgetHeadingsActions end def allowed_params - valid_attributes = [:price, :population, :allow_custom_content, :latitude, :longitude, :max_ballot_lines, :geozone_id] + valid_attributes = [:price, :population, :allow_custom_content, :latitude, :longitude, + :max_ballot_lines, :geozone_id] [*valid_attributes, translation_params(Budget::Heading)] end diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 1acb07778..86ea1dde8 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -7,7 +7,11 @@ module CommentableActions def index @resources = resource_model.all - @resources = @current_order == "recommendations" && current_user.present? ? @resources.recommendations(current_user) : @resources.for_render + @resources = if @current_order == "recommendations" && current_user.present? + @resources.recommendations(current_user) + else + @resources.for_render + end @resources = @resources.search(@search_terms) if @search_terms.present? @resources = @resources.filter_by(@advanced_search_terms) diff --git a/app/controllers/direct_uploads_controller.rb b/app/controllers/direct_uploads_controller.rb index c6856291f..c6b2a034c 100644 --- a/app/controllers/direct_uploads_controller.rb +++ b/app/controllers/direct_uploads_controller.rb @@ -8,7 +8,9 @@ class DirectUploadsController < ApplicationController helper_method :render_destroy_upload_link def create - @direct_upload = DirectUpload.new(direct_upload_params.merge(user: current_user, attachment: params[:attachment])) + @direct_upload = DirectUpload.new( + direct_upload_params.merge(user: current_user, attachment: params[:attachment]) + ) if @direct_upload.valid? @direct_upload.save_attachment diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index 4d68ac201..86b34bce0 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -30,7 +30,8 @@ class Legislation::ProposalsController < Legislation::BaseController @proposal = Legislation::Proposal.new(proposal_params.merge(author: current_user)) if @proposal.save - redirect_to legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t("flash.actions.create.proposal") + redirect_to legislation_process_proposal_path(params[:process_id], @proposal), + notice: I18n.t("flash.actions.create.proposal") else render :new end diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 867d6fc6a..c03ced8bb 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -37,7 +37,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController end def print - @investments = @investments.apply_filters_and_search(@budget, params).order(cached_votes_up: :desc).for_render.limit(15) + @investments = @investments.apply_filters_and_search(@budget, params) + .order(cached_votes_up: :desc) + .for_render + .limit(15) end private diff --git a/app/controllers/management/document_verifications_controller.rb b/app/controllers/management/document_verifications_controller.rb index 16d878c8e..0f5eabeae 100644 --- a/app/controllers/management/document_verifications_controller.rb +++ b/app/controllers/management/document_verifications_controller.rb @@ -15,7 +15,9 @@ class Management::DocumentVerificationsController < Management::BaseController elsif @document_verification.user? render :new elsif @document_verification.in_census? - redirect_to new_management_email_verification_path(email_verification: document_verification_params.to_h) + redirect_to new_management_email_verification_path( + email_verification: document_verification_params.to_h + ) else render :invalid_document end @@ -49,6 +51,8 @@ class Management::DocumentVerificationsController < Management::BaseController def clean_document_number return if params[:document_verification][:document_number].blank? - params[:document_verification][:document_number] = params[:document_verification][:document_number].gsub(/[^a-z0-9]+/i, "").upcase + params[:document_verification][:document_number] = params[:document_verification][:document_number] + .gsub(/[^a-z0-9]+/i, "") + .upcase end end diff --git a/app/controllers/management/proposals_controller.rb b/app/controllers/management/proposals_controller.rb index 371cbf4fd..83bfadb5c 100644 --- a/app/controllers/management/proposals_controller.rb +++ b/app/controllers/management/proposals_controller.rb @@ -31,7 +31,9 @@ class Management::ProposalsController < Management::BaseController super @notifications = @proposal.notifications - redirect_to management_proposal_path(@proposal), status: :moved_permanently if request.path != management_proposal_path(@proposal) + if request.path != management_proposal_path(@proposal) + redirect_to management_proposal_path(@proposal), status: :moved_permanently + end end def vote diff --git a/app/controllers/management/users_controller.rb b/app/controllers/management/users_controller.rb index 786f7b890..44c393143 100644 --- a/app/controllers/management/users_controller.rb +++ b/app/controllers/management/users_controller.rb @@ -24,7 +24,10 @@ class Management::UsersController < Management::BaseController end def erase - managed_user.erase(t("management.users.erased_by_manager", manager: current_manager["login"])) if current_manager.present? + if current_manager.present? + managed_user.erase(t("management.users.erased_by_manager", manager: current_manager["login"])) + end + destroy_session redirect_to management_document_verifications_path, notice: t("management.users.erased_notice") end diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb index 85e9813d2..e1fb05202 100644 --- a/app/controllers/officing/residence_controller.rb +++ b/app/controllers/officing/residence_controller.rb @@ -10,7 +10,8 @@ class Officing::ResidenceController < Officing::BaseController def create @residence = Officing::Residence.new(residence_params.merge(officer: current_user.poll_officer)) if @residence.save - redirect_to new_officing_voter_path(id: @residence.user.id), notice: t("officing.residence.flash.create") + redirect_to new_officing_voter_path(id: @residence.user.id), + notice: t("officing.residence.flash.create") else render :new end diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index 543607b0c..33b952d46 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -46,10 +46,12 @@ class Officing::ResultsController < Officing::BaseController answer = question.question_answers.find_by(given_order: answer_index.to_i + 1).title go_back_to_new if question.blank? - partial_result = ::Poll::PartialResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, - date: Date.current, - question_id: question_id, - answer: answer) + partial_result = ::Poll::PartialResult.find_or_initialize_by( + booth_assignment_id: @officer_assignment.booth_assignment_id, + date: Date.current, + question_id: question_id, + answer: answer + ) partial_result.officer_assignment_id = @officer_assignment.id partial_result.amount = count.to_i partial_result.author = current_user @@ -62,8 +64,10 @@ class Officing::ResultsController < Officing::BaseController end def build_recounts - recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, - date: Date.current) + recount = ::Poll::Recount.find_or_initialize_by( + booth_assignment_id: @officer_assignment.booth_assignment_id, + date: Date.current + ) recount.officer_assignment_id = @officer_assignment.id recount.author = current_user recount.origin = "booth" @@ -90,7 +94,9 @@ class Officing::ResultsController < Officing::BaseController def load_officer_assignment @officer_assignment = current_user.poll_officer - .officer_assignments.final.find_by(id: results_params[:officer_assignment_id]) + .officer_assignments + .final + .find_by(id: results_params[:officer_assignment_id]) end def load_officer_assignments diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 656df3e5e..5fb131053 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -137,7 +137,10 @@ class ProposalsController < ApplicationController def load_retired if params[:retired].present? @resources = @resources.retired - @resources = @resources.where(retired_reason: params[:retired]) if Proposal::RETIRE_OPTIONS.include?(params[:retired]) + + if Proposal::RETIRE_OPTIONS.include?(params[:retired]) + @resources = @resources.where(retired_reason: params[:retired]) + end else @resources = @resources.not_retired end @@ -152,7 +155,8 @@ class ProposalsController < ApplicationController end def load_featured - return unless !@advanced_search_terms && @search_terms.blank? && params[:retired].blank? && @current_order != "recommendations" + return unless !@advanced_search_terms && @search_terms.blank? && + params[:retired].blank? && @current_order != "recommendations" if Setting["feature.featured_proposals"] @featured_proposals = Proposal.not_archived diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 589de5e94..80b0c49ff 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -43,7 +43,8 @@ class Users::ConfirmationsController < Devise::ConfirmationsController yield resource if block_given? - # New condition added to if: when no password was given, display the "show" view (which uses "update" above) + # New condition added to if: when no password was given, display the "show" view + # (which uses "update" above) if resource.encrypted_password.blank? respond_with_navigational(resource) { render :show } elsif resource.errors.empty? @@ -51,9 +52,14 @@ class Users::ConfirmationsController < Devise::ConfirmationsController if resource.confirm set_flash_message(:notice, :confirmed) if is_flashing_format? - respond_with_navigational(resource) { redirect_to after_confirmation_path_for(resource_name, resource) } + + respond_with_navigational(resource) do + redirect_to after_confirmation_path_for(resource_name, resource) + end else - respond_with_navigational(resource.errors, status: :unprocessable_entity) { render :new, status: :unprocessable_entity } + respond_with_navigational(resource.errors, status: :unprocessable_entity) do + render :new, status: :unprocessable_entity + end end else respond_with_navigational(resource.errors, status: :unprocessable_entity) { render :new } diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index a5f2e9cac..b170b32a2 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,5 +1,6 @@ class Users::RegistrationsController < Devise::RegistrationsController - prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy, :finish_signup, :do_finish_signup] + prepend_before_action :authenticate_scope!, + only: [:edit, :update, :destroy, :finish_signup, :do_finish_signup] before_action :configure_permitted_parameters invisible_captcha only: [:create], honeypot: :address, scope: :user @@ -52,16 +53,21 @@ class Users::RegistrationsController < Devise::RegistrationsController def check_username if User.find_by username: params[:username] - render json: { available: false, message: t("devise_views.users.registrations.new.username_is_not_available") } + render json: { available: false, + message: t("devise_views.users.registrations.new.username_is_not_available") } else - render json: { available: true, message: t("devise_views.users.registrations.new.username_is_available") } + render json: { available: true, + message: t("devise_views.users.registrations.new.username_is_available") } end end private def sign_up_params - params[:user].delete(:redeemable_code) if params[:user].present? && params[:user][:redeemable_code].blank? + if params[:user].present? && params[:user][:redeemable_code].blank? + params[:user].delete(:redeemable_code) + end + params.require(:user).permit(allowed_params) end diff --git a/app/controllers/verification/email_controller.rb b/app/controllers/verification/email_controller.rb index 7a6d37c15..13abb1add 100644 --- a/app/controllers/verification/email_controller.rb +++ b/app/controllers/verification/email_controller.rb @@ -22,7 +22,8 @@ class Verification::EmailController < ApplicationController @email.encrypted_token, @verified_user.document_type, @verified_user.document_number).deliver_later - redirect_to account_path, notice: t("verification.email.create.flash.success", email: @verified_user.email) + redirect_to account_path, + notice: t("verification.email.create.flash.success", email: @verified_user.email) else redirect_to verified_user_path, alert: t("verification.email.create.alert.failure") end diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 06d855355..9f854ed55 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -20,8 +20,15 @@ module Types argument :id, ID, required: true, default_value: false end - field :proposal_notifications, Types::ProposalNotificationType.connection_type, "Returns all proposal notifications", null: false - field :proposal_notification, Types::ProposalNotificationType, "Returns proposal notification for ID", null: false do + field :proposal_notifications, + Types::ProposalNotificationType.connection_type, + "Returns all proposal notifications", + null: false + + field :proposal_notification, + Types::ProposalNotificationType, + "Returns proposal notification for ID", + null: false do argument :id, ID, required: true, default_value: false end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index b89b4533a..37aab7594 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -6,7 +6,10 @@ module AdminHelper def official_level_options options = [["", 0]] (1..5).each do |i| - options << [[t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(": "), i] + options << [ + [t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(": "), + i + ] end options end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index bb9015ea1..1bf679bb4 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -21,9 +21,17 @@ module CommentsHelper def comment_button_text(parent_id, commentable) if commentable.class == Legislation::Question - parent_id.present? ? t("comments_helper.reply_button") : t("legislation.questions.comments.comment_button") + if parent_id.present? + t("comments_helper.reply_button") + else + t("legislation.questions.comments.comment_button") + end else - parent_id.present? ? t("comments_helper.reply_button") : t("comments_helper.comment_button") + if parent_id.present? + t("comments_helper.reply_button") + else + t("comments_helper.comment_button") + end end end diff --git a/app/helpers/communities_helper.rb b/app/helpers/communities_helper.rb index 9d0cd61e4..e68eb8d72 100644 --- a/app/helpers/communities_helper.rb +++ b/app/helpers/communities_helper.rb @@ -8,7 +8,11 @@ module CommunitiesHelper end def community_description(community) - community.from_proposal? ? t("community.show.description.proposal") : t("community.show.description.investment") + if community.from_proposal? + t("community.show.description.proposal") + else + t("community.show.description.investment") + end end def author?(community, participant) @@ -28,7 +32,11 @@ module CommunitiesHelper end def community_access_text(community) - community.from_proposal? ? t("community.sidebar.description.proposal") : t("community.sidebar.description.investment") + if community.from_proposal? + t("community.sidebar.description.proposal") + else + t("community.sidebar.description.investment") + end end def create_topic_link(community) diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index 3ec9bfdc7..56e3b2dd0 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -49,7 +49,10 @@ module MailerHelper end def css_for_mailer_button - mailer_font_family + "background: #004a83;border-radius: 6px;color: #fff!important;display: inline-block;font-weight: bold;margin: 0;min-width: 200px;padding: 10px 15px;text-align: center;text-decoration: none;" + mailer_font_family + "background: #004a83;border-radius: 6px;color: #fff!important;" \ + "display: inline-block;font-weight: bold;margin: 0;" \ + "min-width: 200px;padding: 10px 15px;text-align: center;" \ + "text-decoration: none;" end def css_for_mailer_link diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index e5dccab2e..f2b82e8dc 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -2,7 +2,8 @@ module ProposalsHelper def progress_bar_percentage(proposal) case proposal.cached_votes_up when 0 then 0 - when 1..Proposal.votes_needed_for_success then (proposal.total_votes.to_f * 100 / Proposal.votes_needed_for_success).floor + when 1..Proposal.votes_needed_for_success + (proposal.total_votes.to_f * 100 / Proposal.votes_needed_for_success).floor else 100 end end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 324252a2a..2ac040969 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -11,7 +11,10 @@ class Mailer < ApplicationMailer manage_subscriptions_token(@commentable.author) with_user(@commentable.author) do - subject = t("mailers.comment.subject", commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase) + subject = t( + "mailers.comment.subject", + commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase + ) mail(to: @email_to, subject: subject) if @commentable.present? && @commentable.author.present? end end @@ -65,7 +68,8 @@ class Mailer < ApplicationMailer manage_subscriptions_token(user) with_user(user) do - mail(to: @email_to, subject: t("mailers.proposal_notification_digest.title", org_name: Setting["org_name"])) + mail(to: @email_to, + subject: t("mailers.proposal_notification_digest.title", org_name: Setting["org_name"])) end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 234d3c88b..cd5e4d3f0 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -49,8 +49,9 @@ module Abilities can :mark_featured, Debate can :unmark_featured, Debate - can :comment_as_administrator, [Debate, Comment, Proposal, Poll, Poll::Question, Budget::Investment, - Legislation::Question, Legislation::Proposal, Legislation::Annotation, Topic] + can :comment_as_administrator, [Debate, Comment, Proposal, Poll, Poll::Question, + Budget::Investment, Legislation::Question, + Legislation::Proposal, Legislation::Annotation, Topic] can [:search, :create, :index, :destroy, :update], ::Administrator can [:search, :create, :index, :destroy], ::Moderator @@ -121,7 +122,8 @@ module Abilities can [:manage], ::Legislation::DraftVersion can [:manage], ::Legislation::Question can [:manage], ::Legislation::Proposal - cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal] + cannot :comment_as_moderator, + [::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal] can [:create], Document can [:destroy], Document do |document| diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 2a1432354..fe96be60b 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -91,10 +91,10 @@ module Abilities can :vote, Legislation::Proposal can :create, Legislation::Answer - can :create, Budget::Investment, budget: { phase: "accepting" } - can :update, Budget::Investment, budget: { phase: "accepting" }, author_id: user.id - can :suggest, Budget::Investment, budget: { phase: "accepting" } - can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id + can :create, Budget::Investment, budget: { phase: "accepting" } + can :update, Budget::Investment, budget: { phase: "accepting" }, author_id: user.id + can :suggest, Budget::Investment, budget: { phase: "accepting" } + can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id can [:create, :destroy], ActsAsVotable::Vote, voter_id: user.id, votable_type: "Budget::Investment", diff --git a/app/models/abilities/moderator.rb b/app/models/abilities/moderator.rb index 9058c70a0..a8ef282a7 100644 --- a/app/models/abilities/moderator.rb +++ b/app/models/abilities/moderator.rb @@ -5,8 +5,9 @@ module Abilities def initialize(user) merge Abilities::Moderation.new(user) - can :comment_as_moderator, [Debate, Comment, Proposal, Budget::Investment, Poll, Poll::Question, - Legislation::Question, Legislation::Annotation, Legislation::Proposal, Topic] + can :comment_as_moderator, [Debate, Comment, Proposal, Budget::Investment, Poll, + Poll::Question, Legislation::Question, + Legislation::Annotation, Legislation::Proposal, Topic] end end end diff --git a/app/models/banner.rb b/app/models/banner.rb index 45f2ca916..9a8a1ebe4 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -21,5 +21,7 @@ class Banner < ApplicationRecord scope :with_active, -> { where("post_started_at <= :date and post_ended_at >= :date", date: Date.current) } scope :with_inactive, -> { where.not(id: with_active) } - scope :in_section, ->(section_name) { joins(:web_sections, :sections).where("web_sections.name ilike ?", section_name) } + scope :in_section, ->(section_name) do + joins(:web_sections, :sections).where("web_sections.name ilike ?", section_name) + end end diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb index 635f33499..8b0849a19 100644 --- a/app/models/budget/ballot/line.rb +++ b/app/models/budget/ballot/line.rb @@ -28,7 +28,8 @@ class Budget def check_valid_heading return if ballot.valid_heading?(heading) - errors.add(:heading, "This heading's budget is invalid, or a heading on the same group was already selected") + errors.add(:heading, + "This heading's budget is invalid, or a heading on the same group was already selected") end def check_selected diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index d0fd4e1d1..197fbccd7 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -56,7 +56,8 @@ class Budget class_name: "Comment" validates_translation :title, presence: true, length: { in: 4..Budget::Investment.title_max_length } - validates_translation :description, presence: true, length: { maximum: Budget::Investment.description_max_length } + validates_translation :description, presence: true, + length: { maximum: Budget::Investment.description_max_length } validates :author, presence: true validates :heading_id, presence: true @@ -104,7 +105,9 @@ class Budget scope :by_heading, ->(heading_id) { where(heading_id: heading_id) } scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) } scope :by_tag, ->(tag_name) { tagged_with(tag_name).distinct } - scope :visible_to_valuator, ->(valuator) { visible_to_valuators.where(id: valuator&.assigned_investment_ids) } + scope :visible_to_valuator, ->(valuator) do + visible_to_valuators.where(id: valuator&.assigned_investment_ids) + end scope :for_render, -> { includes(:heading) } diff --git a/app/models/concerns/filterable.rb b/app/models/concerns/filterable.rb index db676744c..92f419ef3 100644 --- a/app/models/concerns/filterable.rb +++ b/app/models/concerns/filterable.rb @@ -2,8 +2,10 @@ module Filterable extend ActiveSupport::Concern included do - scope :by_official_level, ->(official_level) { where(users: { official_level: official_level }).joins(:author) } - scope :by_date_range, ->(date_range) { where(created_at: date_range) } + scope :by_date_range, ->(date_range) { where(created_at: date_range) } + scope :by_official_level, ->(official_level) do + where(users: { official_level: official_level }).joins(:author) + end end class_methods do diff --git a/app/models/concerns/globalizable.rb b/app/models/concerns/globalizable.rb index 8961620e8..8b9ea9527 100644 --- a/app/models/concerns/globalizable.rb +++ b/app/models/concerns/globalizable.rb @@ -83,9 +83,10 @@ module Globalizable def validates_translation(method, options = {}) validates(method, options.merge(if: lambda { |resource| resource.translations.blank? })) if options.include?(:length) - lenght_validate = { length: options[:length] } translation_class.instance_eval do - validates method, lenght_validate.merge(if: lambda { |translation| translation.locale == I18n.default_locale }) + validates method, + length: options[:length], + if: lambda { |translation| translation.locale == I18n.default_locale } end if options.count > 1 translation_class.instance_eval do @@ -112,7 +113,9 @@ module Globalizable translations_ids = translation_class .select("DISTINCT ON (#{translations_foreign_key}) id") .where(locale: fallbacks) - .joins("LEFT JOIN (VALUES #{fallbacks_with_order}) AS locales(name, ordering) ON locale = locales.name") + .joins("LEFT JOIN (VALUES #{fallbacks_with_order}) " \ + "AS locales(name, ordering) " \ + "ON locale = locales.name") .order(translations_foreign_key, "locales.ordering") with_translations(fallbacks).where("#{translations_table_name}.id": translations_ids) diff --git a/app/models/concerns/verification.rb b/app/models/concerns/verification.rb index d775d5e96..563f2b6bb 100644 --- a/app/models/concerns/verification.rb +++ b/app/models/concerns/verification.rb @@ -9,10 +9,17 @@ module Verification scope :phone_not_fully_confirmed, -> { where(unconfirmed_phone: nil).or(where(confirmed_phone: nil)) } scope :level_three_verified, -> { where.not(verified_at: nil) } - scope :level_two_verified, -> { where.not(level_two_verified_at: nil).or(residence_and_phone_verified.where(verified_at: nil)) } + scope :level_two_verified, -> do + where.not(level_two_verified_at: nil).or(residence_and_phone_verified.where(verified_at: nil)) + end scope :level_two_or_three_verified, -> { level_two_verified.or(level_three_verified) } - scope :unverified, -> { residence_or_phone_unverified.where(verified_at: nil, level_two_verified_at: nil) } - scope :incomplete_verification, -> { residence_unverified.where("failed_census_calls_count > ?", 0).or(residence_verified.phone_not_fully_confirmed) } + scope :unverified, -> do + residence_or_phone_unverified.where(verified_at: nil, level_two_verified_at: nil) + end + scope :incomplete_verification, -> do + residence_unverified.where("failed_census_calls_count > ?", 0) + .or(residence_verified.phone_not_fully_confirmed) + end end def skip_verification? diff --git a/app/models/debate.rb b/app/models/debate.rb index 0606d6630..4316b4777 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -160,7 +160,11 @@ class Debate < ApplicationRecord def self.debates_orders(user) orders = %w[hot_score confidence_score created_at relevance] - orders << "recommendations" if Setting["feature.user.recommendations_on_debates"] && user&.recommended_debates + + if Setting["feature.user.recommendations_on_debates"] && user&.recommended_debates + orders << "recommendations" + end + orders end diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index e56138087..aeff35fcb 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -16,12 +16,15 @@ class DirectUpload send("#{name}=", value) end - if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?) + if @resource_type.present? && + @resource_relation.present? && + (@attachment.present? || @cached_attachment.present?) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) # Refactor @relation = if @resource.respond_to?(:images) && - ((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?) + (@attachment.present? && !@attachment.content_type.match(/pdf/) || + @cached_attachment.present?) @resource.images.send(:build, relation_attributtes) elsif @resource.class.reflections[@resource_relation].macro == :has_one @resource.send("build_#{resource_relation}", relation_attributtes) diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index c0ea91527..569544b6d 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -10,12 +10,19 @@ class Legislation::Question < ApplicationRecord belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :legislation_questions belongs_to :process, foreign_key: "legislation_process_id", inverse_of: :questions - has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_id", - dependent: :destroy, inverse_of: :question - has_many :answers, class_name: "Legislation::Answer", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question + has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", + foreign_key: "legislation_question_id", + dependent: :destroy, + inverse_of: :question + has_many :answers, class_name: "Legislation::Answer", + foreign_key: "legislation_question_id", + dependent: :destroy, + inverse_of: :question has_many :comments, as: :commentable, inverse_of: :commentable, dependent: :destroy - accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true + accepts_nested_attributes_for :question_options, + reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, + allow_destroy: true validates :process, presence: true validates_translation :title, presence: true diff --git a/app/models/machine_learning.rb b/app/models/machine_learning.rb index 35182cc95..bfe8bb33d 100644 --- a/app/models/machine_learning.rb +++ b/app/models/machine_learning.rb @@ -22,13 +22,15 @@ class MachineLearning return unless run_machine_learning_scripts - if updated_file?(MachineLearning.proposals_taggings_filename) && updated_file?(MachineLearning.proposals_tags_filename) + if updated_file?(MachineLearning.proposals_taggings_filename) && + updated_file?(MachineLearning.proposals_tags_filename) cleanup_proposals_tags! import_ml_proposals_tags update_machine_learning_info_for("tags") end - if updated_file?(MachineLearning.investments_taggings_filename) && updated_file?(MachineLearning.investments_tags_filename) + if updated_file?(MachineLearning.investments_taggings_filename) && + updated_file?(MachineLearning.investments_tags_filename) cleanup_investments_tags! import_ml_investments_tags update_machine_learning_info_for("tags") @@ -95,14 +97,32 @@ class MachineLearning def data_output_files files = { tags: [], related_content: [], comments_summary: [] } - files[:tags] << proposals_tags_filename if File.exist?(data_folder.join(proposals_tags_filename)) - files[:tags] << proposals_taggings_filename if File.exist?(data_folder.join(proposals_taggings_filename)) - files[:tags] << investments_tags_filename if File.exist?(data_folder.join(investments_tags_filename)) - files[:tags] << investments_taggings_filename if File.exist?(data_folder.join(investments_taggings_filename)) - files[:related_content] << proposals_related_filename if File.exist?(data_folder.join(proposals_related_filename)) - files[:related_content] << investments_related_filename if File.exist?(data_folder.join(investments_related_filename)) - files[:comments_summary] << proposals_comments_summary_filename if File.exist?(data_folder.join(proposals_comments_summary_filename)) - files[:comments_summary] << investments_comments_summary_filename if File.exist?(data_folder.join(investments_comments_summary_filename)) + if File.exist?(data_folder.join(proposals_tags_filename)) + files[:tags] << proposals_tags_filename + end + if File.exist?(data_folder.join(proposals_taggings_filename)) + files[:tags] << proposals_taggings_filename + end + if File.exist?(data_folder.join(investments_tags_filename)) + files[:tags] << investments_tags_filename + end + if File.exist?(data_folder.join(investments_taggings_filename)) + files[:tags] << investments_taggings_filename + end + + if File.exist?(data_folder.join(proposals_related_filename)) + files[:related_content] << proposals_related_filename + end + if File.exist?(data_folder.join(investments_related_filename)) + files[:related_content] << investments_related_filename + end + + if File.exist?(data_folder.join(proposals_comments_summary_filename)) + files[:comments_summary] << proposals_comments_summary_filename + end + if File.exist?(data_folder.join(investments_comments_summary_filename)) + files[:comments_summary] << investments_comments_summary_filename + end files end diff --git a/app/models/organization.rb b/app/models/organization.rb index 436521fd4..e311e1622 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -12,8 +12,13 @@ class Organization < ApplicationRecord delegate :email, :phone_number, to: :user scope :pending, -> { where(verified_at: nil, rejected_at: nil) } - scope :verified, -> { where.not(verified_at: nil).where("(rejected_at IS NULL or rejected_at < organizations.verified_at)") } - scope :rejected, -> { where.not(rejected_at: nil).where("(organizations.verified_at IS NULL or organizations.verified_at < rejected_at)") } + scope :verified, -> do + where.not(verified_at: nil).where("(rejected_at IS NULL or rejected_at < organizations.verified_at)") + end + scope :rejected, -> do + where.not(rejected_at: nil) + .where("(organizations.verified_at IS NULL or organizations.verified_at < rejected_at)") + end def verify update(verified_at: Time.current) @@ -33,7 +38,8 @@ class Organization < ApplicationRecord def self.search(text) if text.present? - joins(:user).where("users.email = ? OR users.phone_number = ? OR organizations.name ILIKE ?", text, text, "%#{text}%") + joins(:user).where("users.email = ? OR users.phone_number = ? OR organizations.name ILIKE ?", + text, text, "%#{text}%") else none end diff --git a/app/models/poll.rb b/app/models/poll.rb index 866605117..1ceff3b7b 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -57,7 +57,8 @@ class Poll < ApplicationRecord def self.sort_for_list(user = nil) all.sort do |poll, another_poll| - [poll.weight(user), poll.starts_at, poll.name] <=> [another_poll.weight(user), another_poll.starts_at, another_poll.name] + [poll.weight(user), poll.starts_at, poll.name] <=> + [another_poll.weight(user), another_poll.starts_at, another_poll.name] end end diff --git a/app/models/poll/booth_assignment.rb b/app/models/poll/booth_assignment.rb index 3af585e77..37132be73 100644 --- a/app/models/poll/booth_assignment.rb +++ b/app/models/poll/booth_assignment.rb @@ -24,7 +24,9 @@ class Poll private def shifts - Poll::Shift.where(booth_id: booth_id, officer_id: officer_assignments.pluck(:officer_id), date: officer_assignments.pluck(:date)) + Poll::Shift.where(booth_id: booth_id, + officer_id: officer_assignments.pluck(:officer_id), + date: officer_assignments.pluck(:date)) end def destroy_poll_shifts diff --git a/app/models/poll/recount.rb b/app/models/poll/recount.rb index 578956692..5e1692792 100644 --- a/app/models/poll/recount.rb +++ b/app/models/poll/recount.rb @@ -20,7 +20,9 @@ class Poll::Recount < ApplicationRecord amounts_changed = false [:white, :null, :total].each do |amount| - next unless send("will_save_change_to_#{amount}_amount?") && send("#{amount}_amount_in_database").present? + unless send("will_save_change_to_#{amount}_amount?") && send("#{amount}_amount_in_database").present? + next + end self["#{amount}_amount_log"] += ":#{send("#{amount}_amount_in_database")}" amounts_changed = true diff --git a/app/models/progress_bar.rb b/app/models/progress_bar.rb index 59d051da1..c966f6c9f 100644 --- a/app/models/progress_bar.rb +++ b/app/models/progress_bar.rb @@ -16,7 +16,10 @@ class ProgressBar < ApplicationRecord scope: [:progressable_type, :progressable_id], conditions: -> { primary } } - validates :percentage, presence: true, inclusion: { in: ->(*) { RANGE }}, numericality: { only_integer: true } + validates :percentage, + presence: true, + inclusion: { in: ->(*) { RANGE }}, + numericality: { only_integer: true } validates_translation :title, presence: true, unless: :primary? end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 3ec643b4f..c680cdc0b 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -50,8 +50,12 @@ class Proposal < ApplicationRecord validates :author, presence: true validates :responsible_name, presence: true, unless: :skip_user_verification? - validates :responsible_name, length: { in: 6..Proposal.responsible_name_max_length }, unless: :skip_user_verification? - validates :retired_reason, presence: true, inclusion: { in: ->(*) { RETIRE_OPTIONS }}, unless: -> { retired_at.blank? } + validates :responsible_name, + length: { in: 6..Proposal.responsible_name_max_length }, + unless: :skip_user_verification? + validates :retired_reason, + presence: true, + inclusion: { in: ->(*) { RETIRE_OPTIONS }}, unless: -> { retired_at.blank? } validates :terms_of_service, acceptance: { allow_nil: false }, on: :create @@ -236,7 +240,11 @@ class Proposal < ApplicationRecord def self.proposals_orders(user) orders = %w[hot_score confidence_score created_at relevance archival_date] - orders << "recommendations" if Setting["feature.user.recommendations_on_proposals"] && user&.recommended_proposals + + if Setting["feature.user.recommendations_on_proposals"] && user&.recommended_proposals + orders << "recommendations" + end + orders end diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index 77ebde6f9..5579fd728 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -31,7 +31,11 @@ class ProposalNotification < ApplicationRecord interval = Setting[:proposal_notification_minimum_interval_in_days] minimum_interval = (Time.current - interval.to_i.days).to_datetime if proposal.notifications.last.created_at > minimum_interval - errors.add(:title, I18n.t("activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid", interval: interval)) + errors.add( + :title, + I18n.t("activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid", + interval: interval) + ) end end diff --git a/app/models/related_content.rb b/app/models/related_content.rb index abd45fe51..7a88f960f 100644 --- a/app/models/related_content.rb +++ b/app/models/related_content.rb @@ -11,7 +11,10 @@ class RelatedContent < ApplicationRecord has_one :opposite_related_content, class_name: name, foreign_key: :related_content_id has_many :related_content_scores, dependent: :destroy - validates :parent_relationable_id, uniqueness: { scope: [:parent_relationable_type, :child_relationable_id, :child_relationable_type] } + validates :parent_relationable_id, + uniqueness: { + scope: [:parent_relationable_type, :child_relationable_id, :child_relationable_type] + } validate :different_parent_and_child after_create :create_opposite_related_content, unless: proc { opposite_related_content.present? } @@ -66,7 +69,10 @@ class RelatedContent < ApplicationRecord def score(value, user) score_with_opposite(value, user) - hide_with_opposite if (related_content_scores.sum(:value) / related_content_scores_count) < RELATED_CONTENT_SCORE_THRESHOLD + + if (related_content_scores.sum(:value) / related_content_scores_count) < RELATED_CONTENT_SCORE_THRESHOLD + hide_with_opposite + end end def hide_with_opposite diff --git a/app/models/signature.rb b/app/models/signature.rb index bec7d7f39..8576916ae 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -28,7 +28,9 @@ class Signature < ApplicationRecord def assign_vote_to_user set_user if signable.is_a? Budget::Investment - signable.vote_by(voter: user, vote: "yes") if [nil, :no_selecting_allowed].include?(signable.reason_for_not_being_selectable_by(user)) + if [nil, :no_selecting_allowed].include?(signable.reason_for_not_being_selectable_by(user)) + signable.vote_by(voter: user, vote: "yes") + end else signable.register_vote(user, "yes") end diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index fbda50b8f..cb1c1bc82 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -53,10 +53,12 @@ class Verification::Management::Email return if errors.count > 0 if document_number_mismatch? - errors.add(:email, - I18n.t("management.email_verifications.document_mismatch", - document_type: ApplicationController.helpers.humanize_document_type(user.document_type), - document_number: user.document_number)) + errors.add( + :email, + I18n.t("management.email_verifications.document_mismatch", + document_type: ApplicationController.helpers.humanize_document_type(user.document_type), + document_number: user.document_number) + ) end end diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index f266ed0db..d52e56476 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -48,7 +48,9 @@ class Verification::Residence end def document_number_uniqueness - errors.add(:document_number, I18n.t("errors.messages.taken")) if User.active.where(document_number: document_number).any? + if User.active.where(document_number: document_number).any? + errors.add(:document_number, I18n.t("errors.messages.taken")) + end end def store_failed_attempt @@ -74,7 +76,8 @@ class Verification::Residence end def local_postal_code - errors.add(:postal_code, I18n.t("verification.residence.new.error_not_allowed_postal_code")) unless valid_postal_code? + errors.add(:postal_code, + I18n.t("verification.residence.new.error_not_allowed_postal_code")) unless valid_postal_code? end def local_residence diff --git a/app/views/legislation/processes/summary.xlsx.axlsx b/app/views/legislation/processes/summary.xlsx.axlsx index a36ddd338..675904189 100644 --- a/app/views/legislation/processes/summary.xlsx.axlsx +++ b/app/views/legislation/processes/summary.xlsx.axlsx @@ -4,11 +4,19 @@ xlsx_package.workbook.add_worksheet(name: "Summary") do |sheet| link = styles.add_style(fg_color: "0000FF", u: true) if @process.debate_phase.enabled? && @process.questions.any? - sheet.add_row [t("legislation.summary.debate_phase"), t("legislation.summary.debates", count: @process.questions.count)], style: title + sheet.add_row( + [ + t("legislation.summary.debate_phase"), + t("legislation.summary.debates", count: @process.questions.count) + ], + style: title + ) @process.questions.each do |question| sheet.add_row [question.title, t("shared.comments", count: question.comments.count)], style: link - sheet.add_hyperlink location: legislation_process_question_url(question.process, question), ref: sheet.rows.last.cells.first - sheet.add_hyperlink location: polymorphic_url(question, anchor: "comments"), ref: sheet.rows.last.cells.last + sheet.add_hyperlink location: legislation_process_question_url(question.process, question), + ref: sheet.rows.last.cells.first + sheet.add_hyperlink location: polymorphic_url(question, anchor: "comments"), + ref: sheet.rows.last.cells.last sheet.add_row [t("legislation.summary.most_voted_comments")] if question.best_comments.any? question.best_comments.each do |comment| sheet.add_row [comment.body, t("legislation.summary.votes", count: comment.votes_score)] @@ -20,22 +28,37 @@ xlsx_package.workbook.add_worksheet(name: "Summary") do |sheet| end if @process.proposals_phase.enabled? && @proposals.any? - sheet.add_row [t("legislation.summary.proposals_phase"), t("legislation.summary.proposals", count: @proposals.count)], style: title + sheet.add_row( + [ + t("legislation.summary.proposals_phase"), + t("legislation.summary.proposals", count: @proposals.count) + ], + style: title + ) @proposals.sort_by_supports.each do |proposal| sheet.add_row [proposal.title, t("legislation.summary.votes", count: proposal.votes_score)] - sheet.add_hyperlink location: legislation_process_proposal_url(proposal.legislation_process_id, proposal), ref: sheet.rows.last.cells.first + sheet.add_hyperlink( + location: legislation_process_proposal_url(proposal.legislation_process_id, proposal), + ref: sheet.rows.last.cells.first + ) sheet.rows.last.cells.first.style = link end sheet.add_row ["", ""] end if @process.allegations_phase.enabled? && @comments.any? - sheet.add_row [t("legislation.summary.allegations_phase"), - t("legislation.summary.top_comments", count: @comments.count)], style: title + sheet.add_row( + [ + t("legislation.summary.allegations_phase"), + t("legislation.summary.top_comments", count: @comments.count) + ], + style: title + ) @comments.group_by(&:commentable).each do |annotation, annotation_comments| sheet.add_row [t("legislation.annotations.index.comments_about")] sheet.add_row [annotation.quote, t("shared.comments", count: annotation.comments.count)] - sheet.add_hyperlink location: polymorphic_url(annotation, anchor: "comments"), ref: sheet.rows.last.cells.last + sheet.add_hyperlink location: polymorphic_url(annotation, anchor: "comments"), + ref: sheet.rows.last.cells.last sheet.rows.last.cells.last.style = link annotation_comments.each do |comment| diff --git a/config/deploy.rb b/config/deploy.rb index 92b8abd24..fc60ff594 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -30,7 +30,8 @@ set :pty, true set :use_sudo, false set :linked_files, %w[config/database.yml config/secrets.yml] -set :linked_dirs, %w[.bundle log tmp public/system public/assets public/ckeditor_assets public/machine_learning/data storage] +set :linked_dirs, %w[.bundle log tmp public/system public/assets + public/ckeditor_assets public/machine_learning/data storage] set :keep_releases, 5 diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 511699f4b..cda7ae581 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -99,7 +99,8 @@ Apartment.configure do |config| # # config.pg_excluded_names = ["uuid_generate_v4"] - # Specifies whether the database and schema (when using PostgreSQL schemas) will prepend in ActiveRecord log. + # Specifies whether the database and schema (when using PostgreSQL schemas) + # will prepend in ActiveRecord log. # Uncomment the line below if you want to enable this behavior. # # config.active_record_log = true @@ -107,9 +108,9 @@ end # Setup a custom Tenant switching middleware. The Proc should return the name of the Tenant that # you want to switch to. -Rails.application.config.middleware.insert_before Warden::Manager, Apartment::Elevators::Generic, ->(request) do - Tenant.resolve_host(request.host) -end +Rails.application.config.middleware.insert_before Warden::Manager, + Apartment::Elevators::Generic, + ->(request) { Tenant.resolve_host(request.host) } # Rails.application.config.middleware.use Apartment::Elevators::Domain # Rails.application.config.middleware.use Apartment::Elevators::Subdomain diff --git a/config/initializers/devise-security.rb b/config/initializers/devise-security.rb index ce6877365..6de4d3f80 100644 --- a/config/initializers/devise-security.rb +++ b/config/initializers/devise-security.rb @@ -63,7 +63,11 @@ module Devise if !new_record? && !encrypted_password_change.nil? && !erased? dummy = self.class.new dummy.encrypted_password = encrypted_password_change.first - dummy.password_salt = password_salt_change.first if respond_to?(:password_salt_change) && !password_salt_change.nil? + + if respond_to?(:password_salt_change) && !password_salt_change.nil? + dummy.password_salt = password_salt_change.first + end + errors.add(:password, :equal_to_current_password) if dummy.valid_password?(password) end end diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 2fa509e36..7d97f99e3 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -253,9 +253,12 @@ namespace :admin do end resources :images, only: [:index, :update, :destroy] resources :content_blocks, except: [:show] - delete "/heading_content_blocks/:id", to: "content_blocks#delete_heading_content_block", as: "delete_heading_content_block" - get "/edit_heading_content_blocks/:id", to: "content_blocks#edit_heading_content_block", as: "edit_heading_content_block" - put "/update_heading_content_blocks/:id", to: "content_blocks#update_heading_content_block", as: "update_heading_content_block" + delete "/heading_content_blocks/:id", to: "content_blocks#delete_heading_content_block", + as: "delete_heading_content_block" + get "/edit_heading_content_blocks/:id", to: "content_blocks#edit_heading_content_block", + as: "edit_heading_content_block" + put "/update_heading_content_blocks/:id", to: "content_blocks#update_heading_content_block", + as: "update_heading_content_block" resources :information_texts, only: [:index] do post :update, on: :collection end diff --git a/db/dev_seeds/geozones.rb b/db/dev_seeds/geozones.rb index d608435d0..02f09499f 100644 --- a/db/dev_seeds/geozones.rb +++ b/db/dev_seeds/geozones.rb @@ -2,23 +2,28 @@ section "Creating Geozones" do Geozone.create!(name: I18n.t("seeds.geozones.north_district"), external_code: "001", census_code: "01", html_map_coordinates: "30,139,45,153,77,148,107,165,138,201,146,218,186,198,216," \ - "196,233,203,240,215,283,194,329,185,377,184,388,165,369,126,333,113,334,84,320," \ - "66,286,73,258,65,265,57,249,47,207,58,159,84,108,85,72,101,51,114") + "196,233,203,240,215,283,194,329,185,377,184,388,165,369," \ + "126,333,113,334,84,320,66,286,73,258,65,265,57,249,47," \ + "207,58,159,84,108,85,72,101,51,114") Geozone.create!(name: I18n.t("seeds.geozones.west_district"), external_code: "002", census_code: "02", html_map_coordinates: "42,153,31,176,24,202,20,221,44,235,59,249,55,320,30,354," \ - "31,372,52,396,64,432,89,453,116,432,149,419,162,412,165,377,172,357,189,352,228," \ - "327,246,313,262,297,234,291,210,284,193,284,176,294,158,303,154,310,146,289,140," \ - "268,138,246,135,236,139,222,151,214,136,197,120,179,99,159,85,149,65,149,56,149") + "31,372,52,396,64,432,89,453,116,432,149,419,162,412,165," \ + "377,172,357,189,352,228,327,246,313,262,297,234,291,210," \ + "284,193,284,176,294,158,303,154,310,146,289,140,268,138," \ + "246,135,236,139,222,151,214,136,197,120,179,99,159,85," \ + "149,65,149,56,149") Geozone.create!(name: I18n.t("seeds.geozones.east_district"), external_code: "003", census_code: "03", html_map_coordinates: "175,353,162,378,161,407,153,416,167,432,184,447,225,426," \ - "250,409,283,390,298,369,344,363,351,334,356,296,361,267,376,245,378,185,327,188," \ - "281,195,239,216,245,221,245,232,261,244,281,238,300,242,304,251,285,262,278,277," \ - "267,294,249,312,219,333,198,346,184,353") + "250,409,283,390,298,369,344,363,351,334,356,296,361,267," \ + "376,245,378,185,327,188,281,195,239,216,245,221,245,232," \ + "261,244,281,238,300,242,304,251,285,262,278,277,267,294," \ + "249,312,219,333,198,346,184,353") Geozone.create!(name: I18n.t("seeds.geozones.central_district"), external_code: "004", census_code: "04", html_map_coordinates: "152,308,137,258,133,235,147,216,152,214,186,194,210,196," \ - "228,202,240,216,241,232,263,243,293,241,301,245,302,254,286,265,274,278,267,296," \ - "243,293,226,289,209,285,195,283,177,297") + "228,202,240,216,241,232,263,243,293,241,301,245,302,254," \ + "286,265,274,278,267,296,243,293,226,289,209,285,195,283," \ + "177,297") end diff --git a/db/migrate/20150820103351_create_inappropiate_flags.rb b/db/migrate/20150820103351_create_inappropiate_flags.rb index 265bfdda5..4f4ad06c8 100644 --- a/db/migrate/20150820103351_create_inappropiate_flags.rb +++ b/db/migrate/20150820103351_create_inappropiate_flags.rb @@ -10,6 +10,7 @@ class CreateInappropiateFlags < ActiveRecord::Migration[4.2] end add_index :inappropiate_flags, [:flaggable_type, :flaggable_id] - add_index :inappropiate_flags, [:user_id, :flaggable_type, :flaggable_id], name: "access_inappropiate_flags" + add_index :inappropiate_flags, [:user_id, :flaggable_type, :flaggable_id], + name: "access_inappropiate_flags" end end diff --git a/db/migrate/20171127171925_create_related_content.rb b/db/migrate/20171127171925_create_related_content.rb index 380104342..e9707016f 100644 --- a/db/migrate/20171127171925_create_related_content.rb +++ b/db/migrate/20171127171925_create_related_content.rb @@ -1,12 +1,19 @@ class CreateRelatedContent < ActiveRecord::Migration[4.2] def change create_table :related_contents do |t| - t.references :parent_relationable, polymorphic: true, index: { name: "index_related_contents_on_parent_relationable" } - t.references :child_relationable, polymorphic: true, index: { name: "index_related_contents_on_child_relationable" } + t.references :parent_relationable, polymorphic: true, + index: { name: "index_related_contents_on_parent_relationable" } + t.references :child_relationable, polymorphic: true, + index: { name: "index_related_contents_on_child_relationable" } t.references :related_content, index: { name: "opposite_related_content" } t.timestamps end - add_index :related_contents, [:parent_relationable_id, :parent_relationable_type, :child_relationable_id, :child_relationable_type], name: "unique_parent_child_related_content", unique: true, using: :btree + add_index :related_contents, + [:parent_relationable_id, :parent_relationable_type, + :child_relationable_id, :child_relationable_type], + name: "unique_parent_child_related_content", + unique: true, + using: :btree end end diff --git a/db/migrate/20171219184209_create_related_content_scores.rb b/db/migrate/20171219184209_create_related_content_scores.rb index c5136cbfc..16f8ca473 100644 --- a/db/migrate/20171219184209_create_related_content_scores.rb +++ b/db/migrate/20171219184209_create_related_content_scores.rb @@ -6,6 +6,10 @@ class CreateRelatedContentScores < ActiveRecord::Migration[4.2] t.integer :value end - add_index :related_content_scores, [:user_id, :related_content_id], name: "unique_user_related_content_scoring", unique: true, using: :btree + add_index :related_content_scores, + [:user_id, :related_content_id], + name: "unique_user_related_content_scoring", + unique: true, + using: :btree end end diff --git a/db/migrate/20180723102010_rename_administrator_task_to_dashboard_administrator_task.rb b/db/migrate/20180723102010_rename_administrator_task_to_dashboard_administrator_task.rb index 59ce79074..92c2091d3 100644 --- a/db/migrate/20180723102010_rename_administrator_task_to_dashboard_administrator_task.rb +++ b/db/migrate/20180723102010_rename_administrator_task_to_dashboard_administrator_task.rb @@ -1,6 +1,8 @@ class RenameAdministratorTaskToDashboardAdministratorTask < ActiveRecord::Migration[4.2] def change - rename_index :administrator_tasks, "index_administrator_tasks_on_source_type_and_source_id", "index_dashboard_administrator_tasks_on_source" + rename_index :administrator_tasks, + "index_administrator_tasks_on_source_type_and_source_id", + "index_dashboard_administrator_tasks_on_source" rename_table :administrator_tasks, :dashboard_administrator_tasks end end diff --git a/db/migrate/20190423072214_create_legislation_people_proposals_table.rb b/db/migrate/20190423072214_create_legislation_people_proposals_table.rb index 09485fb9c..5ae6628a3 100644 --- a/db/migrate/20190423072214_create_legislation_people_proposals_table.rb +++ b/db/migrate/20190423072214_create_legislation_people_proposals_table.rb @@ -29,6 +29,9 @@ class CreateLegislationPeopleProposalsTable < ActiveRecord::Migration[4.2] t.boolean "validated" t.integer "cached_votes_score", default: 0 end - add_index "legislation_people_proposals", ["cached_votes_score"], name: "index_legislation_people_proposals_on_cached_votes_score", using: :btree + add_index "legislation_people_proposals", + ["cached_votes_score"], + name: "index_legislation_people_proposals_on_cached_votes_score", + using: :btree end end diff --git a/db/migrate/20201117200945_create_sdg_relations.rb b/db/migrate/20201117200945_create_sdg_relations.rb index 55415c78c..054aabd27 100644 --- a/db/migrate/20201117200945_create_sdg_relations.rb +++ b/db/migrate/20201117200945_create_sdg_relations.rb @@ -4,7 +4,9 @@ class CreateSDGRelations < ActiveRecord::Migration[5.2] t.references :related_sdg, polymorphic: true t.references :relatable, polymorphic: true - t.index [:related_sdg_id, :related_sdg_type, :relatable_id, :relatable_type], name: "sdg_relations_unique", unique: true + t.index [:related_sdg_id, :related_sdg_type, :relatable_id, :relatable_type], + name: "sdg_relations_unique", + unique: true t.timestamps end diff --git a/db/migrate/20210619201902_create_active_storage_tables.active_storage.rb b/db/migrate/20210619201902_create_active_storage_tables.active_storage.rb index ce71f5783..1aeb2879a 100644 --- a/db/migrate/20210619201902_create_active_storage_tables.active_storage.rb +++ b/db/migrate/20210619201902_create_active_storage_tables.active_storage.rb @@ -20,7 +20,9 @@ class CreateActiveStorageTables < ActiveRecord::Migration[5.2] t.datetime :created_at, null: false - t.index [:record_type, :record_id, :name, :blob_id], name: "index_active_storage_attachments_uniqueness", unique: true + t.index [:record_type, :record_id, :name, :blob_id], + name: "index_active_storage_attachments_uniqueness", + unique: true t.foreign_key :active_storage_blobs, column: :blob_id end end diff --git a/lib/manager_authenticator.rb b/lib/manager_authenticator.rb index fbe1ccab8..d0521aa96 100644 --- a/lib/manager_authenticator.rb +++ b/lib/manager_authenticator.rb @@ -1,6 +1,10 @@ class ManagerAuthenticator def initialize(data = {}) - @manager = { login: data[:login], user_key: data[:clave_usuario], date: data[:fecha_conexion] }.with_indifferent_access + @manager = { + login: data[:login], + user_key: data[:clave_usuario], + date: data[:fecha_conexion] + }.with_indifferent_access end def auth @@ -13,7 +17,11 @@ class ManagerAuthenticator private def manager_exists? - response = client.call(:get_status_user_data, message: { ub: { user_key: @manager[:user_key], date: @manager[:date] }}).body + response = client.call( + :get_status_user_data, + message: { ub: { user_key: @manager[:user_key], date: @manager[:date] }} + ).body + parsed_response = parser.parse((response[:get_status_user_data_response][:get_status_user_data_return])) @manager[:login] == parsed_response["USUARIO"]["LOGIN"] rescue @@ -21,13 +29,17 @@ class ManagerAuthenticator end def application_authorized? - response = client.call(:get_applications_user_list, message: { ub: { user_key: @manager[:user_key] }}).body + response = client.call( + :get_applications_user_list, + message: { ub: { user_key: @manager[:user_key] }} + ).body + user_list_return = response[:get_applications_user_list_response][:get_applications_user_list_return] parsed_response = parser.parse(user_list_return) - aplication_value = parsed_response["APLICACIONES"]["APLICACION"] # aplication_value from UWEB can be an array of hashes or a hash - aplication_value.include?("CLAVE_APLICACION" => application_key) || aplication_value["CLAVE_APLICACION"] == application_key + aplication_value.include?("CLAVE_APLICACION" => application_key) || + aplication_value["CLAVE_APLICACION"] == application_key rescue false end diff --git a/spec/components/account/permissions_list_component_spec.rb b/spec/components/account/permissions_list_component_spec.rb index c8d30f5a7..30b047919 100644 --- a/spec/components/account/permissions_list_component_spec.rb +++ b/spec/components/account/permissions_list_component_spec.rb @@ -11,7 +11,8 @@ describe Account::PermissionsListComponent do it "adds a hint when an action cannot be performed" do render_inline Account::PermissionsListComponent.new(User.new) - expect(page).to have_css "li", exact_text: "Additional verification needed Support proposals", normalize_ws: true + expect(page).to have_css "li", exact_text: "Additional verification needed Support proposals", + normalize_ws: true expect(page).to have_css "li", exact_text: "Participate in debates", normalize_ws: true end end diff --git a/spec/components/admin/budget_headings/form_component_spec.rb b/spec/components/admin/budget_headings/form_component_spec.rb index 11ade0905..8a032b9c7 100644 --- a/spec/components/admin/budget_headings/form_component_spec.rb +++ b/spec/components/admin/budget_headings/form_component_spec.rb @@ -26,7 +26,8 @@ describe Admin::BudgetHeadings::FormComponent do render_inline component - expect(page).to have_select "Scope of operation", options: ["All city", "Under the sea", "Above the skies"] + expect(page).to have_select "Scope of operation", + options: ["All city", "Under the sea", "Above the skies"] end end end diff --git a/spec/components/admin/geozones/index_component_spec.rb b/spec/components/admin/geozones/index_component_spec.rb index dc5b7e1e9..75c32f529 100644 --- a/spec/components/admin/geozones/index_component_spec.rb +++ b/spec/components/admin/geozones/index_component_spec.rb @@ -6,7 +6,9 @@ describe Admin::Geozones::IndexComponent, :admin do geozones = [ create(:geozone, :with_geojson, name: "GeoJSON", external_code: "1", census_code: "2"), create(:geozone, :with_html_coordinates, name: "HTML", external_code: "3", census_code: "4"), - create(:geozone, :with_geojson, :with_html_coordinates, name: "With both", external_code: "6", census_code: "7"), + create(:geozone, :with_geojson, :with_html_coordinates, name: "With both", + external_code: "6", + census_code: "7"), create(:geozone, name: "With none", external_code: "8", census_code: "9") ] diff --git a/spec/components/admin/site_customization/pages/index_component_spec.rb b/spec/components/admin/site_customization/pages/index_component_spec.rb index 1792e52cb..157d2bc8b 100644 --- a/spec/components/admin/site_customization/pages/index_component_spec.rb +++ b/spec/components/admin/site_customization/pages/index_component_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" -describe Admin::SiteCustomization::Pages::IndexComponent, controller: Admin::SiteCustomization::PagesController do +describe Admin::SiteCustomization::Pages::IndexComponent, + controller: Admin::SiteCustomization::PagesController do before { SiteCustomization::Page.delete_all } it "shows date in created_at and updated_at fields" do diff --git a/spec/components/budgets/budget_component_spec.rb b/spec/components/budgets/budget_component_spec.rb index 0119c9330..7567b03e5 100644 --- a/spec/components/budgets/budget_component_spec.rb +++ b/spec/components/budgets/budget_component_spec.rb @@ -32,7 +32,8 @@ describe Budgets::BudgetComponent do render_inline Budgets::BudgetComponent.new(budget) page.find(".budget-header") do |header| - expect(header).to have_link "Participate now!", href: "https://consuldemocracy.org", class: "main-link" + expect(header).to have_link "Participate now!", href: "https://consuldemocracy.org", + class: "main-link" end end end diff --git a/spec/components/sdg/related_list_selector_component_spec.rb b/spec/components/sdg/related_list_selector_component_spec.rb index de5cd772b..b0b78af68 100644 --- a/spec/components/sdg/related_list_selector_component_spec.rb +++ b/spec/components/sdg/related_list_selector_component_spec.rb @@ -68,7 +68,8 @@ describe SDG::RelatedListSelectorComponent do expect(page.find_field("Goals and Targets")["data-suggestions-list"]).to eq([{ tag: "1.1. Eradicate Extreme Poverty", display_text: "1.1", - title: "By 2030, eradicate extreme poverty for all people everywhere, currently measured as people living on less than $1.25 a day", + title: "By 2030, eradicate extreme poverty for all people everywhere, " \ + "currently measured as people living on less than $1.25 a day", value: "1.1" }].to_json) end diff --git a/spec/controllers/documents_controller_spec.rb b/spec/controllers/documents_controller_spec.rb index 9b0977034..2fc0638cc 100644 --- a/spec/controllers/documents_controller_spec.rb +++ b/spec/controllers/documents_controller_spec.rb @@ -10,7 +10,8 @@ describe DocumentsController do document = create(:document, documentable: current_answer) delete :destroy, params: { id: document } - expect(flash[:alert]).to eq "You do not have permission to carry out the action 'destroy' on Document." + expect(flash[:alert]).to eq "You do not have permission to " \ + "carry out the action 'destroy' on Document." expect(Document.count).to eq 1 end diff --git a/spec/controllers/moderation/users_controller_spec.rb b/spec/controllers/moderation/users_controller_spec.rb index a1e9fcea2..97bc1b172 100644 --- a/spec/controllers/moderation/users_controller_spec.rb +++ b/spec/controllers/moderation/users_controller_spec.rb @@ -30,7 +30,8 @@ describe Moderation::UsersController do put :block, params: { id: user } expect(response).to redirect_to proposals_path - expect(flash[:notice]).to eq "The user has been blocked. All contents authored by this user have been hidden." + expect(flash[:notice]).to eq "The user has been blocked. " \ + "All contents authored by this user have been hidden." end it "redirects to the index with a nested resource" do diff --git a/spec/factories/administration.rb b/spec/factories/administration.rb index 780bd1e16..a8da8a3ed 100644 --- a/spec/factories/administration.rb +++ b/spec/factories/administration.rb @@ -19,7 +19,9 @@ FactoryBot.define do end trait :with_geojson do - geojson { '{ "geometry": { "type": "Polygon", "coordinates": [[-0.117,51.513],[-0.118,51.512],[-0.119,51.514]] } }' } + geojson do + '{ "geometry": { "type": "Polygon", "coordinates": [[0.117,51.513],[0.118,51.512],[0.119,51.514]] } }' + end end end diff --git a/spec/helpers/signature_sheets_helper_spec.rb b/spec/helpers/signature_sheets_helper_spec.rb index e9b6a2953..6f93a3d4d 100644 --- a/spec/helpers/signature_sheets_helper_spec.rb +++ b/spec/helpers/signature_sheets_helper_spec.rb @@ -14,7 +14,8 @@ describe SignatureSheetsHelper do Setting["remote_census.request.postal_code"] = nil text_help_1 = "To verify a user, your application needs: Document number" - text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_help_2 = "Required fields for each user must be separated by commas " \ + "and each user must be separated by semicolons." text_example = "Example: 12345678Z; 87654321Y" expect(required_fields_to_verify_text_help).to include(text_help_1) @@ -25,8 +26,10 @@ describe SignatureSheetsHelper do it "returns text help when date_of_birth is required" do Setting["remote_census.request.postal_code"] = nil - text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy)" - text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_help_1 = "To verify a user, your application needs: " \ + "Document number, Day of birth (dd/mm/yyyy)" + text_help_2 = "Required fields for each user must be separated by commas " \ + "and each user must be separated by semicolons." text_example = "Example: 12345678Z, 01/01/1980; 87654321Y, 01/02/1990" expect(required_fields_to_verify_text_help).to include(text_help_1) @@ -37,8 +40,10 @@ describe SignatureSheetsHelper do it "returns text help when postal_code is required" do Setting["remote_census.request.date_of_birth"] = nil - text_help_1 = "To verify a user, your application needs: Document number and Postal Code" - text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_help_1 = "To verify a user, your application needs: " \ + "Document number and Postal Code" + text_help_2 = "Required fields for each user must be separated by commas " \ + "and each user must be separated by semicolons." text_example = "Example: 12345678Z, 28001; 87654321Y, 28002" expect(required_fields_to_verify_text_help).to include(text_help_1) @@ -47,8 +52,10 @@ describe SignatureSheetsHelper do end it "returns text help when date_of_birth and postal_code are required" do - text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy) and Postal Code" - text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_help_1 = "To verify a user, your application needs: " \ + "Document number, Day of birth (dd/mm/yyyy) and Postal Code" + text_help_2 = "Required fields for each user must be separated by commas " \ + "and each user must be separated by semicolons." text_example = "Example: 12345678Z, 01/01/1980, 28001; 87654321Y, 01/02/1990, 28002" expect(required_fields_to_verify_text_help).to include(text_help_1) diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 0a032fb73..e48ff015b 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -16,8 +16,10 @@ describe UsersHelper do debate.hide - expect(comment_commentable_title(comment)).to eq("" + comment.commentable.title + - ' (This debate has been deleted)') + expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title} " \ + '' \ + "(This debate has been deleted)" \ + "" end it "returns the appropriate message for deleted proposals" do @@ -26,8 +28,10 @@ describe UsersHelper do proposal.hide - expect(comment_commentable_title(comment)).to eq("" + comment.commentable.title + - ' (This proposal has been deleted)') + expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title} " \ + '' \ + "(This proposal has been deleted)" \ + "" end it "returns the appropriate message for deleted budget investment" do @@ -36,8 +40,10 @@ describe UsersHelper do investment.hide - expect(comment_commentable_title(comment)).to eq("" + comment.commentable.title + - ' (This investment project has been deleted)') + expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title} " \ + '' \ + "(This investment project has been deleted)" \ + "" end end @@ -50,8 +56,10 @@ describe UsersHelper do it "returns a hint if the commentable has been deleted" do comment = create(:comment) comment.commentable.hide - expect(comment_commentable_title(comment)).to eq("" + comment.commentable.title + - ' (This debate has been deleted)') + expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title} " \ + '' \ + "(This debate has been deleted)" \ + "" end end end diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index 41bc9fc28..2f27703d4 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -7,13 +7,13 @@ describe "I18n" do let(:unused_keys) { i18n.unused_keys } it "does not have missing keys" do - expect(missing_keys).to be_empty, - "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" + expect(missing_keys).to be_empty, "Missing #{missing_keys.leaves.count} i18n keys, " \ + "run `i18n-tasks missing' to show them" end it "does not have unused keys" do - expect(unused_keys).to be_empty, - "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" + expect(unused_keys).to be_empty, "#{unused_keys.leaves.count} unused i18n keys, " \ + "run `i18n-tasks unused' to show them" end context "Plurals" do diff --git a/spec/lib/document_parser_spec.rb b/spec/lib/document_parser_spec.rb index 476f3e2ee..6162bc9e7 100644 --- a/spec/lib/document_parser_spec.rb +++ b/spec/lib/document_parser_spec.rb @@ -21,12 +21,16 @@ describe DocumentParser do end it "tries all the dni variants padding with zeroes" do - expect(DocumentParser.get_document_number_variants(1, "0123456")).to eq(["123456", "0123456", "00123456"]) - expect(DocumentParser.get_document_number_variants(1, "00123456")).to eq(["123456", "0123456", "00123456"]) + expect(DocumentParser.get_document_number_variants(1, "0123456")) + .to eq(["123456", "0123456", "00123456"]) + + expect(DocumentParser.get_document_number_variants(1, "00123456")) + .to eq(["123456", "0123456", "00123456"]) end it "adds upper and lowercase letter when the letter is present" do - expect(DocumentParser.get_document_number_variants(1, "1234567A")).to eq(%w[1234567 01234567 1234567a 1234567A 01234567a 01234567A]) + expect(DocumentParser.get_document_number_variants(1, "1234567A")) + .to eq(%w[1234567 01234567 1234567a 1234567A 01234567a 01234567A]) end end end diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index b0b33a638..459547f16 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -185,7 +185,8 @@ describe "Consul Schema" do it "returns nested votes for a proposal" do proposal = create(:proposal, voters: [create(:user), create(:user)]) - response = execute("{ proposal(id: #{proposal.id}) { votes_for { edges { node { public_created_at } } } } }") + response = execute("{ proposal(id: #{proposal.id}) " \ + "{ votes_for { edges { node { public_created_at } } } } }") votes = response["data"]["proposal"]["votes_for"]["edges"] expect(votes.count).to eq(2) diff --git a/spec/lib/manager_authenticator_spec.rb b/spec/lib/manager_authenticator_spec.rb index 13ec6a352..0c456d0dd 100644 --- a/spec/lib/manager_authenticator_spec.rb +++ b/spec/lib/manager_authenticator_spec.rb @@ -1,21 +1,38 @@ require "rails_helper" describe ManagerAuthenticator do - let(:authenticator) { ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") } + let(:authenticator) do + ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") + end describe "initialization params" do it "causes auth to return false if blank login" do - blank_login_authenticator = ManagerAuthenticator.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905") + blank_login_authenticator = ManagerAuthenticator.new( + login: "", + clave_usuario: "31415926", + fecha_conexion: "20151031135905" + ) + expect(blank_login_authenticator.auth).to be false end it "causes auth to return false if blank user_key" do - blank_user_key_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905") + blank_user_key_authenticator = ManagerAuthenticator.new( + login: "JJB033", + clave_usuario: "", + fecha_conexion: "20151031135905" + ) + expect(blank_user_key_authenticator.auth).to be false end it "causes auth to return false if blank date" do - blank_date_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "") + blank_date_authenticator = ManagerAuthenticator.new( + login: "JJB033", + clave_usuario: "31415926", + fecha_conexion: "" + ) + expect(blank_date_authenticator.auth).to be false end end @@ -53,7 +70,8 @@ describe ManagerAuthenticator do it "calls the permissions check method" do allow(authenticator).to receive(:manager_exists?).and_return(true) - allow(authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: { user_key: "31415926" }}) + allow(authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, + message: { ub: { user_key: "31415926" }}) authenticator.auth end end diff --git a/spec/lib/remote_translations/microsoft/client_spec.rb b/spec/lib/remote_translations/microsoft/client_spec.rb index 3a796f476..4fcbbccfe 100644 --- a/spec/lib/remote_translations/microsoft/client_spec.rb +++ b/spec/lib/remote_translations/microsoft/client_spec.rb @@ -80,14 +80,16 @@ describe RemoteTranslations::Microsoft::Client do response_another_start_text = [another_start_translated_text_es] response_another_end_text = [another_end_translated_text_es] - expect_any_instance_of(BingTranslator).to receive(:translate_array).with([start_another_text_en], to: :es) - .exactly(1) - .times - .and_return(response_another_start_text) - expect_any_instance_of(BingTranslator).to receive(:translate_array).with([end_another_text_en], to: :es) - .exactly(1) - .times - .and_return(response_another_end_text) + expect_any_instance_of(BingTranslator).to(receive(:translate_array) + .with([start_another_text_en], to: :es) + .exactly(1) + .times + .and_return(response_another_start_text)) + expect_any_instance_of(BingTranslator).to(receive(:translate_array) + .with([end_another_text_en], to: :es) + .exactly(1) + .times + .and_return(response_another_end_text)) result = client.call([text_en, another_text_en], :es) diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index 956fed48c..39a42dbd6 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -95,7 +95,11 @@ describe Abilities::Administrator do it { should be_able_to(:read_results, create(:budget, :reviewing_ballots, :with_winner)) } it { should be_able_to(:read_results, create(:budget, :finished, :with_winner)) } it { should be_able_to(:read_results, create(:budget, :finished, results_enabled: true)) } - it { should_not be_able_to(:read_results, create(:budget, :balloting, :with_winner, results_enabled: true)) } + + it do + should_not be_able_to(:read_results, create(:budget, :balloting, :with_winner, results_enabled: true)) + end + it { should_not be_able_to(:read_results, create(:budget, :reviewing_ballots, results_enabled: true)) } it { should_not be_able_to(:read_results, create(:budget, :finished, results_enabled: false)) } diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index 92fab9aba..6c3918ec8 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -25,10 +25,18 @@ describe Abilities::Common do let(:investment_in_reviewing_budget) { create(:budget_investment, budget: reviewing_budget) } let(:investment_in_selecting_budget) { create(:budget_investment, budget: selecting_budget) } let(:investment_in_balloting_budget) { create(:budget_investment, budget: balloting_budget) } - let(:own_investment_in_accepting_budget) { create(:budget_investment, budget: accepting_budget, author: user) } - let(:own_investment_in_reviewing_budget) { create(:budget_investment, budget: reviewing_budget, author: user) } - let(:own_investment_in_selecting_budget) { create(:budget_investment, budget: selecting_budget, author: user) } - let(:own_investment_in_balloting_budget) { create(:budget_investment, budget: balloting_budget, author: user) } + let(:own_investment_in_accepting_budget) do + create(:budget_investment, budget: accepting_budget, author: user) + end + let(:own_investment_in_reviewing_budget) do + create(:budget_investment, budget: reviewing_budget, author: user) + end + let(:own_investment_in_selecting_budget) do + create(:budget_investment, budget: selecting_budget, author: user) + end + let(:own_investment_in_balloting_budget) do + create(:budget_investment, budget: balloting_budget, author: user) + end let(:ballot_in_accepting_budget) { create(:budget_ballot, budget: accepting_budget) } let(:ballot_in_selecting_budget) { create(:budget_ballot, budget: selecting_budget) } let(:ballot_in_balloting_budget) { create(:budget_ballot, budget: balloting_budget) } @@ -45,9 +53,13 @@ describe Abilities::Common do let(:poll_question_from_other_geozone) { create(:poll_question, poll: poll_from_other_geozone) } let(:poll_question_from_all_geozones) { create(:poll_question, poll: poll) } - let(:expired_poll_question_from_own_geozone) { create(:poll_question, poll: expired_poll_from_own_geozone) } - let(:expired_poll_question_from_other_geozone) { create(:poll_question, poll: expired_poll_from_other_geozone) } - let(:expired_poll_question_from_all_geozones) { create(:poll_question, poll: expired_poll) } + let(:expired_poll_question_from_own_geozone) do + create(:poll_question, poll: expired_poll_from_own_geozone) + end + let(:expired_poll_question_from_other_geozone) do + create(:poll_question, poll: expired_poll_from_other_geozone) + end + let(:expired_poll_question_from_all_geozones) { create(:poll_question, poll: expired_poll) } let(:own_proposal_document) { build(:document, documentable: own_proposal) } let(:proposal_document) { build(:document, documentable: proposal) } diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb index 328c1cb48..87b52f472 100644 --- a/spec/models/abilities/valuator_spec.rb +++ b/spec/models/abilities/valuator_spec.rb @@ -8,9 +8,15 @@ describe Abilities::Valuator do let(:group) { create(:valuator_group) } let(:valuator) { create(:valuator, valuator_group: group, can_edit_dossier: true, can_comment: true) } let(:non_assigned_investment) { create(:budget_investment) } - let(:assigned_investment) { create(:budget_investment, budget: create(:budget, :valuating), valuators: [valuator]) } - let(:group_assigned_investment) { create(:budget_investment, budget: create(:budget, :valuating), valuator_groups: [group]) } - let(:finished_assigned_investment) { create(:budget_investment, budget: create(:budget, :finished), valuators: [valuator]) } + let(:assigned_investment) do + create(:budget_investment, budget: create(:budget, :valuating), valuators: [valuator]) + end + let(:group_assigned_investment) do + create(:budget_investment, budget: create(:budget, :valuating), valuator_groups: [group]) + end + let(:finished_assigned_investment) do + create(:budget_investment, budget: create(:budget, :finished), valuators: [valuator]) + end it "cannot valuate an assigned investment with a finished valuation" do assigned_investment.update!(valuation_finished: true) diff --git a/spec/models/ahoy/data_source_spec.rb b/spec/models/ahoy/data_source_spec.rb index 4da39bba7..b72f3d728 100644 --- a/spec/models/ahoy/data_source_spec.rb +++ b/spec/models/ahoy/data_source_spec.rb @@ -30,7 +30,9 @@ describe Ahoy::DataSource do ds = Ahoy::DataSource.new ds.add "foo", Ahoy::Event.where(name: "foo").group_by_day(:time).count ds.add "bar", Ahoy::Event.where(name: "bar").group_by_day(:time).count - expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02", "2015-01-03"], "foo" => [2, 1, 0], "bar" => [1, 0, 2] + expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02", "2015-01-03"], + "foo" => [2, 1, 0], + "bar" => [1, 0, 2] end end end diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index d0a754158..04ee16775 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -714,7 +714,8 @@ describe Budget::Investment do unselected_undecided_investment = create(:budget_investment, :unselected, :undecided) unselected_feasible_investment = create(:budget_investment, :unselected, :feasible) - expect(Budget::Investment.unselected).to match_array [unselected_undecided_investment, unselected_feasible_investment] + expect(Budget::Investment.unselected).to match_array [unselected_undecided_investment, + unselected_feasible_investment] end it "does not return selected investments" do @@ -732,8 +733,17 @@ describe Budget::Investment do describe "sort_by_title" do it "sorts using the title in the current locale" do - create(:budget_investment, title_en: "CCCC", title_es: "BBBB", description_en: "CCCC", description_es: "BBBB") - create(:budget_investment, title_en: "DDDD", title_es: "AAAA", description_en: "DDDD", description_es: "AAAA") + create(:budget_investment, + title_en: "CCCC", + title_es: "BBBB", + description_en: "CCCC", + description_es: "BBBB") + + create(:budget_investment, + title_en: "DDDD", + title_es: "AAAA", + description_en: "DDDD", + description_es: "AAAA") expect(Budget::Investment.sort_by_title.map(&:title)).to eq %w[CCCC DDDD] end diff --git a/spec/models/budget/result_spec.rb b/spec/models/budget/result_spec.rb index 37b54729d..282f33ffa 100644 --- a/spec/models/budget/result_spec.rb +++ b/spec/models/budget/result_spec.rb @@ -44,7 +44,9 @@ describe Budget::Result do it "removes winners and recalculates" do create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 90) create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 80) - create(:budget_investment, :winner, :incompatible, heading: heading, price: 500, ballot_lines_count: 70) + create(:budget_investment, :winner, :incompatible, heading: heading, + price: 500, + ballot_lines_count: 70) create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 60) create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 50) diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb index 476969876..e24e42f0d 100644 --- a/spec/models/budget/stats_spec.rb +++ b/spec/models/budget/stats_spec.rb @@ -76,8 +76,9 @@ describe Budget::Stats do end it "doesn't count nil user ids" do - create(:budget_ballot_line, investment: investment, - ballot: create(:budget_ballot, budget: budget.reload, user: nil, physical: true)) + create(:budget_ballot_line, + investment: investment, + ballot: create(:budget_ballot, budget: budget.reload, user: nil, physical: true)) expect(stats.total_participants_vote_phase).to be 0 end diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 85e7a214a..0f086cc05 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -62,12 +62,14 @@ describe Debate do describe "#tag_list" do it "is not valid with a tag list of more than 6 elements" do - debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"] + debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", + "Fiestas populares", "Prensa", "Huelgas"] expect(debate).not_to be_valid end it "is valid with a tag list of 6 elements" do - debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"] + debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", + "Fiestas populares", "Prensa"] expect(debate).to be_valid end end @@ -314,7 +316,9 @@ describe Debate do describe "#confidence_score" do it "takes into account percentage of total votes and total_positive and total negative votes" do - debate = create(:debate, :with_confidence_score, cached_votes_up: 100, cached_votes_score: 100, cached_votes_total: 100) + debate = create(:debate, :with_confidence_score, cached_votes_up: 100, + cached_votes_score: 100, + cached_votes_total: 100) expect(debate.confidence_score).to eq(10000) debate = create(:debate, :with_confidence_score, cached_votes_up: 0, cached_votes_total: 100) diff --git a/spec/models/direct_upload_spec.rb b/spec/models/direct_upload_spec.rb index ec342f0de..ce9b0f22f 100644 --- a/spec/models/direct_upload_spec.rb +++ b/spec/models/direct_upload_spec.rb @@ -10,10 +10,25 @@ describe DirectUpload do end it "is not valid for different kind of combinations with invalid atttachment content types" do - expect(build(:direct_upload, :proposal, :documents, attachment: fixture_file_upload("clippy.png"))).not_to be_valid - expect(build(:direct_upload, :proposal, :image, attachment: fixture_file_upload("empty.pdf"))).not_to be_valid - expect(build(:direct_upload, :budget_investment, :documents, attachment: fixture_file_upload("clippy.png"))).not_to be_valid - expect(build(:direct_upload, :budget_investment, :image, attachment: fixture_file_upload("empty.pdf"))).not_to be_valid + expect(build(:direct_upload, + :proposal, + :documents, + attachment: fixture_file_upload("clippy.png"))).not_to be_valid + + expect(build(:direct_upload, + :proposal, + :image, + attachment: fixture_file_upload("empty.pdf"))).not_to be_valid + + expect(build(:direct_upload, + :budget_investment, + :documents, + attachment: fixture_file_upload("clippy.png"))).not_to be_valid + + expect(build(:direct_upload, + :budget_investment, + :image, + attachment: fixture_file_upload("empty.pdf"))).not_to be_valid end it "is not valid without resource_type" do diff --git a/spec/models/legislation/annotation_spec.rb b/spec/models/legislation/annotation_spec.rb index f0ac81a2e..a3e239521 100644 --- a/spec/models/legislation/annotation_spec.rb +++ b/spec/models/legislation/annotation_spec.rb @@ -10,16 +10,19 @@ RSpec.describe Legislation::Annotation, type: :model do end it "calculates the context for multinode annotations" do - quote = "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." \ - "\n\n" \ - "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." \ - "\n\n" \ + quote = "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.\n\n" \ + "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.\n\n" \ "His audiam" annotation = create( :legislation_annotation, @@ -28,25 +31,37 @@ RSpec.describe Legislation::Annotation, type: :model do ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }] ) - context = "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.\n\nExpetenda 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.\n\nHis audiamdeserunt in, eum" \ - " ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at" \ - " quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim" \ - " alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu." + context = "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.\n\n" \ + "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.\n\n" \ + "His audiam" \ + "deserunt in, eum ubique voluptatibus te. In reque dicta usu. Ne " \ + "rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata " \ + "at quo, insolens complectitur te eos, ea pri dico munere propriae. Vel " \ + "ferri facilis ut, qui paulo ridens praesent ad. Possim alterum qui cu. " \ + "Accusamus consulatu ius te, cu decore soleat appareat usu." expect(annotation.context).to eq(context) end it "calculates the context for multinode annotations 2" do - quote = "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.\r\n\r\nExpetenda 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" + quote = "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.\r\n\r\n" \ + "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" annotation = create( :legislation_annotation, draft_version: draft_version, @@ -54,45 +69,69 @@ RSpec.describe Legislation::Annotation, type: :model do ranges: [{ "start" => "/p[1]", "startOffset" => 273, "end" => "/p[2]", "endOffset" => 190 }] ) - context = "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.\r\n\r\nExpetenda 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." + context = "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.\r\n\r\n" \ + "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." + expect(annotation.context).to eq(context) end it "calculates the context for multinode annotations 3" do - body = "The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed" \ - " to ensure cooperation with the community in the case of network server software.\r\n\r\nThe licenses for most software and" \ - " other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public" \ - " Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free" \ - " software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General" \ - " Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for" \ - " them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces" \ - " of it in new free programs, and that you know you can do these things.\r\n\r\nDevelopers that use our General Public Licenses" \ - " protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you" \ - " legal permission to copy, distribute and/or modify the software.\r\n\r\nA secondary benefit of defending all users' freedom" \ - " is that improvements made in alternate versions of the program, if they receive widespread use, become available for other" \ - " developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation." \ - " However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License" \ - " permits making a modified version and letting the public access it on a server without ever releasing its source code to the" \ - " public.\r\n\r\nThe GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified" \ - " source code becomes available to the community. It requires the operator of a network server to provide the source code of" \ - " the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly" \ - " accessible server, gives the public access to the source code of the modified version.\r\n\r\nAn older license, called the" \ - " Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license," \ - " not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this" \ - " license." + body = "The GNU Affero General Public License is a free, copyleft license for " \ + "software and other kinds of works, specifically designed to ensure " \ + "cooperation with the community in the case of network server software.\r\n\r\n" \ + "The licenses for most software and other practical works are designed to " \ + "take away your freedom to share and change the works. By contrast, our " \ + "General Public Licenses are intended to guarantee your freedom to share and " \ + "change all versions of a program--to make sure it remains free software for " \ + "all its users.\r\n\r\n" \ + "When we speak of free software, we are referring to freedom, not price. " \ + "Our General Public Licenses are designed to make sure that you have the " \ + "freedom to distribute copies of free software (and charge for them if you wish), " \ + "that you receive source code or can get it if you want it, that you can change " \ + "the software or use pieces of it in new free programs, and that you know you " \ + "can do these things.\r\n\r\n" \ + "Developers that use our General Public Licenses protect your rights with two " \ + "steps: (1) assert copyright on the software, and (2) offer you this License which " \ + "gives you legal permission to copy, distribute and/or modify the software.\r\n\r\n" \ + "A secondary benefit of defending all users' freedom is that improvements made in " \ + "alternate versions of the program, if they receive widespread use, become " \ + "available for other developers to incorporate. Many developers of free software " \ + "are heartened and encouraged by the resulting cooperation. " \ + "However, in the case of software used on network servers, this result may fail " \ + "to come about. The GNU General Public License permits making a modified version " \ + "and letting the public access it on a server without ever releasing its source " \ + "code to the public.\r\n\r\n" \ + "The GNU Affero General Public License is designed specifically to ensure that, " \ + "in such cases, the modified source code becomes available to the community. " \ + "It requires the operator of a network server to provide the source code of " \ + "the modified version running there to the users of that server. Therefore, " \ + "public use of a modified version, on a publicly accessible server, gives the " \ + "public access to the source code of the modified version.\r\n\r\n" \ + "An older license, called the Affero General Public License and published by " \ + "Affero, was designed to accomplish similar goals. This is a different license, " \ + "not a version of the Affero GPL, but Affero has released a new version of the " \ + "Affero GPL which permits relicensing under this license." draft_version = create(:legislation_draft_version, body: body) - quote = "By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a" \ - " program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to" \ - " freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of" \ - " free software (and charge for them if you wish)" + quote = "By contrast, our General Public Licenses are intended to guarantee your " \ + "freedom to share and change all versions of a program--to make sure it " \ + "remains free software for all its users.\r\n\r\n" \ + "When we speak of free software, we are referring to freedom, not price. " \ + "Our General Public Licenses are designed to make sure that you have the " \ + "freedom to distribute copies of free software (and charge for them if you wish)" annotation = create( :legislation_annotation, @@ -101,13 +140,17 @@ RSpec.describe Legislation::Annotation, type: :model do ranges: [{ "start" => "/p[2]", "startOffset" => 127, "end" => "/p[3]", "endOffset" => 223 }] ) - context = "The licenses for most software and other practical works are designed to take away your freedom to share and change the" \ - " works. By contrast, our General Public Licenses are intended to guarantee your freedom to share" \ - " and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of" \ - " free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have" \ - " the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code" \ - " or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know" \ - " you can do these things." + context = "The licenses for most software and other practical works are designed to " \ + "take away your freedom to share and change the works. " \ + "By contrast, our General Public Licenses are " \ + "intended to guarantee your freedom to share and change all versions of " \ + "a program--to make sure it remains free software for all its users.\r\n\r\n" \ + "When we speak of free software, we are referring to freedom, not price. " \ + "Our General Public Licenses are designed to make sure that you have the " \ + "freedom to distribute copies of free software (and charge for them if you wish)" \ + ", that you receive source code or can get it if you want it, that " \ + "you can change the software or use pieces of it in new free programs, " \ + "and that you know you can do these things." expect(annotation.context).to eq(context) end diff --git a/spec/models/legislation/question_spec.rb b/spec/models/legislation/question_spec.rb index 2168be88b..d710415ea 100644 --- a/spec/models/legislation/question_spec.rb +++ b/spec/models/legislation/question_spec.rb @@ -46,7 +46,9 @@ describe Legislation::Question do describe "#next_question_id" do let!(:question1) { create(:legislation_question) } - let!(:question2) { create(:legislation_question, legislation_process_id: question1.legislation_process_id) } + let!(:question2) do + create(:legislation_question, legislation_process_id: question1.legislation_process_id) + end it "returns the next question" do expect(question1.next_question_id).to eq(question2.id) @@ -59,7 +61,9 @@ describe Legislation::Question do describe "#first_question_id" do let!(:question1) { create(:legislation_question) } - let!(:question2) { create(:legislation_question, legislation_process_id: question1.legislation_process_id) } + let!(:question2) do + create(:legislation_question, legislation_process_id: question1.legislation_process_id) + end it "returns the first question" do expect(question1.first_question_id).to eq(question1.id) diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb index a9d842d85..d30113111 100644 --- a/spec/models/officing/residence_spec.rb +++ b/spec/models/officing/residence_spec.rb @@ -196,7 +196,11 @@ describe Officing::Residence do end it "makes half-verified users fully verified" do - user = create(:user, residence_verified_at: Time.current, document_type: "1", document_number: "12345678Z") + user = create(:user, + residence_verified_at: Time.current, + document_type: "1", + document_number: "12345678Z") + expect(user).to be_unverified residence = build(:officing_residence, document_number: "12345678Z", year_of_birth: 1980) expect(residence).to be_valid diff --git a/spec/models/poll/ballot_spec.rb b/spec/models/poll/ballot_spec.rb index 1cebae0a2..81f8cc9f0 100644 --- a/spec/models/poll/ballot_spec.rb +++ b/spec/models/poll/ballot_spec.rb @@ -7,7 +7,9 @@ describe Poll::Ballot do let(:investment) { create(:budget_investment, :selected, price: 5000000, heading: heading) } let(:poll) { create(:poll, budget: budget) } let(:poll_ballot_sheet) { create(:poll_ballot_sheet, poll: poll) } - let(:poll_ballot) { create(:poll_ballot, ballot_sheet: poll_ballot_sheet, external_id: 1, data: investment.id) } + let(:poll_ballot) do + create(:poll_ballot, ballot_sheet: poll_ballot_sheet, external_id: 1, data: investment.id) + end before { create(:budget_ballot, budget: budget, physical: true, poll_ballot: poll_ballot) } describe "#verify" do diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index 599a1dd8f..be7d3f7d5 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -5,7 +5,9 @@ describe Poll::Shift do let(:booth) { create(:poll_booth) } let(:user) { create(:user, username: "Ana", email: "ana@example.com") } let(:officer) { create(:poll_officer, user: user) } - let(:recount_shift) { build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny) } + let(:recount_shift) do + build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny) + end describe "validations" do let(:shift) { build(:poll_shift) } @@ -37,19 +39,28 @@ describe Poll::Shift do it "is not valid with same booth, officer, date and task" do recount_shift.save! - expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny)).not_to be_valid + expect(build(:poll_shift, booth: booth, + officer: officer, + date: Date.current, + task: :recount_scrutiny)).not_to be_valid end it "is valid with same booth, officer and date but different task" do recount_shift.save! - expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :vote_collection)).to be_valid + expect(build(:poll_shift, booth: booth, + officer: officer, + date: Date.current, + task: :vote_collection)).to be_valid end it "is valid with same booth, officer and task but different date" do recount_shift.save! - expect(build(:poll_shift, booth: booth, officer: officer, date: Date.tomorrow, task: :recount_scrutiny)).to be_valid + expect(build(:poll_shift, booth: booth, + officer: officer, + date: Date.tomorrow, + task: :recount_scrutiny)).to be_valid end end @@ -58,7 +69,9 @@ describe Poll::Shift do booth_assignment1 = create(:poll_booth_assignment, booth: booth) booth_assignment2 = create(:poll_booth_assignment, booth: booth) - expect { create(:poll_shift, booth: booth, officer: officer, date: Date.current) }.to change { Poll::OfficerAssignment.all.count }.by(2) + expect do + create(:poll_shift, booth: booth, officer: officer, date: Date.current) + end.to change { Poll::OfficerAssignment.all.count }.by(2) officer_assignments = Poll::OfficerAssignment.all oa1 = officer_assignments.first @@ -74,7 +87,9 @@ describe Poll::Shift do expect(oa2.booth_assignment).to eq(booth_assignment2) expect(oa2.final).to be_falsey - create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment1, date: Date.tomorrow) + create(:poll_officer_assignment, officer: officer, + booth_assignment: booth_assignment1, + date: Date.tomorrow) expect { Poll::Shift.last.destroy }.to change { Poll::OfficerAssignment.all.count }.by(-2) end diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index abb152549..90e5dc19b 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -110,12 +110,14 @@ describe Proposal do describe "tag_list" do it "is not valid with a tag list of more than 6 elements" do - proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"] + proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", + "Fiestas populares", "Prensa", "Huelgas"] expect(proposal).not_to be_valid end it "is valid with a tag list of up to 6 elements" do - proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"] + proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", + "Fiestas populares", "Prensa"] expect(proposal).to be_valid end end @@ -256,7 +258,9 @@ describe Proposal do user = create(:user, verified_at: Time.current) archived_proposal = create(:proposal, :archived) - expect { archived_proposal.register_vote(user, "yes") }.to change { proposal.reload.votes_for.size }.by(0) + expect do + archived_proposal.register_vote(user, "yes") + end.to change { proposal.reload.votes_for.size }.by(0) end end @@ -623,7 +627,8 @@ describe Proposal do it "gives much more weight to word matches than votes" do exact_title_few_votes = create(:proposal, title: "stop corruption", cached_votes_up: 5) - similar_title_many_votes = create(:proposal, title: "stop some of the corruption", cached_votes_up: 500) + similar_title_many_votes = create(:proposal, title: "stop some of the corruption", + cached_votes_up: 500) results = Proposal.search("stop corruption") @@ -683,9 +688,9 @@ describe Proposal do end it "is able to reorder by most commented after searching" do - least_commented = create(:proposal, title: "stop corruption", cached_votes_up: 1, comments_count: 1) - most_commented = create(:proposal, title: "stop corruption", cached_votes_up: 2, comments_count: 100) - some_comments = create(:proposal, title: "stop corruption", cached_votes_up: 3, comments_count: 10) + least_commented = create(:proposal, title: "stop corruption", cached_votes_up: 1, comments_count: 1) + most_commented = create(:proposal, title: "stop corruption", cached_votes_up: 2, comments_count: 100) + some_comments = create(:proposal, title: "stop corruption", cached_votes_up: 3, comments_count: 10) results = Proposal.search("stop corruption") diff --git a/spec/models/related_content_spec.rb b/spec/models/related_content_spec.rb index af8851f0b..f5a9a7d85 100644 --- a/spec/models/related_content_spec.rb +++ b/spec/models/related_content_spec.rb @@ -10,9 +10,11 @@ describe RelatedContent do end it "allows relationables from various classes" do - expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid - expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid - expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid + 3.times do + expect(build(:related_content, + parent_relationable: parent_relationable, + child_relationable: child_relationable)).to be_valid + end end it "does not allow empty relationables" do @@ -21,8 +23,15 @@ describe RelatedContent do end it "does not allow repeated related contents" do - related_content = create(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable, author: build(:user)) - new_related_content = build(:related_content, parent_relationable: related_content.parent_relationable, child_relationable: related_content.child_relationable) + related_content = create(:related_content, + parent_relationable: parent_relationable, + child_relationable: child_relationable, + author: build(:user)) + + new_related_content = build(:related_content, + parent_relationable: related_content.parent_relationable, + child_relationable: related_content.child_relationable) + expect(new_related_content).not_to be_valid end @@ -61,7 +70,12 @@ describe RelatedContent do describe "create_opposite_related_content" do let(:parent_relationable) { create(:proposal) } let(:child_relationable) { create(:debate) } - let(:related_content) { build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable, author: build(:user)) } + let(:related_content) do + build(:related_content, + parent_relationable: parent_relationable, + child_relationable: child_relationable, + author: build(:user)) + end it "creates an opposite related_content" do expect { related_content.save }.to change { RelatedContent.count }.by(2) @@ -72,8 +86,14 @@ describe RelatedContent do describe "#relationed_contents" do before do - related_content = create(:related_content, parent_relationable: parent_relationable, child_relationable: create(:proposal), author: build(:user)) - create(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable, author: build(:user)) + related_content = create(:related_content, + parent_relationable: parent_relationable, + child_relationable: create(:proposal), + author: build(:user)) + create(:related_content, + parent_relationable: parent_relationable, + child_relationable: child_relationable, + author: build(:user)) 2.times do related_content.send(:score_positive, build(:user)) diff --git a/spec/models/sdg/local_target_spec.rb b/spec/models/sdg/local_target_spec.rb index df4b341da..2f4def3f6 100644 --- a/spec/models/sdg/local_target_spec.rb +++ b/spec/models/sdg/local_target_spec.rb @@ -25,14 +25,18 @@ describe SDG::LocalTarget do local_target = build(:sdg_local_target, code: "1.6.1", target: SDG::Target[1.1]) expect(local_target).not_to be_valid - expect(local_target.errors.full_messages).to include "Code must start with the same code as its target followed by a dot and end with a number" + expect(local_target.errors.full_messages).to include "Code must start with the same " \ + "code as its target followed by " \ + "a dot and end with a number" end it "is not valid when local target code part is not a number" do local_target = build(:sdg_local_target, code: "1.1.A", target: SDG::Target[1.1]) expect(local_target).not_to be_valid - expect(local_target.errors.full_messages).to include "Code must start with the same code as its target followed by a dot and end with a number" + expect(local_target.errors.full_messages).to include "Code must start with the same " \ + "code as its target followed by " \ + "a dot and end with a number" end it "is not valid if code is not unique" do diff --git a/spec/models/sdg/relatable_spec.rb b/spec/models/sdg/relatable_spec.rb index 20e716d43..f6c9bbb4e 100644 --- a/spec/models/sdg/relatable_spec.rb +++ b/spec/models/sdg/relatable_spec.rb @@ -171,7 +171,10 @@ describe SDG::Relatable do it "assigns goals, targets and local_targets" do relatable.related_sdg_list = "1.1,3,4,4.1,#{another_local_target.code}" - expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], another_local_target.goal, SDG::Goal[3], SDG::Goal[4]] + expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], + another_local_target.goal, + SDG::Goal[3], + SDG::Goal[4]] expect(relatable.reload.sdg_global_targets).to match_array [SDG::Target[1.1], SDG::Target[4.1]] expect(relatable.reload.sdg_local_targets).to match_array [another_local_target] end diff --git a/spec/models/signature_sheet_spec.rb b/spec/models/signature_sheet_spec.rb index 9224b61a9..39caa34a0 100644 --- a/spec/models/signature_sheet_spec.rb +++ b/spec/models/signature_sheet_spec.rb @@ -200,21 +200,32 @@ describe SignatureSheet do it "returns an array after spliting document numbers by semicolons" do signature_sheet.required_fields_to_verify = "123A\r\n;456B;\n789C;123B" - expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A"], ["456B"], ["789C"], ["123B"]]) + expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A"], + ["456B"], + ["789C"], + ["123B"]]) end it "returns an array after spliting all required_fields_to_verify by semicolons" do - required_fields_to_verify = "123A\r\n, 01/01/1980\r\n, 28001\r\n; 456B\n, 01/02/1980\n, 28002\n; 789C, 01/03/1980" + required_fields_to_verify = "123A\r\n, 01/01/1980\r\n, 28001\r\n; " \ + "456B\n, 01/02/1980\n, 28002\n; " \ + "789C, 01/03/1980" # signature_sheet.required_fields_to_verify = "123A\r\n456B\n789C;123B" signature_sheet.required_fields_to_verify = required_fields_to_verify - expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A", "01/01/1980", "28001"], ["456B", "01/02/1980", "28002"], ["789C", "01/03/1980"]]) + expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A", "01/01/1980", "28001"], + ["456B", "01/02/1980", "28002"], + ["789C", "01/03/1980"]]) end it "strips spaces between number and letter" do - signature_sheet.required_fields_to_verify = "123 A, 01/01/1980, 28001;\n456 B , 01/02/1980, 28002;\n 789C ,01/03/1980, 28 003" + signature_sheet.required_fields_to_verify = "123 A, 01/01/1980, 28001;\n" \ + "456 B , 01/02/1980, 28002;\n" \ + "789C ,01/03/1980, 28 003" - expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A", "01/01/1980", "28001"], ["456B", "01/02/1980", "28002"], ["789C", "01/03/1980", "28003"]]) + expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A", "01/01/1980", "28001"], + ["456B", "01/02/1980", "28002"], + ["789C", "01/03/1980", "28003"]]) end end end diff --git a/spec/models/signature_spec.rb b/spec/models/signature_spec.rb index aa524a670..ac237ca76 100644 --- a/spec/models/signature_spec.rb +++ b/spec/models/signature_spec.rb @@ -95,7 +95,8 @@ describe Signature do investment = create(:budget_investment) signature_sheet = create(:signature_sheet, signable: investment) user = create(:user, :level_two, document_number: "123A") - signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet) + signature = create(:signature, document_number: user.document_number, + signature_sheet: signature_sheet) signature.verify @@ -116,7 +117,8 @@ describe Signature do investment = create(:budget_investment) signature_sheet = create(:signature_sheet, signable: investment) user = create(:user, document_number: "123A") - signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet) + signature = create(:signature, document_number: user.document_number, + signature_sheet: signature_sheet) signature.verify @@ -128,7 +130,8 @@ describe Signature do investment = create(:budget_investment) signature_sheet = create(:signature_sheet, signable: investment) user = create(:user, :level_two, document_number: "123A") - signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet) + signature = create(:signature, document_number: user.document_number, + signature_sheet: signature_sheet) signature.verify signature.verify @@ -140,7 +143,8 @@ describe Signature do user = create(:user, :level_two, document_number: "123A") proposal = create(:proposal, voters: [user]) signature_sheet = create(:signature_sheet, signable: proposal) - signature = create(:signature, signature_sheet: signature_sheet, document_number: user.document_number) + signature = create(:signature, signature_sheet: signature_sheet, + document_number: user.document_number) signature.verify @@ -152,7 +156,8 @@ describe Signature do investment = create(:budget_investment, voters: [user]) signature_sheet = create(:signature_sheet, signable: investment) - signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet) + signature = create(:signature, document_number: user.document_number, + signature_sheet: signature_sheet) expect(Vote.count).to eq(1) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fc295d20f..50106de69 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -786,22 +786,26 @@ describe User do debate = create(:debate, :hidden, author: user) investment = create(:budget_investment, :hidden, author: user) proposal = create(:proposal, :hidden, author: user) - proposal_notification = create(:proposal_notification, :hidden, proposal: proposal) legislation_proposal = create(:legislation_proposal, :hidden, author: user) + proposal_notification = create(:proposal_notification, :hidden, proposal: proposal) old_hidden_comment = create(:comment, hidden_at: 3.days.ago, author: user) old_hidden_debate = create(:debate, hidden_at: 3.days.ago, author: user) old_hidden_investment = create(:budget_investment, hidden_at: 3.days.ago, author: user) old_hidden_proposal = create(:proposal, hidden_at: 3.days.ago, author: user) - old_hidden_proposal_notification = create(:proposal_notification, hidden_at: 3.days.ago, proposal: proposal) old_hidden_legislation_proposal = create(:legislation_proposal, hidden_at: 3.days.ago, author: user) + old_hidden_proposal_notification = create(:proposal_notification, + hidden_at: 3.days.ago, + proposal: proposal) other_user_comment = create(:comment, :hidden, author: other_user) other_user_debate = create(:debate, :hidden, author: other_user) other_user_proposal = create(:proposal, :hidden, author: other_user) other_user_investment = create(:budget_investment, :hidden, author: other_user) - other_user_proposal_notification = create(:proposal_notification, :hidden, proposal: other_user_proposal) other_user_legislation_proposal = create(:legislation_proposal, :hidden, author: other_user) + other_user_proposal_notification = create(:proposal_notification, + :hidden, + proposal: other_user_proposal) user.full_restore diff --git a/spec/models/verification/management/document_spec.rb b/spec/models/verification/management/document_spec.rb index 6dee5b10b..f814e088c 100644 --- a/spec/models/verification/management/document_spec.rb +++ b/spec/models/verification/management/document_spec.rb @@ -75,41 +75,49 @@ describe Verification::Management::Document do end describe "Allowed Age" do - let(:min_age) { User.minimum_required_age } - let(:over_minium_age_date_of_birth) { Date.new((min_age + 10).years.ago.year, 12, 31) } - let(:under_minium_age_date_of_birth) { Date.new(min_age.years.ago.year, 12, 31) } - let(:just_minium_age_date_of_birth) { Date.new(min_age.years.ago.year, min_age.years.ago.month, min_age.years.ago.day) } + let(:min_age) { User.minimum_required_age } + let(:over_minium_age_date_of_birth) { Date.new((min_age + 10).years.ago.year, 12, 31) } + let(:under_minium_age_date_of_birth) { Date.new(min_age.years.ago.year, 12, 31) } + let(:just_minium_age_date_of_birth) do + Date.new(min_age.years.ago.year, min_age.years.ago.month, min_age.years.ago.day) + end describe "#valid_age?" do it "returns false when the user is younger than the user's minimum required age" do - census_response = instance_double("CensusApi::Response", date_of_birth: under_minium_age_date_of_birth) + census_response = instance_double("CensusApi::Response", + date_of_birth: under_minium_age_date_of_birth) expect(Verification::Management::Document.new.valid_age?(census_response)).to be false end it "returns true when the user has the user's minimum required age" do - census_response = instance_double("CensusApi::Response", date_of_birth: just_minium_age_date_of_birth) + census_response = instance_double("CensusApi::Response", + date_of_birth: just_minium_age_date_of_birth) expect(Verification::Management::Document.new.valid_age?(census_response)).to be true end it "returns true when the user is older than the user's minimum required age" do - census_response = instance_double("CensusApi::Response", date_of_birth: over_minium_age_date_of_birth) + census_response = instance_double("CensusApi::Response", + date_of_birth: over_minium_age_date_of_birth) expect(Verification::Management::Document.new.valid_age?(census_response)).to be true end end describe "#under_age?" do it "returns true when the user is younger than the user's minimum required age" do - census_response = instance_double("CensusApi::Response", date_of_birth: under_minium_age_date_of_birth) + census_response = instance_double("CensusApi::Response", + date_of_birth: under_minium_age_date_of_birth) expect(Verification::Management::Document.new.under_age?(census_response)).to be true end it "returns false when the user is user's minimum required age" do - census_response = instance_double("CensusApi::Response", date_of_birth: just_minium_age_date_of_birth) + census_response = instance_double("CensusApi::Response", + date_of_birth: just_minium_age_date_of_birth) expect(Verification::Management::Document.new.under_age?(census_response)).to be false end it "returns false when the user is older than user's minimum required age" do - census_response = instance_double("CensusApi::Response", date_of_birth: over_minium_age_date_of_birth) + census_response = instance_double("CensusApi::Response", + date_of_birth: over_minium_age_date_of_birth) expect(Verification::Management::Document.new.under_age?(census_response)).to be false end end diff --git a/spec/models/verification/management/email_spec.rb b/spec/models/verification/management/email_spec.rb index 8f081b061..91d1c62f8 100644 --- a/spec/models/verification/management/email_spec.rb +++ b/spec/models/verification/management/email_spec.rb @@ -2,7 +2,11 @@ require "rails_helper" describe Verification::Management::Email do describe "#user" do - subject { Verification::Management::Email.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com") } + subject do + Verification::Management::Email.new(document_type: "1", + document_number: "1234", + email: "inexisting@gmail.com") + end it "returns nil/false when the user does not exist" do expect(subject.user).to be_nil @@ -12,34 +16,50 @@ describe Verification::Management::Email do describe "validations" do it "is not valid if the user does not exist" do - expect(Verification::Management::Email.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com")).not_to be_valid + expect(Verification::Management::Email.new(document_type: "1", + document_number: "1234", + email: "inexisting@gmail.com")).not_to be_valid end it "is not valid if the user is already level 3" do user = create(:user, :level_three) - expect(Verification::Management::Email.new(document_type: "1", document_number: "1234", email: user.email)).not_to be_valid + + expect(Verification::Management::Email.new(document_type: "1", + document_number: "1234", + email: user.email)).not_to be_valid end it "is not valid if the user already has a different document number" do user = create(:user, document_number: "1234", document_type: "1") - expect(Verification::Management::Email.new(document_type: "1", document_number: "5678", email: user.email)).not_to be_valid + + expect(Verification::Management::Email.new(document_type: "1", + document_number: "5678", + email: user.email)).not_to be_valid end end describe "#save" do it "does nothing if not valid" do - expect(Verification::Management::Email.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com").save).to eq(false) + email = Verification::Management::Email.new(document_type: "1", + document_number: "1234", + email: "inexisting@gmail.com") + + expect(email.save).to eq(false) end it "updates the user and sends an email" do user = create(:user) - validation = Verification::Management::Email.new(document_type: "1", document_number: "1234", email: user.email) + validation = Verification::Management::Email.new(document_type: "1", + document_number: "1234", + email: user.email) mail = double(:mail) allow(validation).to receive(:user).and_return user allow(mail).to receive(:deliver_later) - allow(Devise.token_generator).to receive(:generate).with(User, :email_verification_token).and_return(["1", "2"]) + allow(Devise.token_generator).to(receive(:generate) + .with(User, :email_verification_token) + .and_return(["1", "2"])) allow(Mailer).to receive(:email_verification).with(user, user.email, "2", "1", "1234").and_return(mail) validation.save! diff --git a/spec/models/verification/residence_spec.rb b/spec/models/verification/residence_spec.rb index 8dc4b18e6..988b2a805 100644 --- a/spec/models/verification/residence_spec.rb +++ b/spec/models/verification/residence_spec.rb @@ -11,13 +11,17 @@ describe Verification::Residence do describe "dates" do it "is valid with a valid date of birth" do - residence = Verification::Residence.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "1980") + residence = Verification::Residence.new("date_of_birth(3i)" => "1", + "date_of_birth(2i)" => "1", + "date_of_birth(1i)" => "1980") expect(residence.errors[:date_of_birth]).to be_empty end it "is not valid without a date of birth" do - residence = Verification::Residence.new("date_of_birth(3i)" => "", "date_of_birth(2i)" => "", "date_of_birth(1i)" => "") + residence = Verification::Residence.new("date_of_birth(3i)" => "", + "date_of_birth(2i)" => "", + "date_of_birth(1i)" => "") expect(residence).not_to be_valid expect(residence.errors[:date_of_birth]).to include("can't be blank") end diff --git a/spec/shared/models/acts_as_paranoid.rb b/spec/shared/models/acts_as_paranoid.rb index 899032d02..25feac564 100644 --- a/spec/shared/models/acts_as_paranoid.rb +++ b/spec/shared/models/acts_as_paranoid.rb @@ -37,14 +37,17 @@ shared_examples "acts as paranoid" do |factory_name| resource.destroy! resource.reload - expect { resource.restore(recursive: true) }.to change { resource.translations.with_deleted.first.hidden_at } + expect do + resource.restore(recursive: true) + end.to change { resource.translations.with_deleted.first.hidden_at } end it "can be recovered after soft deletion through recursive restore" do original_translation = resource.translations.first new_translation = resource.translations.build described_class.translated_attribute_names.each do |translated_attribute_name| - new_translation.send("#{translated_attribute_name}=", original_translation.send(translated_attribute_name)) + new_translation.send("#{translated_attribute_name}=", + original_translation.send(translated_attribute_name)) end new_translation.locale = :fr new_translation.save! diff --git a/spec/shared/system/mappable.rb b/spec/shared/system/mappable.rb index cf12103db..66c4742b8 100644 --- a/spec/shared/system/mappable.rb +++ b/spec/shared/system/mappable.rb @@ -1,9 +1,14 @@ -shared_examples "mappable" do |mappable_factory_name, mappable_association_name, mappable_new_path, mappable_edit_path, mappable_show_path, mappable_path_arguments: {}, management: false| +shared_examples "mappable" do |mappable_factory_name, mappable_association_name, + mappable_new_path, mappable_edit_path, mappable_show_path, + mappable_path_arguments: {}, + management: false| let!(:user) { create(:user, :level_two) } let!(:arguments) { {} } let!(:mappable) { create(mappable_factory_name.to_s.to_sym) } - let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } let(:management) { management } + let!(:map_location) do + create(:map_location, :"#{mappable_factory_name}_map_location", "#{mappable_association_name}": mappable) + end before do Setting["feature.map"] = true @@ -181,8 +186,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, visit send(mappable_edit_path, id: mappable.id) expect(page).to have_content "Navigate the map to the location and place the marker." - expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_latitude", type: :hidden, with: "51.48" - expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_longitude", type: :hidden, with: "0.0" + expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_latitude", type: :hidden, + with: "51.48" + expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_longitude", type: :hidden, + with: "0.0" end scenario "Should edit default values from map on #{mappable_factory_name} edit page" do diff --git a/spec/shared/system/relationable.rb b/spec/shared/system/relationable.rb index c9faf9221..e6a4b31ca 100644 --- a/spec/shared/system/relationable.rb +++ b/spec/shared/system/relationable.rb @@ -9,7 +9,10 @@ shared_examples "relationable" do |relationable_model_name| end scenario "related contents are listed" do - create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) + create(:related_content, + parent_relationable: relationable, + child_relationable: related1, + author: build(:user)) visit polymorphic_path(relationable) within("#related-content-list") do @@ -136,7 +139,10 @@ shared_examples "relationable" do |relationable_model_name| end scenario "related content can be scored positively" do - create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) + create(:related_content, + parent_relationable: relationable, + child_relationable: related1, + author: build(:user)) login_as(user) visit polymorphic_path(relationable) @@ -150,7 +156,10 @@ shared_examples "relationable" do |relationable_model_name| end scenario "related content can be scored negatively" do - create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) + create(:related_content, + parent_relationable: relationable, + child_relationable: related1, + author: build(:user)) login_as(user) visit polymorphic_path(relationable) @@ -164,7 +173,10 @@ shared_examples "relationable" do |relationable_model_name| end scenario "if related content has negative score it will be hidden" do - related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) + related_content = create(:related_content, + parent_relationable: relationable, + child_relationable: related1, + author: build(:user)) 2.times do related_content.send(:score_positive, build(:user)) diff --git a/spec/shared/system/remotely_translatable.rb b/spec/shared/system/remotely_translatable.rb index 2912b1497..f23d7e3ac 100644 --- a/spec/shared/system/remotely_translatable.rb +++ b/spec/shared/system/remotely_translatable.rb @@ -58,7 +58,8 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume select "Español", from: "Language:" expect(page).not_to have_button("Traducir página") - expect(page).to have_content("En un breve periodo de tiempo refrescando la página podrá ver todo el contenido en su idioma") + expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \ + "podrá ver todo el contenido en su idioma" end end @@ -152,8 +153,9 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume click_button "Traducir página" - expect(page).to have_content("Se han solicitado correctamente las traducciones.") - expect(page).to have_content("En un breve periodo de tiempo refrescando la página podrá ver todo el contenido en su idioma") + expect(page).to have_content "Se han solicitado correctamente las traducciones." + expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \ + "podrá ver todo el contenido en su idioma" end scenario "should be present only informative text when user visit page with all content enqueued" do @@ -166,8 +168,9 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume select "Español", from: "Idioma:" expect(page).not_to have_button "Traducir página" - expect(page).not_to have_content("Se han solicitado correctamente las traducciones.") - expect(page).to have_content("En un breve periodo de tiempo refrescando la página podrá ver todo el contenido en su idioma") + expect(page).not_to have_content "Se han solicitado correctamente las traducciones." + expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \ + "podrá ver todo el contenido en su idioma" end end diff --git a/spec/support/matchers/be_rendered.rb b/spec/support/matchers/be_rendered.rb index f375f7589..0a2f69182 100644 --- a/spec/support/matchers/be_rendered.rb +++ b/spec/support/matchers/be_rendered.rb @@ -9,7 +9,8 @@ RSpec::Matchers.define :be_rendered do |with: nil| failure_message do |page| if page.has_css?("body") - "expected page to be rendered with #{with}, but was rendered with #{page.find("body").native.inner_html}" + "expected page to be rendered with #{with}, " \ + "but was rendered with #{page.find("body").native.inner_html}" else "expected page to be rendered with #{with}, but was not rendered" end diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index 7d1fb85e7..e1e2a966b 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -198,7 +198,9 @@ describe "Admin budgets", :admin do scenario "Destroy a budget without investments" do visit admin_budget_path(budget) - message = "Are you sure? This will delete the budget and all its associated groups and headings. This action cannot be undone." + message = "Are you sure? " \ + "This will delete the budget and all its associated groups and headings. " \ + "This action cannot be undone." accept_confirm(message) { click_button "Delete budget" } diff --git a/spec/system/admin/hidden_users_spec.rb b/spec/system/admin/hidden_users_spec.rb index 0cf4744d4..4fb320a6f 100644 --- a/spec/system/admin/hidden_users_spec.rb +++ b/spec/system/admin/hidden_users_spec.rb @@ -6,7 +6,9 @@ describe "Admin hidden users", :admin do debate1 = create(:debate, :hidden, author: user) debate2 = create(:debate, author: user) - comment1 = create(:comment, :hidden, user: user, commentable: debate2, body: "You have the manners of a beggar") + comment1 = create(:comment, :hidden, user: user, + commentable: debate2, + body: "You have the manners of a beggar") comment2 = create(:comment, user: user, commentable: debate2, body: "Not Spam") visit admin_hidden_user_path(user) diff --git a/spec/system/admin/machine_learning_spec.rb b/spec/system/admin/machine_learning_spec.rb index f7f4606e8..0332b4db9 100644 --- a/spec/system/admin/machine_learning_spec.rb +++ b/spec/system/admin/machine_learning_spec.rb @@ -217,7 +217,9 @@ describe "Machine learning" do updated_at: 2.minutes.from_now) comments_file = MachineLearning.data_folder.join(MachineLearning.comments_filename) File.write(comments_file, [].to_json) - proposals_comments_summary_file = MachineLearning.data_folder.join(MachineLearning.proposals_comments_summary_filename) + proposals_comments_summary_file = MachineLearning + .data_folder + .join(MachineLearning.proposals_comments_summary_filename) File.write(proposals_comments_summary_file, [].to_json) end diff --git a/spec/system/admin/poll/shifts_spec.rb b/spec/system/admin/poll/shifts_spec.rb index 3effc075c..a5e25a554 100644 --- a/spec/system/admin/poll/shifts_spec.rb +++ b/spec/system/admin/poll/shifts_spec.rb @@ -30,8 +30,16 @@ describe "Admin shifts", :admin do poll = create(:poll) booth = create(:poll_booth, polls: [poll, create(:poll, :expired)]) officer = create(:poll_officer) - vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } - recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) } + vote_collection_dates = (Date.current..poll.ends_at.to_date) + .to_a + .map do |date| + I18n.l(date, format: :long) + end + recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week) + .to_a + .map do |date| + I18n.l(date, format: :long) + end visit available_admin_booths_path @@ -45,7 +53,8 @@ describe "Admin shifts", :admin do click_button "Search" click_link "Edit shifts" - expect(page).to have_select("shift_date_vote_collection_date", options: ["Select day", *vote_collection_dates]) + expect(page).to have_select("shift_date_vote_collection_date", + options: ["Select day", *vote_collection_dates]) expect(page).not_to have_select("shift_date_recount_scrutiny_date") select I18n.l(Date.current, format: :long), from: "shift_date_vote_collection_date" click_button "Add shift" @@ -73,7 +82,8 @@ describe "Admin shifts", :admin do select "Recount & Scrutiny", from: "shift_task" - expect(page).to have_select("shift_date_recount_scrutiny_date", options: ["Select day", *recount_scrutiny_dates]) + expect(page).to have_select("shift_date_recount_scrutiny_date", + options: ["Select day", *recount_scrutiny_dates]) expect(page).not_to have_select("shift_date_vote_collection_date") select I18n.l(poll.ends_at.to_date + 4.days, format: :long), from: "shift_date_recount_scrutiny_date" click_button "Add shift" @@ -98,8 +108,11 @@ describe "Admin shifts", :admin do vote_collection_dates = (Date.current..poll.ends_at.to_date).excluding(Date.current) .map { |date| I18n.l(date, format: :long) } - recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).excluding(Time.zone.tomorrow) - .map { |date| I18n.l(date, format: :long) } + recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week) + .excluding(Time.zone.tomorrow) + .map do |date| + I18n.l(date, format: :long) + end visit available_admin_booths_path @@ -113,9 +126,11 @@ describe "Admin shifts", :admin do click_button "Search" click_link "Edit shifts" - expect(page).to have_select("shift_date_vote_collection_date", options: ["Select day", *vote_collection_dates]) + expect(page).to have_select("shift_date_vote_collection_date", + options: ["Select day", *vote_collection_dates]) select "Recount & Scrutiny", from: "shift_task" - expect(page).to have_select("shift_date_recount_scrutiny_date", options: ["Select day", *recount_scrutiny_dates]) + expect(page).to have_select("shift_date_recount_scrutiny_date", + options: ["Select day", *recount_scrutiny_dates]) end scenario "Change option from Recount & Scrutinity to Collect Votes" do diff --git a/spec/system/admin/signature_sheets_spec.rb b/spec/system/admin/signature_sheets_spec.rb index 032414f1a..d2c36191d 100644 --- a/spec/system/admin/signature_sheets_spec.rb +++ b/spec/system/admin/signature_sheets_spec.rb @@ -83,7 +83,8 @@ describe "Signature sheets", :admin do select "Citizen proposal", from: "signature_sheet_signable_type" fill_in "signature_sheet_signable_id", with: proposal.id - fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z, 31/12/1980, 28013; 99999999Z, 31/12/1980, 28013" + fill_in "signature_sheet_required_fields_to_verify", + with: "12345678Z, 31/12/1980, 28013; 99999999Z, 31/12/1980, 28013" click_button "Create signature sheet" expect(page).to have_content "Signature sheet created successfully" @@ -102,7 +103,8 @@ describe "Signature sheets", :admin do select "Investment", from: "signature_sheet_signable_type" fill_in "signature_sheet_signable_id", with: investment.id - fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z, 31/12/1980, 28013; 99999999Z, 31/12/1980, 28013" + fill_in "signature_sheet_required_fields_to_verify", + with: "12345678Z, 31/12/1980, 28013; 99999999Z, 31/12/1980, 28013" click_button "Create signature sheet" expect(page).to have_content "Signature sheet created successfully" diff --git a/spec/system/admin/widgets/cards_spec.rb b/spec/system/admin/widgets/cards_spec.rb index d34549503..319ab3770 100644 --- a/spec/system/admin/widgets/cards_spec.rb +++ b/spec/system/admin/widgets/cards_spec.rb @@ -211,7 +211,9 @@ describe "Cards", :admin do card_1 = create(:widget_card, cardable: custom_page, title: "Card one") card_2 = create(:widget_card, cardable: custom_page, title: "Card two") - card_1.update!(image: create(:image, imageable: card_1, attachment: fixture_file_upload("clippy.jpg"))) + card_1.update!(image: create(:image, + imageable: card_1, + attachment: fixture_file_upload("clippy.jpg"))) card_2.update!(image: nil) visit custom_page.url diff --git a/spec/system/advanced_search_spec.rb b/spec/system/advanced_search_spec.rb index 12517920d..0adf6ebba 100644 --- a/spec/system/advanced_search_spec.rb +++ b/spec/system/advanced_search_spec.rb @@ -254,9 +254,11 @@ describe "Advanced search" do expect(page).to have_content("citizen proposals cannot be found") within ".advanced-search-form" do - expect(page).to have_select("advanced_search[date_min]", selected: "Customized") - expect(page).to have_selector("input[name='advanced_search[date_min]'][value*='#{7.days.ago.strftime("%d/%m/%Y")}']") - expect(page).to have_selector("input[name='advanced_search[date_max]'][value*='#{1.day.ago.strftime("%d/%m/%Y")}']") + expect(page).to have_select "advanced_search[date_min]", selected: "Customized" + expect(page).to have_selector "input[name='advanced_search[date_min]']" \ + "[value*='#{7.days.ago.strftime("%d/%m/%Y")}']" + expect(page).to have_selector "input[name='advanced_search[date_max]']" \ + "[value*='#{1.day.ago.strftime("%d/%m/%Y")}']" end end end diff --git a/spec/system/budgets/ballots_spec.rb b/spec/system/budgets/ballots_spec.rb index ccd80d364..debd21ee9 100644 --- a/spec/system/budgets/ballots_spec.rb +++ b/spec/system/budgets/ballots_spec.rb @@ -326,7 +326,8 @@ describe "Ballots" do expect(page).not_to have_css "#progressbar" expect(page).to have_content "You have active votes in another heading: California" - expect(page).to have_link california.name, href: budget_investments_path(budget, heading_id: california.id) + expect(page).to have_link california.name, + href: budget_investments_path(budget, heading_id: california.id) end end diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index c48f9425e..f0b42694a 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -661,7 +661,10 @@ describe "Budget Investments" do expect(page).not_to have_content("#{heading.name} (#{budget.formatted_heading_price(heading)})") expect(page).to have_select "Heading", - options: ["", "Health: More hospitals", "Health: Medical supplies", "Education: Schools"] + options: ["", + "Health: More hospitals", + "Health: Medical supplies", + "Education: Schools"] select "Health: Medical supplies", from: "Heading" @@ -691,7 +694,11 @@ describe "Budget Investments" do scenario "Edit" do daniel = create(:user, :level_two) - create(:budget_investment, heading: heading, title: "Get Schwifty", author: daniel, created_at: 1.day.ago) + create(:budget_investment, + heading: heading, + title: "Get Schwifty", + author: daniel, + created_at: 1.day.ago) login_as(daniel) @@ -1101,9 +1108,15 @@ describe "Budget Investments" do expect(page).not_to have_content("Local government is not competent in this matter") end - it_behaves_like "followable", "budget_investment", "budget_investment_path", { budget_id: "budget_id", id: "id" } + it_behaves_like "followable", + "budget_investment", + "budget_investment_path", + { budget_id: "budget_id", id: "id" } - it_behaves_like "imageable", "budget_investment", "budget_investment_path", { budget_id: "budget_id", id: "id" } + it_behaves_like "imageable", + "budget_investment", + "budget_investment_path", + { budget_id: "budget_id", id: "id" } it_behaves_like "nested imageable", "budget_investment", @@ -1113,7 +1126,10 @@ describe "Budget Investments" do "Create Investment", "Budget Investment created successfully." - it_behaves_like "documentable", "budget_investment", "budget_investment_path", { budget_id: "budget_id", id: "id" } + it_behaves_like "documentable", + "budget_investment", + "budget_investment_path", + { budget_id: "budget_id", id: "id" } it_behaves_like "nested documentable", "user", @@ -1383,11 +1399,17 @@ describe "Budget Investments" do end scenario "Order by cost (only when balloting)" do - mid_investment = create(:budget_investment, :selected, heading: heading, title: "Build a nice house", price: 1000) + mid_investment = create(:budget_investment, :selected, heading: heading, + title: "Build a nice house", + price: 1000) mid_investment.update_column(:confidence_score, 10) - low_investment = create(:budget_investment, :selected, heading: heading, title: "Build an ugly house", price: 1000) + low_investment = create(:budget_investment, :selected, heading: heading, + title: "Build an ugly house", + price: 1000) low_investment.update_column(:confidence_score, 5) - high_investment = create(:budget_investment, :selected, heading: heading, title: "Build a skyscraper", price: 20000) + high_investment = create(:budget_investment, :selected, heading: heading, + title: "Build a skyscraper", + price: 20000) visit budget_investments_path(budget, heading_id: heading.id) @@ -1699,8 +1721,23 @@ describe "Budget Investments" do end scenario "Shows the polygon associated to the current heading" do - triangle = '{ "geometry": { "type": "Polygon", "coordinates": [[-0.1,51.5],[-0.2,51.4],[-0.3,51.6]] } }' - rectangle = '{ "geometry": { "type": "Polygon", "coordinates": [[-0.1,51.5],[-0.2,51.5],[-0.2,51.6],[-0.1,51.6]] } }' + triangle = <<~JSON + { + "geometry": { + "type": "Polygon", + "coordinates": [[-0.1,51.5],[-0.2,51.4],[-0.3,51.6]] + } + } + JSON + + rectangle = <<~JSON + { + "geometry": { + "type": "Polygon", + "coordinates": [[-0.1,51.5],[-0.2,51.5],[-0.2,51.6],[-0.1,51.6]] + } + } + JSON park = create(:geozone, geojson: triangle, color: "#03ee03") square = create(:geozone, geojson: rectangle, color: "#ff04ff") diff --git a/spec/system/budgets/results_spec.rb b/spec/system/budgets/results_spec.rb index b17618ef6..777eeb74a 100644 --- a/spec/system/budgets/results_spec.rb +++ b/spec/system/budgets/results_spec.rb @@ -6,10 +6,24 @@ describe "Results" do let(:heading) { create(:budget_heading, group: group, price: 1000) } before do - create(:budget_investment, :selected, title: "First selected", heading: heading, price: 200, ballot_lines_count: 900) - create(:budget_investment, :selected, title: "Second selected", heading: heading, price: 300, ballot_lines_count: 800) - create(:budget_investment, :incompatible, title: "Incompatible investment", heading: heading, price: 500, ballot_lines_count: 700) - create(:budget_investment, :selected, title: "Exceeding price", heading: heading, price: 600, ballot_lines_count: 600) + create(:budget_investment, :selected, title: "First selected", + heading: heading, + price: 200, + ballot_lines_count: 900) + + create(:budget_investment, :selected, title: "Second selected", + heading: heading, price: 300, + ballot_lines_count: 800) + + create(:budget_investment, :incompatible, title: "Incompatible investment", + heading: heading, + price: 500, + ballot_lines_count: 700) + + create(:budget_investment, :selected, title: "Exceeding price", + heading: heading, + price: 600, + ballot_lines_count: 600) Budget::Result.new(budget, heading).calculate_winners end diff --git a/spec/system/budgets/votes_spec.rb b/spec/system/budgets/votes_spec.rb index 9d38b47b6..27df7c53e 100644 --- a/spec/system/budgets/votes_spec.rb +++ b/spec/system/budgets/votes_spec.rb @@ -149,7 +149,8 @@ describe "Votes" do participation = find(".participation-not-allowed") headings = participation.text - .match(/You have already supported investments in (.+) and (.+)\./)&.captures + .match(/You have already supported investments in (.+) and (.+)\./) + &.captures expect(headings).to match_array [new_york.name, san_francisco.name] diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 639db3a24..28f8dea6e 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -36,7 +36,8 @@ describe "Commenting Budget::Investments" do expect(page).to have_content "First subcomment" expect(page).to have_content "Last subcomment" - expect(page).to have_link "Go back to #{investment.title}", href: budget_investment_path(investment.budget, investment) + expect(page).to have_link "Go back to #{investment.title}", + href: budget_investment_path(investment.budget, investment) within ".comment", text: "Parent" do expect(page).to have_selector(".comment", count: 2) @@ -60,8 +61,14 @@ describe "Commenting Budget::Investments" do scenario "Collapsable comments" do parent_comment = create(:comment, body: "Main comment", commentable: investment) - child_comment = create(:comment, body: "First subcomment", commentable: investment, parent: parent_comment) - grandchild_comment = create(:comment, body: "Last subcomment", commentable: investment, parent: child_comment) + child_comment = create(:comment, + body: "First subcomment", + commentable: investment, + parent: parent_comment) + grandchild_comment = create(:comment, + body: "Last subcomment", + commentable: investment, + parent: child_comment) visit budget_investment_path(investment.budget, investment) @@ -126,8 +133,14 @@ describe "Commenting Budget::Investments" do scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: investment, created_at: Time.current - 10) new_root = create(:comment, commentable: investment, created_at: Time.current) - old_child = create(:comment, commentable: investment, parent_id: new_root.id, created_at: Time.current - 10) - new_child = create(:comment, commentable: investment, parent_id: new_root.id, created_at: Time.current) + old_child = create(:comment, + commentable: investment, + parent_id: new_root.id, + created_at: Time.current - 10) + new_child = create(:comment, + commentable: investment, + parent_id: new_root.id, + created_at: Time.current) visit budget_investment_path(investment.budget, investment, order: :most_voted) @@ -160,7 +173,9 @@ describe "Commenting Budget::Investments" do scenario "Sanitizes comment body for security" do create :comment, commentable: investment, - body: "
click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit budget_investment_path(investment.budget, investment) diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index f56e52c35..b3d846f59 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -176,7 +176,9 @@ describe "Commenting debates" do scenario "Sanitizes comment body for security" do create :comment, commentable: debate, - body: " click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit debate_path(debate) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 54ae77b22..0e409c55b 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -57,8 +57,14 @@ describe "Commenting legislation questions" do scenario "Collapsable comments" do parent_comment = annotation.comments.first - child_comment = create(:comment, body: "First subcomment", commentable: annotation, parent: parent_comment) - grandchild_comment = create(:comment, body: "Last subcomment", commentable: annotation, parent: child_comment) + child_comment = create(:comment, + body: "First subcomment", + commentable: annotation, + parent: parent_comment) + grandchild_comment = create(:comment, + body: "Last subcomment", + commentable: annotation, + parent: child_comment) visit polymorphic_path(annotation) @@ -123,8 +129,14 @@ describe "Commenting legislation questions" do scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: annotation, created_at: Time.current - 10) new_root = create(:comment, commentable: annotation, created_at: Time.current) - old_child = create(:comment, commentable: annotation, parent_id: new_root.id, created_at: Time.current - 10) - new_child = create(:comment, commentable: annotation, parent_id: new_root.id, created_at: Time.current) + old_child = create(:comment, + commentable: annotation, + parent_id: new_root.id, + created_at: Time.current - 10) + new_child = create(:comment, + commentable: annotation, + parent_id: new_root.id, + created_at: Time.current) visit polymorphic_path(annotation, order: :most_voted) @@ -158,7 +170,9 @@ describe "Commenting legislation questions" do scenario "Sanitizes comment body for security" do create :comment, commentable: annotation, - body: " click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit polymorphic_path(annotation) @@ -563,12 +577,16 @@ describe "Commenting legislation questions" do describe "Merged comment threads" do let!(:draft_version) { create(:legislation_draft_version, :published) } let!(:annotation1) do - create(:legislation_annotation, draft_version: draft_version, text: "my annotation", - ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my annotation", + ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5 }]) end let!(:annotation2) do - create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", - ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my other annotation", + ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10 }]) end let!(:comment1) { annotation1.comments.first } let!(:comment2) { annotation2.comments.first } diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 83bda571d..bec16a685 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -63,7 +63,10 @@ describe "Commenting legislation questions" do scenario "Collapsable comments" do parent_comment = create(:comment, body: "Main comment", commentable: question) child_comment = create(:comment, body: "First subcomment", commentable: question, parent: parent_comment) - grandchild_comment = create(:comment, body: "Last subcomment", commentable: question, parent: child_comment) + grandchild_comment = create(:comment, + body: "Last subcomment", + commentable: question, + parent: child_comment) visit legislation_process_question_path(question.process, question) @@ -162,7 +165,9 @@ describe "Commenting legislation questions" do scenario "Sanitizes comment body for security" do create :comment, commentable: question, - body: " click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit legislation_process_question_path(question.process, question) diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index c4ffbd90f..461177820 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -154,7 +154,9 @@ describe "Commenting polls" do scenario "Sanitizes comment body for security" do create :comment, commentable: poll, - body: " click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit poll_path(poll) diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index 4e229f3cb..bece16b5a 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -57,7 +57,10 @@ describe "Commenting proposals" do scenario "Collapsable comments" do parent_comment = create(:comment, body: "Main comment", commentable: proposal) child_comment = create(:comment, body: "First subcomment", commentable: proposal, parent: parent_comment) - grandchild_comment = create(:comment, body: "Last subcomment", commentable: proposal, parent: child_comment) + grandchild_comment = create(:comment, + body: "Last subcomment", + commentable: proposal, + parent: child_comment) visit proposal_path(proposal) @@ -156,7 +159,9 @@ describe "Commenting proposals" do scenario "Sanitizes comment body for security" do create :comment, commentable: proposal, - body: " click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit proposal_path(proposal) diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index 51484eec0..1fb666c05 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -169,7 +169,9 @@ describe "Commenting topics from proposals" do community = proposal.community topic = create(:topic, community: community) create :comment, commentable: topic, - body: " click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit community_topic_path(community, topic) @@ -716,7 +718,9 @@ describe "Commenting topics from budget investments" do community = investment.community topic = create(:topic, community: community) create :comment, commentable: topic, - body: " click me http://www.url.com" + body: " " \ + "click me " \ + "http://www.url.com" visit community_topic_path(community, topic) diff --git a/spec/system/debates_spec.rb b/spec/system/debates_spec.rb index 71febb1e9..4f981e0fb 100644 --- a/spec/system/debates_spec.rb +++ b/spec/system/debates_spec.rb @@ -295,7 +295,9 @@ describe "Debates" do scenario "JS injection is prevented but autolinking is respected", :no_js do author = create(:user) - js_injection_string = " click me http://example.org" + js_injection_string = " " \ + "click me " \ + "http://example.org" login_as(author) visit new_debate_path @@ -673,10 +675,19 @@ describe "Debates" do create(:debate, title: "First debate has 1 vote", cached_votes_up: 1) create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2) create(:debate, title: "Third debate has 3 votes", cached_votes_up: 3) - create(:debate, title: "This one has 4 votes", description: "This is the fourth debate", cached_votes_up: 4) + create(:debate, + title: "This one has 4 votes", + description: "This is the fourth debate", + cached_votes_up: 4) create(:debate, title: "Fifth debate has 5 votes", cached_votes_up: 5) - create(:debate, title: "Sixth debate has 6 votes", description: "This is the sixth debate", cached_votes_up: 6) - create(:debate, title: "This has seven votes, and is not suggest", description: "This is the seven", cached_votes_up: 7) + create(:debate, + title: "Sixth debate has 6 votes", + description: "This is the sixth debate", + cached_votes_up: 6) + create(:debate, + title: "This has seven votes, and is not suggest", + description: "This is the seven", + cached_votes_up: 7) login_as(create(:user)) visit new_debate_path diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 38f1ea940..5d488053f 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -386,8 +386,9 @@ describe "Emails" do expect(page).to have_content "Dossier updated" email = open_last_email - expect(email).to have_subject("Your investment project '#{investment.code}' has been marked as unfeasible") - expect(email).to deliver_to(investment.author.email) + expect(email).to have_subject "Your investment project '#{investment.code}' " \ + "has been marked as unfeasible" + expect(email).to deliver_to investment.author.email expect(email).to have_body_text "This is not legal as stated in Article 34.9" end diff --git a/spec/system/legislation/draft_versions_spec.rb b/spec/system/legislation/draft_versions_spec.rb index b306c0207..745494f5d 100644 --- a/spec/system/legislation/draft_versions_spec.rb +++ b/spec/system/legislation/draft_versions_spec.rb @@ -93,8 +93,12 @@ describe "Legislation Draft Versions" do context "for final versions" do it "does not show the comments panel" do - final_version = create(:legislation_draft_version, process: process, title: "Final version", - body: "Final body", status: "published", final_version: true) + final_version = create(:legislation_draft_version, + process: process, + title: "Final version", + body: "Final body", + status: "published", + final_version: true) visit legislation_process_draft_version_path(process, final_version) @@ -213,10 +217,17 @@ describe "Legislation Draft Versions" do end scenario "View annotations and comments" do - annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", - ranges: [{ "start" => "/p[1]", "startOffset" => 5, "end" => "/p[1]", "endOffset" => 10 }]) - create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", - ranges: [{ "start" => "/p[1]", "startOffset" => 12, "end" => "/p[1]", "endOffset" => 19 }]) + annotation1 = create(:legislation_annotation, + draft_version: draft_version, + text: "my annotation", + ranges: [{ "start" => "/p[1]", + "startOffset" => 5, + "end" => "/p[1]", + "endOffset" => 10 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my other annotation", + ranges: [{ "start" => "/p[1]", "startOffset" => 12, "end" => "/p[1]", "endOffset" => 19 }]) comment = create(:comment, commentable: annotation1) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -231,8 +242,10 @@ describe "Legislation Draft Versions" do end scenario "Publish new comment for an annotation from comments box" do - create(:legislation_annotation, draft_version: draft_version, text: "my annotation", - ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my annotation", + ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -306,10 +319,14 @@ describe "Legislation Draft Versions" do before { login_as user } scenario "View annotations and comments in an included range" do - create(:legislation_annotation, draft_version: draft_version, text: "my annotation", - ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5 }]) - create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", - ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my annotation", + ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my other annotation", + ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10 }]) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -328,10 +345,16 @@ describe "Legislation Draft Versions" do let(:draft_version) { create(:legislation_draft_version, :published) } before do - create(:legislation_annotation, draft_version: draft_version, text: "my annotation", quote: "ipsum", - ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) - create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam", - ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my annotation", + quote: "ipsum", + ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my other annotation", + quote: "audiam", + ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }]) end scenario "See all annotations for a draft version" do @@ -347,10 +370,14 @@ describe "Legislation Draft Versions" do let(:current) { create(:legislation_draft_version, :published, process: process, title: "Current") } before do - create(:legislation_annotation, draft_version: original, quote: "quote for version 1", - ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) - create(:legislation_annotation, draft_version: current, quote: "quote for version 2", - ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) + create(:legislation_annotation, + draft_version: original, + quote: "quote for version 1", + ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) + create(:legislation_annotation, + draft_version: current, + quote: "quote for version 2", + ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) end scenario "without js", :no_js do @@ -380,13 +407,22 @@ describe "Legislation Draft Versions" do let(:draft_version) { create(:legislation_draft_version, :published) } before do - create(:legislation_annotation, draft_version: draft_version, text: "my annotation", quote: "ipsum", - ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) + create(:legislation_annotation, + draft_version: draft_version, + text: "my annotation", + quote: "ipsum", + ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) end scenario "See one annotation with replies for a draft version" do - annotation = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam", - ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }]) + annotation = create(:legislation_annotation, + draft_version: draft_version, + text: "my other annotation", + quote: "audiam", + ranges: [{ "start" => "/p[3]", + "startOffset" => 6, + "end" => "/p[3]", + "endOffset" => 11 }]) visit polymorphic_path(annotation) diff --git a/spec/system/legislation/processes_spec.rb b/spec/system/legislation/processes_spec.rb index 6540ae3e5..5a3bee659 100644 --- a/spec/system/legislation/processes_spec.rb +++ b/spec/system/legislation/processes_spec.rb @@ -4,8 +4,10 @@ describe "Legislation" do let!(:administrator) { create(:administrator).user } shared_examples "not published permissions" do |path| - let(:not_published_process) { create(:legislation_process, :not_published, title: "Process not published") } let!(:not_permission_message) { "You do not have permission to carry out the action" } + let(:not_published_process) do + create(:legislation_process, :not_published, title: "Process not published") + end it "is forbidden for a normal user" do visit send(path, not_published_process) @@ -276,7 +278,9 @@ describe "Legislation" do context "debate phase" do scenario "not open", :with_frozen_time do - process = create(:legislation_process, debate_start_date: Date.current + 1.day, debate_end_date: Date.current + 2.days) + process = create(:legislation_process, + debate_start_date: Date.current + 1.day, + debate_end_date: Date.current + 2.days) visit legislation_process_path(process) @@ -284,7 +288,9 @@ describe "Legislation" do end scenario "open without questions" do - process = create(:legislation_process, debate_start_date: Date.current - 1.day, debate_end_date: Date.current + 2.days) + process = create(:legislation_process, + debate_start_date: Date.current - 1.day, + debate_end_date: Date.current + 2.days) visit legislation_process_path(process) @@ -292,7 +298,9 @@ describe "Legislation" do end scenario "open with questions" do - process = create(:legislation_process, debate_start_date: Date.current - 1.day, debate_end_date: Date.current + 2.days) + process = create(:legislation_process, + debate_start_date: Date.current - 1.day, + debate_end_date: Date.current + 2.days) create(:legislation_question, process: process, title: "Question 1") create(:legislation_question, process: process, title: "Question 2") @@ -328,7 +336,9 @@ describe "Legislation" do context "allegations phase" do scenario "not open", :with_frozen_time do - process = create(:legislation_process, allegations_start_date: Date.current + 1.day, allegations_end_date: Date.current + 2.days) + process = create(:legislation_process, + allegations_start_date: Date.current + 1.day, + allegations_end_date: Date.current + 2.days) visit allegations_legislation_process_path(process) @@ -336,7 +346,9 @@ describe "Legislation" do end scenario "open" do - process = create(:legislation_process, allegations_start_date: Date.current - 1.day, allegations_end_date: Date.current + 2.days) + process = create(:legislation_process, + allegations_start_date: Date.current - 1.day, + allegations_end_date: Date.current + 2.days) visit allegations_legislation_process_path(process) diff --git a/spec/system/legislation/summary_spec.rb b/spec/system/legislation/summary_spec.rb index 37618b9e1..36c9ffe28 100644 --- a/spec/system/legislation/summary_spec.rb +++ b/spec/system/legislation/summary_spec.rb @@ -123,12 +123,16 @@ describe "Legislation" do before do user = create(:user, :level_two) - draft_version_1 = create(:legislation_draft_version, process: process, - title: "Version 1", body: "Body of the first version", - status: "published") - draft_version_2 = create(:legislation_draft_version, process: process, - title: "Version 2", body: "Body of the second version and that's it all of it", - status: "published") + draft_version_1 = create(:legislation_draft_version, + process: process, + title: "Version 1", + body: "Body of the first version", + status: "published") + draft_version_2 = create(:legislation_draft_version, + process: process, + title: "Version 2", + body: "Body of the second version and that's it all of it", + status: "published") annotation0 = create(:legislation_annotation, draft_version: draft_version_1, text: "my annotation123", ranges: annotation_ranges(5, 10)) diff --git a/spec/system/management/email_verifications_spec.rb b/spec/system/management/email_verifications_spec.rb index 82e0fbe37..54f511a05 100644 --- a/spec/system/management/email_verifications_spec.rb +++ b/spec/system/management/email_verifications_spec.rb @@ -15,7 +15,8 @@ describe "EmailVerifications" do fill_in "email_verification_email", with: user.email click_button "Send verification email" - expect(page).to have_content("In order to completely verify this user, it is necessary that the user clicks on a link") + expect(page).to have_content "In order to completely verify this user, " \ + "it is necessary that the user clicks on a link" user.reload diff --git a/spec/system/management/managed_users_spec.rb b/spec/system/management/managed_users_spec.rb index db1640796..75f375a29 100644 --- a/spec/system/management/managed_users_spec.rb +++ b/spec/system/management/managed_users_spec.rb @@ -70,7 +70,8 @@ describe "Managed User" do fill_in "email_verification_email", with: user.email click_button "Send verification email" - expect(page).to have_content("In order to completely verify this user, it is necessary that the user clicks on a link") + expect(page).to have_content "In order to completely verify this user, " \ + "it is necessary that the user clicks on a link" within(".account-info") do expect(page).to have_content "Identified as" diff --git a/spec/system/moderation/comments_spec.rb b/spec/system/moderation/comments_spec.rb index 294ba3598..0c980b247 100644 --- a/spec/system/moderation/comments_spec.rb +++ b/spec/system/moderation/comments_spec.rb @@ -211,8 +211,14 @@ describe "Moderate comments" do end scenario "sorting comments" do - flagged_comment = create(:comment, body: "Flagged comment", created_at: 1.day.ago, flags_count: 5) - flagged_new_comment = create(:comment, body: "Flagged new comment", created_at: 12.hours.ago, flags_count: 3) + flagged_comment = create(:comment, + body: "Flagged comment", + created_at: 1.day.ago, + flags_count: 5) + flagged_new_comment = create(:comment, + body: "Flagged new comment", + created_at: 12.hours.ago, + flags_count: 3) newer_comment = create(:comment, body: "Newer comment", created_at: Time.current) visit moderation_comments_path(order: "newest") diff --git a/spec/system/moderation/debates_spec.rb b/spec/system/moderation/debates_spec.rb index 092476220..ba64470dd 100644 --- a/spec/system/moderation/debates_spec.rb +++ b/spec/system/moderation/debates_spec.rb @@ -180,8 +180,14 @@ describe "Moderate debates" do end scenario "sorting debates" do - flagged_debate = create(:debate, title: "Flagged debate", created_at: 1.day.ago, flags_count: 5) - flagged_new_debate = create(:debate, title: "Flagged new debate", created_at: 12.hours.ago, flags_count: 3) + flagged_debate = create(:debate, + title: "Flagged debate", + created_at: 1.day.ago, + flags_count: 5) + flagged_new_debate = create(:debate, + title: "Flagged new debate", + created_at: 12.hours.ago, + flags_count: 3) newer_debate = create(:debate, title: "Newer debate", created_at: Time.current) visit moderation_debates_path(order: "created_at") diff --git a/spec/system/moderation/proposal_notifications_spec.rb b/spec/system/moderation/proposal_notifications_spec.rb index 9b2ee8b83..f609991d0 100644 --- a/spec/system/moderation/proposal_notifications_spec.rb +++ b/spec/system/moderation/proposal_notifications_spec.rb @@ -4,7 +4,9 @@ describe "Moderate proposal notifications" do scenario "Hide" do citizen = create(:user) proposal = create(:proposal) - proposal_notification = create(:proposal_notification, proposal: proposal, created_at: Date.current - 4.days) + proposal_notification = create(:proposal_notification, + proposal: proposal, + created_at: Date.current - 4.days) moderator = create(:moderator) login_as(moderator.user) @@ -27,7 +29,9 @@ describe "Moderate proposal notifications" do scenario "Can not hide own proposal notification" do moderator = create(:moderator) proposal = create(:proposal, author: moderator.user) - proposal_notification = create(:proposal_notification, proposal: proposal, created_at: Date.current - 4.days) + proposal_notification = create(:proposal_notification, + proposal: proposal, + created_at: Date.current - 4.days) login_as(moderator.user) visit proposal_path(proposal) @@ -188,10 +192,21 @@ describe "Moderate proposal notifications" do end scenario "sorting proposal notifications" do - moderated_notification = create(:proposal_notification, :moderated, title: "Moderated notification", created_at: 1.day.ago) - moderated_new_notification = create(:proposal_notification, :moderated, title: "Moderated new notification", created_at: 12.hours.ago) - newer_notification = create(:proposal_notification, title: "Newer notification", created_at: Time.current) - old_moderated_notification = create(:proposal_notification, :moderated, title: "Older notification", created_at: 2.days.ago) + moderated_notification = create(:proposal_notification, + :moderated, + title: "Moderated notification", + created_at: 1.day.ago) + moderated_new_notification = create(:proposal_notification, + :moderated, + title: "Moderated new notification", + created_at: 12.hours.ago) + newer_notification = create(:proposal_notification, + title: "Newer notification", + created_at: Time.current) + old_moderated_notification = create(:proposal_notification, + :moderated, + title: "Older notification", + created_at: 2.days.ago) visit moderation_proposal_notifications_path(filter: "all", order: "created_at") diff --git a/spec/system/moderation/proposals_spec.rb b/spec/system/moderation/proposals_spec.rb index 8bbc739cc..8be434b17 100644 --- a/spec/system/moderation/proposals_spec.rb +++ b/spec/system/moderation/proposals_spec.rb @@ -179,8 +179,14 @@ describe "Moderate proposals" do end scenario "sorting proposals" do - flagged_proposal = create(:proposal, title: "Flagged proposal", created_at: 1.day.ago, flags_count: 5) - flagged_new_proposal = create(:proposal, title: "Flagged new proposal", created_at: 12.hours.ago, flags_count: 3) + flagged_proposal = create(:proposal, + title: "Flagged proposal", + created_at: 1.day.ago, + flags_count: 5) + flagged_new_proposal = create(:proposal, + title: "Flagged new proposal", + created_at: 12.hours.ago, + flags_count: 3) newer_proposal = create(:proposal, title: "Newer proposal", created_at: Time.current) visit moderation_proposals_path(order: "created_at") diff --git a/spec/system/official_positions_spec.rb b/spec/system/official_positions_spec.rb index 7fad3f9d7..8ab484380 100644 --- a/spec/system/official_positions_spec.rb +++ b/spec/system/official_positions_spec.rb @@ -2,7 +2,9 @@ require "rails_helper" describe "Official positions" do context "Badge" do - let(:user1) { create(:user, official_level: 1, official_position: "Employee", official_position_badge: true) } + let(:user1) do + create(:user, official_level: 1, official_position: "Employee", official_position_badge: true) + end let(:user2) { create(:user, official_level: 0, official_position: "") } scenario "Comments" do diff --git a/spec/system/officing/ballot_sheets_spec.rb b/spec/system/officing/ballot_sheets_spec.rb index b6d50acb4..6f9a26f58 100644 --- a/spec/system/officing/ballot_sheets_spec.rb +++ b/spec/system/officing/ballot_sheets_spec.rb @@ -23,7 +23,8 @@ describe "Officing ballot sheets" do within("tr", text: "Latest budget poll") { click_link "Add results" } select "The only booth", from: "Booth" - fill_in "CSV data", with: "#{investments[0..1].map(&:id).join(",")};#{investments[1..2].map(&:id).join(",")}" + fill_in "CSV data", + with: "#{investments[0..1].map(&:id).join(",")};#{investments[1..2].map(&:id).join(",")}" click_button "Save" expect(page).to have_content "Creation date" diff --git a/spec/system/officing/results_spec.rb b/spec/system/officing/results_spec.rb index 7fa0d8926..8f65e714c 100644 --- a/spec/system/officing/results_spec.rb +++ b/spec/system/officing/results_spec.rb @@ -91,7 +91,9 @@ describe "Officing Results", :with_frozen_time do amount: 7777 ) - visit officing_poll_results_path(poll, date: I18n.l(partial_result.date), booth_assignment_id: partial_result.booth_assignment_id) + visit officing_poll_results_path(poll, + date: I18n.l(partial_result.date), + booth_assignment_id: partial_result.booth_assignment_id) within("#question_#{question_1.id}_0_result") { expect(page).to have_content("7777") } diff --git a/spec/system/officing/voters_spec.rb b/spec/system/officing/voters_spec.rb index 4123602d9..63143123d 100644 --- a/spec/system/officing/voters_spec.rb +++ b/spec/system/officing/voters_spec.rb @@ -68,7 +68,10 @@ describe "Voters" do end scenario "Had already verified his residence, but is not level 2 yet" do - user = create(:user, residence_verified_at: Time.current, document_type: "1", document_number: "12345678Z") + user = create(:user, + residence_verified_at: Time.current, + document_type: "1", + document_number: "12345678Z") expect(user).not_to be_level_two_verified visit root_path diff --git a/spec/system/officing_spec.rb b/spec/system/officing_spec.rb index c48bafb48..78a2fe18a 100644 --- a/spec/system/officing_spec.rb +++ b/spec/system/officing_spec.rb @@ -137,7 +137,11 @@ describe "Poll Officing" do expect(page).to have_content "Document verified with Census" click_button "Confirm vote" expect(page).to have_content "Vote introduced!" - expect(Poll::Voter.where(document_number: "12345678Z", poll_id: poll, origin: "booth", officer_id: officer1).count).to be(1) + expect(Poll::Voter.where(document_number: "12345678Z", + poll_id: poll, + origin: "booth", + officer_id: officer1) + .count).to be(1) visit final_officing_polls_path expect(page).to have_content("Polls ready for final recounting") @@ -156,7 +160,11 @@ describe "Poll Officing" do expect(page).to have_content "Document verified with Census" click_button "Confirm vote" expect(page).to have_content "Vote introduced!" - expect(Poll::Voter.where(document_number: "12345678Y", poll_id: poll, origin: "booth", officer_id: officer2).count).to be(1) + expect(Poll::Voter.where(document_number: "12345678Y", + poll_id: poll, + origin: "booth", + officer_id: officer2) + .count).to be(1) visit final_officing_polls_path expect(page).to have_content("Polls ready for final recounting") diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb index 11e13f440..6016c92bf 100644 --- a/spec/system/polls/polls_spec.rb +++ b/spec/system/polls/polls_spec.rb @@ -337,7 +337,8 @@ describe "Polls" do login_as user visit poll_path(poll) - expect(page).to have_content "You have already participated in a physical booth. You can not participate again." + expect(page).to have_content "You have already participated in a physical booth. " \ + "You can not participate again." within("#poll_question_#{question.id}_answers") do expect(page).to have_content("Yes") diff --git a/spec/system/polls/voter_spec.rb b/spec/system/polls/voter_spec.rb index 46086b2e5..640670524 100644 --- a/spec/system/polls/voter_spec.rb +++ b/spec/system/polls/voter_spec.rb @@ -68,8 +68,9 @@ describe "Voter" do expect(page).to have_link("No", href: verification_path) end - expect(page).to have_content("You must verify your account in order to answer") - expect(page).not_to have_content("You have already participated in this poll. If you vote again it will be overwritten") + expect(page).to have_content "You must verify your account in order to answer" + expect(page).not_to have_content "You have already participated in this poll. " \ + "If you vote again it will be overwritten" end scenario "Voting in booth" do @@ -173,7 +174,8 @@ describe "Voter" do within("#poll_question_#{question.id}_answers") do expect(page).not_to have_button("Yes") end - expect(page).to have_content "You have already participated in a physical booth. You can not participate again." + expect(page).to have_content "You have already participated in a physical booth. " \ + "You can not participate again." expect(Poll::Voter.count).to eq(1) visit root_path @@ -213,7 +215,8 @@ describe "Voter" do expect(page).not_to have_button("Yes") end - expect(page).to have_content "You have already participated in a physical booth. You can not participate again." + expect(page).to have_content "You have already participated in a physical booth. " \ + "You can not participate again." expect(Poll::Voter.count).to eq(1) visit root_path diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index 5969d856a..6bd950fef 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -505,7 +505,9 @@ describe "Proposals" do scenario "JS injection is prevented but autolinking is respected", :no_js do author = create(:user) - js_injection_string = " click me http://example.org" + js_injection_string = " " \ + "click me " \ + "http://example.org" login_as(author) visit new_proposal_path diff --git a/spec/system/sdg/goals_spec.rb b/spec/system/sdg/goals_spec.rb index 898e1f52e..5d083cc91 100644 --- a/spec/system/sdg/goals_spec.rb +++ b/spec/system/sdg/goals_spec.rb @@ -166,7 +166,8 @@ describe "SDG Goals" do click_link "Local targets" - expect(page).not_to have_content "15.1 By 2020, ensure the conservation, restoration and sustainable use" + expect(page).not_to have_content "15.1 By 2020, ensure the conservation, " \ + "restoration and sustainable use" expect(page).to have_content "SDG local target sample text" end end diff --git a/spec/system/tags/budget_investments_spec.rb b/spec/system/tags/budget_investments_spec.rb index b970f59e1..8233dbcfb 100644 --- a/spec/system/tags/budget_investments_spec.rb +++ b/spec/system/tags/budget_investments_spec.rb @@ -53,7 +53,9 @@ describe "Tags" do end scenario "Show" do - investment = create(:budget_investment, heading: heading, tag_list: "#{tag_medio_ambiente.name}, #{tag_economia.name}") + investment = create(:budget_investment, + heading: heading, + tag_list: "#{tag_medio_ambiente.name}, #{tag_economia.name}") visit budget_investment_path(budget, investment) @@ -157,7 +159,8 @@ describe "Tags" do fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds" check "budget_investment_terms_of_service" - fill_in "budget_investment_tag_list", with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad" + fill_in "budget_investment_tag_list", + with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad" click_button "Create Investment" diff --git a/spec/system/topics_spec.rb b/spec/system/topics_spec.rb index 45e33492b..f2704f848 100644 --- a/spec/system/topics_spec.rb +++ b/spec/system/topics_spec.rb @@ -42,8 +42,13 @@ describe "Topics" do expect(page).to have_content "Title" expect(page).to have_content "Initial text" expect(page).to have_content "Recommendations to create a topic" - expect(page).to have_content "Do not write the topic title or whole sentences in capital letters. On the internet that is considered shouting. And no one likes to be yelled at." - expect(page).to have_content "Any topic or comment that implies an illegal action will be eliminated, also those that intend to sabotage the spaces of the subject, everything else is allowed." + expect(page).to have_content "Do not write the topic title or whole sentences in " \ + "capital letters. On the internet that is considered " \ + "shouting. And no one likes to be yelled at." + expect(page).to have_content "Any topic or comment that implies an illegal action " \ + "will be eliminated, also those that intend to " \ + "sabotage the spaces of the subject, everything else " \ + "is allowed." expect(page).to have_content "Enjoy this space, the voices that fill it, it's yours too." expect(page).to have_button("Create topic") end diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index 4fb0ed6e3..f5934515a 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -4,7 +4,8 @@ describe "Users" do context "Regular authentication" do context "Sign up" do scenario "Success" do - message = "You have been sent a message containing a verification link. Please click on this link to activate your account." + message = "You have been sent a message containing a verification link. " \ + "Please click on this link to activate your account." visit "/" click_link "Register" @@ -32,7 +33,8 @@ describe "Users" do end scenario "User already confirmed email with the token" do - message = "You have been sent a message containing a verification link. Please click on this link to activate your account." + message = "You have been sent a message containing a verification link. " \ + "Please click on this link to activate your account." visit "/" click_link "Register" @@ -224,7 +226,9 @@ describe "Users" do context "Twitter" do let(:twitter_hash) { { uid: "12345", info: { name: "manuela" }} } - let(:twitter_hash_with_email) { { uid: "12345", info: { name: "manuela", email: "manuelacarmena@example.com" }} } + let(:twitter_hash_with_email) do + { uid: "12345", info: { name: "manuela", email: "manuelacarmena@example.com" }} + end let(:twitter_hash_with_verified_email) do { uid: "12345", @@ -264,7 +268,8 @@ describe "Users" do click_link "Sign up with Twitter" expect(page).to have_current_path(new_user_session_path) - expect(page).to have_content "To continue, please click on the confirmation link that we have sent you via email" + expect(page).to have_content "To continue, please click on the confirmation " \ + "link that we have sent you via email" confirm_email expect(page).to have_content "Your account has been confirmed" @@ -294,7 +299,8 @@ describe "Users" do fill_in "Email", with: "manueladelascarmenas@example.com" click_button "Register" - expect(page).to have_content "To continue, please click on the confirmation link that we have sent you via email" + expect(page).to have_content "To continue, please click on the confirmation " \ + "link that we have sent you via email" confirm_email expect(page).to have_content "Your account has been confirmed" @@ -393,7 +399,8 @@ describe "Users" do fill_in "Username", with: "manuela2" click_button "Register" - expect(page).to have_content "To continue, please click on the confirmation link that we have sent you via email" + expect(page).to have_content "To continue, please click on the confirmation " \ + "link that we have sent you via email" confirm_email @@ -429,7 +436,8 @@ describe "Users" do fill_in "Email", with: "somethingelse@example.com" click_button "Register" - expect(page).to have_content "To continue, please click on the confirmation link that we have sent you via email" + expect(page).to have_content "To continue, please click on the confirmation " \ + "link that we have sent you via email" confirm_email expect(page).to have_content "Your account has been confirmed" @@ -462,7 +470,8 @@ describe "Users" do fill_in "Email", with: "somethingelse@example.com" click_button "Register" - expect(page).to have_content "To continue, please click on the confirmation link that we have sent you via email" + expect(page).to have_content "To continue, please click on the confirmation " \ + "link that we have sent you via email" confirm_email expect(page).to have_content "Your account has been confirmed" @@ -529,7 +538,8 @@ describe "Users" do click_link "Sign up with Wordpress" expect(page).to have_current_path(new_user_session_path) - expect(page).to have_content "To continue, please click on the confirmation link that we have sent you via email" + expect(page).to have_content "To continue, please click on the confirmation " \ + "link that we have sent you via email" confirm_email expect(page).to have_content "Your account has been confirmed" @@ -569,7 +579,8 @@ describe "Users" do click_button "Register" expect(page).to have_current_path(new_user_session_path) - expect(page).to have_content "To continue, please click on the confirmation link that we have sent you via email" + expect(page).to have_content "To continue, please click on the confirmation " \ + "link that we have sent you via email" confirm_email expect(page).to have_content "Your account has been confirmed" diff --git a/spec/system/verification/letter_spec.rb b/spec/system/verification/letter_spec.rb index f75a64669..5f5d61b4b 100644 --- a/spec/system/verification/letter_spec.rb +++ b/spec/system/verification/letter_spec.rb @@ -10,8 +10,10 @@ describe "Verify Letter" do click_link "Send me a letter with the code" - expect(page).to have_content "Thank you for requesting your maximum security code (only required for the final votes). In a few days" \ - " we will send it to the address featuring in the data we have on file." + expect(page).to have_content "Thank you for requesting your maximum security code " \ + "(only required for the final votes). In a few days " \ + "we will send it to the address featuring in the data " \ + "we have on file." user.reload diff --git a/spec/system/verification/level_three_verification_spec.rb b/spec/system/verification/level_three_verification_spec.rb index 0d2a30749..060688b84 100644 --- a/spec/system/verification/level_three_verification_spec.rb +++ b/spec/system/verification/level_three_verification_spec.rb @@ -87,7 +87,9 @@ describe "Level three verification" do click_link "Send me a letter with the code" - expect(page).to have_content "Thank you for requesting your maximum security code (only required for the final votes)." \ - " In a few days we will send it to the address featuring in the data we have on file." + expect(page).to have_content "Thank you for requesting your maximum security code " \ + "(only required for the final votes). In a few days " \ + "we will send it to the address featuring in the data " \ + "we have on file." end end diff --git a/spec/system/verification/verification_path_spec.rb b/spec/system/verification/verification_path_spec.rb index 56c953bfc..d3e826cac 100644 --- a/spec/system/verification/verification_path_spec.rb +++ b/spec/system/verification/verification_path_spec.rb @@ -41,7 +41,10 @@ describe "Verification path" do end scenario "User received a verification sms" do - user = create(:user, residence_verified_at: Time.current, unconfirmed_phone: "666666666", sms_confirmation_code: "666") + user = create(:user, + residence_verified_at: Time.current, + unconfirmed_phone: "666666666", + sms_confirmation_code: "666") login_as(user) visit verification_path