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

Unsuccessful tenant creation inside a rspec test messes with the transaction in which the test is executed. #214

Open
dlupu opened this issue Jan 24, 2023 · 1 comment

Comments

@dlupu
Copy link

dlupu commented Jan 24, 2023

Steps to reproduce

The problem only appears while running some tests. I've managed to reproduce the issue in a simple rspec test

require 'rails_helper'

RSpec.describe 'Apartment Bug Data' do

  it 'works' do
    pending("waiting for an official fix")
    Apartment::Tenant.create('test-schema')

    begin
       Apartment::Tenant.create('test-schema')
    rescue Apartment::TenantExists => e
      # something happens here with the transaction in which the test should be executed that will cause the error below
    end

    create(:model)  # breaks here (on any attempt to save a model into DB)
    # ActiveRecord::StatementInvalid: PG::NoActiveSqlTransaction: ERROR:  SAVEPOINT can only be used in transaction blocks
    # the console output says: WARNING:  there is no transaction in progress
  end
end

Expected behavior

The test should pass (aka the gem should not mess with the existing transaction).

Actual behavior

See the error above.

System configuration

rspec with config.use_transactional_fixtures = true

  • Database: (Tell us what database and its version you use.)

Postgresql 12

  • Apartment version:

the most recent version of ros-apartment gem:

GIT
remote: https://github.com/rails-on-services/apartment.git
revision: 7d626d1
branch: development
specs:
ros-apartment (2.11.0)
activerecord (>= 5.0.0, < 7.1)
parallel (< 2.0)
public_suffix (>= 2.0.5, < 5.0)
rack (>= 1.3.6, < 3.0)

  • Apartment config (in config/initializers/apartment.rb or so):

    • use_schemas: true
  • Rails (or ActiveRecord) version:

7.0.3.1

  • Ruby version:

3.2.0

@dlupu
Copy link
Author

dlupu commented Jan 24, 2023

Might be related to #123

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