-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathserver_query_spec.rb
142 lines (118 loc) · 3.17 KB
/
server_query_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
# This file serves as a record of server query behavior.
describe 'Server queries' do
context 'scalar operator on scalar field' do
let!(:document) do
Survey.create!(
questions: [Question.new(
answers: [Answer.new(position: 3)],
)],
)
end
let(:query) do
{'questions.answers.position' => {'$gt' => 2}}
end
it 'finds' do
Survey.collection.find(query).to_a.should == [document.attributes]
end
end
context 'scalar operator on array field' do
let!(:document) do
Bar.create!(
questions: [
answers: [
position: [3],
],
],
)
end
context '$eq with scalar on array field' do
let(:query) do
{'questions.answers.position' => {'$eq' => 3}}
end
it 'finds' do
Bar.collection.find(query).to_a.should == [document.attributes.with_indifferent_access]
end
end
context '$ne with scalar on array field' do
context 'same value as array item' do
let(:query) do
{'questions.answers.position' => {'$ne' => 3}}
end
it 'matches array and does not find' do
Bar.collection.find(query).to_a.should == []
end
end
context 'different value from array items' do
let(:query) do
{'questions.answers.position' => {'$ne' => 2}}
end
it 'finds' do
Bar.collection.find(query).to_a.should == [document.attributes.with_indifferent_access]
end
end
end
context '$gt on array field' do
let(:query) do
{'questions.answers.position' => {'$gt' => 2}}
end
it 'finds' do
# This finds the document - https://jira.mongodb.org/browse/DOCSP-10717
Bar.collection.find(query).to_a.should == [document.attributes.with_indifferent_access]
end
end
context '$in on a double array field' do
let!(:document) do
Bar.create!(
questions: [
answers: [
position: [[3]],
],
],
)
end
let(:query) do
{'questions.answers.position' => {'$in' => [3]}}
end
it 'does not find' do
Bar.collection.find(query).to_a.should == []
end
end
context '$in on an array field' do
let!(:document) do
Bar.create!(
questions: [
answers: [
position: [3],
],
],
)
end
let(:query) do
{'questions.answers.position' => {'$in' => [3]}}
end
it 'finds' do
Bar.collection.find(query).to_a.should == [document.attributes.with_indifferent_access]
end
end
context '$in on a scalar field' do
let!(:document) do
Bar.create!(
questions: [
answers: [
position: 3,
],
],
)
end
let(:query) do
{'questions.answers.position' => {'$in' => [3]}}
end
it 'finds' do
Bar.collection.find(query).to_a.should == [document.attributes.with_indifferent_access]
end
end
end
end