Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

laxy split on polymorphic association names

  • Loading branch information...
commit 20f9a1c705ef68ddcc591ae0aec10b5265d21b06 1 parent 18e24e7
@binarylogic authored
View
2  lib/searchlogic/named_scopes/association_conditions.rb
@@ -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
View
7 spec/named_scopes/association_conditions_spec.rb
@@ -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
1  spec/spec_helper.rb
@@ -41,6 +41,7 @@
t.string :name
t.integer :age
t.boolean :male
+ t.string :some_type_id
end
create_table :carts do |t|
Please sign in to comment.
Something went wrong with that request. Please try again.