Skip to content

Commit

Permalink
Fix more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Dec 6, 2023
1 parent 0168b90 commit 23eb7d3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
24 changes: 16 additions & 8 deletions lib/decidim/custom_proposal_states/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Decidim
module CustomProposalStates
module Overrides
Expand All @@ -13,4 +14,4 @@ def all_proposals
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/sortitions/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -55,7 +57,9 @@
let(:witnesses) { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_title } }
let(:additional_info) { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_title } }
let(:cancel_reason) { Decidim::Faker::Localized.wrapped("<p>", "</p>") { 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"
Expand Down
7 changes: 6 additions & 1 deletion spec/sortitions/sortition_embeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions spec/sortitions/sortitions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23eb7d3

Please sign in to comment.