omnis 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/omnis/mongo_query.rb +2 -2
- data/lib/omnis/version.rb +1 -1
- data/spec/lib/omnis/mongo_query_spec.rb +8 -2
- metadata +2 -2
data/lib/omnis/mongo_query.rb
CHANGED
@@ -95,8 +95,8 @@ module Omnis
|
|
95
95
|
def mongo_opts(extracted_operators)
|
96
96
|
{}.tap do |opts|
|
97
97
|
params_with_extra_fields = extracted_operators.collect(&:opts).select {|e| e.has_key? :field}
|
98
|
-
extra_fields
|
99
|
-
opts[:fields] = self.class.field_list + extra_fields
|
98
|
+
extra_fields = params_with_extra_fields.map {|e| e[:field]}
|
99
|
+
opts[:fields] = self.class.field_list + extra_fields.flatten
|
100
100
|
opts[:limit] = items_per_page
|
101
101
|
opts[:skip] = skip
|
102
102
|
opts[:sort] = sort_opts if sort_opts.all?
|
data/lib/omnis/version.rb
CHANGED
@@ -50,8 +50,9 @@ describe Omnis::MongoQuery do
|
|
50
50
|
|
51
51
|
fields %w[ref_anixe status]
|
52
52
|
# if this param is in the query, fetch the field "ref_customer"
|
53
|
-
param :ref_customer, Matches,
|
54
|
-
param(:date_booked, Between,
|
53
|
+
param :ref_customer, Matches, :field => 'ref_customer'
|
54
|
+
param(:date_booked, Between, :field => 'date_booked') {|src| Between.new(:date_booked, Time.at(0)..Time.at(1), :field => 'date_booked') }
|
55
|
+
param :extra, Equals, :field => [:one, :two]
|
55
56
|
end
|
56
57
|
|
57
58
|
it 'extra field not requested when param not present' do
|
@@ -66,6 +67,11 @@ describe Omnis::MongoQuery do
|
|
66
67
|
m.opts.should == { :limit => 20, :skip => 0, :fields => ['ref_anixe', 'status', 'ref_customer']}
|
67
68
|
end
|
68
69
|
|
70
|
+
it 'extra fields (many) are requested when param is in request' do
|
71
|
+
m = TestFieldsQuery.new({'extra' => 'value'}).to_mongo
|
72
|
+
m.opts[:fields].should include(:one, :two)
|
73
|
+
end
|
74
|
+
|
69
75
|
it 'works with lambdas, but the lambda must provide the opts!' do
|
70
76
|
m = TestFieldsQuery.new({"date_booked" => "1NOV"}).to_mongo
|
71
77
|
m.selector
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.7
|
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: 2012-12-
|
12
|
+
date: 2012-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|