Skip to content

Commit

Permalink
Add test for AC:Parameter object params in sort_link
Browse files Browse the repository at this point in the history
Follow-up to PR #644 by @ryanswood.

Closes #644.
  • Loading branch information
jonatack committed Mar 15, 2016
1 parent 3a3cb8a commit b1cfed8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@

*Josh Hunter*, *Jon Atack*

* Add test for ActionController:Parameter object params in sort_link to ensure
Ransack is handling the Rails 5 changes correctly. Follow-up to
[#644](https://github.com/activerecord-hackery/ransack/pull/644).

*Ryan Wood*

* Add failing tests to facilitate work on issue
[#566](https://github.com/activerecord-hackery/ransack/issues/566)
of passing boolean values to search scopes. PR
Expand Down
36 changes: 31 additions & 5 deletions spec/ransack/helpers/form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,13 @@ module Helpers
end

context 'view has existing parameters' do
before do
@controller.view_context.params[:exist] = 'existing'
end

describe '#sort_link should not remove existing params' do
subject { @controller.view_context
.sort_link(

before { @controller.view_context.params[:exist] = 'existing' }

subject {
@controller.view_context.sort_link(
Person.search(
{ sorts: ['name desc'] },
search_key: 'people_search'
Expand All @@ -324,8 +325,33 @@ module Helpers
controller: 'people'
)
}

it { should match /exist\=existing/ }
end

context 'using real ActionController Parameter object',
if: ::ActiveRecord::VERSION::MAJOR > 4 do

describe '#sort_link should include search params' do

subject { @controller.view_context.sort_link(Person.search, :name) }

let(:params) {
ActionController::Parameters
.new({ 'q' => { name_eq: 'TEST' }, controller: 'people' })
}

before { @controller.instance_variable_set(:@params, params) }

it {
should match(
/people\?q(%5B|\[)name_eq(%5D|\])=TEST&q(%5B|\[)s(%5D|\])
=name\+asc/x,
)
}
end

end
end

describe '#sort_link with hide order indicator set to true' do
Expand Down

0 comments on commit b1cfed8

Please sign in to comment.