diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 3088a06c2..511699f4b 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -107,7 +107,7 @@ end # Setup a custom Tenant switching middleware. The Proc should return the name of the Tenant that # you want to switch to. -Rails.application.config.middleware.use Apartment::Elevators::Generic, ->(request) do +Rails.application.config.middleware.insert_before Warden::Manager, Apartment::Elevators::Generic, ->(request) do Tenant.resolve_host(request.host) end diff --git a/spec/system/multitenancy_spec.rb b/spec/system/multitenancy_spec.rb index dd1f25e84..45f6d473f 100644 --- a/spec/system/multitenancy_spec.rb +++ b/spec/system/multitenancy_spec.rb @@ -156,4 +156,17 @@ describe "Multitenancy", :seed_tenants do expect(page).to have_content "Invalid Email or username or password." end end + + scenario "Uses the right tenant after failing to sign in" do + with_subdomain("mars") do + visit new_user_session_path + fill_in "Email or username", with: "wrong@consul.dev" + fill_in "Password", with: "wrong" + click_button "Enter" + + expect(page).to have_content "Invalid Email or username or password" + expect(page).to have_css "html.tenant-mars" + expect(page).not_to have_css "html.tenant-public" + end + end end