Sha256: 558578e1db69d628c3d25d6411bd5de2453f8d3a232107ff599488ca68a26cdb

Contents?: true

Size: 813 Bytes

Versions: 14

Compression:

Stored size: 813 Bytes

Contents

require 'spec_helper'

unless ActiveRecord::Migration.table_exists?(:models)
  ActiveRecord::Migration.create_table(:models)
end

class Model < ActiveRecord::Base; end

RSpec.describe 'Transactions' do
  before do
    stub_const 'RollBackTransactions', Class.new
    stub_const 'NestedRoutine', Class.new

    NestedRoutine.class_eval do
      lev_routine

      def exec
        raise 'Rolled back'
      end
    end

    RollBackTransactions.class_eval do
      lev_routine

      uses_routine NestedRoutine

      def exec
        Model.create!
        run(:nested_routine)
      end
    end
  end

  context 'in nested routines' do
    it 'rolls back on exceptions' do
      expect {
        RollBackTransactions.call
      }.to raise_error(RuntimeError)

      expect(Model.count).to eq(0)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lev-13.0.0 spec/transaction_spec.rb
lev-12.1.0 spec/transaction_spec.rb
lev-12.0.0 spec/transaction_spec.rb
lev-11.0.0 spec/transaction_spec.rb
lev-10.1.0 spec/transaction_spec.rb
lev-10.0.0 spec/transaction_spec.rb
lev-9.0.4 spec/transaction_spec.rb
lev-9.0.3 spec/transaction_spec.rb
lev-9.0.2 spec/transaction_spec.rb
lev-9.0.1 spec/transaction_spec.rb
lev-9.0.0 spec/transaction_spec.rb
lev-8.1.0 spec/transaction_spec.rb
lev-8.0.0 spec/transaction_spec.rb
lev-7.1.0 spec/transaction_spec.rb