Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Dec 7, 2023
1 parent 04937c9 commit abc926c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- "spec/budgets"
- "spec/commands"
- "spec/elections"
- "spec/events"
- "spec/forms"
- "spec/models"
- "spec/proposals/cells"
Expand Down
1 change: 1 addition & 0 deletions lib/decidim/custom_proposal_states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/decidim/custom_proposal_states/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions spec/proposals/lib/decidim/proposals/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand All @@ -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 }

Expand Down Expand Up @@ -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 }

Expand All @@ -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 }

Expand Down
12 changes: 0 additions & 12 deletions spec/proposals/lib/decidim/proposals/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit abc926c

Please sign in to comment.