searchlogic 2.1.10 → 2.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 2.1.11 released 2009-07-28
2
+
3
+ * Reworked how alias conditions are created on the fly, uses scope(:find) instead of proxy_options to create the scope. This allows using association alias named scopes.
4
+
1
5
  == 2.1.10 released 2009-07-28
2
6
 
3
7
  * Ignore polymorphic associations when dynamically creating conditions on associations.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 10
2
+ :patch: 11
3
3
  :major: 2
4
4
  :minor: 1
@@ -52,7 +52,13 @@ module Searchlogic
52
52
  assocs = non_polymorphic_associations
53
53
  return nil if assocs.empty?
54
54
  regexes = [association_searchlogic_regex(assocs, Conditions::PRIMARY_CONDITIONS)]
55
- assocs.each { |assoc| regexes << /^(#{assoc.name})_(#{assoc.klass.scopes.keys.join("|")})$/ }
55
+ assocs.each do |assoc|
56
+ scope_names = assoc.klass.scopes.keys + assoc.klass.alias_scopes.keys
57
+ scope_names.uniq!
58
+ scope_names.delete(:scoped)
59
+ next if scope_names.empty?
60
+ regexes << /^(#{assoc.name})_(#{scope_names.join("|")})$/
61
+ end
56
62
 
57
63
  if !local_condition?(name) && regexes.any? { |regex| name.to_s =~ regex }
58
64
  {:association => $1, :column => $2, :condition => $3}
@@ -66,7 +72,10 @@ module Searchlogic
66
72
  end
67
73
 
68
74
  def association_alias_condition_details(name)
69
- if !local_condition?(name) && name.to_s =~ association_searchlogic_regex(non_polymorphic_associations, Conditions::ALIAS_CONDITIONS)
75
+ assocs = non_polymorphic_associations
76
+ return nil if assocs.empty?
77
+
78
+ if !local_condition?(name) && name.to_s =~ association_searchlogic_regex(assocs, Conditions::ALIAS_CONDITIONS)
70
79
  {:association => $1, :column => $2, :condition => $3}
71
80
  end
72
81
  end
@@ -96,7 +105,8 @@ module Searchlogic
96
105
  if !arity || arity == 0
97
106
  # The underlying condition doesn't require any parameters, so let's just create a simple
98
107
  # named scope that is based on a hash.
99
- options = scope.proxy_options
108
+ options = scope.scope(:find)
109
+ options.delete(:readonly)
100
110
  options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
101
111
  options
102
112
  else
@@ -121,7 +131,8 @@ module Searchlogic
121
131
 
122
132
  eval <<-"end_eval"
123
133
  searchlogic_lambda(:#{arg_type}) { |#{proc_args.join(",")}|
124
- options = association.klass.named_scope_options(association_condition).call(#{proc_args.join(",")})
134
+ options = association.klass.send(association_condition, #{proc_args.join(",")}).scope(:find)
135
+ options.delete(:readonly)
125
136
  options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
126
137
  options
127
138
  }
@@ -140,8 +140,8 @@ module Searchlogic
140
140
 
141
141
  def create_primary_condition(column, condition)
142
142
  column_type = columns_hash[column.to_s].type
143
- match_keyword =
144
- ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
143
+ match_keyword = ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
144
+
145
145
  scope_options = case condition.to_s
146
146
  when /^equals/
147
147
  scope_options(condition, column_type, "#{table_name}.#{column} = ?")
data/searchlogic.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{searchlogic}
5
- s.version = "2.1.10"
5
+ s.version = "2.1.11"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Johnson of Binary Logic"]
@@ -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 allow the use of foreign pre-existing alias scopes" do
17
+ Company.users_username_has("bjohnson").proxy_options.should == User.username_has("bjohnson").proxy_options.merge(:joins => :users)
18
+ end
19
+
16
20
  it "should ignore polymorphic associations" do
17
21
  lambda { Fee.owner_created_at_gt(Time.now) }.should raise_error(NoMethodError)
18
22
  end
data/spec/search_spec.rb CHANGED
@@ -109,6 +109,12 @@ describe "Search" do
109
109
  search.orders_total_gt.should == 10
110
110
  end
111
111
 
112
+ it "should allow setting pre-existing association conditions" do
113
+ search = Company.search
114
+ search.users_uname = "bjohnson"
115
+ search.users_uname.should == "bjohnson"
116
+ end
117
+
112
118
  it "should allow using custom conditions" do
113
119
  User.named_scope(:four_year_olds, { :conditions => { :age => 4 } })
114
120
  search = User.search
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.10
4
+ version: 2.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic