From 23eb7d328f95457ed7cba5df5b30df35a68f1a7b Mon Sep 17 00:00:00 2001 From: Alexandru Emil Lupu Date: Wed, 6 Dec 2023 16:10:09 +0200 Subject: [PATCH] Fix more specs --- lib/decidim/custom_proposal_states/engine.rb | 24 ++++++++++++------- .../overrides/import_proposals_to_budgets.rb | 3 ++- .../import_proposals_to_elections.rb | 2 +- spec/sortitions/show_spec.rb | 8 +++++-- spec/sortitions/sortition_embeds_spec.rb | 7 +++++- spec/sortitions/sortitions_controller_spec.rb | 6 +++-- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/decidim/custom_proposal_states/engine.rb b/lib/decidim/custom_proposal_states/engine.rb index b9b88c4..5900479 100644 --- a/lib/decidim/custom_proposal_states/engine.rb +++ b/lib/decidim/custom_proposal_states/engine.rb @@ -39,17 +39,25 @@ class Engine < ::Rails::Engine end end - initializer "decidim_custom_proposal_states.action_controller" do |_app| + initializer "decidim_custom_proposal_states.overrides.budgets" do Rails.application.reloader.to_prepare do - Decidim::Proposals::Proposal.prepend Decidim::CustomProposalStates::Overrides::Proposal + return unless Decidim.module_installed?("budgets") - if Decidim.module_installed?("budgets") - Decidim::Budgets::Admin::ImportProposalsToBudgets.prepend Decidim::CustomProposalStates::Overrides::ImportProposalsToBudgets - end + Decidim::Budgets::Admin::ImportProposalsToBudgets.prepend Decidim::CustomProposalStates::Overrides::ImportProposalsToBudgets + end + end - if Decidim.module_installed?("elections") - Decidim::Elections::Admin::ImportProposalsToElections.prepend Decidim::CustomProposalStates::Overrides::ImportProposalsToElections - end + initializer "decidim_custom_proposal_states.overrides.elections" do + Rails.application.reloader.to_prepare do + return unless Decidim.module_installed?("elections") + + Decidim::Elections::Admin::ImportProposalsToElections.prepend Decidim::CustomProposalStates::Overrides::ImportProposalsToElections + end + end + + initializer "decidim_custom_proposal_states.overrides.proposal" do + Rails.application.reloader.to_prepare do + Decidim::Proposals::Proposal.prepend Decidim::CustomProposalStates::Overrides::Proposal end end end diff --git a/lib/decidim/custom_proposal_states/overrides/import_proposals_to_budgets.rb b/lib/decidim/custom_proposal_states/overrides/import_proposals_to_budgets.rb index d51042c..5589dfe 100644 --- a/lib/decidim/custom_proposal_states/overrides/import_proposals_to_budgets.rb +++ b/lib/decidim/custom_proposal_states/overrides/import_proposals_to_budgets.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Decidim module CustomProposalStates module Overrides @@ -13,4 +14,4 @@ def all_proposals end end end -end \ No newline at end of file +end diff --git a/lib/decidim/custom_proposal_states/overrides/import_proposals_to_elections.rb b/lib/decidim/custom_proposal_states/overrides/import_proposals_to_elections.rb index 8141d2f..06126de 100644 --- a/lib/decidim/custom_proposal_states/overrides/import_proposals_to_elections.rb +++ b/lib/decidim/custom_proposal_states/overrides/import_proposals_to_elections.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true + module Decidim module CustomProposalStates module Overrides module ImportProposalsToElections - def self.prepended(base) base.class_eval do def proposals diff --git a/spec/sortitions/show_spec.rb b/spec/sortitions/show_spec.rb index 51137e9..9773515 100644 --- a/spec/sortitions/show_spec.rb +++ b/spec/sortitions/show_spec.rb @@ -27,7 +27,9 @@ end context "when sortition result" do - let(:sortition) { create(:sortition, component: component) } + let(:proposals_component) { create(:extended_proposal_component, organization: component.organization) } + + let(:sortition) { create(:sortition, decidim_proposals_component: proposals_component, component: component) } let!(:proposals) do create_list(:extended_proposal, 10, component: sortition.decidim_proposals_component, @@ -55,7 +57,9 @@ let(:witnesses) { Decidim::Faker::Localized.wrapped("

", "

") { generate_localized_title } } let(:additional_info) { Decidim::Faker::Localized.wrapped("

", "

") { generate_localized_title } } let(:cancel_reason) { Decidim::Faker::Localized.wrapped("

", "

") { generate_localized_title } } - let!(:sortition) { create(:sortition, :cancelled, component: component, witnesses: witnesses, additional_info: additional_info, cancel_reason: cancel_reason) } + let(:proposals_component) { create(:extended_proposal_component, organization: component.organization) } + + let!(:sortition) { create(:sortition, :cancelled, decidim_proposals_component: proposals_component, component: component, witnesses: witnesses, additional_info: additional_info, cancel_reason: cancel_reason) } before do page.visit "#{main_component_path(component)}?filter[state]=cancelled" diff --git a/spec/sortitions/sortition_embeds_spec.rb b/spec/sortitions/sortition_embeds_spec.rb index 965b1c1..9743ed8 100644 --- a/spec/sortitions/sortition_embeds_spec.rb +++ b/spec/sortitions/sortition_embeds_spec.rb @@ -5,7 +5,12 @@ describe "Sortition embeds", type: :system do include_context "with a component" let(:manifest_name) { "sortitions" } - let(:resource) { create(:sortition, component: component) } + + let(:target_items) { Faker::Number.between(from: 1, to: 5).to_i } + let(:proposals_component) { create(:extended_proposal_component, organization: component.organization) } + let(:selected_proposals) { create_list(:extended_proposal, target_items, component: proposals_component).pluck(:id) } + + let(:resource) { create(:sortition, selected_proposals: selected_proposals, decidim_proposals_component: proposals_component, target_items: target_items, component: component) } it_behaves_like "an embed resource" end diff --git a/spec/sortitions/sortitions_controller_spec.rb b/spec/sortitions/sortitions_controller_spec.rb index a70ee4b..3136202 100644 --- a/spec/sortitions/sortitions_controller_spec.rb +++ b/spec/sortitions/sortitions_controller_spec.rb @@ -8,8 +8,10 @@ module Admin describe SortitionsController, type: :controller do routes { Decidim::Sortitions::AdminEngine.routes } - let(:component) { sortition.component } - let(:sortition) { create(:sortition) } + let(:proposals_component) { create(:extended_proposal_component, organization: component.organization) } + + let(:component) { create(:sortition_component) } + let(:sortition) { create(:sortition, component: component, decidim_proposals_component: proposals_component) } let(:user) { create(:user, :confirmed, :admin, organization: component.organization) } before do