Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:21:56+00:00 2026-06-09T00:21:56+00:00

I am developing this Rails 3.2 application using the Apartment gem as middleware. The

  • 0

I am developing this Rails 3.2 application using the Apartment gem as middleware. The application itself works perfectly and all the RSpec examples also work perfectly when ran individually. However, when I run all the tests at the same time using the bundle exec rspec command, there are two examples that fail in two different controller specs and they do exactly the same thing. Here are the two examples in question:

In the issues_controller_spec.rb file:

describe "GET 'new'" do

  # ...

  context "for authenticated users" do
    before(:each) do
      controller.log_in(create(:user))
      get :new
    end

    # ...

    it "should create a new issue instance and put it in an instance variable" do
      assigns(:issue).should be_an_instance_of Issue
    end
  end
end

In the users_controller_spec.rb file:

describe "GET 'new'" do

    # ...

  context "for authenticated users" do

      # ...

    context "for admin users" do
      before(:each) do
        admin = create(:admin)
        admin.add_role :admin
        controller.log_in(admin)
        get :new
      end

      # ...

      it "should create a new User instance and put it in an instance variable" do
        assigns(:user).should be_an_instance_of User
      end
    end
  end
end

These two examples are affected by a before hook:

before(:each) do
  client = create(:client)
  @request.host = "#{client.account_name}.lvh.me"
end

When creating a new Client, there is an after_create callback:

# Create the client database (Apartment) for multi-tenancy
def create_client_database
  begin
    Apartment::Database.create(self.account_name)
  rescue Apartment::SchemaExists
    return
  rescue
    self.destroy
  end
end

And there is where the examples fail. Now if I remove the begin...rescue...end block and keep the line Apartment::Database.create(self.account_name) I get the following exception in the failling examples:

ActiveRecord::StatementInvalid:
   PG::Error: ERROR:  current transaction is aborted, commands ignored until end of transaction block
   : SET search_path TO public

Again, if I run the examples individually, they pass but if I run all the examples, the two examples above fail.

Does anyone know what I am doing wrong please?

Note: The whole application code can be found here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:21:58+00:00Added an answer on June 9, 2026 at 12:21 am

    I solved this problem by wrapping the line client = create(:client) in a begin, rescue, end block like so:

    before(:each) do
      begin
        client = create(:client)
      rescue
        client = Client.create!(attributes_for(:client))
      end
    
      @request.host = "#{client.account_name}.lvh.me"
    end
    

    I don’t know how or why this works but I know it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an application using rails 2.3.5, gitorious and deploy with vlad, the OS
I am considering developing an application using Ruby on Rails that is a planner
I am developing an application in Rails 3 using a nosql database. I am
I am developing a facebook application in Ruby on Rails using MongoDB as database.
I am developing a Ruby on Rails application, and using the foreigner plugin to
I'm developing a web application using rails. For aesthetic purposes, i need to replace
I started developing my rails application using sqlite. I have reached a point where
I'm currently developing a Rails application to accept recurring billing using Chargify. I've installed
I am developing a web-based application using Rails. I am debating between using a
I'm developing this website: http://parkoura.tk/a/sandbox/ I am using an ajax navigation. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.