Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ransack control params (:m, :s) mangled by translator into :m_, :s_ #659

Open
wants to merge 1 commit into
base: 3-0-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/spree_i18n/ransack_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def translated_params
private

def key_with_translations(key)
return key if key.to_s == 's'
names, pred = split_key key
translated_names = translate_names(names)
join_key translated_names, pred
Expand All @@ -31,7 +30,7 @@ def split_key(key)

def join_key(names, pred)
key = names.join('_or_')
key += "_#{pred}" unless pred == ''
key += "_#{pred}" unless pred.blank?
key
end

Expand Down
13 changes: 13 additions & 0 deletions spec/models/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ module Spree
expect(result.to_a).to match_array [product, other_product]
end

context 'ransacking by taxonomy' do
let(:product_with_taxon) { create(:product, name: 'product-with-taxon') }
let(:sack_params) { {m: 'or', name_cont: product.name, taxons_name_cont: product.name} }
before do
Spree::Product.whitelisted_ransackable_associations.push('taxons')
product_with_taxon.taxons << create(:taxon, name: product.name)
end
it 'handles ransack with and/or grouping parameter safely' do
result = described_class.ransack(sack_params).result
expect(result.to_a).to match_array [product, product_with_taxon]
end
end

it 'handles ransack with an invalid key safely' do
result = described_class.ransack(foo: 'blub').result
expect(result.to_a).to match_array [product, other_product]
Expand Down