Permalink
Browse files

Don't let _ be contained in polymorphic class. Fixes #12

  • Loading branch information...
1 parent 119d470 commit c156fa4a7ac6e1a8d730791c49bf4403aa0f3af7 @ernie ernie committed Aug 4, 2011
@@ -135,7 +135,7 @@ def build_or_find_association(name, parent = @base, klass = nil)
found_association = @join_dependency.join_associations.detect do |assoc|
assoc.reflection.name == name &&
assoc.parent == parent &&
- (!klass || assoc.klass == klass)
+ (!klass || assoc.reflection.klass == klass)
end
unless found_association
@join_dependency.send(:build_polymorphic, name.to_sym, parent, Arel::Nodes::OuterJoin, klass)
@@ -140,7 +140,7 @@ def build_or_find_association(name, parent = @base, klass = nil)
found_association = @join_dependency.join_associations.detect do |assoc|
assoc.reflection.name == name &&
assoc.parent == parent &&
- (!klass || assoc.klass == klass)
+ (!klass || assoc.reflection.klass == klass)
end
unless found_association
@join_dependency.send(:build_polymorphic, name.to_sym, parent, Arel::Nodes::OuterJoin, klass)
@@ -95,7 +95,7 @@ def association_path(str, base = @base)
end
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)]
else
[str, nil]
@@ -31,6 +31,16 @@ module Ransack
condition.value.should eq 'Ernie'
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
search = Search.new(Person, :children_name_eq => '')
condition = search.base[:children_name_eq]

0 comments on commit c156fa4

Please sign in to comment.