Sha256: ae298f0368e95a2264c9e0d2bc2f5ccbcb4804f5e6bca196348559828ff448d9

Contents?: true

Size: 1.2 KB

Versions: 12

Compression:

Stored size: 1.2 KB

Contents

require 'tasks/database'
require 'rack/pact_broker/database_transaction'

module Rack
  module PactBroker
    describe DatabaseTransaction, no_db_clean: true do

      before do
        ::PactBroker::Database.truncate
      end

      after do
        ::PactBroker::Database.truncate
      end

      let(:api) do
        ->(env) { ::PactBroker::Domain::Pacticipant.create(name: 'Foo'); [500, {}, []] }
      end

      let(:api_with_transaction) do
        ::Rack::PactBroker::DatabaseTransaction.new(api, ::PactBroker::DB.connection)
      end

      subject { self.send(http_method, "/") }

      context "for get requests" do
        let(:app) { api_with_transaction }

        let(:http_method) { :get }
        it "does not use a transaction" do
          expect { subject }.to change { ::PactBroker::Domain::Pacticipant.count }.by(1)
        end
      end

      [:post, :put, :patch, :delete].each do | http_meth |
        let(:http_method) { http_meth }
        context "for #{http_meth} requests" do
          it "uses a transaction and rollsback if there is a 500 error" do
            expect { subject }.to change { ::PactBroker::Domain::Pacticipant.count }.by(0)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.4.2 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.4.1 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.4.0 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.3.0 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.2.0 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.1.1 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.1.0 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.0.5 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.0.4 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.0.3 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.0.2 spec/lib/rack/pact_broker/database_transaction_spec.rb
pact_broker-2.0.1 spec/lib/rack/pact_broker/database_transaction_spec.rb