Sha256: ca9ce34e1eb8cbe9af8775e081a6214ff73dc96003d6f491ed15fb452214645b
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
require 'spec_helper' describe 'Commands / Create' do include_context 'users and tasks' subject(:users) { rom.commands.users } before do setup.relation(:users) setup.commands(:users) do define(:create) do result :one end define(:create_many, type: :create) do result :many end end end it 'returns a single tuple when result is set to :one' do result = users.try { create(id: 2, name: 'Jane') } expect(result.value).to eql(id: 2, name: 'Jane') end it 'returns tuples when result is set to :many' do result = users.try { create_many([{ id: 2, name: 'Jane' }, { id: 3, name: 'Jack' }]) } expect(result.value.to_a).to match_array([ { id: 2, name: 'Jane' }, { id: 3, name: 'Jack' } ]) end it 'handles not-null constraint violation error' do result = users.try { create(id: nil, name: 'Jane') } expect(result.error).to be_instance_of(ROM::SQL::ConstraintError) expect(result.error.message).to match(/not-null/) end it 'handles uniqueness constraint violation error' do result = users.try { create(id: 3, name: 'Piotr') } expect(result.error).to be_instance_of(ROM::SQL::ConstraintError) expect(result.error.message).to match(/unique/) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rom-sql-0.3.0 | spec/integration/commands/create_spec.rb |
rom-sql-0.2.0 | spec/integration/commands/create_spec.rb |