Hack in registration prevention #37
3 changed files with 28 additions and 13 deletions
|
@ -17,6 +17,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "should create user" do
|
||||
stub_environment(REGISTRATION_ALLOWED: "true") do
|
||||
assert_difference("User.count") do
|
||||
params = {
|
||||
user: {
|
||||
|
@ -27,6 +28,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
|||
}
|
||||
post users_url, params: params
|
||||
end
|
||||
end
|
||||
|
||||
assert_redirected_to user_url(User.last)
|
||||
end
|
||||
|
|
|
@ -15,12 +15,14 @@ class UsersTest < ApplicationSystemTestCase
|
|||
visit users_url
|
||||
click_on "Sign up"
|
||||
|
||||
stub_environment(REGISTRATION_ALLOWED: "true") do
|
||||
fill_in "Email", with: "userthree@example.local"
|
||||
fill_in "Password", with: "secret"
|
||||
fill_in "Password confirmation", with: "secret"
|
||||
click_on "Create User"
|
||||
|
||||
assert_text "User was successfully created"
|
||||
end
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
|
|
|
@ -14,4 +14,15 @@ class ActiveSupport::TestCase
|
|||
post sessions_url, params: { session: { email: email, password: password } }
|
||||
assert session[:current_user_id].present?
|
||||
end
|
||||
|
||||
def stub_environment(env)
|
||||
old_env = ENV.to_hash
|
||||
ENV.update(env.stringify_keys)
|
||||
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
ENV.replace(old_env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue