More tests

Only one user can sign in - until this becomes multiuser
This commit is contained in:
Jez Caudle 2024-05-14 18:53:34 +01:00
parent ae7846e46e
commit 4c63480a1f
5 changed files with 23 additions and 3 deletions

View File

@ -0,0 +1,17 @@
class RegistrationsController < Devise::RegistrationsController
before_action :one_user_registered?, only: [:new, :create]
protected
def one_user_registered?
if User.count == 1
if user_signed_in?
redirect_to root_path
else
redirect_to new_user_session_path
end
end
end
end

View File

@ -23,3 +23,5 @@
<%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %><br />
<% end %>
<% end %>

View File

@ -31,7 +31,6 @@
<hr/>
<h3>To-Do (In order of importance):</h3>
<ul>
<li>Blocking Sign-up at Routes level</li>
<li>Tests for controllers and integration</li>
<li>2FA</li>
</ul>

View File

@ -2,10 +2,11 @@ Rails.application.routes.draw do
resources :domains do
resources :credentials, only: [ :new, :create, :edit, :update, :destroy]
resources :virtuals
resources :virtuals, only: [ :new, :create, :edit, :update, :destroy]
end
devise_for :users
devise_for :users, controllers: { registrations: "registrations" }
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")

View File

@ -3,6 +3,7 @@ require "test_helper"
class VirtualsControllerTest < ActionDispatch::IntegrationTest
setup do
@virtual = virtuals(:one)
@domain = doamins(:one)
end
test "should get index" do