|
11 | 11 | [ Label.new(age: 12), Label.new(age: 16) ] |
12 | 12 | end |
13 | 13 |
|
14 | | - let!(:band1) { Band.create!(name: '1', likes: 0, rating: 0.9, sales: BigDecimal('90'), decibels: 20..80, founded: today, updated_at: now_utc) } |
15 | | - let!(:band2) { Band.create!(name: '2', likes: 1, rating: 1.0, sales: BigDecimal('100'), decibels: 30..90, founded: today, updated_at: now_utc + 1.days) } |
16 | | - let!(:band3) { Band.create!(name: '3', likes: 1, rating: 2.2, sales: BigDecimal('220'), decibels: 40..100, founded: today + 1.days, updated_at: now_utc + 2.days) } |
17 | | - let!(:band4) { Band.create!(name: '3', likes: 2, rating: 3.1, sales: BigDecimal('310'), decibels: 50..120, founded: today + 1.days, updated_at: now_utc + 3.days) } |
18 | | - let!(:band5) { Band.create!(name: '4', likes: 3, rating: 3.1, sales: BigDecimal('310'), decibels: 60..150, founded: today + 2.days, updated_at: now_utc + 3.days, labels: labels) } |
| 14 | + let!(:band1) { Band.create!(name: '1', likes: 0, rating: 0.9, sales: BigDecimal('90'), decibels: 20..80, founded: today, updated: now_utc) } |
| 15 | + let!(:band2) { Band.create!(name: '2', likes: 1, rating: 1.0, sales: BigDecimal('100'), decibels: 30..90, founded: today, updated: now_utc + 1.days) } |
| 16 | + let!(:band3) { Band.create!(name: '3', likes: 1, rating: 2.2, sales: BigDecimal('220'), decibels: 40..100, founded: today + 1.days, updated: now_utc + 2.days) } |
| 17 | + let!(:band4) { Band.create!(name: '3', likes: 2, rating: 3.1, sales: BigDecimal('310'), decibels: 50..120, founded: today + 1.days, updated: now_utc + 3.days) } |
| 18 | + let!(:band5) { Band.create!(name: '4', likes: 3, rating: 3.1, sales: BigDecimal('310'), decibels: 60..150, founded: today + 2.days, updated: now_utc + 3.days, labels: labels) } |
| 19 | + |
19 | 20 | let!(:band6) do |
20 | 21 | id = BSON::ObjectId.new |
21 | | - Band.collection.insert_one(_id: id, name: 1, likes: '1', rating: '3.1', sales: '310', decibels: '90', founded: today, updated_at: now_utc) |
| 22 | + Band.collection.insert_one(_id: id, name: 1, likes: '1', rating: '3.1', sales: '310', decibels: '90', founded: '2020-01-02', updated: '2020-01-04 16:00:00 UTC') |
22 | 23 | Band.find(id) |
23 | 24 | end |
| 25 | + |
24 | 26 | let!(:band7) do |
25 | 27 | id = BSON::ObjectId.new |
26 | | - Band.collection.insert_one(_id: id, name: 1.0, decibels: 90.0) |
| 28 | + Band.collection.insert_one(_id: id, name: 1.0, decibels: 90.0, founded: 1577923200) |
27 | 29 | Band.find(id) |
28 | 30 | end |
29 | 31 |
|
|
78 | 80 | expect(Band.where(decibels: '90').to_a).to eq [band6] |
79 | 81 | end |
80 | 82 | end |
81 | | - |
| 83 | + |
82 | 84 | context 'Date field' do |
83 | 85 | it 'does not match objects with raw value' do |
84 | | - expect(Band.where(founded: Mongoid::RawValue('2020-01-02')).to_a).to eq [] |
| 86 | + expect(Band.where(founded: Mongoid::RawValue('2020-01-02')).to_a).to eq [band6] |
85 | 87 | end |
86 | | - |
| 88 | + |
87 | 89 | it 'matches objects without raw value' do |
88 | 90 | expect(Band.where(founded: '2020-01-02').to_a).to eq [band3, band4] |
89 | 91 | end |
90 | 92 | end |
91 | | - |
| 93 | + |
92 | 94 | context 'Time field' do |
93 | 95 | it 'does not match objects with raw value' do |
94 | | - expect(Band.where(updated_at: Mongoid::RawValue('2020-01-04 16:00:00 UTC')).to_a).to eq [] |
| 96 | + expect(Band.where(updated: Mongoid::RawValue('2020-01-04 16:00:00 UTC')).to_a).to eq [band6] |
95 | 97 | end |
96 | | - |
97 | | - # TODO: this isn't working for some reason |
98 | | - xit 'matches objects without raw value' do |
99 | | - expect(Band.where(updated_at: '2020-01-04 16:00:00 UTC').to_a).to eq [band4, band5] |
| 98 | + |
| 99 | + it 'matches objects without raw value' do |
| 100 | + expect(Band.where(updated: '2020-01-04 16:00:00 UTC').to_a).to eq [band4, band5] |
100 | 101 | end |
101 | 102 | end |
102 | 103 | end |
|
107 | 108 | it 'matches objects with raw value' do |
108 | 109 | expect(Band.where(likes: Mongoid::RawValue(1)).to_a).to eq [band2, band3] |
109 | 110 | end |
110 | | - |
| 111 | + |
111 | 112 | it 'matches objects without raw value' do |
112 | 113 | expect(Band.where(likes: 1).to_a).to eq [band2, band3] |
113 | 114 | end |
114 | 115 | end |
115 | | - |
| 116 | + |
116 | 117 | context 'Float field' do |
117 | 118 | it 'does not match objects with raw value' do |
118 | 119 | expect(Band.where(rating: Mongoid::RawValue(1)).to_a).to eq [band2] |
119 | 120 | expect(Band.where(rating: Mongoid::RawValue(3)).to_a).to eq [] |
120 | 121 | end |
121 | | - |
| 122 | + |
122 | 123 | it 'matches objects without raw value' do |
123 | 124 | expect(Band.where(rating: 1).to_a).to eq [band2] |
124 | 125 | expect(Band.where(rating: 3).to_a).to eq [] |
|
134 | 135 | expect(Band.where(sales: 310).to_a).to eq [band4, band5] |
135 | 136 | end |
136 | 137 | end |
137 | | - |
| 138 | + |
138 | 139 | context 'String field' do |
139 | 140 | it 'matches objects with raw value' do |
140 | 141 | expect(Band.where(name: Mongoid::RawValue(1)).to_a).to eq [band6, band7] |
141 | 142 | end |
142 | | - |
| 143 | + |
143 | 144 | it 'matches objects without raw value' do |
144 | 145 | expect(Band.where(name: 3).to_a).to eq [band3, band4] |
145 | 146 | end |
146 | 147 | end |
147 | | - |
| 148 | + |
148 | 149 | context 'Range field' do |
149 | 150 | it 'does not match objects with raw value' do |
150 | 151 | expect(Band.where(decibels: Mongoid::RawValue(90)).to_a).to eq [band7] |
|
157 | 158 |
|
158 | 159 | context 'Date field' do |
159 | 160 | it 'does not match objects with raw value' do |
160 | | - expect(Band.where(founded: Mongoid::RawValue(1577923200)).to_a).to eq [] |
| 161 | + expect(Band.where(founded: Mongoid::RawValue(1577923200)).to_a).to eq [band7] |
161 | 162 | end |
162 | | - |
| 163 | + |
163 | 164 | it 'matches objects without raw value' do |
164 | 165 | expect(Band.where(founded: 1577923200).to_a).to eq [band3, band4] |
165 | 166 | end |
166 | 167 | end |
167 | | - |
| 168 | + |
168 | 169 | context 'Time field' do |
169 | 170 | it 'does not match objects with raw value' do |
170 | | - expect(Band.where(updated_at: Mongoid::RawValue(1578153600)).to_a).to eq [] |
| 171 | + expect(Band.where(updated: Mongoid::RawValue(1578153600)).to_a).to eq [] |
171 | 172 | end |
172 | | - |
173 | | - # TODO: this isn't working for some reason |
174 | | - xit 'matches objects without raw value' do |
175 | | - expect(Band.where(updated_at: 1578153600).to_a).to eq [band4, band5] |
| 173 | + |
| 174 | + it 'matches objects without raw value' do |
| 175 | + expect(Band.where(updated: 1578153600).to_a).to eq [band4, band5] |
176 | 176 | end |
177 | 177 | end |
178 | 178 | end |
|
183 | 183 | it 'does not match objects with raw value' do |
184 | 184 | expect(Band.where(likes: Mongoid::RawValue(1.0)).to_a).to eq [band2, band3] |
185 | 185 | end |
186 | | - |
| 186 | + |
187 | 187 | it 'matches objects without raw value' do |
188 | 188 | expect(Band.where(likes: 1.0).to_a).to eq [band2, band3] |
189 | 189 | end |
190 | 190 | end |
191 | | - |
| 191 | + |
192 | 192 | context 'Float field' do |
193 | 193 | it 'does not match objects with raw value' do |
194 | 194 | expect(Band.where(rating: Mongoid::RawValue(3.1)).to_a).to eq [band4, band5] |
195 | 195 | end |
196 | | - |
| 196 | + |
197 | 197 | it 'matches objects without raw value' do |
198 | 198 | expect(Band.where(rating: 3.1).to_a).to eq [band4, band5] |
199 | 199 | end |
|
213 | 213 | it 'matches objects with raw value' do |
214 | 214 | expect(Band.where(name: Mongoid::RawValue(1.0)).to_a).to eq [band6, band7] |
215 | 215 | end |
216 | | - |
| 216 | + |
217 | 217 | it 'matches objects without raw value' do |
218 | 218 | expect(Band.where(name: 1.0).to_a).to eq [] |
219 | 219 | end |
|
231 | 231 |
|
232 | 232 | context 'Date field' do |
233 | 233 | it 'does not match objects with raw value' do |
234 | | - expect(Band.where(founded: Mongoid::RawValue(1577923200.0)).to_a).to eq [] |
| 234 | + expect(Band.where(founded: Mongoid::RawValue(1577923200.0)).to_a).to eq [band7] |
235 | 235 | end |
236 | 236 |
|
237 | 237 | it 'matches objects without raw value' do |
|
241 | 241 |
|
242 | 242 | context 'Time field' do |
243 | 243 | it 'does not match objects with raw value' do |
244 | | - expect(Band.where(updated_at: Mongoid::RawValue(1578153600.0)).to_a).to eq [] |
| 244 | + expect(Band.where(updated: Mongoid::RawValue(1578153600.0)).to_a).to eq [] |
245 | 245 | end |
246 | 246 |
|
247 | | - # TODO: this isn't working for some reason |
248 | | - xit 'matches objects without raw value' do |
249 | | - expect(Band.where(updated_at: 1578153600.0).to_a).to eq [band4, band5] |
| 247 | + it 'matches objects without raw value' do |
| 248 | + expect(Band.where(updated: 1578153600.0).to_a).to eq [band4, band5] |
250 | 249 | end |
251 | 250 | end |
252 | 251 | end |
|
309 | 308 |
|
310 | 309 | context 'Date field' do |
311 | 310 | it 'does not match objects with raw value' do |
312 | | - expect(Band.where(founded: Mongoid::RawValue(BigDecimal('1577923200'))).to_a).to eq [] |
| 311 | + expect(Band.where(founded: Mongoid::RawValue(BigDecimal('1577923200'))).to_a).to eq [band7] |
313 | 312 | end |
314 | 313 |
|
315 | | - xit 'matches objects without raw value' do |
| 314 | + it 'matches objects without raw value' do |
316 | 315 | expect(Band.where(founded: BigDecimal('1577923200')).to_a).to eq [band3, band4] |
317 | 316 | end |
318 | 317 | end |
319 | 318 |
|
320 | 319 | context 'Time field' do |
321 | 320 | it 'does not match objects with raw value' do |
322 | | - expect(Band.where(updated_at: Mongoid::RawValue(BigDecimal('1578153600'))).to_a).to eq [] |
| 321 | + expect(Band.where(updated: Mongoid::RawValue(BigDecimal('1578153600'))).to_a).to eq [] |
323 | 322 | end |
324 | 323 |
|
325 | | - # TODO: this isn't working for some reason |
326 | | - xit 'matches objects without raw value' do |
327 | | - expect(Band.where(updated_at: BigDecimal('1578153600')).to_a).to eq [band4, band5] |
| 324 | + it 'matches objects without raw value' do |
| 325 | + expect(Band.where(updated: BigDecimal('1578153600')).to_a).to eq [band4, band5] |
328 | 326 | end |
329 | 327 | end |
330 | 328 | end |
|
353 | 351 |
|
354 | 352 | context 'BigDecimal field' do |
355 | 353 | it 'raises a BSON error with raw value' do |
356 | | - expect { Band.where(sales: Mongoid::RawValue(100..300)).to_a }.to eq raise_error BSON::Error::UnserializableClass |
| 354 | + expect { Band.where(sales: Mongoid::RawValue(100..300)).to_a }.to raise_error BSON::Error::UnserializableClass |
357 | 355 | end |
358 | 356 |
|
359 | 357 | it 'matches objects without raw value' do |
|
387 | 385 | expect { Band.where(founded: Mongoid::RawValue(1577923199..1577923201)).to_a }.to raise_error BSON::Error::UnserializableClass |
388 | 386 | end |
389 | 387 |
|
390 | | - # TODO: this isn't working for some reason -- returns all bands |
391 | | - xit 'matches objects without raw value' do |
392 | | - expect(Band.where(founded: 1577923199..1577923201).to_a).to eq [band3, band4] |
| 388 | + it 'matches objects without raw value' do |
| 389 | + expect(Band.where(founded: 1577923199..1577923201).to_a).to eq [band1, band2, band3, band4] |
393 | 390 | end |
394 | 391 | end |
395 | 392 |
|
|
398 | 395 | expect { Band.where(founded: Mongoid::RawValue(1578153599..1578153600)).to_a }.to raise_error BSON::Error::UnserializableClass |
399 | 396 | end |
400 | 397 |
|
401 | | - # TODO: this isn't working for some reason |
402 | | - xit 'matches objects without raw value' do |
403 | | - expect(Band.where(updated_at: 1578153599..1578153600).to_a).to eq [band4, band5] |
| 398 | + it 'matches objects without raw value' do |
| 399 | + expect(Band.where(updated: 1578153599..1578153600).to_a).to eq [band4, band5] |
404 | 400 | end |
405 | 401 | end |
406 | 402 | end |
|
0 commit comments