Try a different method of stopping sign_ups
This commit is contained in:
parent
4c63480a1f
commit
be035f9e31
@ -1,10 +1,10 @@
|
|||||||
class RegistrationsController < Devise::RegistrationsController
|
class RegistrationsController < Devise::RegistrationsController
|
||||||
|
|
||||||
before_action :one_user_registered?, only: [:new, :create]
|
before_action :one_user_registered, only: [:new, :create]
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def one_user_registered?
|
def one_user_registered
|
||||||
if User.count == 1
|
if User.count == 1
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
<li><%= link_to "Edit account", edit_user_registration_path %></li>
|
<li><%= link_to "Edit account", edit_user_registration_path %></li>
|
||||||
<li><%= button_to "Log out", destroy_user_session_path, method: :delete %></li><% end %>
|
<li><%= button_to "Log out", destroy_user_session_path, method: :delete %></li><% end %>
|
||||||
</menu>
|
</menu>
|
||||||
|
<br/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,41 @@
|
|||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class VirtualsControllerTest < ActionDispatch::IntegrationTest
|
class VirtualsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
include Devise::Test::IntegrationHelpers
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@virtual = virtuals(:one)
|
@virtual = virtuals(:one)
|
||||||
@domain = doamins(:one)
|
@domain = domains(:one)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test "should get not get new because we are not logged in" do
|
||||||
get virtuals_url
|
get new_domain_virtual_url(@domain)
|
||||||
|
assert_redirected_to new_user_session_path
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new because we are logged in" do
|
||||||
|
sign_in users(:bob)
|
||||||
|
get new_domain_virtual_url(@domain)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get new" do
|
test "should not create virtual because we are not logged in" do
|
||||||
get new_virtual_url
|
assert_no_difference("Virtual.count") do
|
||||||
assert_response :success
|
post domain_virtuals_url(@domain), params: { virtual: { destination: @virtual.destination, email: @virtual.email } }
|
||||||
end
|
|
||||||
|
|
||||||
test "should create virtual" do
|
|
||||||
assert_difference("Virtual.count") do
|
|
||||||
post virtuals_url, params: { virtual: { destination: @virtual.destination, email: @virtual.email } }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to virtual_url(Virtual.last)
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should create virtual because we are logged in" do
|
||||||
|
sign_in users(:bob)
|
||||||
|
assert_difference("Virtual.count") do
|
||||||
|
post domain_virtuals_url(@domain), params: { virtual: { destination: @virtual.destination, email: @virtual.email } }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to domain_path(@domain.id)
|
||||||
|
end
|
||||||
|
=begin
|
||||||
test "should show virtual" do
|
test "should show virtual" do
|
||||||
get virtual_url(@virtual)
|
get virtual_url(@virtual)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
@ -46,4 +58,5 @@ class VirtualsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
assert_redirected_to virtuals_url
|
assert_redirected_to virtuals_url
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user