searchlogic 2.1.9 → 2.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc
CHANGED
data/VERSION.yml
CHANGED
@@ -49,11 +49,10 @@ module Searchlogic
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def association_condition_details(name)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
assocs = non_polymorphic_associations
|
53
|
+
return nil if assocs.empty?
|
54
|
+
regexes = [association_searchlogic_regex(assocs, Conditions::PRIMARY_CONDITIONS)]
|
55
|
+
assocs.each { |assoc| regexes << /^(#{assoc.name})_(#{assoc.klass.scopes.keys.join("|")})$/ }
|
57
56
|
|
58
57
|
if !local_condition?(name) && regexes.any? { |regex| name.to_s =~ regex }
|
59
58
|
{:association => $1, :column => $2, :condition => $3}
|
@@ -67,12 +66,19 @@ module Searchlogic
|
|
67
66
|
end
|
68
67
|
|
69
68
|
def association_alias_condition_details(name)
|
70
|
-
|
71
|
-
if !local_condition?(name) && name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::ALIAS_CONDITIONS.join("|")})$/
|
69
|
+
if !local_condition?(name) && name.to_s =~ association_searchlogic_regex(non_polymorphic_associations, Conditions::ALIAS_CONDITIONS)
|
72
70
|
{:association => $1, :column => $2, :condition => $3}
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
74
|
+
def non_polymorphic_associations
|
75
|
+
reflect_on_all_associations.reject { |assoc| assoc.options[:polymorphic] }
|
76
|
+
end
|
77
|
+
|
78
|
+
def association_searchlogic_regex(assocs, condition_names)
|
79
|
+
/^(#{assocs.collect(&:name).join("|")})_(\w+)_(#{condition_names.join("|")})$/
|
80
|
+
end
|
81
|
+
|
76
82
|
def create_association_alias_condition(association, column, condition, args)
|
77
83
|
primary_condition = primary_condition(condition)
|
78
84
|
alias_name = "#{association}_#{column}_#{condition}"
|
data/searchlogic.gemspec
CHANGED
@@ -13,6 +13,10 @@ describe "Association Conditions" do
|
|
13
13
|
Company.users_uname("bjohnson").proxy_options.should == User.uname("bjohnson").proxy_options.merge(:joins => :users)
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should ignore polymorphic associations" do
|
17
|
+
lambda { Fee.owner_created_at_gt(Time.now) }.should raise_error(NoMethodError)
|
18
|
+
end
|
19
|
+
|
16
20
|
it "should not allow named scopes on non existent association columns" do
|
17
21
|
lambda { User.users_whatever_like("bjohnson") }.should raise_error(NoMethodError)
|
18
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -27,6 +27,12 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
27
27
|
t.integer :age
|
28
28
|
end
|
29
29
|
|
30
|
+
create_table :carts do |t|
|
31
|
+
t.datetime :created_at
|
32
|
+
t.datetime :updated_at
|
33
|
+
t.integer :user_id
|
34
|
+
end
|
35
|
+
|
30
36
|
create_table :orders do |t|
|
31
37
|
t.datetime :created_at
|
32
38
|
t.datetime :updated_at
|
@@ -36,6 +42,14 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
36
42
|
t.float :total
|
37
43
|
end
|
38
44
|
|
45
|
+
create_table :fees do |t|
|
46
|
+
t.datetime :created_at
|
47
|
+
t.datetime :updated_at
|
48
|
+
t.string :owner_type
|
49
|
+
t.integer :owner_id
|
50
|
+
t.float :cost
|
51
|
+
end
|
52
|
+
|
39
53
|
create_table :line_items do |t|
|
40
54
|
t.datetime :created_at
|
41
55
|
t.datetime :updated_at
|
@@ -66,6 +80,10 @@ Spec::Runner.configure do |config|
|
|
66
80
|
has_many :line_items, :dependent => :destroy
|
67
81
|
end
|
68
82
|
|
83
|
+
class Fee < ActiveRecord::Base
|
84
|
+
belongs_to :owner, :polymorphic => true
|
85
|
+
end
|
86
|
+
|
69
87
|
class LineItem < ActiveRecord::Base
|
70
88
|
belongs_to :order
|
71
89
|
end
|