Fix tests after the removal of memberships

This commit is contained in:
Stanko K.R.
2025-11-13 16:58:17 +01:00
committed by Mike Dalessio
parent 8fa9566c07
commit 34d83aaa7c
27 changed files with 84 additions and 360 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
end
test "update all access" do
board = Current.set(session: sessions(:kevin)) do
board = Current.set(account: accounts("37s"), session: sessions(:kevin), user: users(:kevin)) do
Board.create! name: "New board", all_access: false
end
assert_equal [ users(:kevin) ], board.users
@@ -36,7 +36,7 @@ class JoinCodesControllerTest < ActionDispatch::IntegrationTest
test "create" do
untenanted do
assert_difference -> { Identity.count }, 1 do
assert_difference -> { Membership.count }, 1 do
assert_difference -> { User.count }, 1 do
post join_path(tenant: @tenant, code: @join_code.code), params: { email_address: "new_user@example.com" }
end
end
@@ -52,7 +52,7 @@ class JoinCodesControllerTest < ActionDispatch::IntegrationTest
untenanted do
assert_no_difference -> { Identity.count } do
assert_no_difference -> { Membership.count } do
assert_no_difference -> { User.count } do
post join_path(tenant: @tenant, code: @join_code.code), params: { email_address: identity.email_address }
end
end
@@ -1,42 +0,0 @@
require "test_helper"
class Memberships::EmailAddresses::ConfirmationsControllerTest < ActionDispatch::IntegrationTest
test "show" do
untenanted do
membership = memberships(:kevin_in_37signals)
get email_address_confirmation_path(
membership_id: membership.id,
email_address_token: "dummy_token"
)
assert_response :success
end
end
test "create" do
untenanted do
membership = memberships(:kevin_in_37signals)
old_identity = membership.identity
new_email = "updated@example.com"
# Generate a real token
token = membership.send(:generate_email_address_change_token, to: new_email)
assert_difference -> { Identity.count }, 1 do
post email_address_confirmation_path(
membership_id: membership.id,
email_address_token: token
),
params: { email_address_token: token }
end
membership.reload
assert_equal new_email, membership.identity.email_address
assert_not_equal old_identity.id, membership.identity_id
assert cookies[:session_token].present?, "Should have started new session"
assert_redirected_to edit_user_url(script_name: "/#{membership.tenant}", id: membership.user)
end
end
end
@@ -1,43 +0,0 @@
require "test_helper"
class Memberships::EmailAddressesControllerTest < ActionDispatch::IntegrationTest
test "new" do
untenanted do
sign_in_as :kevin
membership = memberships(:kevin_in_37signals)
get new_email_address_path(membership_id: membership.id)
assert_response :success
end
end
test "create" do
untenanted do
sign_in_as :kevin
membership = memberships(:kevin_in_37signals)
assert_enqueued_emails 1 do
post email_addresses_path(membership_id: membership.id),
params: { email_address: "newemail@example.com" }
end
assert_response :success
end
end
test "create with an email for someone already in the account" do
untenanted do
sign_in_as :kevin
membership = memberships(:kevin_in_37signals)
post email_addresses_path(membership_id: membership.id),
params: { email_address: identities(:david).email_address }
assert_redirected_to new_email_address_path
assert_equal "You already have a user in this account with that email address", flash[:alert]
end
end
end
@@ -7,7 +7,7 @@ class Sessions::MenusControllerTest < ActionDispatch::IntegrationTest
test "show with no memberships" do
sign_in_as @identity
@identity.memberships.delete_all
@identity.users.delete_all
untenanted do
get session_menu_url
@@ -18,22 +18,25 @@ class Sessions::MenusControllerTest < ActionDispatch::IntegrationTest
test "show with exactly one membership" do
sign_in_as @identity
@identity.memberships.delete_all
@identity.memberships.create(tenant: "37signals")
@identity.users.delete_all
account = Account.create!(external_account_id: 9999991, name: "Test Account")
@identity.users.create!(account: account, name: "Kevin")
untenanted do
get session_menu_url
end
assert_response :redirect
assert_redirected_to root_url(script_name: "/37signals")
assert_redirected_to root_url(script_name: "/9999991")
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")
@identity.users.delete_all
account1 = Account.create!(external_account_id: 9999992, name: "37signals")
account2 = Account.create!(external_account_id: 9999993, name: "Acme")
@identity.users.create!(account: account1, name: "Kevin")
@identity.users.create!(account: account2, name: "Kevin")
untenanted do
get session_menu_url
@@ -42,28 +45,4 @@ class Sessions::MenusControllerTest < ActionDispatch::IntegrationTest
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