Don't let _ be contained in polymorphic class. Fixes #12
This commit is contained in:
parent
119d470304
commit
c156fa4a7a
|
@ -135,7 +135,7 @@ module Ransack
|
||||||
found_association = @join_dependency.join_associations.detect do |assoc|
|
found_association = @join_dependency.join_associations.detect do |assoc|
|
||||||
assoc.reflection.name == name &&
|
assoc.reflection.name == name &&
|
||||||
assoc.parent == parent &&
|
assoc.parent == parent &&
|
||||||
(!klass || assoc.klass == klass)
|
(!klass || assoc.reflection.klass == klass)
|
||||||
end
|
end
|
||||||
unless found_association
|
unless found_association
|
||||||
@join_dependency.send(:build_polymorphic, name.to_sym, parent, Arel::Nodes::OuterJoin, klass)
|
@join_dependency.send(:build_polymorphic, name.to_sym, parent, Arel::Nodes::OuterJoin, klass)
|
||||||
|
|
|
@ -140,7 +140,7 @@ module Ransack
|
||||||
found_association = @join_dependency.join_associations.detect do |assoc|
|
found_association = @join_dependency.join_associations.detect do |assoc|
|
||||||
assoc.reflection.name == name &&
|
assoc.reflection.name == name &&
|
||||||
assoc.parent == parent &&
|
assoc.parent == parent &&
|
||||||
(!klass || assoc.klass == klass)
|
(!klass || assoc.reflection.klass == klass)
|
||||||
end
|
end
|
||||||
unless found_association
|
unless found_association
|
||||||
@join_dependency.send(:build_polymorphic, name.to_sym, parent, Arel::Nodes::OuterJoin, klass)
|
@join_dependency.send(:build_polymorphic, name.to_sym, parent, Arel::Nodes::OuterJoin, klass)
|
||||||
|
|
|
@ -95,7 +95,7 @@ module Ransack
|
||||||
end
|
end
|
||||||
|
|
||||||
def unpolymorphize_association(str)
|
def unpolymorphize_association(str)
|
||||||
if (match = str.match(/_of_(.+?)_type$/))
|
if (match = str.match(/_of_([^_]+?)_type$/))
|
||||||
[match.pre_match, Kernel.const_get(match.captures.first)]
|
[match.pre_match, Kernel.const_get(match.captures.first)]
|
||||||
else
|
else
|
||||||
[str, nil]
|
[str, nil]
|
||||||
|
|
|
@ -31,6 +31,16 @@ module Ransack
|
||||||
condition.value.should eq 'Ernie'
|
condition.value.should eq 'Ernie'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates Conditions for multiple polymorphic belongs_to association attributes' do
|
||||||
|
search = Search.new(Note, :notable_of_Person_type_name_or_notable_of_Article_type_title_eq => 'Ernie')
|
||||||
|
condition = search.base[:notable_of_Person_type_name_or_notable_of_Article_type_title_eq]
|
||||||
|
condition.should be_a Nodes::Condition
|
||||||
|
condition.predicate.name.should eq 'eq'
|
||||||
|
condition.attributes.first.name.should eq 'notable_of_Person_type_name'
|
||||||
|
condition.attributes.last.name.should eq 'notable_of_Article_type_title'
|
||||||
|
condition.value.should eq 'Ernie'
|
||||||
|
end
|
||||||
|
|
||||||
it 'discards empty conditions' do
|
it 'discards empty conditions' do
|
||||||
search = Search.new(Person, :children_name_eq => '')
|
search = Search.new(Person, :children_name_eq => '')
|
||||||
condition = search.base[:children_name_eq]
|
condition = search.base[:children_name_eq]
|
||||||
|
|
Loading…
Reference in New Issue