|
400 | 400 | end
|
401 | 401 | end
|
402 | 402 | end
|
| 403 | + |
| 404 | + context 'Mongoid::RawValue<Time>' do |
| 405 | + let!(:band7) do |
| 406 | + id = BSON::ObjectId.new |
| 407 | + Band.collection.insert_one(_id: id, name: Time.at(1), likes: Time.at(1), rating: Time.at(3.1), sales: Time.at(310), decibels: Time.at(90)) |
| 408 | + Band.find(id) |
| 409 | + end |
| 410 | + |
| 411 | + context 'Integer field' do |
| 412 | + it 'does not match objects with raw value' do |
| 413 | + expect(Band.where(likes: Mongoid::RawValue(Time.at(1))).to_a).to eq [band7] |
| 414 | + end |
| 415 | + |
| 416 | + it 'matches objects without raw value' do |
| 417 | + expect(Band.where(likes: Time.at(1)).to_a).to eq [band2, band3] |
| 418 | + end |
| 419 | + end |
| 420 | + |
| 421 | + context 'Float field' do |
| 422 | + it 'matches objects with raw value' do |
| 423 | + expect(Band.where(rating: Mongoid::RawValue(Time.at(3.1))).to_a).to eq [band7] |
| 424 | + end |
| 425 | + |
| 426 | + it 'matches objects without raw value' do |
| 427 | + expect(Band.where(rating: Time.at(3.1)).to_a).to eq [band4, band5] |
| 428 | + end |
| 429 | + end |
| 430 | + |
| 431 | + context 'BigDecimal field' do |
| 432 | + it 'matches objects with raw value' do |
| 433 | + expect(Band.where(sales: Mongoid::RawValue(Time.at(310))).to_a).to eq [band7] |
| 434 | + end |
| 435 | + |
| 436 | + it 'matches objects without raw value because Time does not evolve into BigDecimal' do |
| 437 | + expect(Band.where(sales: Time.at(310)).to_a).to eq [band7] |
| 438 | + end |
| 439 | + end |
| 440 | + |
| 441 | + context 'String field' do |
| 442 | + it 'matches objects with raw value' do |
| 443 | + expect(Band.where(name: Mongoid::RawValue(Time.at(1))).to_a).to eq [band7] |
| 444 | + end |
| 445 | + |
| 446 | + it 'does not match objects without raw value' do |
| 447 | + expect(Band.where(name: Time.at(1)).to_a).to eq [] |
| 448 | + end |
| 449 | + end |
| 450 | + |
| 451 | + context 'Range field' do |
| 452 | + it 'matches objects with raw value' do |
| 453 | + expect(Band.where(decibels: Mongoid::RawValue(Time.at(90))).to_a).to eq [band7] |
| 454 | + end |
| 455 | + |
| 456 | + it 'matches objects without raw value because BigDecimal cannot be evolved to Range' do |
| 457 | + expect(Band.where(decibels: Time.at(90)).to_a).to eq [band7] |
| 458 | + end |
| 459 | + end |
| 460 | + |
| 461 | + context 'Date field' do |
| 462 | + it 'matches objects with raw value when exact' do |
| 463 | + expect(Band.where(founded: Mongoid::RawValue(Time.at(1577923200))).to_a).to eq [band3, band4] |
| 464 | + end |
| 465 | + |
| 466 | + it 'does not match objects with raw value when non-exact' do |
| 467 | + expect(Band.where(founded: Mongoid::RawValue(Time.at(1577923199))).to_a).to eq [] |
| 468 | + end |
| 469 | + |
| 470 | + it 'matches objects without raw value when exact' do |
| 471 | + expect(Band.where(founded: Time.at(1577923200)).to_a).to eq [band3, band4] |
| 472 | + end |
| 473 | + |
| 474 | + it 'matches objects without raw value when non-exact' do |
| 475 | + expect(Band.where(founded: Time.at(1577923199)).to_a).to eq [band3, band4] |
| 476 | + end |
| 477 | + end |
| 478 | + |
| 479 | + context 'Time field' do |
| 480 | + it 'matches objects with raw value' do |
| 481 | + expect(Band.where(updated: Mongoid::RawValue(Time.at(1578153600))).to_a).to eq [band4, band5] |
| 482 | + end |
| 483 | + |
| 484 | + it 'matches objects without raw value' do |
| 485 | + expect(Band.where(updated: Time.at(1578153600)).to_a).to eq [band4, band5] |
| 486 | + end |
| 487 | + end |
| 488 | + end |
403 | 489 | end
|
0 commit comments