Permalink
Browse files

laxy split on polymorphic association names

  • Loading branch information...
1 parent 18e24e7 commit 20f9a1c705ef68ddcc591ae0aec10b5265d21b06 @binarylogic committed Feb 11, 2010
@@ -34,7 +34,7 @@ def association_condition_details(name, last_condition = nil)
if name_with_condition.to_s =~ /^(#{non_poly_assocs.collect(&:name).join("|")})_(\w+)$/
association_name = $1
condition = $2
- elsif name_with_condition.to_s =~ /^(#{poly_assocs.collect(&:name).join("|")})_(\w+)_type_(\w+)$/
+ elsif name_with_condition.to_s =~ /^(#{poly_assocs.collect(&:name).join("|")})_(\w+?)_type_(\w+)$/
association_name = $1
poly_type = $2
condition = $3
@@ -172,6 +172,13 @@
}
end
+ it "should delegate to polymorphic relationships (with a lazy split on _type_)" do
+ Audit.auditable_user_type_some_type_id_like("ben").proxy_options.should == {
+ :conditions => ["users.some_type_id LIKE ?", "%ben%"],
+ :joins => "INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'"
+ }
+ end
+
it "should deep delegate to polymorphic relationships" do
Audit.auditable_user_type_company_name_like("company").proxy_options.should == {
:conditions => ["companies.name LIKE ?", "%company%"],
View
@@ -41,6 +41,7 @@
t.string :name
t.integer :age
t.boolean :male
+ t.string :some_type_id
end
create_table :carts do |t|

0 comments on commit 20f9a1c

Please sign in to comment.