Skip to content

Commit c714cca

Browse files
committed
WIP
1 parent 5caff46 commit c714cca

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

spec/integration/criteria/raw_value_spec.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
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) }
1717
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) }
1818
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
1924

2025
context 'Mongoid::RawValue<String> criteria' do
2126

2227
context 'Integer field' do
2328
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]
2530
end
2631

2732
it 'matches objects without raw value' do
@@ -31,21 +36,21 @@
3136

3237
context 'Float field' do
3338
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]
3540
end
3641

37-
it 'matches objects without raw value' do
42+
it 'matches objects with value stored as Float' do
3843
expect(Band.where(rating: '3.1').to_a).to eq [band4, band5]
3944
end
4045
end
4146

4247
context 'BigDecimal field' do
4348
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]
4550
end
4651

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]
4954
end
5055
end
5156

@@ -61,11 +66,11 @@
6166

6267
context 'Range field' do
6368
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]
6570
end
6671

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]
6974
end
7075
end
7176

0 commit comments

Comments
 (0)