searchlogic 2.4.28 → 2.4.29

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source :rubygems
2
+
3
+ gem 'jeweler'
4
+
5
+ gem 'activerecord', '2.3.11'
6
+
7
+ group :test do
8
+ gem 'ruby-debug19'
9
+ gem 'rspec', '1.3.1'
10
+ gem 'sqlite3'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activerecord (2.3.11)
5
+ activesupport (= 2.3.11)
6
+ activesupport (2.3.11)
7
+ archive-tar-minitar (0.5.2)
8
+ columnize (0.3.2)
9
+ git (1.2.5)
10
+ jeweler (1.5.2)
11
+ bundler (~> 1.0.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ linecache19 (0.5.11)
15
+ ruby_core_source (>= 0.1.4)
16
+ rake (0.8.7)
17
+ rspec (1.3.1)
18
+ ruby-debug-base19 (0.11.24)
19
+ columnize (>= 0.3.1)
20
+ linecache19 (>= 0.5.11)
21
+ ruby_core_source (>= 0.1.4)
22
+ ruby-debug19 (0.11.6)
23
+ columnize (>= 0.3.1)
24
+ linecache19 (>= 0.5.11)
25
+ ruby-debug-base19 (>= 0.11.19)
26
+ ruby_core_source (0.1.4)
27
+ archive-tar-minitar (>= 0.5.2)
28
+ sqlite3 (1.3.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ activerecord (= 2.3.11)
35
+ jeweler
36
+ rspec (= 1.3.1)
37
+ ruby-debug19
38
+ sqlite3
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'bundler'
4
+
5
+ Bundler.setup
3
6
 
4
7
  begin
5
8
  require 'jeweler'
@@ -10,7 +13,7 @@ begin
10
13
  gem.email = "bjohnson@binarylogic.com"
11
14
  gem.homepage = "http://github.com/binarylogic/searchlogic"
12
15
  gem.authors = ["Ben Johnson of Binary Logic"]
13
- gem.add_dependency "activerecord", ">= 2.0.0"
16
+ gem.add_bundler_dependencies
14
17
  end
15
18
  Jeweler::GemcutterTasks.new
16
19
  rescue LoadError
@@ -29,6 +32,4 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
32
  spec.rcov = true
30
33
  end
31
34
 
32
- task :spec => :check_dependencies
33
-
34
35
  task :default => :spec
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 4
4
- :patch: 28
4
+ :patch: 29
5
5
  :build:
@@ -8,11 +8,12 @@ module Searchlogic
8
8
  end
9
9
 
10
10
  def send_with_searchlogic(method, *args)
11
+ # create the scope if it doesn't exist yet, then delegate back to the original method
11
12
  if !proxy_respond_to?(method) && proxy_reflection.macro != :belongs_to && !proxy_reflection.options[:polymorphic] && proxy_reflection.klass.condition?(method)
12
13
  proxy_reflection.klass.send(method, *args)
13
- else
14
- send_without_searchlogic(method, *args)
15
14
  end
15
+
16
+ send_without_searchlogic(method, *args)
16
17
  end
17
18
  end
18
19
  end
@@ -5,12 +5,12 @@ module Searchlogic
5
5
  def condition?(name) # :nodoc:
6
6
  super || association_condition?(name)
7
7
  end
8
-
8
+
9
9
  private
10
10
  def association_condition?(name)
11
11
  !association_condition_details(name).nil? unless name.to_s.downcase.match("_or_")
12
12
  end
13
-
13
+
14
14
  def method_missing(name, *args, &block)
15
15
  if !local_condition?(name) && details = association_condition_details(name)
16
16
  create_association_condition(details[:association], details[:condition], args, details[:poly_class])
@@ -19,18 +19,18 @@ module Searchlogic
19
19
  super
20
20
  end
21
21
  end
22
-
22
+
23
23
  def association_condition_details(name, last_condition = nil)
24
24
  non_poly_assocs = reflect_on_all_associations.reject { |assoc| assoc.options[:polymorphic] }.sort { |a, b| b.name.to_s.size <=> a.name.to_s.size }
25
25
  poly_assocs = reflect_on_all_associations.reject { |assoc| !assoc.options[:polymorphic] }.sort { |a, b| b.name.to_s.size <=> a.name.to_s.size }
26
26
  return nil if non_poly_assocs.empty? && poly_assocs.empty?
27
-
27
+
28
28
  name_with_condition = [name, last_condition].compact.join('_')
29
-
29
+
30
30
  association_name = nil
31
31
  poly_type = nil
32
32
  condition = nil
33
-
33
+
34
34
  if name_with_condition.to_s =~ /^(#{non_poly_assocs.collect(&:name).join("|")})_(\w+)$/
35
35
  association_name = $1
36
36
  condition = $2
@@ -39,7 +39,7 @@ module Searchlogic
39
39
  poly_type = $2
40
40
  condition = $3
41
41
  end
42
-
42
+
43
43
  if association_name && condition
44
44
  association = reflect_on_association(association_name.to_sym)
45
45
  klass = poly_type ? poly_type.camelcase.constantize : association.klass
@@ -50,18 +50,18 @@ module Searchlogic
50
50
  end
51
51
  end
52
52
  end
53
-
53
+
54
54
  def create_association_condition(association, condition_name, args, poly_class = nil)
55
55
  name = [association.name, poly_class && "#{poly_class.name.underscore}_type", condition_name].compact.join("_")
56
56
  named_scope(name, association_condition_options(association, condition_name, args, poly_class))
57
57
  end
58
-
58
+
59
59
  def association_condition_options(association, association_condition, args, poly_class = nil)
60
60
  klass = poly_class ? poly_class : association.klass
61
61
  scope = klass.send(association_condition, *args)
62
62
  scope_options = klass.named_scope_options(association_condition)
63
63
  arity = klass.named_scope_arity(association_condition)
64
-
64
+
65
65
  if !arity || arity == 0
66
66
  # The underlying condition doesn't require any parameters, so let's just create a simple
67
67
  # named scope that is based on a hash.
@@ -73,24 +73,24 @@ module Searchlogic
73
73
  proc_args = arity_args(arity)
74
74
  scope_options = scope_options.respond_to?(:searchlogic_options) ? scope_options.searchlogic_options.clone : {}
75
75
  arg_type = scope_options.delete(:type) || :string
76
-
76
+
77
77
  eval <<-"end_eval"
78
78
  searchlogic_lambda(:#{arg_type}, #{scope_options.inspect}) { |#{proc_args.join(",")}|
79
79
  options = {}
80
-
80
+
81
81
  in_searchlogic_delegation do
82
82
  scope = klass.send(association_condition, #{proc_args.join(",")})
83
83
  options = scope.scope(:find) if scope
84
84
  end
85
-
86
-
85
+
86
+
87
87
  prepare_named_scope_options(options, association, poly_class)
88
88
  options
89
89
  }
90
90
  end_eval
91
91
  end
92
92
  end
93
-
93
+
94
94
  # Used to match the new scopes parameters to the underlying scope. This way we can disguise the
95
95
  # new scope as best as possible instead of taking the easy way out and using *args.
96
96
  def arity_args(arity)
@@ -109,16 +109,16 @@ module Searchlogic
109
109
  end
110
110
  args
111
111
  end
112
-
112
+
113
113
  def prepare_named_scope_options(options, association, poly_class = nil)
114
114
  options.delete(:readonly) # AR likes to set :readonly to true when using the :joins option, we don't want that
115
-
115
+
116
116
  klass = poly_class || association.klass
117
117
  # sanitize the conditions locally so we get the right table name, otherwise the conditions will be evaluated on the original model
118
118
  options[:conditions] = klass.sanitize_sql_for_conditions(options[:conditions]) if options[:conditions].is_a?(Hash)
119
-
119
+
120
120
  poly_join = poly_class && inner_polymorphic_join(poly_class.name.underscore, :as => association.name)
121
-
121
+
122
122
  if options[:joins].is_a?(String) || array_of_strings?(options[:joins])
123
123
  options[:joins] = [poly_class ? poly_join : inner_joins(association.name), options[:joins]].flatten
124
124
  elsif poly_class
@@ -37,7 +37,14 @@ module Searchlogic
37
37
  end
38
38
 
39
39
  def create_association_ordering_condition(association, order_as, condition, args)
40
- named_scope("#{order_as}_by_#{association.name}_#{condition}", association_condition_options(association, "#{order_as}_by_#{condition}", args))
40
+ cond = condition
41
+ poly_class = nil
42
+ if condition =~ /^(\w+)_type_(\w+)$/
43
+ poly_type = $1
44
+ cond = $2
45
+ poly_class = poly_type.camelcase.constantize if poly_type
46
+ end
47
+ named_scope("#{order_as}_by_#{association.name}_#{condition}", association_condition_options(association, "#{order_as}_by_#{cond}", args, poly_class))
41
48
  end
42
49
  end
43
50
  end
@@ -82,7 +82,6 @@ module Searchlogic
82
82
  end
83
83
  end
84
84
 
85
-
86
85
  def condition_details(method_name)
87
86
  column_name_matcher = column_names.join("|")
88
87
  conditions_matcher = (PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")
data/searchlogic.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{searchlogic}
8
- s.version = "2.4.28"
8
+ s.version = "2.4.29"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Johnson of Binary Logic"]
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
20
22
  "LICENSE",
21
23
  "README.rdoc",
22
24
  "Rakefile",
@@ -83,12 +85,21 @@ Gem::Specification.new do |s|
83
85
  s.specification_version = 3
84
86
 
85
87
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
86
- s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
88
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
89
+ s.add_runtime_dependency(%q<activerecord>, ["= 2.3.11"])
90
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
91
+ s.add_runtime_dependency(%q<activerecord>, ["= 2.3.11"])
87
92
  else
88
- s.add_dependency(%q<activerecord>, [">= 2.0.0"])
93
+ s.add_dependency(%q<jeweler>, [">= 0"])
94
+ s.add_dependency(%q<activerecord>, ["= 2.3.11"])
95
+ s.add_dependency(%q<jeweler>, [">= 0"])
96
+ s.add_dependency(%q<activerecord>, ["= 2.3.11"])
89
97
  end
90
98
  else
91
- s.add_dependency(%q<activerecord>, [">= 2.0.0"])
99
+ s.add_dependency(%q<jeweler>, [">= 0"])
100
+ s.add_dependency(%q<activerecord>, ["= 2.3.11"])
101
+ s.add_dependency(%q<jeweler>, [">= 0"])
102
+ s.add_dependency(%q<activerecord>, ["= 2.3.11"])
92
103
  end
93
104
  end
94
105
 
@@ -6,19 +6,19 @@ describe "Searchlogic::ActiveRecord::AssociationProxy" do
6
6
  user = company.users.create(:username => "bjohnson")
7
7
  company.users.send(:username_like, "bjohnson").should == [user]
8
8
  end
9
-
9
+
10
10
  it "should call ordering conditions" do
11
11
  company = Company.create
12
12
  user = company.users.create(:username => "bjohnson")
13
13
  company.users.send(:ascend_by_username).should == [user]
14
14
  end
15
-
15
+
16
16
  it "should call 'or' conditions" do
17
17
  company = Company.create
18
18
  user = company.users.create(:username => "bjohnson")
19
19
  company.users.send(:username_or_some_type_id_like, "bjohnson").should == [user]
20
20
  end
21
-
21
+
22
22
  it "should ignore belongs_to associations" do
23
23
  user = User.create(:male => true)
24
24
  cart = user.carts.create
@@ -4,82 +4,82 @@ describe Searchlogic::NamedScopes::AssociationConditions do
4
4
  it "should create a named scope" do
5
5
  Company.users_username_like("bjohnson").proxy_options.should == User.username_like("bjohnson").proxy_options.merge(:joins => :users)
6
6
  end
7
-
7
+
8
8
  it "should create a deep named scope" do
9
9
  Company.users_orders_total_greater_than(10).proxy_options.should == Order.total_greater_than(10).proxy_options.merge(:joins => {:users => :orders})
10
10
  end
11
-
11
+
12
12
  it "should allow the use of foreign pre-existing named scopes" do
13
13
  User.named_scope :uname, lambda { |value| {:conditions => ["users.username = ?", value]} }
14
14
  Company.users_uname("bjohnson").proxy_options.should == User.uname("bjohnson").proxy_options.merge(:joins => :users)
15
15
  end
16
-
16
+
17
17
  it "should allow the use of deep foreign pre-existing named scopes" do
18
18
  pending
19
19
  Order.named_scope :big_id, :conditions => "orders.id > 100"
20
20
  Company.users_orders_big_id.proxy_options.should == Order.big_id.proxy_options.merge(:joins => {:users => :orders})
21
21
  end
22
-
22
+
23
23
  it "should allow the use of foreign pre-existing alias scopes" do
24
24
  User.alias_scope :username_has, lambda { |value| User.username_like(value) }
25
25
  Company.users_username_has("bjohnson").proxy_options.should == User.username_has("bjohnson").proxy_options.merge(:joins => :users)
26
26
  end
27
-
27
+
28
28
  it "should not raise errors for scopes that don't return anything" do
29
29
  User.alias_scope :blank_scope, lambda { |value| }
30
30
  Company.users_blank_scope("bjohnson").proxy_options.should == {:joins => :users}
31
31
  end
32
-
32
+
33
33
  it "should ignore polymorphic associations" do
34
34
  lambda { Fee.owner_created_at_gt(Time.now) }.should raise_error(NoMethodError)
35
35
  end
36
-
36
+
37
37
  it "should not allow named scopes on non existent association columns" do
38
38
  lambda { User.users_whatever_like("bjohnson") }.should raise_error(NoMethodError)
39
39
  end
40
-
40
+
41
41
  it "should not allow named scopes on non existent deep association columns" do
42
42
  lambda { User.users_orders_whatever_like("bjohnson") }.should raise_error(NoMethodError)
43
43
  end
44
-
44
+
45
45
  it "should allow named scopes to be called multiple times and reflect the value passed" do
46
46
  Company.users_username_like("bjohnson").proxy_options.should == User.username_like("bjohnson").proxy_options.merge(:joins => :users)
47
47
  Company.users_username_like("thunt").proxy_options.should == User.username_like("thunt").proxy_options.merge(:joins => :users)
48
48
  end
49
-
49
+
50
50
  it "should allow deep named scopes to be called multiple times and reflect the value passed" do
51
51
  Company.users_orders_total_greater_than(10).proxy_options.should == Order.total_greater_than(10).proxy_options.merge(:joins => {:users => :orders})
52
52
  Company.users_orders_total_greater_than(20).proxy_options.should == Order.total_greater_than(20).proxy_options.merge(:joins => {:users => :orders})
53
53
  end
54
-
54
+
55
55
  it "should have an arity of 1 if the underlying scope has an arity of 1" do
56
56
  Company.users_orders_total_greater_than(10)
57
57
  Company.named_scope_arity("users_orders_total_greater_than").should == Order.named_scope_arity("total_greater_than")
58
58
  end
59
-
59
+
60
60
  it "should have an arity of nil if the underlying scope has an arity of nil" do
61
61
  Company.users_orders_total_null
62
62
  Company.named_scope_arity("users_orders_total_null").should == Order.named_scope_arity("total_null")
63
63
  end
64
-
64
+
65
65
  it "should have an arity of -1 if the underlying scope has an arity of -1" do
66
66
  Company.users_id_equals_any
67
67
  Company.named_scope_arity("users_id_equals_any").should == User.named_scope_arity("id_equals_any")
68
68
  end
69
-
69
+
70
70
  it "should allow aliases" do
71
71
  Company.users_username_contains("bjohnson").proxy_options.should == User.username_contains("bjohnson").proxy_options.merge(:joins => :users)
72
72
  end
73
-
73
+
74
74
  it "should allow deep aliases" do
75
75
  Company.users_orders_total_gt(10).proxy_options.should == Order.total_gt(10).proxy_options.merge(:joins => {:users => :orders})
76
76
  end
77
-
77
+
78
78
  it "should copy over the named scope options" do
79
79
  Order.user_whatever_at_equals(1)
80
80
  Order.named_scope_options(:user_whatever_at_equals).searchlogic_options[:skip_conversion].should == true
81
81
  end
82
-
82
+
83
83
  it "should include optional associations" do
84
84
  pending # this is a problem with using inner joins and left outer joins
85
85
  Company.create
@@ -88,7 +88,7 @@ describe Searchlogic::NamedScopes::AssociationConditions do
88
88
  order = user.orders.create(:total => 20, :taxes => 3)
89
89
  Company.ascend_by_users_orders_total.all.should == Company.all
90
90
  end
91
-
91
+
92
92
  it "should implement exclusive scoping" do
93
93
  scope = Company.users_company_name_like("name").users_company_description_like("description")
94
94
  scope.scope(:find)[:joins].should == [
@@ -97,7 +97,7 @@ describe Searchlogic::NamedScopes::AssociationConditions do
97
97
  ]
98
98
  lambda { scope.all }.should_not raise_error
99
99
  end
100
-
100
+
101
101
  it "should not create the same join twice" do
102
102
  scope = Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total
103
103
  scope.scope(:find)[:joins].should == [
@@ -106,7 +106,7 @@ describe Searchlogic::NamedScopes::AssociationConditions do
106
106
  ]
107
107
  lambda { scope.count }.should_not raise_error
108
108
  end
109
-
109
+
110
110
  it "should not create the same join twice when traveling through the duplicate join" do
111
111
  scope = Company.users_username_like("bjohnson").users_orders_total_gt(100)
112
112
  scope.scope(:find)[:joins].should == [
@@ -115,7 +115,7 @@ describe Searchlogic::NamedScopes::AssociationConditions do
115
115
  ]
116
116
  lambda { scope.count }.should_not raise_error
117
117
  end
118
-
118
+
119
119
  it "should not create the same join twice when traveling through the deep duplicate join" do
120
120
  scope = Company.users_orders_total_gt(100).users_orders_line_items_price_gt(20)
121
121
  scope.scope(:find)[:joins].should == [
@@ -125,35 +125,35 @@ describe Searchlogic::NamedScopes::AssociationConditions do
125
125
  ]
126
126
  lambda { scope.all }.should_not raise_error
127
127
  end
128
-
128
+
129
129
  it "should allow the use of :include when a join was created" do
130
130
  company = Company.create
131
131
  user = company.users.create
132
132
  order = user.orders.create(:total => 20, :taxes => 3)
133
133
  Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => :users).should == Company.all
134
134
  end
135
-
135
+
136
136
  it "should allow the use of deep :include when a join was created" do
137
137
  company = Company.create
138
138
  user = company.users.create
139
139
  order = user.orders.create(:total => 20, :taxes => 3)
140
140
  Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => {:users => :orders}).should == Company.all
141
141
  end
142
-
142
+
143
143
  it "should allow the use of :include when traveling through the duplicate join" do
144
144
  company = Company.create
145
145
  user = company.users.create(:username => "bjohnson")
146
146
  order = user.orders.create(:total => 20, :taxes => 3)
147
147
  Company.users_username_like("bjohnson").users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => :users).should == Company.all
148
148
  end
149
-
149
+
150
150
  it "should allow the use of deep :include when traveling through the duplicate join" do
151
151
  company = Company.create
152
152
  user = company.users.create(:username => "bjohnson")
153
153
  order = user.orders.create(:total => 20, :taxes => 3)
154
154
  Company.users_orders_taxes_lt(50).ascend_by_users_orders_total.all(:include => {:users => :orders}).should == Company.all
155
155
  end
156
-
156
+
157
157
  it "should automatically add string joins if the association condition is using strings" do
158
158
  User.named_scope(:orders_big_id, :joins => User.inner_joins(:orders))
159
159
  Company.users_orders_big_id.proxy_options.should == {:joins=>[" INNER JOIN \"users\" ON users.company_id = companies.id ", " INNER JOIN \"orders\" ON orders.user_id = users.id "]}
@@ -164,40 +164,50 @@ describe Searchlogic::NamedScopes::AssociationConditions do
164
164
  user = company.users.create(:company_id => company.id)
165
165
  company.users.company_id_eq(company.id).should == [user]
166
166
  end
167
-
167
+
168
168
  it "should sanitize the scope on a foreign model instead of passing the raw options back to the original" do
169
169
  Company.named_scope(:users_count_10, :conditions => {:users_count => 10})
170
170
  User.company_users_count_10.proxy_options.should == {:conditions => "\"companies\".\"users_count\" = 10", :joins => :company}
171
171
  end
172
-
172
+
173
173
  it "should delegate to polymorphic relationships" do
174
174
  Audit.auditable_user_type_name_like("ben").proxy_options.should == {
175
175
  :conditions => ["users.name LIKE ?", "%ben%"],
176
176
  :joins => "INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'"
177
177
  }
178
178
  end
179
-
179
+
180
180
  it "should delegate to polymorphic relationships (with a lazy split on _type_)" do
181
181
  Audit.auditable_user_type_some_type_id_like("ben").proxy_options.should == {
182
182
  :conditions => ["users.some_type_id LIKE ?", "%ben%"],
183
183
  :joins => "INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'"
184
184
  }
185
185
  end
186
-
186
+
187
187
  it "should deep delegate to polymorphic relationships" do
188
188
  Audit.auditable_user_type_company_name_like("company").proxy_options.should == {
189
189
  :conditions => ["companies.name LIKE ?", "%company%"],
190
190
  :joins => ["INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'", " INNER JOIN \"companies\" ON \"companies\".id = \"users\".company_id "]
191
191
  }
192
192
  end
193
-
193
+
194
194
  it "should allow any on a has_many relationship" do
195
195
  company1 = Company.create
196
196
  user1 = company1.users.create
197
197
  company2 = Company.create
198
198
  user2 = company2.users.create
199
199
  user3 = company2.users.create
200
-
200
+
201
201
  Company.users_id_equals_any([user2.id, user3.id]).all(:select => "DISTINCT companies.*").should == [company2]
202
202
  end
203
- end
203
+
204
+ it "should allow dynamic scope generation on associations without losing association scope options" do
205
+ user = User.create
206
+ Order.create :user => user, :shipped_on => Time.now
207
+ Order.create :shipped_on => Time.now
208
+ Order.named_scope :shipped_on_not_null, :conditions => ['shipped_on is not null']
209
+ user.orders.count.should == 1
210
+ user.orders.shipped_on_not_null.shipped_on_greater_than(2.days.ago).count.should == 1
211
+ end
212
+
213
+ end
@@ -4,24 +4,31 @@ describe Searchlogic::NamedScopes::Ordering do
4
4
  it "should allow ascending" do
5
5
  Company.ascend_by_users_username.proxy_options.should == User.ascend_by_username.proxy_options.merge(:joins => :users)
6
6
  end
7
-
7
+
8
8
  it "should allow descending" do
9
9
  Company.descend_by_users_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
10
10
  end
11
-
11
+
12
12
  it "should allow deep ascending" do
13
13
  Company.ascend_by_users_orders_total.proxy_options.should == Order.ascend_by_total.proxy_options.merge(:joins => {:users => :orders})
14
14
  end
15
-
15
+
16
16
  it "should allow deep descending" do
17
17
  Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
18
18
  end
19
-
19
+
20
20
  it "should ascend with a belongs to" do
21
21
  User.ascend_by_company_name.proxy_options.should == Company.ascend_by_name.proxy_options.merge(:joins => :company)
22
22
  end
23
-
23
+
24
24
  it "should work through #order" do
25
25
  Company.order('ascend_by_users_username').proxy_options.should == Company.ascend_by_users_username.proxy_options
26
26
  end
27
- end
27
+
28
+ it "should ascend with a polymorphic belongs to" do
29
+ Audit.descend_by_auditable_user_type_username.proxy_options.should ==
30
+ User.descend_by_username.proxy_options.merge(
31
+ :joins => "INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'"
32
+ )
33
+ end
34
+ end
data/spec/spec_helper.rb CHANGED
@@ -105,6 +105,7 @@ Spec::Runner.configure do |config|
105
105
  has_many :carts, :dependent => :destroy
106
106
  has_many :orders, :dependent => :destroy
107
107
  has_many :orders_big, :class_name => 'Order', :conditions => 'total > 100'
108
+ has_many :audits, :as => :auditable
108
109
  has_and_belongs_to_many :user_groups
109
110
 
110
111
  self.skip_time_zone_conversion_for_attributes = [:whatever_at]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: searchlogic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.4.28
5
+ version: 2.4.29
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Johnson of Binary Logic
@@ -14,16 +14,49 @@ date: 2011-02-28 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: activerecord
18
- prerelease: false
17
+ name: jeweler
19
18
  requirement: &id001 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
22
21
  - - ">="
23
22
  - !ruby/object:Gem::Version
24
- version: 2.0.0
23
+ version: "0"
25
24
  type: :runtime
25
+ prerelease: false
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.11
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: jeweler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: activerecord
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.3.11
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *id004
27
60
  description: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
28
61
  email: bjohnson@binarylogic.com
29
62
  executables: []
@@ -34,6 +67,8 @@ extra_rdoc_files:
34
67
  - LICENSE
35
68
  - README.rdoc
36
69
  files:
70
+ - Gemfile
71
+ - Gemfile.lock
37
72
  - LICENSE
38
73
  - README.rdoc
39
74
  - Rakefile
@@ -90,6 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
125
  requirements:
91
126
  - - ">="
92
127
  - !ruby/object:Gem::Version
128
+ hash: -2462757578712156859
129
+ segments:
130
+ - 0
93
131
  version: "0"
94
132
  required_rubygems_version: !ruby/object:Gem::Requirement
95
133
  none: false