mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 22:34:47 +00:00
* Implement dynamic role assignment for new family creators. Introduced `User.role_for_new_family_creator` to assign `super_admin` to the first user of an instance and a configurable fallback role (e.g., `admin`) to subsequent users. Updated controllers and tests accordingly. * Update default fallback role for family creators to admin. --------- Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
71 lines
2.1 KiB
Ruby
71 lines
2.1 KiB
Ruby
require "test_helper"
|
|
|
|
class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|
test "new" do
|
|
get new_registration_url
|
|
assert_response :success
|
|
end
|
|
|
|
test "create redirects to correct URL" do
|
|
post registration_url, params: { user: {
|
|
email: "john@example.com",
|
|
password: "Password1!" } }
|
|
|
|
assert_redirected_to root_url
|
|
end
|
|
|
|
test "first user of instance becomes super_admin" do
|
|
# Clear all users to simulate fresh instance
|
|
User.destroy_all
|
|
|
|
assert_difference "User.count", +1 do
|
|
post registration_url, params: { user: {
|
|
email: "firstuser@example.com",
|
|
password: "Password1!" } }
|
|
end
|
|
|
|
first_user = User.find_by(email: "firstuser@example.com")
|
|
assert first_user.super_admin?, "First user should be super_admin"
|
|
end
|
|
|
|
test "subsequent users become admin not super_admin" do
|
|
# Ensure users exist from fixtures
|
|
assert User.exists?
|
|
|
|
assert_difference "User.count", +1 do
|
|
post registration_url, params: { user: {
|
|
email: "seconduser@example.com",
|
|
password: "Password1!" } }
|
|
end
|
|
|
|
new_user = User.find_by(email: "seconduser@example.com")
|
|
assert new_user.admin?, "Subsequent user should be admin"
|
|
assert_not new_user.super_admin?, "Subsequent user should not be super_admin"
|
|
end
|
|
|
|
test "create when hosted requires an invite code" do
|
|
with_env_overrides REQUIRE_INVITE_CODE: "true" do
|
|
assert_no_difference "User.count" do
|
|
post registration_url, params: { user: {
|
|
email: "john@example.com",
|
|
password: "Password1!" } }
|
|
assert_redirected_to new_registration_url
|
|
|
|
post registration_url, params: { user: {
|
|
email: "john@example.com",
|
|
password: "Password1!",
|
|
invite_code: "foo" } }
|
|
assert_redirected_to new_registration_url
|
|
end
|
|
|
|
assert_difference "User.count", +1 do
|
|
post registration_url, params: { user: {
|
|
email: "john@example.com",
|
|
password: "Password1!",
|
|
invite_code: InviteCode.generate! } }
|
|
assert_redirected_to root_url
|
|
end
|
|
end
|
|
end
|
|
end
|