From baaada39b6fb532d4791117dfc14b408177f1ead Mon Sep 17 00:00:00 2001 From: Joonas Date: Wed, 15 Jan 2025 14:22:11 +0200 Subject: [PATCH] Fix lint --- Gemfile | 7 ++ Gemfile.lock | 12 ++-- .../project_cell_extensions.rb | 2 +- .../admin_update_project_extensions.rb | 2 +- .../export_projects_to_accountability.rb | 2 +- .../decidim/budgets/checkout_orders.rb | 6 +- app/commands/decidim/budgets/start_voting.rb | 4 +- .../admin/projects_controller_extensions.rb | 6 +- .../budgeting_pipeline/authorizable.rb | 2 +- .../line_items_controller_extensions.rb | 2 +- .../orders_controller_extensions.rb | 2 + .../projects_controller_extensions.rb | 4 +- .../budgets/admin/help_sections_controller.rb | 14 ++-- .../decidim/budgets/results_controller.rb | 6 +- .../decidim/budgets/votes_controller.rb | 4 +- .../projects_helper_extensions.rb | 4 +- app/helpers/decidim/budgets/results_helper.rb | 2 +- .../decidim/budgets/order_summaries_mailer.rb | 2 +- .../decidim/budgets/project_presenter.rb | 2 +- .../20210820123351_create_budgeting_votes.rb | 4 +- lib/decidim/api/budget_mutation_type.rb | 12 ++-- .../budgeting_pipeline/api/permissions.rb | 2 +- .../budgeting_pipeline/help_container.rb | 2 +- .../budgeting_pipeline/test/factories.rb | 26 ++++---- .../workflows/base_extensions.rb | 2 +- .../budgets/admin/create_project_spec.rb | 48 +++++++------- .../budgets/admin/update_project_spec.rb | 52 +++++++-------- .../decidim/budgets/checkout_orders_spec.rb | 30 ++++----- .../decidim/budgets/start_voting_spec.rb | 8 +-- .../budgets/line_items_controller_spec.rb | 22 +++---- .../decidim/budgets/orders_controller_spec.rb | 10 +-- .../budgets/results_controller_spec.rb | 2 +- .../decidim/budgets/votes_controller_spec.rb | 58 ++++++++--------- .../budgets/admin/component_form_spec.rb | 2 +- .../budgets/admin/project_form_spec.rb | 38 +++++------ .../decidim/budgets/projects_helper_spec.rb | 6 +- .../budgets/send_order_summaries_job_spec.rb | 8 +-- .../budgets/order_summaries_mailer_spec.rb | 30 ++++----- spec/models/decidim/action_log_spec.rb | 20 +++--- spec/models/decidim/budgets/line_item_spec.rb | 14 ++-- spec/models/decidim/budgets/order_spec.rb | 64 +++++++++---------- spec/models/decidim/budgets/project_spec.rb | 56 ++++++++-------- spec/requests/admin_validates_images_spec.rb | 6 +- .../budgeting_pipeline/project_search_spec.rb | 18 +++--- spec/shared/budgeting_setup_shared_context.rb | 34 +++++----- ...exports_projects_to_accountability_spec.rb | 28 ++++---- .../admin/admin_manages_help_sections_spec.rb | 22 +++---- spec/system/explore_projects_spec.rb | 30 ++++----- spec/system/explore_results_spec.rb | 6 +- spec/system/voting_spec.rb | 25 +++----- .../budget_mutation_type_spec.rb | 12 ++-- .../decidim/budgets/project_type_spec.rb | 8 +-- 52 files changed, 396 insertions(+), 394 deletions(-) diff --git a/Gemfile b/Gemfile index 832e46f..3c1fde4 100644 --- a/Gemfile +++ b/Gemfile @@ -33,7 +33,14 @@ end group :development do gem "letter_opener_web", "~> 2.0" gem "listen", "~> 3.8" + + # rubocop & rubocop-rspec are set to the following versions because of a change where FactoryBot/CreateList + # must be a boolean instead of contextual. These version locks can be removed when this problem is handled + # through decidim-dev. + gem "rubocop", "~>1.28" gem "rubocop-faker" + gem "rubocop-rspec", "2.20" + gem "spring", "~> 4.1.3" gem "spring-watcher-listen", "~> 2.1" gem "web-console", "~> 4.2" diff --git a/Gemfile.lock b/Gemfile.lock index e18e91a..a4e2172 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -725,8 +725,6 @@ GEM parser (>= 3.3.1.0) rubocop-capybara (2.21.0) rubocop (~> 1.41) - rubocop-factory_bot (2.26.0) - rubocop (~> 1.41) rubocop-faker (1.2.0) faker (>= 2.12.0) rubocop (>= 1.13.0) @@ -735,13 +733,9 @@ GEM rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (2.31.0) - rubocop (~> 1.40) + rubocop-rspec (2.20.0) + rubocop (~> 1.33) rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) - rubocop-rspec_rails (~> 2.28) - rubocop-rspec_rails (2.29.0) - rubocop (~> 1.40) ruby-progressbar (1.13.0) ruby-vips (2.2.2) ffi (~> 1.12) @@ -870,7 +864,9 @@ DEPENDENCIES letter_opener_web (~> 2.0) listen (~> 3.8) puma (>= 5.6.2) + rubocop (~> 1.28) rubocop-faker + rubocop-rspec (= 2.20) spring (~> 4.1.3) spring-watcher-listen (~> 2.1) web-console (~> 4.2) diff --git a/app/cells/concerns/decidim/budgeting_pipeline/project_cell_extensions.rb b/app/cells/concerns/decidim/budgeting_pipeline/project_cell_extensions.rb index d43f278..04d24aa 100644 --- a/app/cells/concerns/decidim/budgeting_pipeline/project_cell_extensions.rb +++ b/app/cells/concerns/decidim/budgeting_pipeline/project_cell_extensions.rb @@ -27,7 +27,7 @@ def resource_path def card_wrapper cls = card_classes.is_a?(Array) ? card_classes.join(" ") : card_classes - wrapper_options = { class: "card #{cls}", aria: { label: t(".card_label", title: title) } } + wrapper_options = { class: "card #{cls}", aria: { label: t(".card_label", title:) } } if has_link_to_resource? && !voting? link_to resource_path, **wrapper_options do yield diff --git a/app/commands/concerns/decidim/budgeting_pipeline/admin_update_project_extensions.rb b/app/commands/concerns/decidim/budgeting_pipeline/admin_update_project_extensions.rb index 61f8ced..138fb10 100644 --- a/app/commands/concerns/decidim/budgeting_pipeline/admin_update_project_extensions.rb +++ b/app/commands/concerns/decidim/budgeting_pipeline/admin_update_project_extensions.rb @@ -21,7 +21,7 @@ def update_project description: form.description, budget_amount: form.budget_amount, budget_amount_min: form.budget_amount_min, - selected_at: selected_at, + selected_at:, address: form.address, latitude: form.latitude, longitude: form.longitude diff --git a/app/commands/decidim/budgets/admin/export_projects_to_accountability.rb b/app/commands/decidim/budgets/admin/export_projects_to_accountability.rb index 24db26d..747c797 100644 --- a/app/commands/decidim/budgets/admin/export_projects_to_accountability.rb +++ b/app/commands/decidim/budgets/admin/export_projects_to_accountability.rb @@ -84,7 +84,7 @@ def result_attributes_from(original_project, weight: 0) description: original_project.description, progress: statuses.first&.progress || 0, status: statuses.first, - weight: weight + weight: }.merge(extra_result_attributes_from(original_project)) end diff --git a/app/commands/decidim/budgets/checkout_orders.rb b/app/commands/decidim/budgets/checkout_orders.rb index f37e3fe..da82aa8 100644 --- a/app/commands/decidim/budgets/checkout_orders.rb +++ b/app/commands/decidim/budgets/checkout_orders.rb @@ -62,15 +62,15 @@ def create_vote user, { component: orders.first.component, - user: user, - orders: orders + user:, + orders: }, visibility: "private-only" ) end def has_existing_vote? - Decidim::Budgets::Vote.find_by(component: orders.first.component, user: user).present? + Decidim::Budgets::Vote.find_by(component: orders.first.component, user:).present? end def send_summary diff --git a/app/commands/decidim/budgets/start_voting.rb b/app/commands/decidim/budgets/start_voting.rb index dab66bc..2cc092a 100644 --- a/app/commands/decidim/budgets/start_voting.rb +++ b/app/commands/decidim/budgets/start_voting.rb @@ -33,14 +33,14 @@ def call attr_reader :form, :user, :workflow, :orders def destroy_previous_orders! - Decidim::Budgets::Order.where(budget: budgets, user: user).where.not( + Decidim::Budgets::Order.where(budget: budgets, user:).where.not( budget: selected_budgets ).destroy_all end def create_orders! @orders = selected_budgets.map do |budget| - Decidim::Budgets::Order.find_or_create_by!(user: user, budget: budget) + Decidim::Budgets::Order.find_or_create_by!(user:, budget:) end end diff --git a/app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb b/app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb index cd748bf..28b3231 100644 --- a/app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb +++ b/app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb @@ -13,13 +13,13 @@ def new enforce_permission_to :create, :project @form = form(Decidim::Budgets::Admin::ProjectForm).from_params( { attachment: form(AttachmentForm).instance }, - budget: budget + budget: ) end def edit - enforce_permission_to :update, :project, project: project - @form = form(Decidim::Budgets::Admin::ProjectForm).from_model(project, budget: budget) + enforce_permission_to(:update, :project, project:) + @form = form(Decidim::Budgets::Admin::ProjectForm).from_model(project, budget:) @form.attachment = form(AttachmentForm).instance end end diff --git a/app/controllers/concerns/decidim/budgeting_pipeline/authorizable.rb b/app/controllers/concerns/decidim/budgeting_pipeline/authorizable.rb index 355689d..e935bf8 100644 --- a/app/controllers/concerns/decidim/budgeting_pipeline/authorizable.rb +++ b/app/controllers/concerns/decidim/budgeting_pipeline/authorizable.rb @@ -20,7 +20,7 @@ def authorization_required? if handlers && handlers.any? providers = Decidim::BudgetingPipeline.authorization_providers providers = providers.call(current_organization) if providers.respond_to?(:call) - (handlers & providers).any? + handlers.intersect?(providers) else false end diff --git a/app/controllers/concerns/decidim/budgeting_pipeline/line_items_controller_extensions.rb b/app/controllers/concerns/decidim/budgeting_pipeline/line_items_controller_extensions.rb index d4dafc1..7b84f0f 100644 --- a/app/controllers/concerns/decidim/budgeting_pipeline/line_items_controller_extensions.rb +++ b/app/controllers/concerns/decidim/budgeting_pipeline/line_items_controller_extensions.rb @@ -14,7 +14,7 @@ module LineItemsControllerExtensions helper Decidim::Budgets::VotesHelper def create - enforce_permission_to :vote, :project, project: project, budget: budget, workflow: current_workflow + enforce_permission_to :vote, :project, project:, budget:, workflow: current_workflow @added = true diff --git a/app/controllers/concerns/decidim/budgeting_pipeline/orders_controller_extensions.rb b/app/controllers/concerns/decidim/budgeting_pipeline/orders_controller_extensions.rb index f173248..5aff149 100644 --- a/app/controllers/concerns/decidim/budgeting_pipeline/orders_controller_extensions.rb +++ b/app/controllers/concerns/decidim/budgeting_pipeline/orders_controller_extensions.rb @@ -14,6 +14,8 @@ module OrdersControllerExtensions before_action :set_breadcrumbs, only: [:index] end + def index; end + private def ensure_checked_out_orders! diff --git a/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb b/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb index a72417d..40e8bf7 100644 --- a/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb +++ b/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb @@ -14,14 +14,14 @@ module ProjectsControllerExtensions include Decidim::BudgetingPipeline::Orderable included do + # rubocop:disable Rails/LexicallyScopedActionFilter before_action :set_breadcrumbs, only: [:index, :show] + # rubocop:enable Rails/LexicallyScopedActionFilter helper_method :authorization_required?, :user_authorized?, :help_sections, :geocoded_projects, :budgets, :maximum_project_budget, :vote_success? helper Decidim::BudgetingPipeline::AuthorizationHelper - def index; end - def show raise ActionController::RoutingError, "Not Found" unless project end diff --git a/app/controllers/decidim/budgets/admin/help_sections_controller.rb b/app/controllers/decidim/budgets/admin/help_sections_controller.rb index af8ed83..bb513ca 100644 --- a/app/controllers/decidim/budgets/admin/help_sections_controller.rb +++ b/app/controllers/decidim/budgets/admin/help_sections_controller.rb @@ -18,9 +18,14 @@ def new @form = form(HelpSectionForm).instance end + def edit + enforce_permission_to :update, :help_section, help_section: section + @form = form(HelpSectionForm).from_model(section) + end + def create enforce_permission_to :create, :help_section - @form = form(HelpSectionForm).from_params(params, current_component: current_component) + @form = form(HelpSectionForm).from_params(params, current_component:) CreateHelpSection.call(@form, container) do on(:ok) do @@ -35,14 +40,9 @@ def create end end - def edit - enforce_permission_to :update, :help_section, help_section: section - @form = form(HelpSectionForm).from_model(section) - end - def update enforce_permission_to :update, :help_section, help_section: section - @form = form(HelpSectionForm).from_params(params, current_component: current_component) + @form = form(HelpSectionForm).from_params(params, current_component:) UpdateHelpSection.call(@form, section) do on(:ok) do diff --git a/app/controllers/decidim/budgets/results_controller.rb b/app/controllers/decidim/budgets/results_controller.rb index 9f79dfe..9a5cea3 100644 --- a/app/controllers/decidim/budgets/results_controller.rb +++ b/app/controllers/decidim/budgets/results_controller.rb @@ -68,7 +68,7 @@ def projects_with_votes(budget) @projects_with_votes ||= {} return @projects_with_votes[budget.id] if @projects_with_votes[budget.id].present? - @projects_with_votes[budget.id] = Decidim::Budgets::Project.where(budget: budget).order_by_most_voted(only_voted: true).select( + @projects_with_votes[budget.id] = Decidim::Budgets::Project.where(budget:).order_by_most_voted(only_voted: true).select( "decidim_budgets_projects.*", "decidim_budgets_projects_with_votes.votes_count" ) @@ -78,14 +78,14 @@ def minimum_project_budget(budget) @minimum_project_budget ||= {} return @minimum_project_budget[budget.id] if @minimum_project_budget[budget.id].present? - @minimum_project_budget[budget.id] = Decidim::Budgets::Project.where(budget: budget).minimum(:budget_amount) + @minimum_project_budget[budget.id] = Decidim::Budgets::Project.where(budget:).minimum(:budget_amount) end def maximum_project_budget(budget) @maximum_project_budget ||= {} return @maximum_project_budget[budget.id] if @maximum_project_budget[budget.id].present? - @maximum_project_budget[budget.id] = Decidim::Budgets::Project.where(budget: budget).maximum(:budget_amount) + @maximum_project_budget[budget.id] = Decidim::Budgets::Project.where(budget:).maximum(:budget_amount) end def vote_success? diff --git a/app/controllers/decidim/budgets/votes_controller.rb b/app/controllers/decidim/budgets/votes_controller.rb index f4dc080..19d1427 100644 --- a/app/controllers/decidim/budgets/votes_controller.rb +++ b/app/controllers/decidim/budgets/votes_controller.rb @@ -56,6 +56,8 @@ def show redirect_to routes_proxy.budgets_vote_path end + def preview; end + def budgets @form = form(BudgetSelectForm).from_model(current_workflow) end @@ -256,7 +258,7 @@ def voting_steps false end - OpenStruct.new(key: key, done: done, available: available, link: step_link) + OpenStruct.new(key:, done:, available:, link: step_link) end steps diff --git a/app/helpers/concerns/decidim/budgeting_pipeline/projects_helper_extensions.rb b/app/helpers/concerns/decidim/budgeting_pipeline/projects_helper_extensions.rb index bc316a1..bde1b95 100644 --- a/app/helpers/concerns/decidim/budgeting_pipeline/projects_helper_extensions.rb +++ b/app/helpers/concerns/decidim/budgeting_pipeline/projects_helper_extensions.rb @@ -24,7 +24,7 @@ def projects_data_for_map(geocoded_projects_data) { id: data[0], title: data[1], - body: body, + body:, address: data[4], latitude: data[5], longitude: data[6], @@ -125,7 +125,7 @@ def project_map_link(resource, options = {}) map_utility_static.link( latitude: resource.latitude, longitude: resource.longitude, - options: options + options: ) end diff --git a/app/helpers/decidim/budgets/results_helper.rb b/app/helpers/decidim/budgets/results_helper.rb index ee7560e..84b7c84 100644 --- a/app/helpers/decidim/budgets/results_helper.rb +++ b/app/helpers/decidim/budgets/results_helper.rb @@ -42,7 +42,7 @@ def display_amounts_for?(budget) end def selected_projects(budget) - Decidim::Budgets::Project.where(budget: budget).where.not(selected_at: nil) + Decidim::Budgets::Project.where(budget:).where.not(selected_at: nil) end end end diff --git a/app/mailers/decidim/budgets/order_summaries_mailer.rb b/app/mailers/decidim/budgets/order_summaries_mailer.rb index 5ed74c0..2f01b49 100644 --- a/app/mailers/decidim/budgets/order_summaries_mailer.rb +++ b/app/mailers/decidim/budgets/order_summaries_mailer.rb @@ -33,7 +33,7 @@ def order_summaries(orders, user) scope: "decidim.budgets.order_summaries_mailer", budget_names: @budget_names.join(", ") ) - mail(to: user.email, subject: subject) + mail(to: user.email, subject:) end end end diff --git a/app/presenters/decidim/budgets/project_presenter.rb b/app/presenters/decidim/budgets/project_presenter.rb index 71b24be..b792dae 100644 --- a/app/presenters/decidim/budgets/project_presenter.rb +++ b/app/presenters/decidim/budgets/project_presenter.rb @@ -21,7 +21,7 @@ def project def title(links: false, extras: true, html_escape: false, all_locales: false) return unless project - super project.title, links, html_escape, all_locales, extras: extras + super project.title, links, html_escape, all_locales, extras: end end end diff --git a/db/migrate/20210820123351_create_budgeting_votes.rb b/db/migrate/20210820123351_create_budgeting_votes.rb index ff0945a..1a95e93 100644 --- a/db/migrate/20210820123351_create_budgeting_votes.rb +++ b/db/migrate/20210820123351_create_budgeting_votes.rb @@ -85,7 +85,7 @@ def change :decidim_budgets_votes, decidim_user_id: user_id, decidim_component_id: component_id, - created_at: created_at, + created_at:, updated_at: created_at ) @@ -116,7 +116,7 @@ def change manifest_name: space_manifest } }, - created_at: created_at, + created_at:, updated_at: created_at, visibility: "private-only", decidim_scope_id: scope_id, diff --git a/lib/decidim/api/budget_mutation_type.rb b/lib/decidim/api/budget_mutation_type.rb index f3a5142..a9317bb 100644 --- a/lib/decidim/api/budget_mutation_type.rb +++ b/lib/decidim/api/budget_mutation_type.rb @@ -53,10 +53,10 @@ def create_project(attributes:) end def update_project(id:, attributes:) - project = object.projects.find_by(id: id) + project = object.projects.find_by(id:) return unless project - enforce_permission_to :update, :project, project: project + enforce_permission_to(:update, :project, project:) form = project_form_from(attributes, project) Decidim::Budgets::Admin::UpdateProject.call(form, project) do @@ -76,10 +76,10 @@ def update_project(id:, attributes:) end def delete_project(id:) - project = object.projects.find_by(id: id) + project = object.projects.find_by(id:) return unless project - enforce_permission_to :destroy, :project, project: project + enforce_permission_to(:destroy, :project, project:) Decidim::Budgets::Admin::DestroyProject.call(project, current_user) do on(:ok) do @@ -98,9 +98,9 @@ def project_form_from(attributes, project = nil) Decidim::Budgets::Admin::ProjectForm.from_params( "project" => project_params(attributes, project) ).with_context( - current_organization: current_organization, + current_organization:, current_component: object.component, - current_user: current_user, + current_user:, budget: object ) end diff --git a/lib/decidim/budgeting_pipeline/api/permissions.rb b/lib/decidim/budgeting_pipeline/api/permissions.rb index cb5ab82..b573827 100644 --- a/lib/decidim/budgeting_pipeline/api/permissions.rb +++ b/lib/decidim/budgeting_pipeline/api/permissions.rb @@ -14,7 +14,7 @@ def enforce_permission_to(action, subject, extra_context = {}) def allowed_to?(action, subject, extra_context = {}, user = current_user) scope ||= :admin - permission_action = Decidim::PermissionAction.new(scope: scope, action: action, subject: subject) + permission_action = Decidim::PermissionAction.new(scope:, action:, subject:) permission_class_chain.inject(permission_action) do |current_permission_action, permission_class| permission_class.new( diff --git a/lib/decidim/budgeting_pipeline/help_container.rb b/lib/decidim/budgeting_pipeline/help_container.rb index b60e720..cb457ab 100644 --- a/lib/decidim/budgeting_pipeline/help_container.rb +++ b/lib/decidim/budgeting_pipeline/help_container.rb @@ -19,7 +19,7 @@ def self.find(key) def self.all @all ||= [:index, :pipeline].map do |key| - new(key: key) + new(key:) end end end diff --git a/lib/decidim/budgeting_pipeline/test/factories.rb b/lib/decidim/budgeting_pipeline/test/factories.rb index 4938be4..6926551 100644 --- a/lib/decidim/budgeting_pipeline/test/factories.rb +++ b/lib/decidim/budgeting_pipeline/test/factories.rb @@ -33,17 +33,17 @@ settings do vote_rule_settings.merge( # Pipeline settings - geocoding_enabled: geocoding_enabled, - default_map_center_coordinates: default_map_center_coordinates, - vote_identify_page_content: vote_identify_page_content, - vote_identify_page_more_information: vote_identify_page_more_information, - vote_identify_invalid_authorization_title: vote_identify_invalid_authorization_title, - vote_identify_invalid_authorization_content: vote_identify_invalid_authorization_content, - vote_budgets_page_content: vote_budgets_page_content, - vote_projects_page_content: vote_projects_page_content, - vote_preview_page_content: vote_preview_page_content, - vote_success_content: vote_success_content, - results_page_content: results_page_content + geocoding_enabled:, + default_map_center_coordinates:, + vote_identify_page_content:, + vote_identify_page_more_information:, + vote_identify_invalid_authorization_title:, + vote_identify_invalid_authorization_content:, + vote_budgets_page_content:, + vote_projects_page_content:, + vote_preview_page_content:, + vote_success_content:, + results_page_content: ) end end @@ -89,7 +89,7 @@ budget = budgets[idx] budget ||= create(:budget, component: vote.component) - order = create(:order, budget: budget, user: vote.user) + order = create(:order, budget:, user: vote.user) order.update!(checked_out_at: Time.current) if evaluator.order_checked_out vote.orders << order end @@ -98,6 +98,6 @@ end factory :budgeting_pipeline_order, parent: :order do - vote { create(:budgeting_pipeline_vote, user: user, component: budget.component, order_checked_out: false) } + vote { create(:budgeting_pipeline_vote, user:, component: budget.component, order_checked_out: false) } end end diff --git a/lib/decidim/budgeting_pipeline/workflows/base_extensions.rb b/lib/decidim/budgeting_pipeline/workflows/base_extensions.rb index b3f7436..0478301 100644 --- a/lib/decidim/budgeting_pipeline/workflows/base_extensions.rb +++ b/lib/decidim/budgeting_pipeline/workflows/base_extensions.rb @@ -16,7 +16,7 @@ module BaseExtensions # for their checkout validity. def orders @orders ||= Decidim::Budgets::Order.includes(:projects).where(decidim_user_id: user, decidim_budgets_budget_id: budgets).map do |order| - [order.decidim_budgets_budget_id, { order: order, status: order.checked_out? ? :voted : :progress }] + [order.decidim_budgets_budget_id, { order:, status: order.checked_out? ? :voted : :progress }] end.compact.to_h end end diff --git a/spec/commands/decidim/budgets/admin/create_project_spec.rb b/spec/commands/decidim/budgets/admin/create_project_spec.rb index 49994d2..8cd2727 100644 --- a/spec/commands/decidim/budgets/admin/create_project_spec.rb +++ b/spec/commands/decidim/budgets/admin/create_project_spec.rb @@ -7,13 +7,13 @@ module Decidim::Budgets include Decidim::BudgetingPipeline::AdminCreateProjectExtensions subject { described_class.new(form) } - let(:organization) { create :organization, available_locales: [:en] } - let(:current_user) { create :user, :admin, :confirmed, organization: organization } - let(:participatory_process) { create :participatory_process, organization: organization } - let(:current_component) { create :component, manifest_name: :budgets, participatory_space: participatory_process } - let(:budget) { create :budget, component: current_component } - let(:scope) { create :scope, organization: organization } - let(:category) { create :category, participatory_space: participatory_process } + let(:organization) { create(:organization, available_locales: [:en]) } + let(:current_user) { create(:user, :admin, :confirmed, organization:) } + let(:participatory_process) { create(:participatory_process, organization:) } + let(:current_component) { create(:component, manifest_name: :budgets, participatory_space: participatory_process) } + let(:budget) { create(:budget, component: current_component) } + let(:scope) { create(:scope, organization:) } + let(:category) { create(:category, participatory_space: participatory_process) } let(:uploaded_photos) { [] } let(:main_image) { nil } let(:photos) { [] } @@ -33,25 +33,25 @@ module Decidim::Budgets let(:form) do double( invalid?: invalid, - current_component: current_component, - current_user: current_user, + current_component:, + current_user:, title: { en: "title" }, summary: { en: "Summary for the project" }, description: { en: "description" }, budget_amount: 10_000_000, budget_amount_min: nil, - address: address, - latitude: latitude, - longitude: longitude, + address:, + latitude:, + longitude:, proposal_ids: proposals.map(&:id), - scope: scope, - category: category, - photos: photos, + scope:, + category:, + photos:, add_photos: uploaded_photos, - budget: budget, - idea_ids: idea_ids, - plan_ids: plan_ids, - main_image: main_image + budget:, + idea_ids:, + plan_ids:, + main_image: ) end let(:idea_ids) { [] } @@ -102,7 +102,7 @@ module Decidim::Budgets end context "when geocoding is enabled" do - let(:current_component) { create :budgets_component, :with_geocoding_enabled, participatory_space: participatory_process } + let(:current_component) { create(:budgets_component, :with_geocoding_enabled, participatory_space: participatory_process) } context "when the address is present" do let(:address) { "Some address" } @@ -122,7 +122,7 @@ module Decidim::Budgets end context "with ideas" do - let(:idea_component) { create :idea_component, participatory_space: participatory_process } + let(:idea_component) { create(:idea_component, participatory_space: participatory_process) } let(:idea1) { create(:idea, component: idea_component) } let(:idea_ids) { [idea1.id] } @@ -132,12 +132,12 @@ module Decidim::Budgets project = Decidim::Budgets::Project.last linked_ideas = project.linked_resources(:ideas, "included_ideas") - expect(linked_ideas).to match_array([idea1]) + expect(linked_ideas).to contain_exactly(idea1) end end context "with plans" do - let(:plan_component) { create :plan_component, participatory_space: participatory_process } + let(:plan_component) { create(:plan_component, participatory_space: participatory_process) } let(:plan1) { create(:plan, component: plan_component) } let(:plan_ids) { [plan1.id] } @@ -147,7 +147,7 @@ module Decidim::Budgets project = Decidim::Budgets::Project.last linked_plans = project.linked_resources(:plans, "included_plans") - expect(linked_plans).to match_array([plan1]) + expect(linked_plans).to contain_exactly(plan1) end end end diff --git a/spec/commands/decidim/budgets/admin/update_project_spec.rb b/spec/commands/decidim/budgets/admin/update_project_spec.rb index 63aa24f..f89b970 100644 --- a/spec/commands/decidim/budgets/admin/update_project_spec.rb +++ b/spec/commands/decidim/budgets/admin/update_project_spec.rb @@ -7,14 +7,14 @@ module Decidim::Budgets include Decidim::BudgetingPipeline::AdminUpdateProjectExtensions subject { described_class.new(form, project) } - let!(:project) { create :project, budget: budget } - let(:organization) { create :organization, available_locales: [:en] } - let(:current_user) { create :user, :admin, :confirmed, organization: organization } - let(:participatory_process) { create :participatory_process, organization: organization } - let(:current_component) { create :component, manifest_name: :budgets, participatory_space: participatory_process } - let(:budget) { create :budget, component: current_component } - let(:scope) { create :scope, organization: organization } - let(:category) { create :category, participatory_space: participatory_process } + let!(:project) { create(:project, budget:) } + let(:organization) { create(:organization, available_locales: [:en]) } + let(:current_user) { create(:user, :admin, :confirmed, organization:) } + let(:participatory_process) { create(:participatory_process, organization:) } + let(:current_component) { create(:component, manifest_name: :budgets, participatory_space: participatory_process) } + let(:budget) { create(:budget, component: current_component) } + let(:scope) { create(:scope, organization:) } + let(:category) { create(:category, participatory_space: participatory_process) } let(:uploaded_photos) { [] } let(:main_image) { nil } let(:photos) { [] } @@ -35,26 +35,26 @@ module Decidim::Budgets let(:form) do double( invalid?: invalid, - current_component: current_component, - current_user: current_user, + current_component:, + current_user:, title: { en: "title" }, summary: { en: "Summary for the project" }, description: { en: "description" }, budget_amount: 10_000_000, budget_amount_min: nil, - address: address, - latitude: latitude, - longitude: longitude, + address:, + latitude:, + longitude:, proposal_ids: proposals.map(&:id), - selected: selected, - scope: scope, - category: category, - photos: photos, + selected:, + scope:, + category:, + photos:, add_photos: uploaded_photos, - budget: budget, - idea_ids: idea_ids, - plan_ids: plan_ids, - main_image: main_image + budget:, + idea_ids:, + plan_ids:, + main_image: ) end let(:idea_ids) { [] } @@ -98,7 +98,7 @@ module Decidim::Budgets end context "when geocoding is enabled" do - let(:current_component) { create :budgets_component, :with_geocoding_enabled, participatory_space: participatory_process } + let(:current_component) { create(:budgets_component, :with_geocoding_enabled, participatory_space: participatory_process) } context "when the address is present" do let(:address) { "Some address" } @@ -118,7 +118,7 @@ module Decidim::Budgets end context "with ideas" do - let(:idea_component) { create :idea_component, participatory_space: participatory_process } + let(:idea_component) { create(:idea_component, participatory_space: participatory_process) } let(:idea1) { create(:idea, component: idea_component) } let(:idea_ids) { [idea1.id] } @@ -128,12 +128,12 @@ module Decidim::Budgets project = Decidim::Budgets::Project.last linked_ideas = project.linked_resources(:ideas, "included_ideas") - expect(linked_ideas).to match_array([idea1]) + expect(linked_ideas).to contain_exactly(idea1) end end context "with plans" do - let(:plan_component) { create :plan_component, participatory_space: participatory_process } + let(:plan_component) { create(:plan_component, participatory_space: participatory_process) } let(:plan1) { create(:plan, component: plan_component) } let(:plan_ids) { [plan1.id] } @@ -143,7 +143,7 @@ module Decidim::Budgets project = Decidim::Budgets::Project.last linked_plans = project.linked_resources(:plans, "included_plans") - expect(linked_plans).to match_array([plan1]) + expect(linked_plans).to contain_exactly(plan1) end end end diff --git a/spec/commands/decidim/budgets/checkout_orders_spec.rb b/spec/commands/decidim/budgets/checkout_orders_spec.rb index 4fb5251..876c8f9 100644 --- a/spec/commands/decidim/budgets/checkout_orders_spec.rb +++ b/spec/commands/decidim/budgets/checkout_orders_spec.rb @@ -7,27 +7,27 @@ let(:form) { Decidim::Budgets::BudgetSelectForm.from_params(budget_ids: [budget.id]) } let(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, organization: organization) } + let(:user) { create(:user, :confirmed, organization:) } - let(:participatory_space) { create(:participatory_process, organization: organization) } - let(:component) { create(:budgets_component, :with_budget_projects_range, participatory_space: participatory_space) } - let(:budget1) { create(:budget, component: component) } - let(:budget1_projects) { create_list(:project, 5, budget: budget1) } - let(:budget2) { create(:budget, component: component) } - let(:budget2_projects) { create_list(:project, 5, budget: budget2) } + let(:participatory_space) { create(:participatory_process, organization:) } + let(:component) { create(:budgets_component, :with_budget_projects_range, participatory_space:) } + let(:budget_one) { create(:budget, component:) } + let(:budget_one_projects) { create_list(:project, 5, budget: budget_one) } + let(:budget_two) { create(:budget, component:) } + let(:budget_two_projects) { create_list(:project, 5, budget: budget_two) } let(:amt_projects) { [3, 4] } - let(:orders) { [order1, order2] } - let(:order1) do - create(:order, user: user, budget: budget1).tap do |ord| - budget1_projects.sample(amt_projects[0]).each { |pr| ord.projects << pr } + let(:orders) { [order_one, order_two] } + let(:order_one) do + create(:order, user:, budget: budget_one).tap do |ord| + budget_one_projects.sample(amt_projects[0]).each { |pr| ord.projects << pr } ord.save! end end - let(:order2) do - create(:order, user: user, budget: budget2).tap do |ord| - budget2_projects.sample(amt_projects[1]).each { |pr| ord.projects << pr } + let(:order_two) do + create(:order, user:, budget: budget_two).tap do |ord| + budget_two_projects.sample(amt_projects[1]).each { |pr| ord.projects << pr } ord.save! end end @@ -96,7 +96,7 @@ context "when one of the orders is invalid" do it "broadcasts invalid" do - allow(order1).to receive(:invalid?).and_return(true) + allow(order_one).to receive(:invalid?).and_return(true) expect { subject }.to broadcast(:invalid) end diff --git a/spec/commands/decidim/budgets/start_voting_spec.rb b/spec/commands/decidim/budgets/start_voting_spec.rb index d6986e5..b68509e 100644 --- a/spec/commands/decidim/budgets/start_voting_spec.rb +++ b/spec/commands/decidim/budgets/start_voting_spec.rb @@ -7,11 +7,11 @@ let(:form) { Decidim::Budgets::BudgetSelectForm.from_params(budget_ids: [budget.id]) } let(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, organization: organization) } + let(:user) { create(:user, :confirmed, organization:) } - let(:participatory_space) { create(:participatory_process, organization: organization) } - let(:component) { create(:budgets_component, :with_budget_projects_range, participatory_space: participatory_space) } - let(:budget) { create(:budget, component: component) } + let(:participatory_space) { create(:participatory_process, organization:) } + let(:component) { create(:budgets_component, :with_budget_projects_range, participatory_space:) } + let(:budget) { create(:budget, component:) } let(:workflow) { Decidim::Budgets.workflows[:one].new(component, user) } describe "#call" do diff --git a/spec/controllers/decidim/budgets/line_items_controller_spec.rb b/spec/controllers/decidim/budgets/line_items_controller_spec.rb index 073d2a8..e8ad5ac 100644 --- a/spec/controllers/decidim/budgets/line_items_controller_spec.rb +++ b/spec/controllers/decidim/budgets/line_items_controller_spec.rb @@ -2,14 +2,14 @@ require "spec_helper" -describe Decidim::Budgets::LineItemsController, type: :controller do +describe Decidim::Budgets::LineItemsController do routes { Decidim::Budgets::Engine.routes } let(:user) { create(:user, :confirmed, organization: component.organization) } - let!(:budget) { create(:budgeting_pipeline_budget, component: component) } + let!(:budget) { create(:budgeting_pipeline_budget, component:) } let(:component) { create(:budgeting_pipeline_component) } - let(:project) { create(:budgeting_pipeline_project, budget: budget) } + let(:project) { create(:budgeting_pipeline_project, budget:) } before do request.env["decidim.current_organization"] = component.organization @@ -65,15 +65,15 @@ end context "when no more allocation is available" do - let(:order) { create(:budgeting_pipeline_order, budget: budget, user: user) } + let(:order) { create(:budgeting_pipeline_order, budget:, user:) } before do - order.projects << create(:budgeting_pipeline_project, budget: budget, budget_amount: budget.total_budget) - order.projects << create(:budgeting_pipeline_project, budget: budget, budget_amount: budget.total_budget) - order.projects << create(:budgeting_pipeline_project, budget: budget, budget_amount: budget.total_budget) - order.projects << create(:budgeting_pipeline_project, budget: budget, budget_amount: budget.total_budget) - order.projects << create(:budgeting_pipeline_project, budget: budget, budget_amount: budget.total_budget) - order.projects << create(:budgeting_pipeline_project, budget: budget, budget_amount: budget.total_budget) + order.projects << create(:budgeting_pipeline_project, budget:, budget_amount: budget.total_budget) + order.projects << create(:budgeting_pipeline_project, budget:, budget_amount: budget.total_budget) + order.projects << create(:budgeting_pipeline_project, budget:, budget_amount: budget.total_budget) + order.projects << create(:budgeting_pipeline_project, budget:, budget_amount: budget.total_budget) + order.projects << create(:budgeting_pipeline_project, budget:, budget_amount: budget.total_budget) + order.projects << create(:budgeting_pipeline_project, budget:, budget_amount: budget.total_budget) order.save!(validate: false) end @@ -81,7 +81,7 @@ end context "when the order is checked out" do - let(:order) { create(:budgeting_pipeline_order, budget: budget, user: user) } + let(:order) { create(:budgeting_pipeline_order, budget:, user:) } before do order.update!(checked_out_at: Time.current) diff --git a/spec/controllers/decidim/budgets/orders_controller_spec.rb b/spec/controllers/decidim/budgets/orders_controller_spec.rb index e83d605..f1ed8ea 100644 --- a/spec/controllers/decidim/budgets/orders_controller_spec.rb +++ b/spec/controllers/decidim/budgets/orders_controller_spec.rb @@ -2,12 +2,12 @@ require "spec_helper" -describe Decidim::Budgets::OrdersController, type: :controller do +describe Decidim::Budgets::OrdersController do routes { Decidim::Budgets::Engine.routes } let(:user) { create(:user, :confirmed, organization: component.organization) } - let!(:budget1) { create(:budgeting_pipeline_budget, component: component) } - let!(:budget2) { create(:budgeting_pipeline_budget, component: component) } + let!(:budget_one) { create(:budgeting_pipeline_budget, component:) } + let!(:budget_two) { create(:budgeting_pipeline_budget, component:) } let(:component) { create(:budgeting_pipeline_component) } before do @@ -19,7 +19,7 @@ describe "GET index" do context "with checked out orders" do - let!(:vote) { create(:budgeting_pipeline_vote, order_count: 2, order_checked_out: true, user: user, component: component) } + let!(:vote) { create(:budgeting_pipeline_vote, order_count: 2, order_checked_out: true, user:, component:) } it "renders" do get :index @@ -29,7 +29,7 @@ end context "with no checked out orders" do - let!(:vote) { create(:budgeting_pipeline_vote, order_count: 2, order_checked_out: false, user: user, component: component) } + let!(:vote) { create(:budgeting_pipeline_vote, order_count: 2, order_checked_out: false, user:, component:) } it "redirects" do get :index diff --git a/spec/controllers/decidim/budgets/results_controller_spec.rb b/spec/controllers/decidim/budgets/results_controller_spec.rb index 02dd7c7..7c3c798 100644 --- a/spec/controllers/decidim/budgets/results_controller_spec.rb +++ b/spec/controllers/decidim/budgets/results_controller_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe Decidim::Budgets::ResultsController, type: :controller do +describe Decidim::Budgets::ResultsController do routes { Decidim::Budgets::Engine.routes } let(:user) { create(:user, :confirmed, organization: component.organization) } diff --git a/spec/controllers/decidim/budgets/votes_controller_spec.rb b/spec/controllers/decidim/budgets/votes_controller_spec.rb index fb5a065..2134e34 100644 --- a/spec/controllers/decidim/budgets/votes_controller_spec.rb +++ b/spec/controllers/decidim/budgets/votes_controller_spec.rb @@ -2,16 +2,16 @@ require "spec_helper" -describe Decidim::Budgets::VotesController, type: :controller do +describe Decidim::Budgets::VotesController do routes { Decidim::Budgets::Engine.routes } let(:organization) { build(:organization, tos_version: Time.current, available_authorizations: ["dummy_authorization_handler"]) } - let(:user) { create(:user, :confirmed, organization: organization) } - let(:participatory_space) { create(:participatory_process, :with_steps, organization: organization) } + let(:user) { create(:user, :confirmed, organization:) } + let(:participatory_space) { create(:participatory_process, :with_steps, organization:) } let(:component) do create( :budgeting_pipeline_component, - participatory_space: participatory_space, + participatory_space:, permissions: { "vote" => { "authorization_handlers" => { @@ -36,10 +36,10 @@ end shared_context "with existing orders" do - let!(:budget1) { create(:budgeting_pipeline_budget, component: component) } - let!(:budget2) { create(:budgeting_pipeline_budget, component: component) } - let!(:order1) { create(:order, budget: budget1, user: user) } - let!(:order2) { create(:order, budget: budget2, user: user) } + let!(:budget_one) { create(:budgeting_pipeline_budget, component:) } + let!(:budget_two) { create(:budgeting_pipeline_budget, component:) } + let!(:order_one) { create(:order, budget: budget_one, user:) } + let!(:order_two) { create(:order, budget: budget_two, user:) } end shared_examples "ensured voting open" do @@ -84,10 +84,10 @@ end context "when the user is authorized" do - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } context "when the user has voted" do - let!(:vote) { create(:budgeting_pipeline_vote, order_count: 2, order_checked_out: true, user: user, component: component) } + let!(:vote) { create(:budgeting_pipeline_vote, order_count: 2, order_checked_out: true, user:, component:) } it "redirects to projects" do do_request @@ -105,7 +105,7 @@ context "when voting is open and the user is authorized" do let(:step_settings) { { votes: :enabled } } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } context "when there are no orders available" do it "redirects to budgets selection" do @@ -122,18 +122,18 @@ context "when orders are not valid" do let(:step_settings) { { votes: :enabled } } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } include_context "with existing orders" before do - order1.projects << create(:project, budget_amount: 10, budget: budget1) - order1.projects << create(:project, budget_amount: 20, budget: budget1) - order1.projects << create(:project, budget_amount: 5, budget: budget1) - order1.projects << create(:project, budget_amount: 15, budget: budget1) - order1.projects << create(:project, budget_amount: 30, budget: budget1) - order1.projects << create(:project, budget_amount: 25, budget: budget1) - order1.save!(validate: false) + order_one.projects << create(:project, budget_amount: 10, budget: budget_one) + order_one.projects << create(:project, budget_amount: 20, budget: budget_one) + order_one.projects << create(:project, budget_amount: 5, budget: budget_one) + order_one.projects << create(:project, budget_amount: 15, budget: budget_one) + order_one.projects << create(:project, budget_amount: 30, budget: budget_one) + order_one.projects << create(:project, budget_amount: 25, budget: budget_one) + order_one.save!(validate: false) end it "redirects to projects selection" do @@ -157,7 +157,7 @@ context "when everything is set for voting" do let(:step_settings) { { votes: :enabled } } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } it "renders" do expect(response).to have_http_status(:ok) @@ -172,7 +172,7 @@ context "when everything is set for voting" do let(:step_settings) { { votes: :enabled } } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } context "when budgets are not selected" do it "renders budgets" do @@ -184,11 +184,11 @@ end context "when budgets are selected" do - let!(:budget1) { create(:budgeting_pipeline_budget, component: component) } - let!(:budget2) { create(:budgeting_pipeline_budget, component: component) } + let!(:budget_one) { create(:budgeting_pipeline_budget, component:) } + let!(:budget_two) { create(:budgeting_pipeline_budget, component:) } it "redirects to projects selection" do - post :start, params: { budget_ids: [budget1.id, budget2.id] } + post :start, params: { budget_ids: [budget_one.id, budget_two.id] } expect(response).to redirect_to("/processes/#{participatory_space.slug}/f/#{component.id}/vote/projects") end @@ -203,7 +203,7 @@ context "when everything is set for voting" do let(:step_settings) { { votes: :enabled } } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } context "when there are orders available" do include_context "with existing orders" @@ -224,7 +224,7 @@ context "when everything is set for voting" do let(:step_settings) { { votes: :enabled } } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } context "when there are orders available" do include_context "with existing orders" @@ -245,7 +245,7 @@ context "when everything is set for voting" do let(:step_settings) { { votes: :enabled } } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } include_context "with existing orders" @@ -258,8 +258,8 @@ it "checks out the orders" do post :create - expect(order1.reload.checked_out?).to be(true) - expect(order2.reload.checked_out?).to be(true) + expect(order_one.reload.checked_out?).to be(true) + expect(order_two.reload.checked_out?).to be(true) end context "with show votes enabled" do diff --git a/spec/forms/decidim/budgets/admin/component_form_spec.rb b/spec/forms/decidim/budgets/admin/component_form_spec.rb index 3326c94..07aa179 100644 --- a/spec/forms/decidim/budgets/admin/component_form_spec.rb +++ b/spec/forms/decidim/budgets/admin/component_form_spec.rb @@ -10,7 +10,7 @@ module Admin subject { form } let(:organization) { create(:organization) } - let(:participatory_space) { create(:participatory_process, organization: organization) } + let(:participatory_space) { create(:participatory_process, organization:) } let(:manifest) { Decidim.find_component_manifest("dummy") } let(:name) { generate_localized_title } diff --git a/spec/forms/decidim/budgets/admin/project_form_spec.rb b/spec/forms/decidim/budgets/admin/project_form_spec.rb index 76707d5..3d9735d 100644 --- a/spec/forms/decidim/budgets/admin/project_form_spec.rb +++ b/spec/forms/decidim/budgets/admin/project_form_spec.rb @@ -9,11 +9,11 @@ let(:context) do { current_organization: organization, - current_component: current_component, + current_component:, current_participatory_space: participatory_process } end - let(:participatory_process) { create(:participatory_process, organization: organization) } + let(:participatory_process) { create(:participatory_process, organization:) } let(:current_component) { create(:budgets_component, participatory_space: participatory_process) } let(:budget) { create(:budget, component: current_component) } let(:title) do @@ -23,7 +23,7 @@ Decidim::Faker::Localized.sentence end let(:budget_amount) { Faker::Number.number } - let(:parent_scope) { create(:scope, organization: organization) } + let(:parent_scope) { create(:scope, organization:) } let(:scope) { create(:subscope, parent: parent_scope) } let(:scope_id) { scope.id } let(:category) { create(:category, participatory_space: participatory_process) } @@ -38,11 +38,11 @@ decidim_category_id: category_id, title_en: title[:en], description_en: description[:en], - budget_amount: budget_amount, - selected: selected, - address: address, - latitude: latitude, - longitude: longitude + budget_amount:, + selected:, + address:, + latitude:, + longitude: } end let(:idea_ids) { [] } @@ -63,10 +63,10 @@ describe "#map_model" do subject { described_class.from_model(project) } - let(:project) { create(:project, budget: budget) } + let(:project) { create(:project, budget:) } context "with ideas" do - let(:idea_component) { create :idea_component, participatory_space: participatory_process } + let(:idea_component) { create(:idea_component, participatory_space: participatory_process) } let(:idea1) { create(:idea, component: idea_component) } let(:idea_ids) { [idea1.id] } @@ -77,7 +77,7 @@ end context "with plans" do - let(:plan_component) { create :plan_component, participatory_space: participatory_process } + let(:plan_component) { create(:plan_component, participatory_space: participatory_process) } let(:plan1) { create(:plan, component: plan_component) } let(:plan_ids) { [plan1.id] } @@ -113,13 +113,13 @@ describe "#ideas" do subject { described_class.from_model(project).with_context(context) } - let!(:project) { create(:project, budget: budget) } - let(:idea_component) { create :idea_component, participatory_space: participatory_process } + let!(:project) { create(:project, budget:) } + let(:idea_component) { create(:idea_component, participatory_space: participatory_process) } let!(:idea1) { create(:idea, component: idea_component) } context "with no ideas" do it "returns empty" do - expect(subject.ideas).to match_array([]) + expect(subject.ideas).to be_empty end end @@ -131,7 +131,7 @@ end it "returns ideas" do - expect(subject.ideas).to match_array([idea1]) + expect(subject.ideas).to contain_exactly(idea1) end end end @@ -139,13 +139,13 @@ describe "#plans" do subject { described_class.from_model(project).with_context(context) } - let!(:project) { create(:project, budget: budget) } - let(:plan_component) { create :plan_component, participatory_space: participatory_process } + let!(:project) { create(:project, budget:) } + let(:plan_component) { create(:plan_component, participatory_space: participatory_process) } let!(:plan1) { create(:plan, component: plan_component) } context "with no plans" do it "returns empty" do - expect(subject.plans).to match_array([]) + expect(subject.plans).to be_empty end end @@ -157,7 +157,7 @@ end it "returns ideas" do - expect(subject.plans).to match_array([plan1]) + expect(subject.plans).to contain_exactly(plan1) end end end diff --git a/spec/helpers/decidim/budgets/projects_helper_spec.rb b/spec/helpers/decidim/budgets/projects_helper_spec.rb index e724402..3f1d776 100644 --- a/spec/helpers/decidim/budgets/projects_helper_spec.rb +++ b/spec/helpers/decidim/budgets/projects_helper_spec.rb @@ -9,10 +9,10 @@ module Budgets include Decidim::BudgetingPipeline::ProjectsHelperExtensions let!(:organization) { create(:organization) } - let!(:budgets_component) { create(:budgets_component, :with_geocoding_enabled, organization: organization) } + let!(:budgets_component) { create(:budgets_component, :with_geocoding_enabled, organization:) } let(:budgets) { create_list(:budget, 2, component: budgets_component) } - let!(:user) { create(:user, organization: organization) } - let!(:projects) { create_list(:project, 5, budget: budgets.first, address: address, latitude: latitude, longitude: longitude, component: budgets_component) } + let!(:user) { create(:user, organization:) } + let!(:projects) { create_list(:project, 5, budget: budgets.first, address:, latitude:, longitude:, component: budgets_component) } let!(:project) { projects.first } let(:address) { "Carrer Pic de Peguera 15, 17003 Girona" } let(:latitude) { 40.1234 } diff --git a/spec/jobs/decidim/budgets/send_order_summaries_job_spec.rb b/spec/jobs/decidim/budgets/send_order_summaries_job_spec.rb index 8b8f767..7dc973a 100644 --- a/spec/jobs/decidim/budgets/send_order_summaries_job_spec.rb +++ b/spec/jobs/decidim/budgets/send_order_summaries_job_spec.rb @@ -6,9 +6,9 @@ subject { described_class.perform_now(vote, user) } let!(:organization) { create(:organization, tos_version: Time.current) } - let(:user) { create(:user, :confirmed, organization: organization) } - let(:component) { create(:budgeting_pipeline_component, organization: organization) } - let(:vote) { create(:budgeting_pipeline_vote, order_count: 2, user: user, component: component) } + let(:user) { create(:user, :confirmed, organization:) } + let(:component) { create(:budgeting_pipeline_component, organization:) } + let(:vote) { create(:budgeting_pipeline_vote, order_count: 2, user:, component:) } before do clear_emails @@ -21,7 +21,7 @@ end context "when the user does not have an email" do - let(:user) { create(:user, :confirmed, email: "", managed: true, organization: organization) } + let(:user) { create(:user, :confirmed, email: "", managed: true, organization:) } it "does not send email" do expect(last_email).to be_nil diff --git a/spec/mailers/decidim/budgets/order_summaries_mailer_spec.rb b/spec/mailers/decidim/budgets/order_summaries_mailer_spec.rb index 4be50ba..61aefc8 100644 --- a/spec/mailers/decidim/budgets/order_summaries_mailer_spec.rb +++ b/spec/mailers/decidim/budgets/order_summaries_mailer_spec.rb @@ -2,37 +2,37 @@ require "spec_helper" -describe Decidim::Budgets::OrderSummariesMailer, type: :mailer do +describe Decidim::Budgets::OrderSummariesMailer do describe "#order_summaries" do - let(:mail) { described_class.order_summaries([order1, order2], user) } + let(:mail) { described_class.order_summaries([order_one, order_two], user) } let(:organization) { create(:organization, tos_version: Time.current) } - let(:component) { create(:budgeting_pipeline_component, organization: organization) } - let(:user) { create(:user, :confirmed, organization: organization) } - let(:budget1) { create(:budgeting_pipeline_budget, component: component) } - let(:budget2) { create(:budgeting_pipeline_budget, component: component) } - let(:order1) { create(:budgeting_pipeline_order, :with_projects, budget: budget1, user: user) } - let(:order2) { create(:budgeting_pipeline_order, :with_projects, budget: budget2, user: user) } + let(:component) { create(:budgeting_pipeline_component, organization:) } + let(:user) { create(:user, :confirmed, organization:) } + let(:budget_one) { create(:budgeting_pipeline_budget, component:) } + let(:budget_two) { create(:budgeting_pipeline_budget, component:) } + let(:order_one) { create(:budgeting_pipeline_order, :with_projects, budget: budget_one, user:) } + let(:order_two) { create(:budgeting_pipeline_order, :with_projects, budget: budget_two, user:) } before do - order1.update!(checked_out_at: Time.current) - order2.update!(checked_out_at: Time.current) + order_one.update!(checked_out_at: Time.current) + order_two.update!(checked_out_at: Time.current) end it "adds the correct subject" do - expect(mail.subject).to eq("You voted in #{translated(budget1.title)}, #{translated(budget2.title)}") + expect(mail.subject).to eq("You voted in #{translated(budget_one.title)}, #{translated(budget_two.title)}") end it "adds the budgets to the body" do - expect(email_body(mail)).to include(decidim_sanitize(translated(budget1.title))) - expect(email_body(mail)).to include(decidim_sanitize(translated(budget2.title))) + expect(email_body(mail)).to include(decidim_sanitize(translated(budget_one.title))) + expect(email_body(mail)).to include(decidim_sanitize(translated(budget_two.title))) end it "adds the selected projects to the body" do - order1.projects.each do |project| + order_one.projects.each do |project| expect(email_body(mail)).to include("
  • #{decidim_escape_translated(project.title)}
  • ") end - order2.projects.each do |project| + order_two.projects.each do |project| expect(email_body(mail)).to include("
  • #{decidim_escape_translated(project.title)}
  • ") end end diff --git a/spec/models/decidim/action_log_spec.rb b/spec/models/decidim/action_log_spec.rb index 83d4aea..fe9baf1 100644 --- a/spec/models/decidim/action_log_spec.rb +++ b/spec/models/decidim/action_log_spec.rb @@ -5,14 +5,14 @@ describe Decidim::ActionLog do subject do described_class.create!( - user: user, - organization: organization, - action: action, - resource: resource, + user:, + organization:, + action:, + resource:, resource_id: resource.id, resource_type: resource.class.name, - participatory_space: participatory_space, - component: component, + participatory_space:, + component:, area: nil, scope: nil, version_id: 1, @@ -22,11 +22,11 @@ end let(:organization) { create(:organization, tos_version: Time.current) } - let(:user) { create(:user, organization: organization) } + let(:user) { create(:user, organization:) } let(:action) { :create } - let(:participatory_space) { create(:participatory_process, organization: organization) } - let(:component) { create(:budgeting_pipeline_component, participatory_space: participatory_space) } - let(:resource) { create(:budgeting_pipeline_vote, component: component) } + let(:participatory_space) { create(:participatory_process, organization:) } + let(:component) { create(:budgeting_pipeline_component, participatory_space:) } + let(:resource) { create(:budgeting_pipeline_vote, component:) } let(:extra_data) { {} } it "accepts a private-only type log entry" do diff --git a/spec/models/decidim/budgets/line_item_spec.rb b/spec/models/decidim/budgets/line_item_spec.rb index 791862b..f472ef5 100644 --- a/spec/models/decidim/budgets/line_item_spec.rb +++ b/spec/models/decidim/budgets/line_item_spec.rb @@ -4,15 +4,15 @@ describe Decidim::Budgets::LineItem do let(:component) { create(:budgeting_pipeline_component) } - let(:budget) { create(:budgeting_pipeline_budget, component: component, total_budget: 50_000) } - let(:project1) { create(:budgeting_pipeline_project, budget: budget, budget_amount: 20_000) } - let(:project2) { create(:budgeting_pipeline_project, budget: budget, budget_amount: 30_000) } - let(:project3) { create(:budgeting_pipeline_project, budget: budget, budget_amount: 20_000) } - let(:order) { create(:budgeting_pipeline_order, budget: budget) } + let(:budget) { create(:budgeting_pipeline_budget, component:, total_budget: 50_000) } + let(:project_one) { create(:budgeting_pipeline_project, budget:, budget_amount: 20_000) } + let(:project_two) { create(:budgeting_pipeline_project, budget:, budget_amount: 30_000) } + let(:project_three) { create(:budgeting_pipeline_project, budget:, budget_amount: 20_000) } + let(:order) { create(:budgeting_pipeline_order, budget:) } before do - order.projects << project1 - order.projects << project2 + order.projects << project_one + order.projects << project_two order.save! end diff --git a/spec/models/decidim/budgets/order_spec.rb b/spec/models/decidim/budgets/order_spec.rb index 5779558..a6c841a 100644 --- a/spec/models/decidim/budgets/order_spec.rb +++ b/spec/models/decidim/budgets/order_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" describe Decidim::Budgets::Order do - let(:component) { create(:budgeting_pipeline_component, vote_rule_settings: vote_rule_settings) } + let(:component) { create(:budgeting_pipeline_component, vote_rule_settings:) } let(:vote_rule_settings) do { vote_rule_threshold_percent_enabled: true, @@ -15,37 +15,37 @@ vote_selected_projects_maximum: 1 } end - let(:budget) { create(:budgeting_pipeline_budget, component: component, total_budget: 40_000) } - let(:project1) { create(:budgeting_pipeline_project, budget: budget, budget_amount: 20_000) } - let(:project2) { create(:budgeting_pipeline_project, budget: budget, budget_amount: 30_000) } + let(:budget) { create(:budgeting_pipeline_budget, component:, total_budget: 40_000) } + let(:project_one) { create(:budgeting_pipeline_project, budget:, budget_amount: 20_000) } + let(:project_two) { create(:budgeting_pipeline_project, budget:, budget_amount: 30_000) } shared_context "with first project selected" do - before { order.projects << project1 } + before { order.projects << project_one } end shared_context "with second project selected" do - before { order.projects << project2 } + before { order.projects << project_two } end describe ".order_by_budgets" do - subject { described_class.where(budget: [budget1, budget2, budget3]).order_by_budgets } - - let(:budget1) { create(:budgeting_pipeline_budget, component: component, weight: 3) } - let(:budget2) { create(:budgeting_pipeline_budget, component: component, weight: 1) } - let(:budget3) { create(:budgeting_pipeline_budget, component: component, weight: 2) } - let!(:budget1_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget1) } - let!(:budget2_projects) { create_list(:budgeting_pipeline_project, 5, budget: budget2) } - let!(:budget3_projects) { create_list(:budgeting_pipeline_project, 3, budget: budget3) } + subject { described_class.where(budget: [budget_one, budget_two, budget_three]).order_by_budgets } + + let(:budget_one) { create(:budgeting_pipeline_budget, component:, weight: 3) } + let(:budget_two) { create(:budgeting_pipeline_budget, component:, weight: 1) } + let(:budget_three) { create(:budgeting_pipeline_budget, component:, weight: 2) } + let!(:budget_one_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget_one) } + let!(:budget_two_projects) { create_list(:budgeting_pipeline_project, 5, budget: budget_two) } + let!(:budget_three_projects) { create_list(:budgeting_pipeline_project, 3, budget: budget_three) } let(:order_amounts) do { - budget1.id => 4, - budget2.id => 3, - budget3.id => 2 + budget_one.id => 4, + budget_two.id => 3, + budget_three.id => 2 } end before do - (budget1_projects + budget2_projects + budget3_projects).each do |project| + (budget_one_projects + budget_two_projects + budget_three_projects).each do |project| orders = create_list(:budgeting_pipeline_order, order_amounts[project.budget.id], budget: project.budget) orders.each do |order| order.projects << project @@ -57,26 +57,26 @@ it "orders the results by the budget weights" do indexes = {} - indexes[budget2.id] = order_amounts[budget2.id] * budget2_projects.count - indexes[budget3.id] = indexes[budget2.id] + (order_amounts[budget3.id] * budget3_projects.count) - indexes[budget1.id] = indexes[budget3.id] + (order_amounts[budget1.id] * budget1_projects.count) + indexes[budget_two.id] = order_amounts[budget_two.id] * budget_two_projects.count + indexes[budget_three.id] = indexes[budget_two.id] + (order_amounts[budget_three.id] * budget_three_projects.count) + indexes[budget_one.id] = indexes[budget_three.id] + (order_amounts[budget_one.id] * budget_one_projects.count) subject.each_with_index do |order, idx| msg = "Expected budget ##{order.budget.id} at index #{idx}" - if idx < indexes[budget2.id] - expect(order.budget).to eq(budget2), msg - elsif idx < indexes[budget3.id] - expect(order.budget).to eq(budget3), msg + if idx < indexes[budget_two.id] + expect(order.budget).to eq(budget_two), msg + elsif idx < indexes[budget_three.id] + expect(order.budget).to eq(budget_three), msg else - expect(order.budget).to eq(budget1), msg + expect(order.budget).to eq(budget_one), msg end end end end describe "#allocation_available_for?" do - subject { order.allocation_available_for?(project2) } + subject { order.allocation_available_for?(project_two) } - let!(:order) { create(:budgeting_pipeline_order, budget: budget) } + let!(:order) { create(:budgeting_pipeline_order, budget:) } context "when there is enough budget left" do it { is_expected.to be(true) } @@ -116,7 +116,7 @@ describe "#unused_allocation" do subject { order.unused_allocation } - let!(:order) { create(:budgeting_pipeline_order, budget: budget) } + let!(:order) { create(:budgeting_pipeline_order, budget:) } context "when no projects are selected" do it { is_expected.to eq(budget.total_budget) } @@ -125,7 +125,7 @@ context "with a selected project" do include_context "with first project selected" - it { is_expected.to eq(budget.total_budget - project1.budget_amount) } + it { is_expected.to eq(budget.total_budget - project_one.budget_amount) } end context "with projects rule" do @@ -156,7 +156,7 @@ describe "#allocation_exceeded?" do subject { order.allocation_exceeded? } - let!(:order) { create(:budgeting_pipeline_order, budget: budget) } + let!(:order) { create(:budgeting_pipeline_order, budget:) } context "when no projects are selected" do it { is_expected.to be(false) } @@ -198,7 +198,7 @@ describe "#valid_for_checkout?" do subject { order.valid_for_checkout? } - let!(:order) { create(:budgeting_pipeline_order, budget: budget) } + let!(:order) { create(:budgeting_pipeline_order, budget:) } context "with the minimum projects rule" do let(:minimum_projects) { 0 } diff --git a/spec/models/decidim/budgets/project_spec.rb b/spec/models/decidim/budgets/project_spec.rb index 21f1900..f8d1e78 100644 --- a/spec/models/decidim/budgets/project_spec.rb +++ b/spec/models/decidim/budgets/project_spec.rb @@ -13,13 +13,13 @@ let(:data_mapping) { [:id, :title, :summary, :description, :address, :latitude, :longitude] } let(:data_mapping_translated) { [:title, :summary, :description] } - let(:budget1) { create(:budgeting_pipeline_budget, component: component) } - let(:budget2) { create(:budgeting_pipeline_budget, component: component) } - let!(:budget1_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget1) } - let!(:budget2_projects) { create_list(:budgeting_pipeline_project, 5, budget: budget2) } + let(:budget_one) { create(:budgeting_pipeline_budget, component:) } + let(:budget_two) { create(:budgeting_pipeline_budget, component:) } + let!(:budget_one_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget_one) } + let!(:budget_two_projects) { create_list(:budgeting_pipeline_project, 5, budget: budget_two) } let(:expected_data) do - budget1_projects.map { |project| convert_project_data(project) } + - budget2_projects.map { |project| convert_project_data(project) } + budget_one_projects.map { |project| convert_project_data(project) } + + budget_two_projects.map { |project| convert_project_data(project) } end let(:component_coordinates) { component.settings.default_map_center_coordinates.split(",") } @@ -37,9 +37,9 @@ describe "case statements" do subject { geocoded_data.first } - let(:project) { create(:budgeting_pipeline_project, budget: budget1) } - let!(:budget1_projects) { [project] } - let!(:budget2_projects) { [] } + let(:project) { create(:budgeting_pipeline_project, budget: budget_one) } + let!(:budget_one_projects) { [project] } + let!(:budget_two_projects) { [] } context "when the locale is not the default locale" do let(:returned_data) do @@ -65,7 +65,7 @@ title: { en: "Title" }, summary: { en: "Summary" }, description: { en: "

    Description

    " }, - budget: budget1 + budget: budget_one ) end @@ -78,24 +78,24 @@ end context "when the project does not have an address" do - let(:project) { create(:budgeting_pipeline_project, budget: budget1, address: nil) } + let(:project) { create(:budgeting_pipeline_project, budget: budget_one, address: nil) } let(:returned_data) { data_for_key(subject, :address) } it "returns the budget title as address" do - expect(returned_data).to eq(translated(budget1.title)) + expect(returned_data).to eq(translated(budget_one.title)) end end context "when the project does not have a latitude" do - let(:project) { create(:budgeting_pipeline_project, budget: budget1, latitude: nil) } + let(:project) { create(:budgeting_pipeline_project, budget: budget_one, latitude: nil) } let(:returned_data) { data_for_key(subject, :latitude) } it "returns the budget center latitude" do - expect(returned_data).to eq(budget1.center_latitude) + expect(returned_data).to eq(budget_one.center_latitude) end context "and the budget does not have a center latitude" do - let(:budget1) { create(:budgeting_pipeline_budget, component: component, center_latitude: nil) } + let(:budget_one) { create(:budgeting_pipeline_budget, component:, center_latitude: nil) } it "returns the default latitude" do expect(returned_data).to eq(default_latitude) @@ -104,15 +104,15 @@ end context "when the project does not have a longitude" do - let(:project) { create(:budgeting_pipeline_project, budget: budget1, longitude: nil) } + let(:project) { create(:budgeting_pipeline_project, budget: budget_one, longitude: nil) } let(:returned_data) { data_for_key(subject, :longitude) } it "returns the budget center longitude" do - expect(returned_data).to eq(budget1.center_longitude) + expect(returned_data).to eq(budget_one.center_longitude) end context "and the budget does not have a center longitude" do - let(:budget1) { create(:budgeting_pipeline_budget, component: component, center_longitude: nil) } + let(:budget_one) { create(:budgeting_pipeline_budget, component:, center_longitude: nil) } it "returns the default longitude" do expect(returned_data).to eq(default_longitude) @@ -137,10 +137,10 @@ def data_for_key(member, key) end describe ".order_by_most_voted" do - subject { described_class.where(budget: budget).order_by_most_voted } + subject { described_class.where(budget:).order_by_most_voted } - let(:budget) { create(:budgeting_pipeline_budget, component: component) } - let(:budget_projects) { create_list(:budgeting_pipeline_project, 5, budget: budget, paper_orders_count: 0) } + let(:budget) { create(:budgeting_pipeline_budget, component:) } + let(:budget_projects) { create_list(:budgeting_pipeline_project, 5, budget:, paper_orders_count: 0) } let(:expected_order) { [1, 3, 2, 4, 0].map { |idx| budget_projects[idx] } } let!(:complete_votes) { [0, 11, 7, 9, 1] } @@ -150,7 +150,7 @@ def data_for_key(member, key) [:complete_votes, :incomplete_votes].each do |key| amounts = public_send(key) budget_projects.each_with_index do |project, idx| - orders = create_list(:budgeting_pipeline_order, amounts[idx], budget: budget) + orders = create_list(:budgeting_pipeline_order, amounts[idx], budget:) orders.each do |order| order.projects << project order.checked_out_at = Time.current if key == :complete_votes @@ -165,7 +165,7 @@ def data_for_key(member, key) end context "with only_voted set to true" do - subject { described_class.where(budget: budget).order_by_most_voted(only_voted: true) } + subject { described_class.where(budget:).order_by_most_voted(only_voted: true) } let(:expected_order) { [1, 3, 2, 4].map { |idx| budget_projects[idx] } } @@ -190,11 +190,11 @@ def data_for_key(member, key) end context "with favorites filtering" do - subject { described_class.where(budget: budget).user_favorites(user).order_by_most_voted } + subject { described_class.where(budget:).user_favorites(user).order_by_most_voted } let(:user) { create(:user, :confirmed, organization: component.organization) } let(:favorite_projects) { budget_projects[0..1] } - let!(:favorites) { favorite_projects.map { |pr| create(:favorite, favoritable: pr, user: user) } } + let!(:favorites) { favorite_projects.map { |pr| create(:favorite, favoritable: pr, user:) } } it "returns the favorites" do expect(subject).to match_array(favorite_projects) @@ -205,8 +205,8 @@ def data_for_key(member, key) describe "#confirmed_orders_count" do subject { project.confirmed_orders_count } - let(:budget) { create(:budgeting_pipeline_budget, component: component) } - let(:project) { create(:budgeting_pipeline_project, budget: budget, paper_orders_count: paper_orders_count) } + let(:budget) { create(:budgeting_pipeline_budget, component:) } + let(:project) { create(:budgeting_pipeline_project, budget:, paper_orders_count:) } let(:paper_orders_count) { 0 } let!(:complete_votes) { 123 } @@ -215,7 +215,7 @@ def data_for_key(member, key) before do [:complete_votes, :incomplete_votes].each do |key| amount = public_send(key) - orders = create_list(:budgeting_pipeline_order, amount, budget: budget) + orders = create_list(:budgeting_pipeline_order, amount, budget:) orders.each do |order| order.projects << project order.checked_out_at = Time.current if key == :complete_votes diff --git a/spec/requests/admin_validates_images_spec.rb b/spec/requests/admin_validates_images_spec.rb index 73d6955..3af6ffe 100644 --- a/spec/requests/admin_validates_images_spec.rb +++ b/spec/requests/admin_validates_images_spec.rb @@ -44,18 +44,18 @@ let(:params) do { resource_class: record, - property: property, + property:, blob: blob.signed_id, form_class: details[:form] } end it "validates the image" do - post(request_path, params: params, headers: headers) + post(request_path, params:, headers:) expect(response).to have_http_status(:ok) - messages = JSON.parse(response.body) + messages = response.parsed_body expect(messages).to be_empty end end diff --git a/spec/services/decidim/budgeting_pipeline/project_search_spec.rb b/spec/services/decidim/budgeting_pipeline/project_search_spec.rb index ef53800..37c1db7 100644 --- a/spec/services/decidim/budgeting_pipeline/project_search_spec.rb +++ b/spec/services/decidim/budgeting_pipeline/project_search_spec.rb @@ -5,19 +5,19 @@ describe Decidim::BudgetingPipeline::ProjectSearch do subject { described_class.new(base_query, params, options) } - let(:base_query) { Decidim::Budgets::Project.where(component: component) } + let(:base_query) { Decidim::Budgets::Project.where(component:) } let(:params) { {} } - let(:options) { { component: component } } + let(:options) { { component: } } let(:component) { create(:budgeting_pipeline_component) } - let!(:budget1) { create(:budget, component: component) } - let!(:budget2) { create(:budget, component: component) } + let!(:budget_one) { create(:budget, component:) } + let!(:budget_two) { create(:budget, component:) } let!(:projects) do [].tap do |list| - list << create(:project, title: { en: "First project" }, budget: budget1) - list << create(:project, title: { en: "Second project" }, budget: budget1) - list << create(:project, title: { en: "Third project" }, budget: budget2) - list << create(:project, title: { en: "Fourth project" }, budget: budget2) + list << create(:project, title: { en: "First project" }, budget: budget_one) + list << create(:project, title: { en: "Second project" }, budget: budget_one) + list << create(:project, title: { en: "Third project" }, budget: budget_two) + list << create(:project, title: { en: "Fourth project" }, budget: budget_two) end end @@ -75,7 +75,7 @@ context "when searching with searchable plan content" do let(:section) { create(:section, :field_text, component: plans_component) } - let!(:content) { create(:content, section: section, plan: plans.first, body: { en: "This content should be discoverable through the search." }) } + let!(:content) { create(:content, section:, plan: plans.first, body: { en: "This content should be discoverable through the search." }) } let(:params) { { search_text_cont: "discoverable" } } diff --git a/spec/shared/budgeting_setup_shared_context.rb b/spec/shared/budgeting_setup_shared_context.rb index ad9831d..7aa4410 100644 --- a/spec/shared/budgeting_setup_shared_context.rb +++ b/spec/shared/budgeting_setup_shared_context.rb @@ -2,8 +2,8 @@ shared_context "with budgeting setup" do let(:organization) { build(:organization, available_authorizations: ["dummy_authorization_handler"], tos_version: Time.current) } - let(:component) { create(:budgeting_pipeline_component, permissions: component_permissions, participatory_space: create(:participatory_process, :with_steps, organization: organization)) } - let(:step_settings) { { votes: voting_mode, show_votes: show_votes } } + let(:component) { create(:budgeting_pipeline_component, permissions: component_permissions, participatory_space: create(:participatory_process, :with_steps, organization:)) } + let(:step_settings) { { votes: voting_mode, show_votes: } } let(:voting_mode) { :enabled } let(:show_votes) { true } let(:requires_authorization) { true } @@ -23,26 +23,26 @@ end end - let!(:budget1) { create(:budgeting_pipeline_budget, component: component, total_budget: 200_000) } - let!(:budget2) { create(:budgeting_pipeline_budget, component: component, total_budget: 100_000) } - let!(:budget3) { create(:budgeting_pipeline_budget, component: component, total_budget: 120_000) } - let!(:budget4) { create(:budgeting_pipeline_budget, component: component, total_budget: 80_000) } - let!(:budget5) { create(:budgeting_pipeline_budget, component: component, total_budget: 110_000) } - let(:budgets) { [budget1, budget2, budget3, budget4, budget5] } + let!(:budget_one) { create(:budgeting_pipeline_budget, component:, total_budget: 200_000) } + let!(:budget_two) { create(:budgeting_pipeline_budget, component:, total_budget: 100_000) } + let!(:budget_three) { create(:budgeting_pipeline_budget, component:, total_budget: 120_000) } + let!(:budget_four) { create(:budgeting_pipeline_budget, component:, total_budget: 80_000) } + let!(:budget_five) { create(:budgeting_pipeline_budget, component:, total_budget: 110_000) } + let(:budgets) { [budget_one, budget_two, budget_three, budget_four, budget_five] } - let!(:budget1_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget1, budget_amount: 40_000, paper_orders_count: 0) } - let!(:budget2_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget2, budget_amount: 20_000, paper_orders_count: 0) } - let!(:budget3_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget3, budget_amount: 24_000, paper_orders_count: 0) } - let!(:budget4_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget4, budget_amount: 16_000, paper_orders_count: 0) } - let!(:budget5_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget5, budget_amount: 22_000, paper_orders_count: 0) } + let!(:budget_one_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget_one, budget_amount: 40_000, paper_orders_count: 0) } + let!(:budget_two_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget_two, budget_amount: 20_000, paper_orders_count: 0) } + let!(:budget_three_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget_three, budget_amount: 24_000, paper_orders_count: 0) } + let!(:budget_four_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget_four, budget_amount: 16_000, paper_orders_count: 0) } + let!(:budget_five_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget_five, budget_amount: 22_000, paper_orders_count: 0) } let(:voted_budgets) { budgets.sample(2) } let!(:votes) do [].tap do |values| voted_budgets.each do |budget| 10.times do - vote = create(:budgeting_pipeline_vote, component: component) - order = create(:budgeting_pipeline_order, budget: budget, user: vote.user, vote: vote) + vote = create(:budgeting_pipeline_vote, component:) + order = create(:budgeting_pipeline_order, budget:, user: vote.user, vote:) Array(budget.projects.sample(rand(0..5))).each do |project| order.projects << project project.update!(paper_orders_count: rand(1..10)) if project.paper_orders_count < 1 @@ -56,8 +56,8 @@ end end - let!(:user) { create(:user, :confirmed, organization: organization) } - let!(:authorization) { create(:authorization, :granted, user: user, name: "dummy_authorization_handler", unique_id: "123456789X") } + let!(:user) { create(:user, :confirmed, organization:) } + let!(:authorization) { create(:authorization, :granted, user:, name: "dummy_authorization_handler", unique_id: "123456789X") } before do component.update!(step_settings: { component.participatory_space.active_step.id => step_settings }) if step_settings.present? diff --git a/spec/system/admin/admin_exports_projects_to_accountability_spec.rb b/spec/system/admin/admin_exports_projects_to_accountability_spec.rb index 70ab25c..73f8b02 100644 --- a/spec/system/admin/admin_exports_projects_to_accountability_spec.rb +++ b/spec/system/admin/admin_exports_projects_to_accountability_spec.rb @@ -2,11 +2,11 @@ require "spec_helper" -describe "Admin exports projects to accountability", type: :system do +describe "AdminExportsProjectsToAccountability" do let(:manifest_name) { "budgets" } let(:budget) { create(:budgeting_pipeline_budget, component: current_component) } - let!(:selected_projects) { create_list(:budgeting_pipeline_project, 5, budget: budget, selected_at: Time.current) } - let!(:other_projects) { create_list(:budgeting_pipeline_project, 10, budget: budget) } + let!(:selected_projects) { create_list(:budgeting_pipeline_project, 5, budget:, selected_at: Time.current) } + let!(:other_projects) { create_list(:budgeting_pipeline_project, 10, budget:) } let!(:accountability_component) { create(:accountability_component, participatory_space: current_component.participatory_space) } @@ -16,20 +16,20 @@ switch_to_host(organization.host) login_as user, scope: :user visit_component_admin - click_link "Exports proposals to results" + click_on "Exports proposals to results" end it "can export projects to accountability" do select translated(accountability_component.name), from: :accountability_export_target_component_id check :accountability_export_export_all_selected_projects - expect { click_button "Export to results" }.to change(Decidim::Accountability::Result, :count).by(selected_projects.count) + expect { click_on "Export to results" }.to change(Decidim::Accountability::Result, :count).by(selected_projects.count) expect(page).to have_content("Proposals successfully exported to results") end context "when checking the exported details" do - let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget: budget, selected_at: Time.current) } + let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget:, selected_at: Time.current) } let(:project) { selected_projects.first } let(:result) { Decidim::Accountability::Result.order(:id).last } @@ -46,7 +46,7 @@ end context "with scope" do - let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget: budget, selected_at: Time.current, scope: scope) } + let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget:, selected_at: Time.current, scope:) } let(:scope) { create(:scope, organization: current_component.organization) } it "sets the correct scope" do @@ -56,8 +56,8 @@ end context "when defined by budget" do - let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget: budget, selected_at: Time.current) } - let(:budget) { create(:budgeting_pipeline_budget, component: current_component, scope: scope) } + let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget:, selected_at: Time.current) } + let(:budget) { create(:budgeting_pipeline_budget, component: current_component, scope:) } it "sets the correct scope" do perform_export @@ -68,7 +68,7 @@ end context "with category" do - let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget: budget, selected_at: Time.current, category: category) } + let!(:selected_projects) { create_list(:budgeting_pipeline_project, 1, budget:, selected_at: Time.current, category:) } let(:category) { create(:category, participatory_space: current_component.participatory_space) } it "sets the correct category" do @@ -79,21 +79,21 @@ end context "with statuses" do - let!(:status1) { create(:status, component: accountability_component, progress: 10) } - let!(:status2) { create(:status, component: accountability_component, progress: 50) } + let!(:status_one) { create(:status, component: accountability_component, progress: 10) } + let!(:status_two) { create(:status, component: accountability_component, progress: 50) } it "sets the correct status for the result" do perform_export expect(result.progress).to eq(10) - expect(result.status).to eq(status1) + expect(result.status).to eq(status_one) end end def perform_export select translated(accountability_component.name), from: :accountability_export_target_component_id check :accountability_export_export_all_selected_projects - click_button "Export to results" + click_on "Export to results" end end end diff --git a/spec/system/admin/admin_manages_help_sections_spec.rb b/spec/system/admin/admin_manages_help_sections_spec.rb index c31276b..e576945 100644 --- a/spec/system/admin/admin_manages_help_sections_spec.rb +++ b/spec/system/admin/admin_manages_help_sections_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Admin manages help sections", type: :system do +describe "AdminManagesHelpSections" do let(:manifest_name) { "budgets" } let!(:index_sections) { create_list(:budgeting_pipeline_help_section, 2, component: current_component, key: :index) } let!(:pipeline_sections) { create_list(:budgeting_pipeline_help_section, 2, component: current_component, key: :pipeline) } @@ -13,7 +13,7 @@ switch_to_host(organization.host) login_as user, scope: :user visit_component_admin - click_link "Helping content" + click_on "Helping content" end describe "index" do @@ -26,7 +26,7 @@ it "browsing through the help sections" do within ".table-list" do - click_link "Front page" + click_on "Front page" end within "h1.item_show__header-title" do @@ -40,11 +40,11 @@ end within "h1.item_show__header-title" do - click_link "Helping content" + click_on "Helping content" end within ".table-list" do - click_link "Voting pipeline" + click_on "Voting pipeline" end within ".table-list" do @@ -58,7 +58,7 @@ describe "create" do before do within ".table-list" do - click_link "Front page" + click_on "Front page" end click_on "New help section" @@ -83,17 +83,17 @@ before do within ".table-list" do - click_link "Front page" + click_on "Front page" end within ".table-list" do - click_link translated(section.title) + click_on translated(section.title) end end it "allows updating the help section" do fill_in_details - click_button "Update help section" + click_on "Update help section" expect(page).to have_content("Help section successfully updated") within ".table-list" do @@ -109,7 +109,7 @@ before do within ".table-list" do - click_link "Front page" + click_on "Front page" end within "h1.item_show__header-title" do @@ -121,7 +121,7 @@ expect do within ".table-list" do within "tr[data-id='#{section.id}']" do - accept_confirm { click_link "Delete" } + accept_confirm { click_on "Delete" } end end end.to change(Decidim::Budgets::HelpSection, :count).by(-1) diff --git a/spec/system/explore_projects_spec.rb b/spec/system/explore_projects_spec.rb index b539b73..a6b2d24 100644 --- a/spec/system/explore_projects_spec.rb +++ b/spec/system/explore_projects_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Explore projects", type: :system do +describe "ExploreProjects" do include_context "with budgeting setup" describe "index" do @@ -21,7 +21,7 @@ it "can filter based on keywords" do within "form.new_filter" do find(%(input[name="filter[search_text_cont]"])).set(translated(budget1_projects.first.title)) - click_button "Search" + click_on "Search" end expect(page).to have_content("Found 1 proposal") @@ -30,7 +30,7 @@ it "can filter based on the area" do within "form.new_filter" do find(%(select[name="filter[decidim_budgets_budget_id_eq]"])).find(%(option[value="#{budget1.id}"])).select_option - click_button "Search" + click_on "Search" end expect(page).to have_content("Found 10 proposals") @@ -38,13 +38,13 @@ it "can filter based on the budget" do within "form.new_filter" do - click_button "Show more search criteria" - scroll_to find("#additional_search") + click_on "Show more search criteria" + scroll_to find_by_id("additional_search") end - find("#additional_search").find("input[name='filter[budget_amount_lteq]']").set(16_000) - find("#additional_search").find("input[name='filter[budget_amount_lteq]']").set(20_000) - click_button "Search" + find_by_id("additional_search").find("input[name='filter[budget_amount_lteq]']").set(16_000) + find_by_id("additional_search").find("input[name='filter[budget_amount_lteq]']").set(20_000) + click_on "Search" expect(page).to have_content("Found 20 proposals") end end @@ -58,7 +58,7 @@ end it "shows the project details" do - expect(page).to have_content("#{project.id}") + expect(page).to have_content(project.id.to_s) expect(page).to have_content(translated(project.budget.title)) expect(page).to have_content(project.address) expect(page).to have_content(translated(project.title)) @@ -69,7 +69,7 @@ let(:category) { create(:category, participatory_space: component.participatory_space, parent: parent_category) } let(:parent_category) { create(:category, participatory_space: component.participatory_space) } - let!(:project) { create(:budgeting_pipeline_project, budget: budget1, category: category) } + let!(:project) { create(:budgeting_pipeline_project, budget: budget1, category:) } it "displays the category and its parent category" do expect(page).to have_content(translated(parent_category.name)) @@ -87,11 +87,11 @@ it "renders status selection" do visit_component select_element = find("select[name='filter[with_any_status]']") - expect(select_element).to have_selector("option", text: "Proceeds to implementation") - expect(select_element).to have_selector("option", text: "Will not proceed to implementation") + expect(select_element).to have_css("option", text: "Proceeds to implementation") + expect(select_element).to have_css("option", text: "Will not proceed to implementation") find("select[name='filter[with_any_status]']").select("Proceeds to implementation") within "form.new_filter" do - click_button "Search" + click_on "Search" end within "#project-#{project.id}-item" do expect(page).to have_css(".card__text--status", text: "Selected") @@ -105,8 +105,8 @@ it "shows the categories" do visit_component select_element = find("select[name='filter[with_any_category]']") - expect(select_element).to have_selector("option", text: translated(categories.first.name)) - expect(select_element).to have_selector("option", text: translated(categories.last.name)) + expect(select_element).to have_css("option", text: translated(categories.first.name)) + expect(select_element).to have_css("option", text: translated(categories.last.name)) end end end diff --git a/spec/system/explore_results_spec.rb b/spec/system/explore_results_spec.rb index 3b4a104..24b0757 100644 --- a/spec/system/explore_results_spec.rb +++ b/spec/system/explore_results_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Explore results", type: :system do +describe "ExploreResults" do include ActionView::Helpers::NumberHelper include_context "with budgeting setup" @@ -21,7 +21,7 @@ expect(page).to have_content(number_to_currency(budget.total_budget, unit: Decidim.currency_unit, precision: 0)) if voted_budgets.include?(budget) - click_button "Show more" + click_on "Show more" projects = sorted_projects_for(budget) @@ -77,6 +77,6 @@ def find_budget_by_title(title) end def sorted_projects_for(budget) - Decidim::Budgets::Project.where(budget: budget).order_by_most_voted(only_voted: false) + Decidim::Budgets::Project.where(budget:).order_by_most_voted(only_voted: false) end end diff --git a/spec/system/voting_spec.rb b/spec/system/voting_spec.rb index 291be02..8f319a9 100644 --- a/spec/system/voting_spec.rb +++ b/spec/system/voting_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Voting", type: :system do +describe "Voting" do include_context "with budgeting setup" describe "show" do @@ -10,15 +10,11 @@ it "displays the sign in page" do visit_voting - page.scroll_to find("h2", text: "Strong identification") - - contents = all(".wrapper .static__content") - within contents[0] do + page.scroll_to find("h2", text: "Log in to the service to vote") + content = find(".layout-container #content") + within content do expect(page).to have_content(strip_tags(translated(component.settings.vote_identify_page_content))) end - within contents[1] do - expect(page).to have_content(strip_tags(translated(component.settings.vote_identify_page_more_information))) - end within ".voting-identity" do expect(page).to have_link("Sign in with Facebook") @@ -33,13 +29,12 @@ context "when not authorized" do let!(:authorization) { nil } - let(:authorizations) { [:foo] } it "displays the authorization options" do visit_voting - expect(page).to have_content("Strong identification") - page.scroll_to find("h2", text: "Strong identification") + expect(page).to have_content("Log in to the service to vote") + page.scroll_to find("h2", text: "Log in to the service to vote") within ".voting-identity" do expect(page).to have_link("Example authorization") @@ -137,7 +132,7 @@ end end - page.scroll_to find("#orders-summary") + page.scroll_to find_by_id("orders-summary") within "#orders-summary" do expect(page).to have_content("4 votes remaining") @@ -161,7 +156,7 @@ describe "preview" do let(:budget) { budget1 } - let!(:order) { create(:order, budget: budget1, user: user) } + let!(:order) { create(:order, budget: budget1, user:) } before do order.projects << budget1_projects.first @@ -182,7 +177,7 @@ describe "create" do let(:budget) { budget1 } - let!(:order) { create(:order, budget: budget1, user: user) } + let!(:order) { create(:order, budget: budget1, user:) } before do order.projects << budget1_projects.first @@ -196,7 +191,7 @@ end it "can cast the vote" do - click_button "Vote" + click_on "Vote" within "#vote-finished-modal" do expect(page).to have_content("Thank you for your vote!") diff --git a/spec/types/decidim/budgeting_pipeline/budget_mutation_type_spec.rb b/spec/types/decidim/budgeting_pipeline/budget_mutation_type_spec.rb index c686bea..1f7e971 100644 --- a/spec/types/decidim/budgeting_pipeline/budget_mutation_type_spec.rb +++ b/spec/types/decidim/budgeting_pipeline/budget_mutation_type_spec.rb @@ -6,19 +6,19 @@ describe Decidim::BudgetingPipeline::BudgetMutationType do include_context "with a graphql class type" - let(:model) { create(:budgeting_pipeline_budget, component: component) } + let(:model) { create(:budgeting_pipeline_budget, component:) } let(:participatory_space) { create(:participatory_process, organization: current_organization) } - let(:component) { create(:budgeting_pipeline_component, participatory_space: participatory_space) } + let(:component) { create(:budgeting_pipeline_component, participatory_space:) } - let(:category) { create(:category, participatory_space: participatory_space) } + let(:category) { create(:category, participatory_space:) } let(:scope) { create(:scope, organization: current_organization) } let(:proposals) { create_list(:proposal, 3, component: proposals_component) } - let(:proposals_component) { create(:proposal_component, participatory_space: participatory_space) } + let(:proposals_component) { create(:proposal_component, participatory_space:) } let(:ideas) { create_list(:idea, 2, component: ideas_component) } - let(:ideas_component) { create(:idea_component, participatory_space: participatory_space) } + let(:ideas_component) { create(:idea_component, participatory_space:) } let(:plans) { create_list(:plan, 3, component: plans_component) } - let(:plans_component) { create(:plan_component, participatory_space: participatory_space) } + let(:plans_component) { create(:plan_component, participatory_space:) } describe "createProject" do let(:query) { "{ createProject(attributes: #{attributes_to_graphql(attributes)}) { id } }" } diff --git a/spec/types/decidim/budgets/project_type_spec.rb b/spec/types/decidim/budgets/project_type_spec.rb index a7e2396..cc6dce7 100644 --- a/spec/types/decidim/budgets/project_type_spec.rb +++ b/spec/types/decidim/budgets/project_type_spec.rb @@ -6,11 +6,11 @@ describe Decidim::Budgets::ProjectType do include_context "with a graphql class type" - let(:model) { create(:budgeting_pipeline_project, component: component) } + let(:model) { create(:budgeting_pipeline_project, component:) } let(:participatory_space) { create(:participatory_process) } - let(:component) { create(:budgeting_pipeline_component, participatory_space: participatory_space) } + let(:component) { create(:budgeting_pipeline_component, participatory_space:) } let(:proposal) { create(:proposal, component: proposals_component) } - let(:proposals_component) { create(:proposal_component, participatory_space: participatory_space) } + let(:proposals_component) { create(:proposal_component, participatory_space:) } describe "summary" do let(:query) { "{ summary { translations { text locale } } }" } @@ -124,7 +124,7 @@ end describe "budgetAmountMin" do - let(:model) { create(:budgeting_pipeline_project, component: component, budget_amount_min: 10_000) } + let(:model) { create(:budgeting_pipeline_project, component:, budget_amount_min: 10_000) } let(:query) { "{ budgetAmountMin }" }