Sha256: 41a3ad5599912fb249852e8c8ac96624147a58604bfa4c386cdc28a1883ac60b
Contents?: true
Size: 1.63 KB
Versions: 3
Compression:
Stored size: 1.63 KB
Contents
require 'spec_helper' describe 'Commands / Delete' do include_context 'users and tasks' subject(:users) { rom.commands.users } before do setup.relation(:users) do def by_name(name) restrict(name: name) end end setup.commands(:users) do define(:delete) end end it 'deletes all tuples when there is no restriction' do result = users.try { delete } expect(result).to match_array([ { name: 'Jane', email: 'jane@doe.org' }, { name: 'Joe', email: 'joe@doe.org' } ]) end it 'deletes tuples matching restriction' do result = users.try { delete(:by_name, 'Joe').call } expect(result).to match_array([{ name: 'Joe', email: 'joe@doe.org' }]) end it 'returns untouched relation if there are no tuples to delete' do result = users.try { delete(:by_name, 'Not here').call } expect(result).to match_array([]) end it 'returns deleted tuple when result is set to :one' do setup.commands(:users) do define(:delete_one, type: :delete) do result :one end end result = users.try { delete_one(:by_name, 'Jane').call } expect(result.value).to eql(name: 'Jane', email: 'jane@doe.org') end it 'raises error when result is set to :one and relation contains more tuples' do setup.commands(:users) do define(:delete) do result :one end end result = users.try { delete } expect(result.error).to be_instance_of(ROM::TupleCountMismatchError) expect(rom.relations.users.to_a).to match_array([ { name: 'Jane', email: 'jane@doe.org' }, { name: 'Joe', email: 'joe@doe.org' } ]) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rom-0.4.2 | spec/integration/commands/delete_spec.rb |
rom-0.4.1 | spec/integration/commands/delete_spec.rb |
rom-0.4.0 | spec/integration/commands/delete_spec.rb |