Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Test actions wrapped in transaction with Hanami

Open
#12 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
postgresql, ruby
Domain
databases, testing

Research direction

Begin with the failing RSpec examples and the DatabaseCleaner before/after configuration shown; verify how the repository transaction interacts with the cleaner transaction and PostgreSQL's aborted state. Done means both duplicate-email and duplicate-note examples run independently without PG::InFailedSqlTransaction while retaining their expected exception assertions.

Written by the indexing model from the issue text.

Description

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
Dominant language
Ruby
Stars
76
Forks
76
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DatabaseCleaner/database_cleaner-active_record

All issues in DatabaseCleaner/database_cleaner-active_record

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.