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>
|
<h1>OpenSMTPD User Admin</h1>
|
||||||
<p>Find me in app/views/home/index.html.erb</p>
|
|
||||||
|
<%= link_to "Domains", domains_path %>
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
|
resources :domains do
|
||||||
resources :credentials
|
resources :credentials
|
||||||
resources :virtuals
|
resources :virtuals
|
||||||
resources :domains
|
end
|
||||||
|
|
||||||
devise_for :users
|
devise_for :users
|
||||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
# 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.
|
# 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|
|
create_table "credentials", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
||||||
t.string "email"
|
t.string "email"
|
||||||
t.string "password"
|
t.string "password"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "domain_id"
|
||||||
|
t.index ["domain_id"], name: "index_credentials_on_domain_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domains", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
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.string "destination"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,6 +8,7 @@ class CredentialsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
test "should get index" do
|
test "should get index" do
|
||||||
get credentials_url
|
get credentials_url
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get new" do
|
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
|
test "not should get index because we are not logged in" do
|
||||||
get domains_url
|
get domains_url
|
||||||
assert_response :success
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index because we are logged in" do
|
test "should get index because we are logged in" do
|
||||||
@ -18,34 +18,71 @@ class DomainsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should not get new" do
|
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
|
get new_domain_url
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
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
|
test "should create domain" do
|
||||||
|
sign_in users(:bob)
|
||||||
assert_difference("Domain.count") do
|
assert_difference("Domain.count") do
|
||||||
post domains_url, params: { domain: { domain: @domain.domain } }
|
post domains_url, params: { domain: { domain: "brand-new-domain.com" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to domain_url(Domain.last)
|
assert_redirected_to domain_url(Domain.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show domain" do
|
test "should show domain" do
|
||||||
|
sign_in users(:bob)
|
||||||
get domain_url(@domain)
|
get domain_url(@domain)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should not show domain" do
|
||||||
|
get domain_url(@domain)
|
||||||
|
assert_redirected_to new_user_session_path
|
||||||
|
end
|
||||||
|
|
||||||
test "should get edit" do
|
test "should get edit" do
|
||||||
|
sign_in users(:bob)
|
||||||
get edit_domain_url(@domain)
|
get edit_domain_url(@domain)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
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
|
test "should update domain" do
|
||||||
|
sign_in users(:bob)
|
||||||
patch domain_url(@domain), params: { domain: { domain: @domain.domain } }
|
patch domain_url(@domain), params: { domain: { domain: @domain.domain } }
|
||||||
assert_redirected_to domain_url(@domain)
|
assert_redirected_to domain_url(@domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should not destroy domain" do
|
||||||
|
delete domain_url(@domain)
|
||||||
|
assert_redirected_to new_user_session_path
|
||||||
|
end
|
||||||
|
|
||||||
test "should destroy domain" do
|
test "should destroy domain" do
|
||||||
|
sign_in users(:bob)
|
||||||
assert_difference("Domain.count", -1) do
|
assert_difference("Domain.count", -1) do
|
||||||
delete domain_url(@domain)
|
delete domain_url(@domain)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,16 @@
|
|||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class HomeControllerTest < ActionDispatch::IntegrationTest
|
class HomeControllerTest < ActionDispatch::IntegrationTest
|
||||||
# test "the truth" do
|
include Devise::Test::IntegrationHelpers
|
||||||
# assert true
|
|
||||||
# end
|
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
|
end
|
||||||
|
|||||||
4
test/fixtures/users.yml
vendored
4
test/fixtures/users.yml
vendored
@ -11,3 +11,7 @@ bob:
|
|||||||
alice:
|
alice:
|
||||||
email: "alice@example.org"
|
email: "alice@example.org"
|
||||||
encrypted_password: <= Devise::Encryptor.digest(User, 'password')
|
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"
|
require "test_helper"
|
||||||
|
|
||||||
class UserTest < ActiveSupport::TestCase
|
class UserTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
test "user must be unique" do
|
||||||
# assert true
|
# assert flunk
|
||||||
# end
|
end
|
||||||
|
|
||||||
|
test "test_name" do
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user