diff --git a/app/models/credential.rb b/app/models/credential.rb
index cb9acd8..1c914ea 100644
--- a/app/models/credential.rb
+++ b/app/models/credential.rb
@@ -1,4 +1,5 @@
class Credential < ApplicationRecord
+ belongs_to :domain
validates :email, presence: true
validates :email, uniqueness: true
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "email must be valid"}
diff --git a/app/models/domain.rb b/app/models/domain.rb
index a2e3053..2bff786 100644
--- a/app/models/domain.rb
+++ b/app/models/domain.rb
@@ -1,4 +1,6 @@
class Domain < ApplicationRecord
+ has_many :credentials, dependent: :destroy
+ has_many :virtuals, dependent: :destroy
validates :domain, presence: true
validates :domain, uniqueness: true
end
diff --git a/app/models/virtual.rb b/app/models/virtual.rb
index 581dbbf..f72b887 100644
--- a/app/models/virtual.rb
+++ b/app/models/virtual.rb
@@ -1,4 +1,5 @@
class Virtual < ApplicationRecord
+ belongs_to :domain
validate :domain_name_exists
validates :email, presence: true
validates :destination, presence: true
diff --git a/app/views/domains/index.html.erb b/app/views/domains/index.html.erb
index 703f7f2..5d5e685 100644
--- a/app/views/domains/index.html.erb
+++ b/app/views/domains/index.html.erb
@@ -3,12 +3,11 @@
Domains
+
<% @domains.each do |domain| %>
- <%= render domain %>
-
- <%= link_to "Show this domain", domain %>
-
+ - <%= link_to domain.domain, domain %>
<% end %>
+
<%= link_to "New domain", new_domain_path %>
diff --git a/app/views/domains/show.html.erb b/app/views/domains/show.html.erb
index d248bf8..ab491de 100644
--- a/app/views/domains/show.html.erb
+++ b/app/views/domains/show.html.erb
@@ -1,6 +1,5 @@
<%= notice %>
-
-<%= render @domain %>
+<%= @domain.domain %>
<%= link_to "Edit this domain", edit_domain_path(@domain) %> |
@@ -8,3 +7,19 @@
<%= button_to "Destroy this domain", @domain, method: :delete %>
+
+Credentials (<%= @domain.credentials.count %>)
+
+ - <%= link_to "Add #{@domain.domain} email address", new_domain_credential_path(@domain) %>
+<% @domain.credentials.each do |credential| %>
+
- <%= credential.email %>
+<% end %>
+
+
+Virtuals (<%= @domain.virtuals.count %>)
+
+ - <%= link_to "Add #{@domain.domain} virtual email", new_domain_virtual_path(@domain) %>
+<% @domain.virtuals.each do |virtual| %>
+ - <%= virtual.email%> >> <%= virtual.destination%>
+<% end %>
+
diff --git a/test/fixtures/virtuals.yml b/test/fixtures/virtuals.yml
index 3509592..431682f 100644
--- a/test/fixtures/virtuals.yml
+++ b/test/fixtures/virtuals.yml
@@ -1,9 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
+ domain: one
email: abuse@example.net
destination: bob@example.net
two:
+ domain: one
email: postmaster@example.net
destination: bob@example.net