searchlogic 2.5.13 → 2.5.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,12 +15,15 @@ module Searchlogic
15
15
  if setter?(name)
16
16
  if scope?(scope_name)
17
17
  if args.size == 1
18
+ options = scope_options(scope_name).respond_to?(:searchlogic_options) ? scope_options(scope_name).searchlogic_options : {}
19
+ options[:cast_single_val_to_array] = cast_single_val_to_array?(condition_name)
20
+
18
21
  write_condition(
19
22
  condition_name,
20
23
  type_cast(
21
24
  args.first,
22
25
  cast_type(scope_name),
23
- scope_options(scope_name).respond_to?(:searchlogic_options) ? scope_options(scope_name).searchlogic_options : {}
26
+ options
24
27
  )
25
28
  )
26
29
  else
@@ -100,7 +103,7 @@ module Searchlogic
100
103
  casted_value = column_for_type_cast.type_cast(value)
101
104
 
102
105
  if Time.zone && casted_value.is_a?(Time)
103
- if value.is_a?(String)
106
+ casted_value = if value.is_a?(String)
104
107
  # if its a string, we should assume the user means the local time
105
108
  # we need to update the object to include the proper time zone without changing
106
109
  # the time
@@ -108,11 +111,16 @@ module Searchlogic
108
111
  else
109
112
  casted_value.in_time_zone
110
113
  end
111
- else
112
- casted_value
113
114
  end
115
+
116
+ options[:cast_single_val_to_array] ? [casted_value] : casted_value
114
117
  end
115
118
  end
119
+
120
+ # For *_equals_any conditions, cast single values to an array, ex: 5 to [5] or 'ben' to ['ben']
121
+ def cast_single_val_to_array?(condition_name)
122
+ condition_name =~ /^\w+_equals_any/
123
+ end
116
124
  end
117
125
  end
118
126
  end
@@ -1,3 +1,3 @@
1
1
  module Searchlogic
2
- VERSION = "2.5.13"
2
+ VERSION = "2.5.14"
3
3
  end
@@ -321,6 +321,18 @@ describe Searchlogic::Search do
321
321
  search.id_equals_any.should == [1, 2, 3]
322
322
  end
323
323
 
324
+ it "should be an Array given a single value for *_equals_any" do
325
+ search = Order.search
326
+ search.id_equals_any = 5
327
+ search.id_equals_any.should == [5]
328
+ end
329
+
330
+ it "shouldn't change to an Array given a single value for *_equals" do
331
+ search = Order.search
332
+ search.id_equals = 5
333
+ search.id_equals.should_not == [5]
334
+ end
335
+
324
336
  it "should type cast association conditions" do
325
337
  search = User.search
326
338
  search.orders_total_gt = "10"
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.5.13
4
+ version: 2.5.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-13 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -142,7 +142,6 @@ files:
142
142
  - lib/searchlogic/search/unknown_condition_error.rb
143
143
  - lib/searchlogic/version.rb
144
144
  - rails/init.rb
145
- - searchlogic-2.5.12.gem
146
145
  - searchlogic.gemspec
147
146
  - spec/searchlogic/active_record/association_proxy_spec.rb
148
147
  - spec/searchlogic/active_record/consistency_spec.rb
@@ -176,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
175
  version: '0'
177
176
  requirements: []
178
177
  rubyforge_project:
179
- rubygems_version: 1.8.23
178
+ rubygems_version: 1.8.25
180
179
  signing_key:
181
180
  specification_version: 3
182
181
  summary: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
Binary file