Sha256: ea44dd45fe8b53f13f8aab332837dd816d83f0e0ea455b5446b1938b3cf60a02

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 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)
        where(name: name)
      end
    end

    setup.commands(:users) do
      define(:delete) do
        result :one
      end
    end

    rom.relations.users.insert(id: 2, name: 'Jane')
  end

  context '#transaction' do
    it 'delete in normal way if no error raised' do
      expect {
        users.delete.transaction do
          users.delete.by_name('Jane').call
        end
      }.to change { rom.relations.users.count }.by(-1)
    end

    it 'delete nothing if error was raised' do
      expect {
        users.delete.transaction do
          users.delete.by_name('Jane').call
          raise ROM::SQL::Rollback
        end
      }.to_not change { rom.relations.users.count }
    end
  end

  it 'raises error when tuple count does not match expectation' do
    result = users.try { users.delete.call }

    expect(result.value).to be(nil)
    expect(result.error).to be_instance_of(ROM::TupleCountMismatchError)
  end

  it 'deletes all tuples in a restricted relation' do
    result = users.try { users.delete.by_name('Jane').call }

    expect(result.value).to eql(id: 2, name: 'Jane')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rom-sql-0.4.0 spec/integration/commands/delete_spec.rb
rom-sql-0.4.0.rc1 spec/integration/commands/delete_spec.rb
rom-sql-0.4.0.beta2 spec/integration/commands/delete_spec.rb
rom-sql-0.4.0.beta1 spec/integration/commands/delete_spec.rb