From d2aa40c2c6654dad6646fcf0726c6c89d2ae3b40 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 13 Sep 2017 14:16:50 -0500 Subject: [PATCH] Fix links that have been improperly cast to hashes. Fixes #1784 --- .rubocop_todo.yml | 1 + lib/blacklight/search_state.rb | 10 +++++++++- spec/lib/blacklight/search_state_spec.rb | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7a40e3a023..097e231eb4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,6 +37,7 @@ Metrics/ClassLength: Exclude: - 'lib/blacklight/configuration.rb' - 'lib/blacklight/search_builder.rb' + - 'lib/blacklight/search_state.rb' # Offense count: 20 Metrics/CyclomaticComplexity: diff --git a/lib/blacklight/search_state.rb b/lib/blacklight/search_state.rb index 892b7f15f9..93a79cdb53 100644 --- a/lib/blacklight/search_state.rb +++ b/lib/blacklight/search_state.rb @@ -114,7 +114,15 @@ def remove_facet_params(field, item) # from the session will get remove in the show view... p[:f] = (p[:f] || {}).dup p[:f][url_field] = (p[:f][url_field] || []).dup - p[:f][url_field] = p[:f][url_field] - [value] + + collection = p[:f][url_field] + # collection should be an array, because we link to ?f[key][]=value, + # however, Facebook (and maybe some other PHP tools) tranform that parameters + # into ?f[key][0]=value, which Rails interprets as a Hash. + if collection.is_a? Hash + collection = collection.values + end + p[:f][url_field] = collection - [value] p[:f].delete(url_field) if p[:f][url_field].empty? p.delete(:f) if p[:f].empty? p diff --git a/spec/lib/blacklight/search_state_spec.rb b/spec/lib/blacklight/search_state_spec.rb index ee09955023..da37dbc797 100644 --- a/spec/lib/blacklight/search_state_spec.rb +++ b/spec/lib/blacklight/search_state_spec.rb @@ -266,6 +266,17 @@ end end + context "when the facet_params is a HWIA" do + let(:facet_values) { { '0' => 'some_value', '1' => 'another_value' }.with_indifferent_access } + let(:facet_params) { { 'some_field' => facet_values } } + + it "removes the facet / value tuple from the query parameters" do + params = search_state.remove_facet_params('some_field', 'some_value') + expect(params[:f]['some_field']).not_to include 'some_value' + expect(params[:f]['some_field']).to include 'another_value' + end + end + context "when the facet has configuration" do before do allow(search_state).to receive(:facet_configuration_for_field).with('some_field').and_return(