diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4d2c53..cc82d32 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,7 @@ jobs: - "spec/budgets" - "spec/commands" - "spec/elections" + - "spec/events" - "spec/forms" - "spec/models" - "spec/proposals/cells" diff --git a/lib/decidim/custom_proposal_states.rb b/lib/decidim/custom_proposal_states.rb index 2a2f6bd..afe547c 100644 --- a/lib/decidim/custom_proposal_states.rb +++ b/lib/decidim/custom_proposal_states.rb @@ -16,6 +16,7 @@ module Overrides autoload :ImportProposals, "decidim/custom_proposal_states/overrides/import_proposals" autoload :AnswerProposal, "decidim/custom_proposal_states/overrides/answer_proposal" autoload :NotifyProposalAnswer, "decidim/custom_proposal_states/overrides/notify_proposal_answer" + autoload :ProposalAnswerCreator, "decidim/custom_proposal_states/overrides/proposal_answer_creator" end def self.create_default_states!(component, admin_user, with_traceability: true) diff --git a/lib/decidim/custom_proposal_states/engine.rb b/lib/decidim/custom_proposal_states/engine.rb index d38c170..36ca3f1 100644 --- a/lib/decidim/custom_proposal_states/engine.rb +++ b/lib/decidim/custom_proposal_states/engine.rb @@ -62,6 +62,7 @@ class Engine < ::Rails::Engine Decidim::Proposals::Admin::ImportProposals.prepend Decidim::CustomProposalStates::Overrides::ImportProposals Decidim::Proposals::Admin::AnswerProposal.prepend Decidim::CustomProposalStates::Overrides::AnswerProposal Decidim::Proposals::Admin::NotifyProposalAnswer.prepend Decidim::CustomProposalStates::Overrides::NotifyProposalAnswer + Decidim::Proposals::Import::ProposalAnswerCreator.prepend Decidim::CustomProposalStates::Overrides::ProposalAnswerCreator end end end diff --git a/lib/decidim/custom_proposal_states/overrides/proposal_answer_creator.rb b/lib/decidim/custom_proposal_states/overrides/proposal_answer_creator.rb new file mode 100644 index 0000000..3082802 --- /dev/null +++ b/lib/decidim/custom_proposal_states/overrides/proposal_answer_creator.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Decidim + module CustomProposalStates + module Overrides + module ProposalAnswerCreator + def self.prepended(base) + base.class_eval do + def fetch_resource + proposal = Decidim::Proposals::Proposal.find_by(id: id) + return nil unless proposal + return nil if proposal.emendation? + + if proposal.component != component + proposal.errors.add(:component, :invalid) + return proposal + end + + proposal.answer = answer + proposal.answered_at = Time.current + @initial_state = proposal.proposal_state + + proposal_state = Decidim::CustomProposalStates::ProposalState.where(component: component, token: state).first + + if proposal_state.answerable? + proposal.proposal_state = proposal_state + proposal.state_published_at = Time.current if component.current_settings.publish_answers_immediately? + else + proposal.errors.add(:state, :invalid) + end + proposal + end + end + end + end + end + end +end \ No newline at end of file diff --git a/spec/proposals/lib/decidim/proposals/component_spec.rb b/spec/proposals/lib/decidim/proposals/component_spec.rb index 3f76e2d..2371a8e 100644 --- a/spec/proposals/lib/decidim/proposals/component_spec.rb +++ b/spec/proposals/lib/decidim/proposals/component_spec.rb @@ -46,11 +46,11 @@ raw_stats.select { |stat| stat[0] == :proposals } end - let!(:proposal) { create :proposal } + let!(:proposal) { create :extended_proposal } let(:component) { proposal.component } - let!(:hidden_proposal) { create :proposal, component: component } - let!(:draft_proposal) { create :proposal, :draft, component: component } - let!(:withdrawn_proposal) { create :proposal, :withdrawn, component: component } + let!(:hidden_proposal) { create :extended_proposal, component: component } + let!(:draft_proposal) { create :extended_proposal, :draft, component: component } + let!(:withdrawn_proposal) { create :extended_proposal, :withdrawn, component: component } let!(:moderation) { create :moderation, reportable: hidden_proposal, hidden_at: 1.day.ago } let(:current_stat) { stats.find { |stat| stat[1] == stats_name } } @@ -65,8 +65,8 @@ end describe "proposals_accepted" do - let!(:accepted_proposal) { create :proposal, :accepted, component: component } - let!(:accepted_hidden_proposal) { create :proposal, :accepted, component: component } + let!(:accepted_proposal) { create :extended_proposal, :accepted, component: component } + let!(:accepted_hidden_proposal) { create :extended_proposal, :accepted, component: component } let!(:moderation) { create :moderation, reportable: accepted_hidden_proposal, hidden_at: 1.day.ago } let(:stats_name) { :proposals_accepted } @@ -259,9 +259,9 @@ .call(component, user) end - let!(:assigned_proposal) { create :proposal } + let!(:assigned_proposal) { create :extended_proposal } let(:component) { assigned_proposal.component } - let!(:unassigned_proposal) { create :proposal, component: component } + let!(:unassigned_proposal) { create :extended_proposal, component: component } let(:participatory_process) { component.participatory_space } let(:organization) { participatory_process.organization } @@ -287,7 +287,7 @@ end context "when proposal is moderated" do - let(:hidden_proposal) { create :proposal, component: component } + let(:hidden_proposal) { create :extended_proposal, component: component } let!(:moderation) { create(:moderation, hidden_at: 6.hours.ago, reportable: hidden_proposal) } let!(:user) { create :user, admin: true, organization: organization } diff --git a/spec/proposals/lib/decidim/proposals/engine_spec.rb b/spec/proposals/lib/decidim/proposals/engine_spec.rb index 032be59..a5710a9 100644 --- a/spec/proposals/lib/decidim/proposals/engine_spec.rb +++ b/spec/proposals/lib/decidim/proposals/engine_spec.rb @@ -31,17 +31,5 @@ end.to change(Decidim::Proposals::ValuationAssignment, :count).by(-1) end end - - context "when removing conference admin" do - let(:space) { valuator_role.conference } - let(:valuator_role) { create(:conference_user_role) } - let!(:assignment) { create :valuation_assignment, proposal: proposal, valuator_role: valuator_role } - - it "removes the record" do - expect do - ActiveSupport::Notifications.publish("decidim.system.participatory_space.admin.destroyed", valuator_role.class.name, valuator_role.id) - end.to change(Decidim::Proposals::ValuationAssignment, :count).by(-1) - end - end end end diff --git a/spec/proposals/lib/decidim/proposals/import/proposal_answer_creator_spec.rb b/spec/proposals/lib/decidim/proposals/import/proposal_answer_creator_spec.rb index 1fbbe06..8266c26 100644 --- a/spec/proposals/lib/decidim/proposals/import/proposal_answer_creator_spec.rb +++ b/spec/proposals/lib/decidim/proposals/import/proposal_answer_creator_spec.rb @@ -25,7 +25,7 @@ } end let(:participatory_process) { create :participatory_process, organization: organization } - let(:component) { create :component, manifest_name: :proposals, participatory_space: participatory_process } + let(:component) { create :extended_proposal_component, participatory_space: participatory_process } let(:state) { %w(evaluating accepted rejected).sample } describe "#resource_klass" do @@ -51,7 +51,7 @@ expect(record).to be_a(Decidim::Proposals::Proposal) expect(record.id).to eq(data[:id]) expect(record.answer["en"]).to eq(data[:"answer/en"]) - expect(record[:state]).to eq(data[:state]) + expect(record.state).to eq(data[:state]) expect(record.answered_at).to be >= (moment) end @@ -93,7 +93,7 @@ context "and notifies followers" do before do - allow(::Decidim::Proposals::Admin::NotifyProposalAnswer).to receive(:call).with(proposal, "evaluating") + allow(::Decidim::Proposals::Admin::NotifyProposalAnswer).to receive(:call).with(proposal, proposal.proposal_state) end it "notifies followers" do diff --git a/spec/proposals/lib/decidim/proposals/import/proposal_creator_spec.rb b/spec/proposals/lib/decidim/proposals/import/proposal_creator_spec.rb index 730b523..07963fb 100644 --- a/spec/proposals/lib/decidim/proposals/import/proposal_creator_spec.rb +++ b/spec/proposals/lib/decidim/proposals/import/proposal_creator_spec.rb @@ -32,7 +32,7 @@ } end let(:participatory_process) { create :participatory_process, organization: organization } - let(:component) { create :component, manifest_name: :proposals, participatory_space: participatory_process } + let(:component) { create :extended_proposal_component, participatory_space: participatory_process } let(:scope) { create :scope, organization: organization } let(:category) { create :category, participatory_space: participatory_process }