data_table 0.2.3 → 0.2.4

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.
@@ -10,7 +10,11 @@ module DataTable
10
10
  def _where_conditions raw_query, search_fields
11
11
  return if (query = raw_query.gsub(/\//, "")).blank?
12
12
 
13
- {"$or" => search_fields.map {|field| {field => /#{query}/i} }}
13
+ if search_fields.size == 1
14
+ {search_fields.first => /#{query}/i}
15
+ else
16
+ {"$or" => search_fields.map {|field| {field => /#{query}/i} }}
17
+ end
14
18
  end
15
19
 
16
20
  def _order_by_fields params, fields
@@ -1,3 +1,3 @@
1
1
  module DataTable
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -33,6 +33,10 @@ describe DataTable do
33
33
  send(:_where_conditions, "q", %w(foo bar)).should == {"$or" => [{"foo" => /q/i}, {"bar" => /q/i}]}
34
34
  end
35
35
 
36
+ it "should not use $or if there is only one search field" do
37
+ send(:_where_conditions, "q", %w(f)).should == {"f" => /q/i}
38
+ end
39
+
36
40
  end
37
41
 
38
42
  context "#_order_by_fields" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: data_table
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.3
5
+ version: 0.2.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jason Dew
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-03 00:00:00 -04:00
13
+ date: 2011-09-05 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency