diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index 2085730..e10ccc1 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -1,2 +1,3 @@
-
Home#index
-Find me in app/views/home/index.html.erb
+OpenSMTPD User Admin
+
+<%= link_to "Domains", domains_path %>
diff --git a/config/routes.rb b/config/routes.rb
index 8047b0c..4c0b7eb 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/db/migrate/20230621060115_add_domain_id_to_virtuals.rb b/db/migrate/20230621060115_add_domain_id_to_virtuals.rb
new file mode 100644
index 0000000..2cfa529
--- /dev/null
+++ b/db/migrate/20230621060115_add_domain_id_to_virtuals.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 92a327b..808319f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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
diff --git a/test/controllers/credentials_controller_test.rb b/test/controllers/credentials_controller_test.rb
index 2c8d856..4f11874 100644
--- a/test/controllers/credentials_controller_test.rb
+++ b/test/controllers/credentials_controller_test.rb
@@ -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
diff --git a/test/controllers/domains_controller_test.rb b/test/controllers/domains_controller_test.rb
index 902e221..46f501d 100644
--- a/test/controllers/domains_controller_test.rb
+++ b/test/controllers/domains_controller_test.rb
@@ -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
diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb
index eac0e33..a603f17 100644
--- a/test/controllers/home_controller_test.rb
+++ b/test/controllers/home_controller_test.rb
@@ -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
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
index 22312d9..5d928d1 100644
--- a/test/fixtures/users.yml
+++ b/test/fixtures/users.yml
@@ -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')
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
index 5c07f49..428c06d 100644
--- a/test/models/user_test.rb
+++ b/test/models/user_test.rb
@@ -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