Skip to content

Commit

Permalink
Ensure #remove_constraint_url parameter is a ActionController::Parame…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
cbeer committed Aug 15, 2016
1 parent fa10313 commit 0c87ce6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/helpers/blacklight/render_constraints_helper_behavior.rb
Expand Up @@ -50,6 +50,11 @@ def render_constraints_query(localized_params = params)
# @return [String]
def remove_constraint_url(localized_params)
scope = localized_params.delete(:route_set) || self

unless localized_params.is_a? ActionController::Parameters
localized_params = ActionController::Parameters.new(localized_params)
end

options = localized_params.merge(q: nil, action: 'index')
options.permit!
scope.url_for(options)
Expand Down
8 changes: 8 additions & 0 deletions spec/helpers/render_constraints_helper_spec.rb
Expand Up @@ -25,6 +25,14 @@
expect(subject).to have_selector "a[href='/?f%5Btype%5D=journal']"
end

context 'with an ordinary hash' do
let(:params) { { q: 'foobar', f: { type: 'journal' } } }

it "has a link relative to the current url" do
expect(subject).to have_selector "a[href='/?f%5Btype%5D=journal']"
end
end

context "with a route_set" do
let(:params) { ActionController::Parameters.new(q: 'foobar', f: { type: 'journal' }, route_set: my_engine) }
it "accepts an optional route set" do
Expand Down

0 comments on commit 0c87ce6

Please sign in to comment.