searchlogic 2.3.9 → 2.3.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/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :minor: 3
3
- :patch: 9
4
2
  :major: 2
3
+ :minor: 3
5
4
  :build:
5
+ :patch: 10
@@ -89,13 +89,11 @@ module Searchlogic
89
89
  end
90
90
  end
91
91
 
92
- def condition_details(name, *args)
93
- if args.size > 0 and !args.first.nil?
94
- assoc = reflect_on_association(args.first.to_sym)
95
- klass = assoc.klass
96
- name.to_s =~ /^(#{klass.column_names.join("|")})_(#{(PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")})$/
97
- {:column => $1, :condition => $2}
98
- elsif name.to_s =~ /^(#{column_names.join("|")})_(#{(PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")})$/
92
+ def condition_details(method_name)
93
+ column_name_matcher = column_names.join("|")
94
+ conditions_matcher = (PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")
95
+
96
+ if method_name.to_s =~ /^(#{column_name_matcher})_(#{conditions_matcher})$/
99
97
  {:column => $1, :condition => $2}
100
98
  end
101
99
  end
@@ -10,6 +10,10 @@ module Searchlogic
10
10
  super || or_condition?(name)
11
11
  end
12
12
 
13
+ def named_scope_options(name) # :nodoc:
14
+ super || super(or_conditions(name).join("_or_"))
15
+ end
16
+
13
17
  private
14
18
  def or_condition?(name)
15
19
  !or_conditions(name).nil?
@@ -106,7 +110,7 @@ module Searchlogic
106
110
  path << details[:association]
107
111
  part = details[:condition]
108
112
  given_assoc = details[:association]
109
- elsif details = klass.send(:condition_details, part, nil)
113
+ elsif details = klass.send(:condition_details, part)
110
114
  return { :path => path, :column => details[:column], :condition => details[:condition] }
111
115
  end
112
116
  end
@@ -114,7 +118,11 @@ module Searchlogic
114
118
  end
115
119
 
116
120
  def create_or_condition(scopes, args)
117
- named_scope scopes.join("_or_"), lambda { |*args|
121
+ scopes_options = scopes.collect { |scope, *args| send(scope, *args).proxy_options }
122
+ # We're using first scope to determine column's type
123
+ scope = named_scope_options(scopes.first)
124
+ column_type = scope.respond_to?(:searchlogic_arg_type) ? scope.searchlogic_arg_type : :string
125
+ named_scope scopes.join("_or_"), searchlogic_lambda(column_type) { |*args|
118
126
  merge_scopes_with_or(scopes.collect { |scope| [scope, *args] })
119
127
  }
120
128
  end
@@ -66,7 +66,7 @@ module Searchlogic
66
66
  def fields_for(*args, &block)
67
67
  if search_obj = args.find { |arg| arg.is_a?(Searchlogic::Search) }
68
68
  args.unshift(:search) if args.first == search_obj
69
- concat(content_tag("div", hidden_field_tag("#{args.first}[order]", search_obj.order)) + "\n")
69
+ concat(content_tag("div", hidden_field_tag("#{args.first}[order]", search_obj.order)))
70
70
  super
71
71
  else
72
72
  super
@@ -84,7 +84,11 @@ module Searchlogic
84
84
 
85
85
  if setter?(name)
86
86
  if scope?(scope_name)
87
- conditions[condition_name] = type_cast(args.first, cast_type(scope_name))
87
+ if args.size == 1
88
+ conditions[condition_name] = type_cast(args.first, cast_type(scope_name))
89
+ else
90
+ conditions[condition_name] = args
91
+ end
88
92
  else
89
93
  raise UnknownConditionError.new(condition_name)
90
94
  end
@@ -109,11 +113,7 @@ module Searchlogic
109
113
  scope
110
114
  end
111
115
  else
112
- if value.is_a?(Array)
113
- scope.send(scope_name, *value)
114
- else
115
- scope.send(scope_name, value)
116
- end
116
+ scope.send(scope_name, *value)
117
117
  end
118
118
  end
119
119
  scope.send(name, *args, &block)
data/searchlogic.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{searchlogic}
8
- s.version = "2.3.9"
8
+ s.version = "2.3.10"
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"]
12
- s.date = %q{2009-11-27}
12
+ s.date = %q{2010-01-14}
13
13
  s.description = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
14
14
  s.email = %q{bjohnson@binarylogic.com}
15
15
  s.extra_rdoc_files = [
@@ -56,4 +56,11 @@ describe "Or conditions" do
56
56
  User.find_or_create_by_name_and_username("Fred", "fredb").should be_a_kind_of User
57
57
  end
58
58
 
59
+ it "should work with User.search(conditions) method" do
60
+ User.search(:username_or_name_like => 'ben').proxy_options.should == {:conditions => "(users.username LIKE '%ben%') OR (users.name LIKE '%ben%')"}
61
+ end
62
+
63
+ it "should convert types properly when used with User.search(conditions) method" do
64
+ User.search(:id_or_age_lte => '10').proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age <= 10)"}
65
+ end
59
66
  end
data/spec/search_spec.rb CHANGED
@@ -365,5 +365,13 @@ describe "Search" do
365
365
  search1.empty?.should == false
366
366
  search2.empty?.should == true
367
367
  end
368
+
369
+ it "should delegate to named scopes with arity > 1" do
370
+ User.named_scope :paged, lambda {|start, limit| { :limit => limit, :offset => start }}
371
+ User.create(:username => "bjohnson")
372
+ search = User.search(:username => "bjohnson")
373
+ search.paged(0, 1).count.should == 1
374
+ search.paged(0, 0).count.should == 0
375
+ end
368
376
  end
369
377
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec'
2
2
  require 'rubygems'
3
3
  require 'ruby-debug'
4
- require 'activerecord'
4
+ require 'active_record'
5
5
 
6
6
  ENV['TZ'] = 'UTC'
7
7
  Time.zone = 'Eastern Time (US & Canada)'
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.3.9
4
+ version: 2.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-27 00:00:00 -05:00
12
+ date: 2010-01-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency