Skip the menu screen if there is just one account
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
class Sessions::MenusController < ApplicationController
|
||||
require_untenanted_access
|
||||
|
||||
before_action(if: :render_as_menu_section?) { request.variant = :menu_section }
|
||||
|
||||
layout "public"
|
||||
|
||||
def show
|
||||
if params[:menu_section]
|
||||
request.variant = :menu_section
|
||||
end
|
||||
|
||||
@memberships = Current.identity.memberships
|
||||
|
||||
if params[:without]
|
||||
@memberships = @memberships.where.not(tenant: params[:without])
|
||||
end
|
||||
|
||||
if @memberships.one? && !render_as_menu_section?
|
||||
redirect_to root_url(script_name: "/#{@memberships.first.tenant}")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def render_as_menu_section?
|
||||
params[:menu_section]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,69 @@
|
||||
require "test_helper"
|
||||
|
||||
class Sessions::MenusControllerTest < ActionDispatch::IntegrationTest
|
||||
test "show" do
|
||||
setup do
|
||||
@identity = identities(:kevin)
|
||||
end
|
||||
|
||||
test "show with no memberships" do
|
||||
sign_in_as @identity
|
||||
@identity.memberships.delete_all
|
||||
|
||||
untenanted do
|
||||
sign_in_as :kevin
|
||||
|
||||
get session_menu_url
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
assert_response :success, "Renders an empty menu"
|
||||
end
|
||||
|
||||
test "show with exactly one membership" do
|
||||
sign_in_as @identity
|
||||
@identity.memberships.delete_all
|
||||
@identity.memberships.create(tenant: "37signals")
|
||||
|
||||
untenanted do
|
||||
get session_menu_url
|
||||
end
|
||||
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_url(script_name: "/37signals")
|
||||
end
|
||||
|
||||
test "show with multiple memeberships" do
|
||||
sign_in_as @identity
|
||||
@identity.memberships.delete_all
|
||||
@identity.memberships.create(tenant: "37signals")
|
||||
@identity.memberships.create(tenant: "acme")
|
||||
|
||||
untenanted do
|
||||
get session_menu_url
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "show renders as a menu section" do
|
||||
sign_in_as @identity
|
||||
@identity.memberships.delete_all
|
||||
@identity.memberships.create(tenant: "37signals")
|
||||
@identity.memberships.create(tenant: "acme")
|
||||
|
||||
untenanted do
|
||||
get session_menu_url menu_section: true
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "show doesn't redirect when rendered as a menu section" do
|
||||
sign_in_as @identity
|
||||
@identity.memberships.delete_all
|
||||
@identity.memberships.create(tenant: "37signals")
|
||||
|
||||
untenanted do
|
||||
get session_menu_url menu_section: true
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,8 +50,7 @@ class SmokeTest < ApplicationSystemTestCase
|
||||
private
|
||||
def sign_in_as(user)
|
||||
visit session_transfer_url(user.identity.transfer_id, script_name: nil)
|
||||
click_on ApplicationRecord.with_tenant(user.tenant) { Account.sole.name }
|
||||
assert_selector "h1", text: "Writebook"
|
||||
assert_selector "h1", text: "Latest Activity"
|
||||
end
|
||||
|
||||
def fill_in_lexxy(selector = "lexxy-editor", with:)
|
||||
|
||||
Reference in New Issue
Block a user