Skip to content

Commit 10e053d

Browse files
committed
Add specs for filtering based on null value attributes
1 parent f31370f commit 10e053d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

spec/dynamoid/criteria/chain_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,59 @@ def request_params
10811081
end
10821082
end
10831083
end
1084+
1085+
context 'nil check' do
1086+
let(:model) do
1087+
new_class do
1088+
field :name
1089+
end
1090+
end
1091+
1092+
before do
1093+
@mike = model.create(name: 'Mike')
1094+
@johndoe = model.create(name: nil)
1095+
end
1096+
1097+
context 'store_attribute_with_nil_value = true', config: { store_attribute_with_nil_value: true } do
1098+
it 'supports "eq nil" check' do
1099+
expect(model.where('name': nil).to_a).to eq [@johndoe]
1100+
end
1101+
1102+
it 'supports "in [nil]" check', log_level: :debug do
1103+
pending 'because of temporary bug with nil type casting'
1104+
expect(model.where('name.in': [nil]).to_a).to eq [@johndoe]
1105+
end
1106+
1107+
it 'supports "ne nil" check' do
1108+
expect(model.where('name.ne': nil).to_a).to eq [@mike]
1109+
end
1110+
end
1111+
1112+
context 'store_attribute_with_nil_value = false', config: { store_attribute_with_nil_value: false } do
1113+
it 'supports "null" check' do
1114+
expect(model.where('name.null': true).to_a).to eq [@johndoe]
1115+
expect(model.where('name.null': false).to_a).to eq [@mike]
1116+
end
1117+
1118+
it 'supports "not_null" check' do
1119+
expect(model.where('name.not_null': true).to_a).to eq [@mike]
1120+
expect(model.where('name.not_null': false).to_a).to eq [@johndoe]
1121+
end
1122+
1123+
it 'does not support "eq nil" check' do
1124+
expect(model.where('name': nil).to_a).to eq []
1125+
end
1126+
1127+
it 'does not supports "in [nil]" check' do
1128+
pending 'because of temporary bug with nil type casting'
1129+
expect(model.where('name.in': [nil]).to_a).to eq []
1130+
end
1131+
1132+
it 'does not support "ne nil" check' do
1133+
expect(model.where('name.ne': nil).to_a).to contain_exactly(@mike, @johndoe)
1134+
end
1135+
end
1136+
end
10841137
end
10851138

10861139
describe '#find_by_pages' do

0 commit comments

Comments
 (0)