Merge pull request #449 from joeyates/master
Allow attributes containing `and` or `or` by checking exact matches before splitting.
This commit is contained in:
commit
397b581dad
|
@ -127,6 +127,7 @@ module Ransack
|
|||
|
||||
def attribute_method?(name)
|
||||
name = strip_predicate_and_index(name)
|
||||
return true if @context.attribute_method?(name)
|
||||
case name
|
||||
when /^(g|c|m|groupings|conditions|combinator)=?$/
|
||||
true
|
||||
|
|
|
@ -7,7 +7,29 @@ module Ransack
|
|||
@g = 1
|
||||
end
|
||||
|
||||
let(:context) { Context.for(Person) }
|
||||
|
||||
subject { described_class.new(context) }
|
||||
|
||||
describe '#attribute_method?' do
|
||||
context 'for attributes of the context' do
|
||||
it 'is true' do
|
||||
expect(subject.attribute_method?('name')).to be_true
|
||||
end
|
||||
|
||||
context "where the attribute contains '_and_'" do
|
||||
it 'is true' do
|
||||
expect(subject.attribute_method?('terms_and_conditions')).to be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'for unknown attributes' do
|
||||
it 'is false' do
|
||||
expect(subject.attribute_method?('not_an_attribute')).to be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -135,6 +135,7 @@ module Schema
|
|||
t.string :only_admin
|
||||
t.integer :salary
|
||||
t.boolean :awesome, default: false
|
||||
t.boolean :terms_and_conditions, default: false
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue