Added doamins

This commit is contained in:
Jez Caudle 2023-05-10 14:29:15 +01:00
parent 1b08798306
commit 843b510395
22 changed files with 304 additions and 5 deletions

View File

@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_action :authenticate_user!
end end

View File

@ -0,0 +1,70 @@
class DomainsController < ApplicationController
before_action :set_domain, only: %i[ show edit update destroy ]
# GET /domains or /domains.json
def index
@domains = Domain.all
end
# GET /domains/1 or /domains/1.json
def show
end
# GET /domains/new
def new
@domain = Domain.new
end
# GET /domains/1/edit
def edit
end
# POST /domains or /domains.json
def create
@domain = Domain.new(domain_params)
respond_to do |format|
if @domain.save
format.html { redirect_to domain_url(@domain), notice: "Domain was successfully created." }
format.json { render :show, status: :created, location: @domain }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @domain.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /domains/1 or /domains/1.json
def update
respond_to do |format|
if @domain.update(domain_params)
format.html { redirect_to domain_url(@domain), notice: "Domain was successfully updated." }
format.json { render :show, status: :ok, location: @domain }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @domain.errors, status: :unprocessable_entity }
end
end
end
# DELETE /domains/1 or /domains/1.json
def destroy
@domain.destroy
respond_to do |format|
format.html { redirect_to domains_url, notice: "Domain was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_domain
@domain = Domain.find(params[:id])
end
# Only allow a list of trusted parameters through.
def domain_params
params.require(:domain).permit(:domain)
end
end

View File

@ -0,0 +1,2 @@
module DomainsHelper
end

2
app/models/domain.rb Normal file
View File

@ -0,0 +1,2 @@
class Domain < ApplicationRecord
end

View File

@ -0,0 +1,7 @@
<div id="<%= dom_id domain %>">
<p>
<strong>Domain:</strong>
<%= domain.domain %>
</p>
</div>

View File

@ -0,0 +1,2 @@
json.extract! domain, :id, :domain, :created_at, :updated_at
json.url domain_url(domain, format: :json)

View File

@ -0,0 +1,22 @@
<%= form_with(model: domain) do |form| %>
<% if domain.errors.any? %>
<div style="color: red">
<h2><%= pluralize(domain.errors.count, "error") %> prohibited this domain from being saved:</h2>
<ul>
<% domain.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= form.label :domain, style: "display: block" %>
<%= form.text_field :domain %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>

View File

@ -0,0 +1,10 @@
<h1>Editing domain</h1>
<%= render "form", domain: @domain %>
<br>
<div>
<%= link_to "Show this domain", @domain %> |
<%= link_to "Back to domains", domains_path %>
</div>

View File

@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>
<h1>Domains</h1>
<div id="domains">
<% @domains.each do |domain| %>
<%= render domain %>
<p>
<%= link_to "Show this domain", domain %>
</p>
<% end %>
</div>
<%= link_to "New domain", new_domain_path %>

View File

@ -0,0 +1 @@
json.array! @domains, partial: "domains/domain", as: :domain

View File

@ -0,0 +1,9 @@
<h1>New domain</h1>
<%= render "form", domain: @domain %>
<br>
<div>
<%= link_to "Back to domains", domains_path %>
</div>

View File

@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>
<%= render @domain %>
<div>
<%= link_to "Edit this domain", edit_domain_path(@domain) %> |
<%= link_to "Back to domains", domains_path %>
<%= button_to "Destroy this domain", @domain, method: :delete %>
</div>

View File

@ -0,0 +1 @@
json.partial! "domains/domain", domain: @domain

View File

@ -14,19 +14,19 @@ default: &default
encoding: utf8mb4 encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root username: root
password: password: password
host: localhost host: localhost
development: development:
<<: *default <<: *default
database: opensmtpd_rails_frontend_development database: opensmtpd_dev
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
<<: *default <<: *default
database: opensmtpd_rails_frontend_test database: opensmtpd_test
# As with config/credentials.yml, you never want to store sensitive information, # As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is # like your database password, in your source code. If your source code is
@ -50,6 +50,6 @@ test:
# #
production: production:
<<: *default <<: *default
database: opensmtpd_rails_frontend_production database: opensmtpd
username: opensmtpd_rails_frontend username: opensmtpd
password: <%= ENV["OPENSMTPD_RAILS_FRONTEND_DATABASE_PASSWORD"] %> password: <%= ENV["OPENSMTPD_RAILS_FRONTEND_DATABASE_PASSWORD"] %>

View File

@ -1,4 +1,5 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resources :domains
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

View File

@ -0,0 +1,9 @@
class CreateDomains < ActiveRecord::Migration[7.0]
def change
create_table :domains do |t|
t.string :domain
t.timestamps
end
end
end

35
db/schema.rb generated Normal file
View File

@ -0,0 +1,35 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_05_10_075444) do
create_table "users", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end
end

View File

@ -0,0 +1,48 @@
require "test_helper"
class DomainsControllerTest < ActionDispatch::IntegrationTest
setup do
@domain = domains(:one)
end
test "should get index" do
get domains_url
assert_response :success
end
test "should get new" do
get new_domain_url
assert_response :success
end
test "should create domain" do
assert_difference("Domain.count") do
post domains_url, params: { domain: { domain: @domain.domain } }
end
assert_redirected_to domain_url(Domain.last)
end
test "should show domain" do
get domain_url(@domain)
assert_response :success
end
test "should get edit" do
get edit_domain_url(@domain)
assert_response :success
end
test "should update domain" do
patch domain_url(@domain), params: { domain: { domain: @domain.domain } }
assert_redirected_to domain_url(@domain)
end
test "should destroy domain" do
assert_difference("Domain.count", -1) do
delete domain_url(@domain)
end
assert_redirected_to domains_url
end
end

7
test/fixtures/domains.yml vendored Normal file
View File

@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
domain: MyString
two:
domain: MyString

View File

@ -0,0 +1,7 @@
require "test_helper"
class DomainTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,41 @@
require "application_system_test_case"
class DomainsTest < ApplicationSystemTestCase
setup do
@domain = domains(:one)
end
test "visiting the index" do
visit domains_url
assert_selector "h1", text: "Domains"
end
test "should create domain" do
visit domains_url
click_on "New domain"
fill_in "Domain", with: @domain.domain
click_on "Create Domain"
assert_text "Domain was successfully created"
click_on "Back"
end
test "should update Domain" do
visit domain_url(@domain)
click_on "Edit this domain", match: :first
fill_in "Domain", with: @domain.domain
click_on "Update Domain"
assert_text "Domain was successfully updated"
click_on "Back"
end
test "should destroy Domain" do
visit domain_url(@domain)
click_on "Destroy this domain", match: :first
assert_text "Domain was successfully destroyed"
end
end