From a8a48ebf5cf0663fdb73886b3a2ce8f50ccd52ab Mon Sep 17 00:00:00 2001 From: Gaspar Bucuane Date: Thu, 19 Feb 2026 19:39:43 +0200 Subject: [PATCH] Adjust proposals query to ignore rejected state and allow nil state --- .../chatbot/workflows/proposals_workflow.rb | 17 ++++++++-- .../workflows/proposals_workflow_spec.rb | 33 +++++-------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/app/services/decidim/chatbot/workflows/proposals_workflow.rb b/app/services/decidim/chatbot/workflows/proposals_workflow.rb index 6d8df7f..c8eb595 100644 --- a/app/services/decidim/chatbot/workflows/proposals_workflow.rb +++ b/app/services/decidim/chatbot/workflows/proposals_workflow.rb @@ -103,11 +103,24 @@ def send_ending def component @component ||= Decidim::Component.find_by(id: config[:component_id]) end - + def proposals - @proposals ||= Decidim::Proposals::Proposal.where(component:).published.except_rejected.only_amendables + base = Decidim::Proposals::Proposal + .where(decidim_component_id: component.id) + .published + .only_amendables + + base.where(proposal_state: none_rejected) + .or(base.where(proposal_state: nil)) end + def none_rejected + Decidim::Proposals::ProposalState + .where(decidim_component_id: component.id) + .where.not(token: "rejected") + end + + def commentable_id @commentable_id ||= received_message.button_id.to_s.start_with?("comment-") && received_message.button_id.to_s.sub("comment-", "") end diff --git a/spec/services/workflows/proposals_workflow_spec.rb b/spec/services/workflows/proposals_workflow_spec.rb index f74625d..6590e0f 100644 --- a/spec/services/workflows/proposals_workflow_spec.rb +++ b/spec/services/workflows/proposals_workflow_spec.rb @@ -87,35 +87,20 @@ module Workflows end end - context "when there are exactly per_page proposals" do + context "when there are proposals without states" do let!(:proposals) do - create_list(:proposal, 10, :evaluating, component: proposals_component, published_at: Time.current) + create_list(:proposal, 7, :evaluating, component: proposals_component, published_at: Time.current) end - - before do - allow(received_message).to receive(:user_text?).and_return(true) - allow(received_message).to receive(:actionable?).and_return(false) - end - - # With 10 proposals and per_page=10: remaining = 10 - (10*1) = 0, not negative - # So it enters the main flow: mark_as_responding, send_cards, send_ending - it "sends carousel cards then ending" do - expect(adapter).to receive(:send_message!).with(hash_including(type: :interactive_carousel)).ordered - expect(adapter).to receive(:send_message!).with(hash_including(type: :interactive_buttons)).ordered - subject.start + let!(:proposals_without_states) do + create_list(:proposal, 3, component: proposals_component, published_at: Time.current) end - - it "marks as responding" do - expect(adapter).to receive(:mark_as_responding!) - subject.start + let!(:rejected_proposals) do + create_list(:proposal, 5, :rejected, component: proposals_component, published_at: Time.current) end - - it "updates page in current_workflow_options" do - subject.start - sender.reload - expect(sender.current_workflow_options["page"]).to eq(2) + it "only the none rejected proposals will be return" do + expect(subject.send(:proposals).count).to eq(10) end - end + end context "when there are more than per_page proposals" do let!(:proposals) do