Sha256: 88e752ff148bb9892405b6b6e70338fcc785a4cb223209e7ab59f2fd7aafd7f2

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'
require 'sequel_transaction/sidekiq'

describe Sidekiq::Middleware::Client::AfterCommit do
  let(:table_name) { :sidekiq }
  let(:dataset) { connection[table_name] }
  let(:error) { RuntimeError.new }

  subject { Sidekiq::Middleware::Client::AfterCommit.new connection: connection }

  before do
    connection.create_table table_name do
      column :name, String, null: false
    end
  end

  after { connection.drop_table table_name }

  it 'defers yield until after committing a transaction' do
    called = false
    connection.transaction do
      subject.call do
        called = true
      end
      called.must_equal false
    end
    called.must_equal true
  end

  it 'yields immediately without transaction' do
    called = false
    subject.call do
      called = true
    end
    called.must_equal true
  end

  it 'does not yield after failing to commit transaction' do
    called = false
    begin
      connection.transaction do
        subject.call do
          called = true
        end
        raise
      end
    rescue
    end
    called.must_equal false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sequel_transaction-0.2.0 spec/sequel_transaction/sidekiq/middleware/client/after_commit_spec.rb