Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add store_attribute_with_nil_value config option #360

Merged
merged 4 commits into from
Jun 1, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add specs for filtering based on null value attributes
  • Loading branch information
andrykonchin committed Jun 1, 2019
commit 10e053dfc54d885bdcbed079aeb9e0e1c72a92ad
53 changes: 53 additions & 0 deletions spec/dynamoid/criteria/chain_spec.rb
Original file line number Diff line number Diff line change
@@ -1081,6 +1081,59 @@ def request_params
end
end
end

context 'nil check' do
let(:model) do
new_class do
field :name
end
end

before do
@mike = model.create(name: 'Mike')
@johndoe = model.create(name: nil)
end

context 'store_attribute_with_nil_value = true', config: { store_attribute_with_nil_value: true } do
it 'supports "eq nil" check' do
expect(model.where('name': nil).to_a).to eq [@johndoe]
end

it 'supports "in [nil]" check', log_level: :debug do
pending 'because of temporary bug with nil type casting'
expect(model.where('name.in': [nil]).to_a).to eq [@johndoe]
end

it 'supports "ne nil" check' do
expect(model.where('name.ne': nil).to_a).to eq [@mike]
end
end

context 'store_attribute_with_nil_value = false', config: { store_attribute_with_nil_value: false } do
it 'supports "null" check' do
expect(model.where('name.null': true).to_a).to eq [@johndoe]
expect(model.where('name.null': false).to_a).to eq [@mike]
end

it 'supports "not_null" check' do
expect(model.where('name.not_null': true).to_a).to eq [@mike]
expect(model.where('name.not_null': false).to_a).to eq [@johndoe]
end

it 'does not support "eq nil" check' do
expect(model.where('name': nil).to_a).to eq []
end

it 'does not supports "in [nil]" check' do
pending 'because of temporary bug with nil type casting'
expect(model.where('name.in': [nil]).to_a).to eq []
end

it 'does not support "ne nil" check' do
expect(model.where('name.ne': nil).to_a).to contain_exactly(@mike, @johndoe)
end
end
end
end

describe '#find_by_pages' do