diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d1..cd7f6aa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,3 @@ class ApplicationController < ActionController::Base + before_action :authenticate_user! end diff --git a/app/controllers/domains_controller.rb b/app/controllers/domains_controller.rb new file mode 100644 index 0000000..7ce2ea7 --- /dev/null +++ b/app/controllers/domains_controller.rb @@ -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 diff --git a/app/helpers/domains_helper.rb b/app/helpers/domains_helper.rb new file mode 100644 index 0000000..04b2f61 --- /dev/null +++ b/app/helpers/domains_helper.rb @@ -0,0 +1,2 @@ +module DomainsHelper +end diff --git a/app/models/domain.rb b/app/models/domain.rb new file mode 100644 index 0000000..5cd0fc4 --- /dev/null +++ b/app/models/domain.rb @@ -0,0 +1,2 @@ +class Domain < ApplicationRecord +end diff --git a/app/views/domains/_domain.html.erb b/app/views/domains/_domain.html.erb new file mode 100644 index 0000000..d77e703 --- /dev/null +++ b/app/views/domains/_domain.html.erb @@ -0,0 +1,7 @@ +
+

+ Domain: + <%= domain.domain %> +

+ +
diff --git a/app/views/domains/_domain.json.jbuilder b/app/views/domains/_domain.json.jbuilder new file mode 100644 index 0000000..92889fb --- /dev/null +++ b/app/views/domains/_domain.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! domain, :id, :domain, :created_at, :updated_at +json.url domain_url(domain, format: :json) diff --git a/app/views/domains/_form.html.erb b/app/views/domains/_form.html.erb new file mode 100644 index 0000000..4dd9f60 --- /dev/null +++ b/app/views/domains/_form.html.erb @@ -0,0 +1,22 @@ +<%= form_with(model: domain) do |form| %> + <% if domain.errors.any? %> +
+

<%= pluralize(domain.errors.count, "error") %> prohibited this domain from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :domain, style: "display: block" %> + <%= form.text_field :domain %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/domains/edit.html.erb b/app/views/domains/edit.html.erb new file mode 100644 index 0000000..4f9bd87 --- /dev/null +++ b/app/views/domains/edit.html.erb @@ -0,0 +1,10 @@ +

Editing domain

+ +<%= render "form", domain: @domain %> + +
+ +
+ <%= link_to "Show this domain", @domain %> | + <%= link_to "Back to domains", domains_path %> +
diff --git a/app/views/domains/index.html.erb b/app/views/domains/index.html.erb new file mode 100644 index 0000000..703f7f2 --- /dev/null +++ b/app/views/domains/index.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

Domains

+ +
+ <% @domains.each do |domain| %> + <%= render domain %> +

+ <%= link_to "Show this domain", domain %> +

+ <% end %> +
+ +<%= link_to "New domain", new_domain_path %> diff --git a/app/views/domains/index.json.jbuilder b/app/views/domains/index.json.jbuilder new file mode 100644 index 0000000..aceef20 --- /dev/null +++ b/app/views/domains/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @domains, partial: "domains/domain", as: :domain diff --git a/app/views/domains/new.html.erb b/app/views/domains/new.html.erb new file mode 100644 index 0000000..6c75318 --- /dev/null +++ b/app/views/domains/new.html.erb @@ -0,0 +1,9 @@ +

New domain

+ +<%= render "form", domain: @domain %> + +
+ +
+ <%= link_to "Back to domains", domains_path %> +
diff --git a/app/views/domains/show.html.erb b/app/views/domains/show.html.erb new file mode 100644 index 0000000..d248bf8 --- /dev/null +++ b/app/views/domains/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @domain %> + +
+ <%= link_to "Edit this domain", edit_domain_path(@domain) %> | + <%= link_to "Back to domains", domains_path %> + + <%= button_to "Destroy this domain", @domain, method: :delete %> +
diff --git a/app/views/domains/show.json.jbuilder b/app/views/domains/show.json.jbuilder new file mode 100644 index 0000000..b16db14 --- /dev/null +++ b/app/views/domains/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "domains/domain", domain: @domain diff --git a/config/database.yml b/config/database.yml index 1975af4..8a14a0e 100644 --- a/config/database.yml +++ b/config/database.yml @@ -14,19 +14,19 @@ default: &default encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root - password: + password: password host: localhost development: <<: *default - database: opensmtpd_rails_frontend_development + database: opensmtpd_dev # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default - database: opensmtpd_rails_frontend_test + database: opensmtpd_test # 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 @@ -50,6 +50,6 @@ test: # production: <<: *default - database: opensmtpd_rails_frontend_production - username: opensmtpd_rails_frontend + database: opensmtpd + username: opensmtpd password: <%= ENV["OPENSMTPD_RAILS_FRONTEND_DATABASE_PASSWORD"] %> diff --git a/config/routes.rb b/config/routes.rb index ecf33f0..4dc56b4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :domains devise_for :users # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html diff --git a/db/migrate/.20230510075444_devise_create_users.rb.kate-swp b/db/migrate/.20230510075444_devise_create_users.rb.kate-swp new file mode 100644 index 0000000..b358701 Binary files /dev/null and b/db/migrate/.20230510075444_devise_create_users.rb.kate-swp differ diff --git a/db/migrate/20230510132506_create_domains.rb b/db/migrate/20230510132506_create_domains.rb new file mode 100644 index 0000000..382c63b --- /dev/null +++ b/db/migrate/20230510132506_create_domains.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..3557b34 --- /dev/null +++ b/db/schema.rb @@ -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 diff --git a/test/controllers/domains_controller_test.rb b/test/controllers/domains_controller_test.rb new file mode 100644 index 0000000..216edf7 --- /dev/null +++ b/test/controllers/domains_controller_test.rb @@ -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 diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml new file mode 100644 index 0000000..1315aeb --- /dev/null +++ b/test/fixtures/domains.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + domain: MyString + +two: + domain: MyString diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb new file mode 100644 index 0000000..7b12fc2 --- /dev/null +++ b/test/models/domain_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class DomainTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/domains_test.rb b/test/system/domains_test.rb new file mode 100644 index 0000000..9bff775 --- /dev/null +++ b/test/system/domains_test.rb @@ -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