Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test actions wrapped in transaction with Hanami #12

Open
rybex opened this issue Jun 12, 2017 · 0 comments
Open

Test actions wrapped in transaction with Hanami #12

rybex opened this issue Jun 12, 2017 · 0 comments

Comments

@rybex
Copy link

rybex commented Jun 12, 2017

Hi,

I am using the hanami framework and the rspec lib to test my code and PG database. When I trying to test one action I get following error:

PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block

My action has been wrapped in repository transaction:

def call(params, dependencies)
    begin
      dependencies.repository.transaction do
        create_user(params, dependencies)
        assign_tags(params, dependencies)
        assign_notes(params, dependencies)
      end
    rescue Hanami::Model::Error, Domain::Errors::Exception => error
      raise Domain::Errors::CreateUserFailed, error.message
    end
  end

Here you can see part of my test which are failing:

it 'should raise exception if params contains duplicated email' do
expect{service.call(duplicated_email)}
  .to raise_exception(Domain::Errors::CreateUserFailed)
  .with_message('Duplicated values found (id or 
  email)')
end

it 'should raise exception if params contains duplicated note id' do
expect{service.call(duplicated_note_id)}
  .to raise_exception(Domain::Errors::CreateUserFailed)
end

First test pass but the second one raises exception I mentioned earlier. I know this is caused that previous test raised exception in transaction block. I tried to configure DB cleaner to fix this but without success.

RSpec.configure do |config|
  config.before(:suite) do
   DatabaseCleaner.clean_with :deletion
  end

  config.before(:each) do
   DatabaseCleaner.strategy = :transaction
  end

  config.before(:each) do
   DatabaseCleaner.start
  end

  config.after(:each) do
   DatabaseCleaner.clean
  end
end
@botandrose botandrose transferred this issue from DatabaseCleaner/database_cleaner Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant