Skip to content

Commit

Permalink
fix: updates with rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Stef-Rousset committed Dec 30, 2024
1 parent beccfa8 commit 4649060
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
inherit_from:
- .rubocop_ruby.yml
- .rubocop_rails.yml

AllCops:
TargetRubyVersion: 3.2
2 changes: 2 additions & 0 deletions .rubocop_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,8 @@ RSpec/DescribeClass:
- "**/*/spec/**/*_badge_spec.rb"
- decidim-core/spec/lib/global_engines_spec.rb
- "**/tasks/**/*"
- decidim-budgets_booth/spec/system/**
- decidim-budgets_booth/spec/i18n_spec.rb

RSpec/EmptyExampleGroup:
Exclude:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def completed_vote_snippets
def add_javascript_file
if Rails.env.test?
<<~HTML
<script src="#{ActionController::Base.helpers.asset_pack_path('decidim_handle_voting_complete.js')}" defer="defer"></script>
<script src="#{ActionController::Base.helpers.asset_pack_path("decidim_handle_voting_complete.js")}" defer="defer"></script>
HTML
else
<<~HTML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module OrdersControllerExtensions
helper_method :budget

def checkout
enforce_permission_to :vote, :project, order: current_order, budget: budget, workflow: current_workflow
enforce_permission_to :vote, :project, order: current_order, budget:, workflow: current_workflow
Decidim::Budgets::Checkout.call(current_order) do
on(:ok) do
reset_workflow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module ProjectsControllerExtensions
include VotingSupport

included do
# rubocop:disable Rails/LexicallyScopedActionFilter
before_action :set_view_mode, only: :index
# rubocop:enable Rails/LexicallyScopedActionFilter
layout :determine_layout

def index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def toggle_view_mode_link(current_mode, target_mode, title, params)
icon_name = target_mode == "grid" ? "layout-grid-fill" : "list-check"
icon_class = "view-icon--disabled" unless current_mode == target_mode

link_to path, remote: true, title: title do
link_to(path, remote: true, title:) do
icon(icon_name, class: icon_class, role: "img", "aria-hidden": true)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Decidim::Budgets

subject(:cell_html) { my_cell.call }


let(:my_cell) { cell("decidim/budgets/project_g", project, card_size: :g) }
let!(:organization) { create(:organization) }
let!(:budgets_component) { create(:budgets_component, organization:) }
Expand Down Expand Up @@ -50,4 +49,3 @@ module Decidim::Budgets
end
end
end

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module BudgetsBooth
let(:organization) { create(:organization) }
let(:component) { create(:budgets_component, organization:, settings: component_settings) }
let(:decidim_budgets) { Decidim::EngineRouter.main_proxy(component) }
let(:component_settings) { { votes: "enabled" } }
let(:component_settings) { { votes: "enabled" } }
let!(:budgets) do
[].tap do |list|
list << create(:budget, component:)
Expand All @@ -24,31 +24,29 @@ module BudgetsBooth
end
end


before do
request.env["decidim.current_organization"] = organization
request.env["decidim.current_participatory_space"] = component.participatory_space
request.env["decidim.current_component"] = component
end

context "when voting enabled" do
it "renders index with budgets_booth application layout" do
get :index
expect(response).to render_template(:index, layout: "layouts/decidim/application")
end
context "when voting enabled" do
it "renders index with budgets_booth application layout" do
get :index
expect(response).to render_template(:index, layout: "layouts/decidim/application")
end
end

context "when voting is not enabled" do
before do
component.update(settings: component_settings.merge(votes: "finished"))
end

it "renders index with budgets_booth voting_layout" do
get :index
expect(response).to render_template(:index, layout: "decidim/budgets/voting_layout")
end
context "when voting is not enabled" do
before do
component.update(settings: component_settings.merge(votes: "finished"))
end

it "renders index with budgets_booth voting_layout" do
get :index
expect(response).to render_template(:index, layout: "decidim/budgets/voting_layout")
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
let(:user) { create(:user, :confirmed, organization:) }
let(:component) { create(:budgets_component, organization:) }
let(:projects_count) { 5 }
let!(:budgets) { create_list(:budget, 3, component: component, total_budget: 100_000_000) }
let!(:budgets) { create_list(:budget, 3, component:, total_budget: 100_000_000) }
let(:decidim_budgets) { Decidim::EngineRouter.main_proxy(component) }
let(:projects) { create_list(:project, 3, budget: budgets.first, budget_amount: 75_000_000) }
let!(:order) { create(:order, user: user, budget: budgets.first) }
let!(:order) { create(:order, user:, budget: budgets.first) }

before do
request.env["decidim.current_organization"] = organization
Expand All @@ -26,15 +26,15 @@
request.env["decidim.current_component"] = component
order.projects << projects.first
order.save!
allow(controller).to receive(:budget).and_return(budgets.first)
allow(controller).to receive(:current_user).and_return(user)
allow(controller).to receive_messages(budget: budgets.first, current_user: user)
end

describe "#checkout" do
context "when command call returns ok" do
before do
component.update!(settings: { workflow: "all" })
end

it "sets thanks session and redirects the user" do
post :checkout, params: { budget_id: budgets.first.id, component_id: component.id, participatory_process_slug: component.participatory_space.slug }
expect(session[:booth_thanks_message]).to be(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ module BudgetsBooth
let(:component) do
create(
:budgets_component,
step_settings: step_settings,
participatory_space: participatory_space,
organization: organization
step_settings:,
participatory_space:,
organization:
)
end
let(:parent_scope) { create(:scope, organization: organization) }
let(:step_settings) { { active_step_id => { votes: votes } } }
let(:parent_scope) { create(:scope, organization:) }
let(:step_settings) { { active_step_id => { votes: } } }
let(:active_step_id) { participatory_space.active_step.id }
let!(:budgets) { create_list(:budget, 3, component: component) }
let!(:budgets) { create_list(:budget, 3, component:) }
let(:project) { create(:project, budget: budgets.last) }
let(:votes) { "enabled" }
let(:decidim_budgets) { Decidim::EngineRouter.main_proxy(component) }
Expand Down Expand Up @@ -64,7 +64,7 @@ module BudgetsBooth
context "when budget and no project" do
it "raises error" do
expect do
get :show, params: { id: 1000000, budget_id: budgets.last.id }
get :show, params: { id: 1_000_000, budget_id: budgets.last.id }
end.to raise_error(ActionController::RoutingError, "Not Found")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

describe Decidim::BudgetsBooth::ProjectsHelperExtensions, type: :helper do
let(:organization) { create(:organization) }
let(:participatory_process) { create(:participatory_process, organization: organization) }
let(:participatory_process) { create(:participatory_process, organization:) }
let!(:step_one) do
create(:participatory_process_step,
active: true,
end_date: Time.zone.now.to_date,
participatory_process: participatory_process)
participatory_process:)
end
let!(:step_two) do
create(:participatory_process_step,
active: false,
end_date: 1.month.from_now.to_date,
participatory_process: participatory_process)
participatory_process:)
end

before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ def voting_open?
create(
:budgets_component,
settings: component_settings.merge(workflow: "all"),
step_settings: step_settings,
organization: organization
step_settings:,
organization:
)
end
let(:step_settings) { { active_step_id => { votes: votes } } }
let(:step_settings) { { active_step_id => { votes: } } }
let(:votes) { "enabled" }
let(:active_step_id) { component.participatory_space.active_step.id }
let!(:user) { create(:user, :confirmed, organization: organization) }
let!(:user) { create(:user, :confirmed, organization:) }
let(:decidim_budgets) { Decidim::EngineRouter.main_proxy(component) }
let(:projects_count) { 5 }
let(:projects) { create_list(:project, 3, budget: budgets.first, budget_amount: 75_000) }
let(:second_projects) { create_list(:project, 3, budget: budgets.second, budget_amount: 75_000) }
let(:third_projects) { create_list(:project, 3, budget: budgets.third, budget_amount: 75_000) }
let!(:order) { create(:order, user: user, budget: budgets.first) }
let!(:second_order) { create(:order, user: user, budget: budgets.second) }
let!(:third_order) { create(:order, user: user, budget: budgets.third) }
let!(:order) { create(:order, user:, budget: budgets.first) }
let!(:second_order) { create(:order, user:, budget: budgets.second) }
let!(:third_order) { create(:order, user:, budget: budgets.third) }

include_context "with scoped budgets"

before do
component.update!(settings: component_settings.merge(workflow: "all"))
allow(dummy).to receive_messages(component: component, user: user, organization: organization, current_settings: component.current_settings)
allow(dummy).to receive_messages(component:, user:, organization:, current_settings: component.current_settings)
end

describe "#voted_all_budgets?" do
Expand Down
16 changes: 8 additions & 8 deletions decidim-budgets_booth/spec/shared/shared_context.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

shared_context "with scopes" do
let(:parent_scope) { create(:scope, organization: organization) }
let!(:subscopes) { create_list(:scope, 3, parent: parent_scope, organization: organization) }
let(:parent_scope) { create(:scope, organization:) }
let!(:subscopes) { create_list(:scope, 3, parent: parent_scope, organization:) }
end

shared_context "with scoped budgets" do
include_context "with scopes"

let(:organization) { create(:organization) }
let(:component) { create(:budgets_component, settings: component_settings, organization: organization) }
let(:component) { create(:budgets_component, settings: component_settings, organization:) }
let(:component_settings) { { scopes_enabled: true, scope_id: parent_scope.id } }

let(:budgets) { create_list(:budget, 3, component: component, total_budget: 100_000) }
let(:budgets) { create_list(:budget, 3, component:, total_budget: 100_000) }
let!(:first_projects_set) { create_list(:project, projects_count, budget: budgets[0], budget_amount: 25_000) }
let!(:second_projects_set) { create_list(:project, projects_count, budget: budgets[1], budget_amount: 25_000) }
let!(:last_projects_set) { create_list(:project, projects_count, budget: budgets[2], budget_amount: 25_000) }
Expand All @@ -29,11 +29,11 @@
include_context "with scopes"

let(:organization) { create(:organization) }
let(:component) { create(:budgets_component, settings: component_settings, organization: organization) }
let(:component) { create(:budgets_component, settings: component_settings, organization:) }
let(:component_settings) { { scopes_enabled: true, scope_id: parent_scope.id } }

let!(:budget) { create(:budget, component: component, total_budget: 100_000) }
let!(:projects_set) { create_list(:project, 3, budget: budget, budget_amount: 25_000) }
let!(:budget) { create(:budget, component:, total_budget: 100_000) }
let!(:projects_set) { create_list(:project, 3, budget:, budget_amount: 25_000) }

before do
budget.update!(scope: subscopes[0], description: { en: "<p>Eius officiis expedita. 55</p>" })
Expand All @@ -42,7 +42,7 @@

shared_context "with a survey" do
let!(:participatory_space) { component.participatory_space }
let!(:surveys_component) { create(:surveys_component, :published, participatory_space: participatory_space) }
let!(:surveys_component) { create(:surveys_component, :published, participatory_space:) }
let!(:survey) { create(:survey, component: surveys_component) }
let!(:questionnaire) { create(:questionnaire, questionnaire_for: survey) }
end
2 changes: 1 addition & 1 deletion decidim-budgets_booth/spec/system/explore_budgets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
end

describe "budget list item" do
let!(:component){ create(:budgets_component, :with_vote_threshold_percent, manifest:, participatory_space: participatory_process, settings: { landing_page_content: description }) }
let!(:component) { create(:budgets_component, :with_vote_threshold_percent, manifest:, participatory_space: participatory_process, settings: { landing_page_content: description }) }
let(:description) { { en: "Short description", ca: "Descripció curta", es: "Descripción corta" } }
let(:budget) { budgets.first }
let(:item) { page.find("#budgets .card--list__item", match: :first) }
Expand Down
14 changes: 7 additions & 7 deletions decidim-budgets_booth/spec/system/explore_projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
describe "Explore projects", :slow do
include_context "with a component"
let(:manifest_name) { "budgets" }
let(:budget) { create(:budget, component: component) }
let(:budget) { create(:budget, component:) }
let(:projects_count) { 5 }
let!(:projects) do
create_list(:project, projects_count, budget: budget)
create_list(:project, projects_count, budget:)
end
let!(:project) { projects.first }
let(:categories) { create_list(:category, 3, participatory_space: component.participatory_space) }

describe "show" do
let(:description) { { en: "Short description", ca: "Descripció curta", es: "Descripción corta" } }
let(:project) { create(:project, budget: budget, description: description) }
let(:project) { create(:project, budget:, description:) }

before do
visit_budget
Expand Down Expand Up @@ -83,8 +83,8 @@
end

it "updates the current URL with the text filter" do
create(:project, budget: budget, title: { en: "Foobar project" })
create(:project, budget: budget, title: { en: "Another project" })
create(:project, budget:, title: { en: "Foobar project" })
create(:project, budget:, title: { en: "Another project" })
visit_budget

within "aside form.new_filter" do
Expand All @@ -102,7 +102,7 @@
end

it "allows filtering by scope" do
scope = create(:scope, organization: organization)
scope = create(:scope, organization:)
project.scope = scope
project.save

Expand Down Expand Up @@ -139,7 +139,7 @@
let!(:component) do
create(:budgets_component,
:with_voting_finished,
manifest: manifest,
manifest:,
participatory_space: participatory_process)
end

Expand Down
Loading

0 comments on commit 4649060

Please sign in to comment.