-
Notifications
You must be signed in to change notification settings - Fork 15
Fix proposals order in index #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c7cfd1
feat: add proposals controller extends to fix proposals order in index
Stef-Rousset 9a8a885
test: add tests for proposal controller and system test for proposals…
Stef-Rousset adc3131
style: refacto with rubocop
Stef-Rousset dbc319e
test: update system test
Stef-Rousset 9070bff
test: refacto with rubocop
Stef-Rousset 451ad8f
fix: update filter order in default_filter_params
Stef-Rousset 55773f8
test: add test to check the order of proposals is kept when using filter
Stef-Rousset df9d3a9
Merge branch 'develop' into fix/proposals_order_in_index
Stef-Rousset File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
lib/extends/controllers/decidim/proposals/proposals_controller_extends.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "active_support/concern" | ||
|
|
||
| module Decidim | ||
| module Proposals | ||
| module ProposalsControllerExtends | ||
| extend ActiveSupport::Concern | ||
|
|
||
| included do | ||
| def index | ||
| if component_settings.participatory_texts_enabled? | ||
| @proposals = Decidim::Proposals::Proposal | ||
| .where(component: current_component) | ||
| .published | ||
| .not_hidden | ||
| .only_amendables | ||
| .includes(:category, :scope, :attachments, :coauthorships) | ||
| .order(position: :asc) | ||
| render "decidim/proposals/proposals/participatory_texts/participatory_text" | ||
| else | ||
| @proposals = search.result | ||
| @proposals = reorder(@proposals) | ||
| ids = @proposals.ids | ||
| @proposals = Decidim::Proposals::Proposal.where(id: ids) | ||
| .order(Arel.sql("position(decidim_proposals_proposals.id::text in '#{ids.join(",")}')")) | ||
| .page(params[:page]) | ||
| .per(per_page) | ||
| @proposals = @proposals.includes(:component, :coauthorships, :attachments) | ||
|
|
||
| @voted_proposals = if current_user | ||
| ProposalVote.where( | ||
| author: current_user, | ||
| proposal: @proposals.pluck(:id) | ||
| ).pluck(:decidim_proposal_id) | ||
| else | ||
| [] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def default_filter_params | ||
| { | ||
| activity: "all", | ||
| related_to: "", | ||
| search_text_cont: "", | ||
| type: "all", | ||
| with_any_category: nil, | ||
| with_any_origin: nil, | ||
| with_any_scope: nil, | ||
| with_any_state: default_states | ||
| } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| Decidim::Proposals::ProposalsController.include(Decidim::Proposals::ProposalsControllerExtends) | ||
BarbaraOliveira13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "spec_helper" | ||
|
|
||
| module Decidim | ||
| module Proposals | ||
| describe ProposalsController do | ||
| routes { Decidim::Proposals::Engine.routes } | ||
|
|
||
| let(:user) { create(:user, :confirmed, organization: component.organization) } | ||
|
|
||
| let(:proposal_params) do | ||
| { | ||
| component_id: component.id | ||
| } | ||
| end | ||
| let(:params) { { proposal: proposal_params } } | ||
|
|
||
| before do | ||
| request.env["decidim.current_organization"] = component.organization | ||
| request.env["decidim.current_participatory_space"] = component.participatory_space | ||
| request.env["decidim.current_component"] = component | ||
| stub_const("Decidim::Paginable::OPTIONS", [100]) | ||
| end | ||
|
|
||
| describe "GET index" do | ||
| context "when participatory texts are disabled" do | ||
| let(:component) { create(:proposal_component, :with_geocoding_enabled) } | ||
|
|
||
| it "sorts proposals by search defaults" do | ||
| get :index | ||
| expect(response).to have_http_status(:ok) | ||
| expect(subject).to render_template(:index) | ||
| expect(assigns(:proposals).order_values).to eq(["position(decidim_proposals_proposals.id::text in '')"]) | ||
| end | ||
|
|
||
| it "sets two different collections" do | ||
| geocoded_proposals = create_list(:proposal, 10, component:, latitude: 1.1, longitude: 2.2) | ||
| non_geocoded_proposals = create_list(:proposal, 2, component:, latitude: nil, longitude: nil) | ||
|
|
||
| get :index | ||
| expect(response).to have_http_status(:ok) | ||
| expect(subject).to render_template(:index) | ||
|
|
||
| expect(assigns(:proposals).count).to eq 12 | ||
| expect(assigns(:proposals)).to match_array(geocoded_proposals + non_geocoded_proposals) | ||
| end | ||
| end | ||
|
|
||
| context "when participatory texts are enabled" do | ||
| let(:component) { create(:proposal_component, :with_participatory_texts_enabled) } | ||
|
|
||
| it "sorts proposals by position" do | ||
| get :index | ||
| expect(response).to have_http_status(:ok) | ||
| expect(subject).to render_template(:participatory_text) | ||
| expect(assigns(:proposals).order_values.first.expr.name).to eq("position") | ||
| end | ||
|
|
||
| context "when emendations exist" do | ||
| let!(:amendable) { create(:proposal, component:) } | ||
| let!(:emendation) { create(:proposal, component:) } | ||
| let!(:amendment) { create(:amendment, amendable:, emendation:, state: "accepted") } | ||
|
|
||
| it "does not include emendations" do | ||
| get :index | ||
| expect(response).to have_http_status(:ok) | ||
| emendations = assigns(:proposals).select(&:emendation?) | ||
| expect(emendations).to be_empty | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.