From 4c8123ee2f18ab78ac246e37fb9379cabd35e37b Mon Sep 17 00:00:00 2001 From: Ivan Schneider Date: Fri, 20 Oct 2023 10:51:52 +0200 Subject: [PATCH] Create and access multiple accounts --- app/views/layouts/_menu.slim | 18 ++++++++---------- test/integration/setup_test.rb | 31 ++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/app/views/layouts/_menu.slim b/app/views/layouts/_menu.slim index 7af5ca97..6d4088a4 100644 --- a/app/views/layouts/_menu.slim +++ b/app/views/layouts/_menu.slim @@ -1,23 +1,21 @@ ul.nav.navbar-nav.navbar-right - - if current_user.nil? && current_account.nil? + - if current_user.nil? li= link_to 'Sign in', new_session_path - else li.dropdown a.apps-list.dropdown-toggle data-toggle="dropdown" href="#" ' Signed in as - b = current_user&.name || current_user&.email || 'heroku admin' + b= current_user.name || current_user.email b.caret< - ul.dropdown-menu.accounts-menu - li - a Loading... + ul.dropdown-menu + - current_user.accounts.each do |account| + li= link_to account.name, switch_account_session_path(account_id: account.id) + - if admin? + li= link_to 'New database connection', new_account_path li.divider - if admin? && current_account li= link_to 'Account settings', edit_account_path li= link_to 'Roles and permissions', roles_path li= link_to 'Collaborators', collaborators_path li= link_to 'Sign out', signout_path - li.dropdown - a.dropdown-toggle data-toggle="dropdown" href="#" - i.fa.fa-question-circle - ul.dropdown-menu - li= link_to 'Docs', docs_path + li= link_to 'Docs', docs_path diff --git a/test/integration/setup_test.rb b/test/integration/setup_test.rb index 60010460..d511bbb9 100644 --- a/test/integration/setup_test.rb +++ b/test/integration/setup_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class SetupTest < ActionDispatch::IntegrationTest - test 'sign up and setup account' do + test 'sign up and setup account then invite collaborators' do add_virtual_authenticator visit root_path click_on 'Sign up' @@ -67,6 +67,35 @@ class SetupTest < ActionDispatch::IntegrationTest end end + test 'sign up and setup two accounts' do + add_virtual_authenticator + visit root_path + click_on 'Sign up' + fill_in 'Email', with: 'joe@mail.com' + click_on 'Sign up' + fill_in 'Database name', with: 'adminium-fixture' + click_on 'Create' + fill_in 'postgresql://user:password@host/database', with: Rails.configuration.test_database_conn_spec + click_on 'Connect' + click_on 'Close' + assert has_link?('comments') + click_on 'Signed in as joe@mail.com' + click_on 'New database connection' + fill_in 'Database name', with: 'adminium-test' + click_on 'Create' + spec = ActiveRecord::Base.connection_db_config.configuration_hash + url ="#{spec[:adapter]}://#{spec[:username]}:#{spec[:password]}@#{spec[:host]}/#{spec[:database]}" + fill_in 'postgresql://user:password@host/database', with: url + click_on 'Connect' + click_on 'Close' + assert has_link?('accounts') + assert has_no_link?('comments') + click_on 'Signed in as joe@mail.com' + click_on 'adminium-fixture' + assert has_link?('comments') + assert has_no_link?('accounts') + end + def add_virtual_authenticator options = { protocol: :ctap2, transport: :internal, hasResidentKey: false, hasUserVerification: true, isUserVerified: true } page.driver.browser.add_virtual_authenticator options