diff --git a/app/controllers/virtuals_controller.rb b/app/controllers/virtuals_controller.rb
new file mode 100644
index 0000000..749c3f1
--- /dev/null
+++ b/app/controllers/virtuals_controller.rb
@@ -0,0 +1,70 @@
+class VirtualsController < ApplicationController
+ before_action :set_virtual, only: %i[ show edit update destroy ]
+
+ # GET /virtuals or /virtuals.json
+ def index
+ @virtuals = Virtual.all
+ end
+
+ # GET /virtuals/1 or /virtuals/1.json
+ def show
+ end
+
+ # GET /virtuals/new
+ def new
+ @virtual = Virtual.new
+ end
+
+ # GET /virtuals/1/edit
+ def edit
+ end
+
+ # POST /virtuals or /virtuals.json
+ def create
+ @virtual = Virtual.new(virtual_params)
+
+ respond_to do |format|
+ if @virtual.save
+ format.html { redirect_to virtual_url(@virtual), notice: "Virtual was successfully created." }
+ format.json { render :show, status: :created, location: @virtual }
+ else
+ format.html { render :new, status: :unprocessable_entity }
+ format.json { render json: @virtual.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /virtuals/1 or /virtuals/1.json
+ def update
+ respond_to do |format|
+ if @virtual.update(virtual_params)
+ format.html { redirect_to virtual_url(@virtual), notice: "Virtual was successfully updated." }
+ format.json { render :show, status: :ok, location: @virtual }
+ else
+ format.html { render :edit, status: :unprocessable_entity }
+ format.json { render json: @virtual.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /virtuals/1 or /virtuals/1.json
+ def destroy
+ @virtual.destroy
+
+ respond_to do |format|
+ format.html { redirect_to virtuals_url, notice: "Virtual was successfully destroyed." }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_virtual
+ @virtual = Virtual.find(params[:id])
+ end
+
+ # Only allow a list of trusted parameters through.
+ def virtual_params
+ params.require(:virtual).permit(:email, :destination)
+ end
+end
diff --git a/app/helpers/virtuals_helper.rb b/app/helpers/virtuals_helper.rb
new file mode 100644
index 0000000..46971d3
--- /dev/null
+++ b/app/helpers/virtuals_helper.rb
@@ -0,0 +1,2 @@
+module VirtualsHelper
+end
diff --git a/app/models/domain.rb b/app/models/domain.rb
index 5cd0fc4..a2e3053 100644
--- a/app/models/domain.rb
+++ b/app/models/domain.rb
@@ -1,2 +1,4 @@
class Domain < ApplicationRecord
+ validates :domain, presence: true
+ validates :domain, uniqueness: true
end
diff --git a/app/models/virtual.rb b/app/models/virtual.rb
new file mode 100644
index 0000000..5759752
--- /dev/null
+++ b/app/models/virtual.rb
@@ -0,0 +1,2 @@
+class Virtual < ApplicationRecord
+end
diff --git a/app/views/virtuals/_form.html.erb b/app/views/virtuals/_form.html.erb
new file mode 100644
index 0000000..0b80272
--- /dev/null
+++ b/app/views/virtuals/_form.html.erb
@@ -0,0 +1,27 @@
+<%= form_with(model: virtual) do |form| %>
+ <% if virtual.errors.any? %>
+
+
<%= pluralize(virtual.errors.count, "error") %> prohibited this virtual from being saved:
+
+
+ <% virtual.errors.each do |error| %>
+ - <%= error.full_message %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= form.label :email, style: "display: block" %>
+ <%= form.text_field :email %>
+
+
+
+ <%= form.label :destination, style: "display: block" %>
+ <%= form.text_field :destination %>
+
+
+
+ <%= form.submit %>
+
+<% end %>
diff --git a/app/views/virtuals/_virtual.html.erb b/app/views/virtuals/_virtual.html.erb
new file mode 100644
index 0000000..728e403
--- /dev/null
+++ b/app/views/virtuals/_virtual.html.erb
@@ -0,0 +1,12 @@
+
+
+ Email:
+ <%= virtual.email %>
+
+
+
+ Destination:
+ <%= virtual.destination %>
+
+
+
diff --git a/app/views/virtuals/_virtual.json.jbuilder b/app/views/virtuals/_virtual.json.jbuilder
new file mode 100644
index 0000000..e1915a7
--- /dev/null
+++ b/app/views/virtuals/_virtual.json.jbuilder
@@ -0,0 +1,2 @@
+json.extract! virtual, :id, :email, :destination, :created_at, :updated_at
+json.url virtual_url(virtual, format: :json)
diff --git a/app/views/virtuals/edit.html.erb b/app/views/virtuals/edit.html.erb
new file mode 100644
index 0000000..5d4083b
--- /dev/null
+++ b/app/views/virtuals/edit.html.erb
@@ -0,0 +1,10 @@
+Editing virtual
+
+<%= render "form", virtual: @virtual %>
+
+
+
+
+ <%= link_to "Show this virtual", @virtual %> |
+ <%= link_to "Back to virtuals", virtuals_path %>
+
diff --git a/app/views/virtuals/index.html.erb b/app/views/virtuals/index.html.erb
new file mode 100644
index 0000000..c91b22c
--- /dev/null
+++ b/app/views/virtuals/index.html.erb
@@ -0,0 +1,14 @@
+<%= notice %>
+
+Virtuals
+
+
+ <% @virtuals.each do |virtual| %>
+ <%= render virtual %>
+
+ <%= link_to "Show this virtual", virtual %>
+
+ <% end %>
+
+
+<%= link_to "New virtual", new_virtual_path %>
diff --git a/app/views/virtuals/index.json.jbuilder b/app/views/virtuals/index.json.jbuilder
new file mode 100644
index 0000000..6c10d9b
--- /dev/null
+++ b/app/views/virtuals/index.json.jbuilder
@@ -0,0 +1 @@
+json.array! @virtuals, partial: "virtuals/virtual", as: :virtual
diff --git a/app/views/virtuals/new.html.erb b/app/views/virtuals/new.html.erb
new file mode 100644
index 0000000..b37c8dd
--- /dev/null
+++ b/app/views/virtuals/new.html.erb
@@ -0,0 +1,9 @@
+New virtual
+
+<%= render "form", virtual: @virtual %>
+
+
+
+
+ <%= link_to "Back to virtuals", virtuals_path %>
+
diff --git a/app/views/virtuals/show.html.erb b/app/views/virtuals/show.html.erb
new file mode 100644
index 0000000..7a64f31
--- /dev/null
+++ b/app/views/virtuals/show.html.erb
@@ -0,0 +1,10 @@
+<%= notice %>
+
+<%= render @virtual %>
+
+
+ <%= link_to "Edit this virtual", edit_virtual_path(@virtual) %> |
+ <%= link_to "Back to virtuals", virtuals_path %>
+
+ <%= button_to "Destroy this virtual", @virtual, method: :delete %>
+
diff --git a/app/views/virtuals/show.json.jbuilder b/app/views/virtuals/show.json.jbuilder
new file mode 100644
index 0000000..d9a6b01
--- /dev/null
+++ b/app/views/virtuals/show.json.jbuilder
@@ -0,0 +1 @@
+json.partial! "virtuals/virtual", virtual: @virtual
diff --git a/config/environments/.development.rb.kate-swp b/config/environments/.development.rb.kate-swp
deleted file mode 100644
index af90e83..0000000
Binary files a/config/environments/.development.rb.kate-swp and /dev/null differ
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 8500f45..eddb0d0 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -67,4 +67,6 @@ Rails.application.configure do
# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
+
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end
diff --git a/config/routes.rb b/config/routes.rb
index 4dc56b4..e4b288e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
+ resources :virtuals
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
deleted file mode 100644
index b358701..0000000
Binary files a/db/migrate/.20230510075444_devise_create_users.rb.kate-swp and /dev/null differ
diff --git a/db/migrate/20230510075444_devise_create_users.rb b/db/migrate/20230510075444_devise_create_users.rb
index 791ba78..a6fd747 100644
--- a/db/migrate/20230510075444_devise_create_users.rb
+++ b/db/migrate/20230510075444_devise_create_users.rb
@@ -31,7 +31,7 @@ class DeviseCreateUsers < ActiveRecord::Migration[7.0]
t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
-
+ t.integer :role, default: 1000, null: false
t.timestamps null: false
end
diff --git a/db/migrate/20230510141218_create_virtuals.rb b/db/migrate/20230510141218_create_virtuals.rb
new file mode 100644
index 0000000..9289096
--- /dev/null
+++ b/db/migrate/20230510141218_create_virtuals.rb
@@ -0,0 +1,10 @@
+class CreateVirtuals < ActiveRecord::Migration[7.0]
+ def change
+ create_table :virtuals do |t|
+ t.string :email
+ t.string :destination
+
+ t.timestamps
+ end
+ end
+end
diff --git a/git.core b/git.core
new file mode 100644
index 0000000..9fd5bb3
Binary files /dev/null and b/git.core differ
diff --git a/test/controllers/virtuals_controller_test.rb b/test/controllers/virtuals_controller_test.rb
new file mode 100644
index 0000000..446a770
--- /dev/null
+++ b/test/controllers/virtuals_controller_test.rb
@@ -0,0 +1,48 @@
+require "test_helper"
+
+class VirtualsControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ @virtual = virtuals(:one)
+ end
+
+ test "should get index" do
+ get virtuals_url
+ assert_response :success
+ end
+
+ test "should get new" do
+ get new_virtual_url
+ assert_response :success
+ end
+
+ test "should create virtual" do
+ assert_difference("Virtual.count") do
+ post virtuals_url, params: { virtual: { destination: @virtual.destination, email: @virtual.email } }
+ end
+
+ assert_redirected_to virtual_url(Virtual.last)
+ end
+
+ test "should show virtual" do
+ get virtual_url(@virtual)
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get edit_virtual_url(@virtual)
+ assert_response :success
+ end
+
+ test "should update virtual" do
+ patch virtual_url(@virtual), params: { virtual: { destination: @virtual.destination, email: @virtual.email } }
+ assert_redirected_to virtual_url(@virtual)
+ end
+
+ test "should destroy virtual" do
+ assert_difference("Virtual.count", -1) do
+ delete virtual_url(@virtual)
+ end
+
+ assert_redirected_to virtuals_url
+ end
+end
diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml
index 1315aeb..e11b45a 100644
--- a/test/fixtures/domains.yml
+++ b/test/fixtures/domains.yml
@@ -1,7 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
- domain: MyString
+ domain: example.net
two:
- domain: MyString
+ domain: example.org
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
index d7a3329..82f27e2 100644
--- a/test/fixtures/users.yml
+++ b/test/fixtures/users.yml
@@ -1,11 +1,11 @@
-# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
-
-# This model initially had no columns defined. If you add columns to the
-# model remove the "{}" from the fixture names and add the columns immediately
-# below each fixture, per the syntax in the comments below
+# # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
#
-one: {}
-# column: value
-#
-two: {}
-# column: value
+# # This model initially had no columns defined. If you add columns to the
+# # model remove the "{}" from the fixture names and add the columns immediately
+# # below each fixture, per the syntax in the comments below
+# #
+# one: {}
+# # column: value
+# #
+# two: {}
+# # column: value
diff --git a/test/fixtures/virtuals.yml b/test/fixtures/virtuals.yml
new file mode 100644
index 0000000..798393d
--- /dev/null
+++ b/test/fixtures/virtuals.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ email: MyString
+ destination: MyString
+
+two:
+ email: MyString
+ destination: MyString
diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb
index d3022b1..8b1a68f 100644
--- a/test/models/domain_test.rb
+++ b/test/models/domain_test.rb
@@ -8,11 +8,11 @@ class DomainTest < ActiveSupport::TestCase
test "domain can no tbe duplicated" do
@d1 = Domain.new
- @d1.name = "example.com"
+ @d1.domain = "example.com"
assert @d1.save
@d2 = Domain.new
- @d2.name = "example.com"
+ @d2.domain = "example.com"
assert !@d2.save
end
end
diff --git a/test/models/virtual_test.rb b/test/models/virtual_test.rb
new file mode 100644
index 0000000..affa4d1
--- /dev/null
+++ b/test/models/virtual_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class VirtualTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/system/virtuals_test.rb b/test/system/virtuals_test.rb
new file mode 100644
index 0000000..6418658
--- /dev/null
+++ b/test/system/virtuals_test.rb
@@ -0,0 +1,43 @@
+require "application_system_test_case"
+
+class VirtualsTest < ApplicationSystemTestCase
+ setup do
+ @virtual = virtuals(:one)
+ end
+
+ test "visiting the index" do
+ visit virtuals_url
+ assert_selector "h1", text: "Virtuals"
+ end
+
+ test "should create virtual" do
+ visit virtuals_url
+ click_on "New virtual"
+
+ fill_in "Destination", with: @virtual.destination
+ fill_in "Email", with: @virtual.email
+ click_on "Create Virtual"
+
+ assert_text "Virtual was successfully created"
+ click_on "Back"
+ end
+
+ test "should update Virtual" do
+ visit virtual_url(@virtual)
+ click_on "Edit this virtual", match: :first
+
+ fill_in "Destination", with: @virtual.destination
+ fill_in "Email", with: @virtual.email
+ click_on "Update Virtual"
+
+ assert_text "Virtual was successfully updated"
+ click_on "Back"
+ end
+
+ test "should destroy Virtual" do
+ visit virtual_url(@virtual)
+ click_on "Destroy this virtual", match: :first
+
+ assert_text "Virtual was successfully destroyed"
+ end
+end