Skip to content

Commit

Permalink
Fix links that have been improperly cast to hashes.
Browse files Browse the repository at this point in the history
Fixes #1784
  • Loading branch information
jcoyne committed Sep 13, 2017
1 parent da11007 commit d2aa40c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion lib/blacklight/search_state.rb
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/blacklight/search_state_spec.rb
Expand Up @@ -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(
Expand Down

0 comments on commit d2aa40c

Please sign in to comment.