diff --git a/CHANGELOG.md b/CHANGELOG.md index 194d812b8..fc3170b42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index 67b7661b8..2c571f4e6 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -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' @@ -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