Nested routes and database changes that are required
Basic home screen Model and controller tests coming along
This commit is contained in:
parent
bfd5d8533e
commit
b76375d086
@ -1,2 +1,3 @@
|
||||
<h1>Home#index</h1>
|
||||
<p>Find me in app/views/home/index.html.erb</p>
|
||||
<h1>OpenSMTPD User Admin</h1>
|
||||
|
||||
<%= link_to "Domains", domains_path %>
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
Rails.application.routes.draw do
|
||||
resources :credentials
|
||||
resources :virtuals
|
||||
resources :domains
|
||||
|
||||
resources :domains do
|
||||
resources :credentials
|
||||
resources :virtuals
|
||||
end
|
||||
|
||||
devise_for :users
|
||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||
|
||||
|
||||
8
db/migrate/20230621060115_add_domain_id_to_virtuals.rb
Normal file
8
db/migrate/20230621060115_add_domain_id_to_virtuals.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class AddDomainIdToVirtuals < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :virtuals, :domain_id, :integer
|
||||
add_column :credentials, :domain_id, :integer
|
||||
add_index :virtuals, :domain_id
|
||||
add_index :credentials, :domain_id
|
||||
end
|
||||
end
|
||||
6
db/schema.rb
generated
6
db/schema.rb
generated
@ -10,12 +10,14 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_05_10_184959) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_06_21_060115) do
|
||||
create_table "credentials", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
||||
t.string "email"
|
||||
t.string "password"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "domain_id"
|
||||
t.index ["domain_id"], name: "index_credentials_on_domain_id"
|
||||
end
|
||||
|
||||
create_table "domains", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
||||
@ -50,6 +52,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_10_184959) do
|
||||
t.string "destination"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "domain_id"
|
||||
t.index ["domain_id"], name: "index_virtuals_on_domain_id"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -8,6 +8,7 @@ class CredentialsControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get index" do
|
||||
get credentials_url
|
||||
assert_response :success
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
|
||||
@ -8,7 +8,7 @@ class DomainsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test "not should get index because we are not logged in" do
|
||||
get domains_url
|
||||
assert_response :success
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should get index because we are logged in" do
|
||||
@ -18,34 +18,71 @@ class DomainsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should not get new" do
|
||||
get new_domain_url
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
sign_in users(:bob)
|
||||
get new_domain_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should not create domain" do
|
||||
post domains_url, params: { domain: { domain: "brand-new-domain.com" } }
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should create domain" do
|
||||
sign_in users(:bob)
|
||||
assert_difference("Domain.count") do
|
||||
post domains_url, params: { domain: { domain: @domain.domain } }
|
||||
post domains_url, params: { domain: { domain: "brand-new-domain.com" } }
|
||||
end
|
||||
|
||||
assert_redirected_to domain_url(Domain.last)
|
||||
end
|
||||
|
||||
test "should show domain" do
|
||||
sign_in users(:bob)
|
||||
get domain_url(@domain)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should not show domain" do
|
||||
get domain_url(@domain)
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
sign_in users(:bob)
|
||||
get edit_domain_url(@domain)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should not get edit" do
|
||||
get edit_domain_url(@domain)
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
|
||||
test "should not update domain" do
|
||||
patch domain_url(@domain), params: { domain: { domain: @domain.domain } }
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should update domain" do
|
||||
sign_in users(:bob)
|
||||
patch domain_url(@domain), params: { domain: { domain: @domain.domain } }
|
||||
assert_redirected_to domain_url(@domain)
|
||||
end
|
||||
|
||||
test "should not destroy domain" do
|
||||
delete domain_url(@domain)
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should destroy domain" do
|
||||
sign_in users(:bob)
|
||||
assert_difference("Domain.count", -1) do
|
||||
delete domain_url(@domain)
|
||||
end
|
||||
|
||||
@ -1,7 +1,16 @@
|
||||
require "test_helper"
|
||||
|
||||
class HomeControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
include Devise::Test::IntegrationHelpers
|
||||
|
||||
test "when not logged in you will be redirected to the login page" do
|
||||
get root_path
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "when logged in you will be redirected to the home page" do
|
||||
sign_in users(:bob)
|
||||
get root_path
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
4
test/fixtures/users.yml
vendored
4
test/fixtures/users.yml
vendored
@ -11,3 +11,7 @@ bob:
|
||||
alice:
|
||||
email: "alice@example.org"
|
||||
encrypted_password: <= Devise::Encryptor.digest(User, 'password')
|
||||
|
||||
eve:
|
||||
email: "eve@example.org"
|
||||
encrypted_password: <= Devise::Encryptor.digest(User, 'password')
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
require "test_helper"
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
test "user must be unique" do
|
||||
# assert flunk
|
||||
end
|
||||
|
||||
test "test_name" do
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user