|
16 | 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 | 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 | 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) }
|
| 19 | + let!(:band6) do |
| 20 | + 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.find(id) |
| 23 | + end |
19 | 24 |
|
20 | 25 | context 'Mongoid::RawValue<String> criteria' do
|
21 | 26 |
|
22 | 27 | context 'Integer field' do
|
23 | 28 | it 'does not match objects' do
|
24 |
| - expect(Band.where(likes: Mongoid::RawValue('1')).to_a).to eq [] |
| 29 | + expect(Band.where(likes: Mongoid::RawValue('1')).to_a).to eq [band6] |
25 | 30 | end
|
26 | 31 |
|
27 | 32 | it 'matches objects without raw value' do
|
|
31 | 36 |
|
32 | 37 | context 'Float field' do
|
33 | 38 | it 'does not match objects' do
|
34 |
| - expect(Band.where(rating: Mongoid::RawValue('3.1')).to_a).to eq [] |
| 39 | + expect(Band.where(rating: Mongoid::RawValue('3.1')).to_a).to eq [band6] |
35 | 40 | end
|
36 | 41 |
|
37 |
| - it 'matches objects without raw value' do |
| 42 | + it 'matches objects with value stored as Float' do |
38 | 43 | expect(Band.where(rating: '3.1').to_a).to eq [band4, band5]
|
39 | 44 | end
|
40 | 45 | end
|
41 | 46 |
|
42 | 47 | context 'BigDecimal field' do
|
43 | 48 | it 'does not match objects with raw value' do
|
44 |
| - expect(Band.where(sales: Mongoid::RawValue('310')).to_a).to eq [] |
| 49 | + expect(Band.where(sales: Mongoid::RawValue('310')).to_a).to eq [band6] |
45 | 50 | end
|
46 | 51 |
|
47 |
| - it 'does not match objects without raw value' do |
48 |
| - expect(Band.where(sales: '310').to_a).to eq [] |
| 52 | + it 'matches objects with value stored as Decimal128' do |
| 53 | + expect(Band.where(sales: '310').to_a).to eq [band4, band5] |
49 | 54 | end
|
50 | 55 | end
|
51 | 56 |
|
|
61 | 66 |
|
62 | 67 | context 'Range field' do
|
63 | 68 | it 'does not match objects with raw value' do
|
64 |
| - expect(Band.where(decibels: Mongoid::RawValue('90')).to_a).to eq [] |
| 69 | + expect(Band.where(decibels: Mongoid::RawValue('90')).to_a).to eq [band6] |
65 | 70 | end
|
66 | 71 |
|
67 |
| - it 'does not match objects without raw value' do |
68 |
| - expect(Band.where(decibels: '90').to_a).to eq [] |
| 72 | + it 'matches objects because String cannot be evolved to Range' do |
| 73 | + expect(Band.where(decibels: '90').to_a).to eq [band6] |
69 | 74 | end
|
70 | 75 | end
|
71 | 76 |
|
|
0 commit comments