data_table 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/data_table/mongoid.rb +7 -1
- data/lib/data_table/version.rb +1 -1
- data/spec/mongoid_data_table_spec.rb +6 -0
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/data_table/mongoid.rb
CHANGED
@@ -16,7 +16,13 @@ module DataTable
|
|
16
16
|
return if (query = raw_query.gsub(/\//, "")).blank?
|
17
17
|
|
18
18
|
if search_fields.size == 1
|
19
|
-
|
19
|
+
terms = query.strip.split(/\s/)
|
20
|
+
|
21
|
+
if terms.size == 1
|
22
|
+
{search_fields.first => /#{query}/i}
|
23
|
+
else
|
24
|
+
{search_fields.first => {"$all" => terms.map {|term| /#{term}/i }}}
|
25
|
+
end
|
20
26
|
else
|
21
27
|
{"$or" => search_fields.map {|field| {field => /#{query}/i} }}
|
22
28
|
end
|
data/lib/data_table/version.rb
CHANGED
@@ -37,6 +37,12 @@ describe DataTable do
|
|
37
37
|
send(:_where_conditions, "q", %w(f)).should == {"f" => /q/i}
|
38
38
|
end
|
39
39
|
|
40
|
+
context "given multiple search terms" do
|
41
|
+
it "should require a match for each term when there is a single search field" do
|
42
|
+
send(:_where_conditions, "q1 q2", %w(f)).should == {"f" => {"$all" => [/q1/i, /q2/i]}}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
40
46
|
end
|
41
47
|
|
42
48
|
context "#_order_by_fields" do
|