2024-02-02 17:49:28 -06:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
test "new" do
|
|
|
|
get new_registration_url
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2024-03-07 19:15:50 +01:00
|
|
|
test "create redirects to correct URL" do
|
2024-02-02 17:49:28 -06:00
|
|
|
post registration_url, params: { user: {
|
|
|
|
email: "john@example.com",
|
|
|
|
password: "password",
|
|
|
|
password_confirmation: "password" } }
|
|
|
|
|
|
|
|
assert_redirected_to root_url
|
|
|
|
end
|
2024-03-07 19:15:50 +01:00
|
|
|
|
|
|
|
test "create seeds default transaction categories" do
|
|
|
|
assert_difference "Transaction::Category.count", Transaction::Category::DEFAULT_CATEGORIES.size do
|
|
|
|
post registration_url, params: { user: {
|
|
|
|
email: "john@example.com",
|
|
|
|
password: "password",
|
|
|
|
password_confirmation: "password" } }
|
|
|
|
end
|
|
|
|
end
|
2024-02-02 17:49:28 -06:00
|
|
|
|
2024-02-02 19:37:10 -06:00
|
|
|
test "create when hosted requires an invite code" do
|
2024-04-13 09:28:45 -04:00
|
|
|
in_invited_app do
|
2024-02-02 19:48:45 -06:00
|
|
|
assert_no_difference "User.count" do
|
|
|
|
post registration_url, params: { user: {
|
|
|
|
email: "john@example.com",
|
|
|
|
password: "password",
|
|
|
|
password_confirmation: "password" } }
|
|
|
|
assert_redirected_to new_registration_url
|
2024-02-02 17:49:28 -06:00
|
|
|
|
2024-02-02 19:48:45 -06:00
|
|
|
post registration_url, params: { user: {
|
|
|
|
email: "john@example.com",
|
|
|
|
password: "password",
|
|
|
|
password_confirmation: "password",
|
|
|
|
invite_code: "foo" } }
|
|
|
|
assert_redirected_to new_registration_url
|
|
|
|
end
|
2024-02-02 17:49:28 -06:00
|
|
|
|
2024-02-02 19:48:45 -06:00
|
|
|
assert_difference "User.count", +1 do
|
|
|
|
post registration_url, params: { user: {
|
|
|
|
email: "john@example.com",
|
|
|
|
password: "password",
|
|
|
|
password_confirmation: "password",
|
|
|
|
invite_code: InviteCode.generate! } }
|
|
|
|
assert_redirected_to root_url
|
|
|
|
end
|
2024-02-02 17:49:28 -06:00
|
|
|
end
|
2024-02-02 19:48:45 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-04-13 09:28:45 -04:00
|
|
|
def in_invited_app
|
|
|
|
ENV["REQUIRE_INVITE_CODE"] = "true"
|
2024-02-02 19:48:45 -06:00
|
|
|
yield
|
2024-02-02 17:49:28 -06:00
|
|
|
ensure
|
2024-04-13 09:28:45 -04:00
|
|
|
ENV["REQUIRE_INVITE_CODE"] = nil
|
2024-02-02 17:49:28 -06:00
|
|
|
end
|
|
|
|
end
|