Added doamins
This commit is contained in:
parent
1b08798306
commit
843b510395
@ -1,2 +1,3 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
before_action :authenticate_user!
|
||||||
end
|
end
|
||||||
|
|||||||
70
app/controllers/domains_controller.rb
Normal file
70
app/controllers/domains_controller.rb
Normal 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
|
||||||
2
app/helpers/domains_helper.rb
Normal file
2
app/helpers/domains_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module DomainsHelper
|
||||||
|
end
|
||||||
2
app/models/domain.rb
Normal file
2
app/models/domain.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class Domain < ApplicationRecord
|
||||||
|
end
|
||||||
7
app/views/domains/_domain.html.erb
Normal file
7
app/views/domains/_domain.html.erb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<div id="<%= dom_id domain %>">
|
||||||
|
<p>
|
||||||
|
<strong>Domain:</strong>
|
||||||
|
<%= domain.domain %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
2
app/views/domains/_domain.json.jbuilder
Normal file
2
app/views/domains/_domain.json.jbuilder
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
json.extract! domain, :id, :domain, :created_at, :updated_at
|
||||||
|
json.url domain_url(domain, format: :json)
|
||||||
22
app/views/domains/_form.html.erb
Normal file
22
app/views/domains/_form.html.erb
Normal 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 %>
|
||||||
10
app/views/domains/edit.html.erb
Normal file
10
app/views/domains/edit.html.erb
Normal 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>
|
||||||
14
app/views/domains/index.html.erb
Normal file
14
app/views/domains/index.html.erb
Normal 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 %>
|
||||||
1
app/views/domains/index.json.jbuilder
Normal file
1
app/views/domains/index.json.jbuilder
Normal file
@ -0,0 +1 @@
|
|||||||
|
json.array! @domains, partial: "domains/domain", as: :domain
|
||||||
9
app/views/domains/new.html.erb
Normal file
9
app/views/domains/new.html.erb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<h1>New domain</h1>
|
||||||
|
|
||||||
|
<%= render "form", domain: @domain %>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= link_to "Back to domains", domains_path %>
|
||||||
|
</div>
|
||||||
10
app/views/domains/show.html.erb
Normal file
10
app/views/domains/show.html.erb
Normal 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>
|
||||||
1
app/views/domains/show.json.jbuilder
Normal file
1
app/views/domains/show.json.jbuilder
Normal file
@ -0,0 +1 @@
|
|||||||
|
json.partial! "domains/domain", domain: @domain
|
||||||
@ -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"] %>
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
BIN
db/migrate/.20230510075444_devise_create_users.rb.kate-swp
Normal file
BIN
db/migrate/.20230510075444_devise_create_users.rb.kate-swp
Normal file
Binary file not shown.
9
db/migrate/20230510132506_create_domains.rb
Normal file
9
db/migrate/20230510132506_create_domains.rb
Normal 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
35
db/schema.rb
generated
Normal 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
|
||||||
48
test/controllers/domains_controller_test.rb
Normal file
48
test/controllers/domains_controller_test.rb
Normal 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
7
test/fixtures/domains.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
domain: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
domain: MyString
|
||||||
7
test/models/domain_test.rb
Normal file
7
test/models/domain_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class DomainTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
41
test/system/domains_test.rb
Normal file
41
test/system/domains_test.rb
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user