Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter by scope on search page #12036

Merged
merged 1 commit into from Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion decidim-core/app/commands/decidim/search.rb
Expand Up @@ -3,7 +3,7 @@
module Decidim
# A command that will act as a search service, with all the business logic for performing searches.
class Search < Decidim::Command
ACCEPTED_FILTERS = [:decidim_scope_id_eq].freeze
ACCEPTED_FILTERS = [:decidim_scope_id_in].freeze
HIGHLIGHTED_RESULTS_COUNT = 4

# Public: Initializes the command.
Expand Down
Expand Up @@ -26,7 +26,7 @@ def default_filter_params
term: params[:term],
with_resource_type: nil,
with_space_state: nil,
decidim_scope_id_eq: nil
decidim_scope_id_in: nil
}
end

Expand Down
4 changes: 3 additions & 1 deletion decidim-core/app/views/decidim/searches/_filters.html.erb
Expand Up @@ -12,8 +12,10 @@
<%= render partial: "resources_filter_block", locals: { sections: @sections, types: Decidim::Searchable.searchable_resources_of_type_comment } %>
<div class="card card--secondary">
<%= filter_form_for filter do |form| %>
<%= scopes_picker_filter form, :decidim_scope_id_eq %>
<%= scopes_picker_filter form, :decidim_scope_id_in %>
<%= form.hidden_field :term %>
<%= form.hidden_field :with_space_state %>
<%= form.hidden_field :with_resource_type %>
andreslucena marked this conversation as resolved.
Show resolved Hide resolved
<% end %>
</div>
<div class="row collapse order-by">
Expand Down
4 changes: 2 additions & 2 deletions decidim-core/spec/commands/decidim/search_spec.rb
Expand Up @@ -283,7 +283,7 @@

context "when scope is setted" do
it "only return resources in the given scope" do
described_class.call(term, current_organization, "decidim_scope_id_eq" => scope.id.to_s) do
described_class.call(term, current_organization, "decidim_scope_id_in" => [scope.id.to_s]) do
on(:ok) do |results_by_type|
results = results_by_type["Decidim::DummyResources::DummyResource"]
expect(results[:count]).to eq 1
Expand All @@ -296,7 +296,7 @@

context "when scope is blank" do
it "does not apply scope filter" do
described_class.call(term, current_organization, "decidim_scope_id_eq" => "") do
described_class.call(term, current_organization, "decidim_scope_id_in" => nil) do
on(:ok) do |results_by_type|
results = results_by_type["Decidim::DummyResources::DummyResource"]
expect(results[:results]).not_to be_empty
Expand Down
Expand Up @@ -61,9 +61,9 @@ module Decidim
before { allow(Decidim::Search).to receive(:call) }

it "takes the scope filter into account" do
expect(Decidim::Search).to receive(:call).with(any_args, hash_including(decidim_scope_id_eq: scope_id), a_kind_of(Hash))
expect(Decidim::Search).to receive(:call).with(any_args, hash_including(decidim_scope_id_in: [scope_id]), a_kind_of(Hash))

get :index, params: { term: "Blues", "filter[decidim_scope_id_eq]" => scope_id }
get :index, params: { term: "Blues", "filter[decidim_scope_id_in]" => [scope_id] }
end
end

Expand Down