From b80e6392b9deb9fd6b0966bc1d3e6ecd088121ae Mon Sep 17 00:00:00 2001
From: kd00506 <kd00506@surrey.ac.uk>
Date: Sun, 29 Nov 2020 14:24:38 +0000
Subject: [PATCH] Commented Models

---
 app/mailers/application_mailer.rb |  2 +-
 app/mailers/contact_mailer.rb     |  2 +-
 app/models/list.rb                | 10 +++++-----
 app/models/product.rb             | 10 +++++-----
 app/models/user.rb                |  8 ++++----
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index b976204..eb1b823 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -1,4 +1,4 @@
 class ApplicationMailer < ActionMailer::Base
-  default to: 'admin@team.com', from: 'a@customer.com'
+  default to: 'admin@team.com', from: 'a@customer.com' # Mailer defaults
   layout 'mailer'
 end
diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb
index 6de699a..f8e7737 100644
--- a/app/mailers/contact_mailer.rb
+++ b/app/mailers/contact_mailer.rb
@@ -1,6 +1,6 @@
 class ContactMailer < ApplicationMailer
 
-  def contact_email(email, message)
+  def contact_email(email, message) # Handling of mail
     @email = email
     @message = message
 
diff --git a/app/models/list.rb b/app/models/list.rb
index 1526ca6..7cec1b6 100644
--- a/app/models/list.rb
+++ b/app/models/list.rb
@@ -1,9 +1,9 @@
 class List < ApplicationRecord
-  belongs_to :user
-  validates :name, presence: true
-  validates :user_id, presence: true
+  belongs_to :user # A list is owned by a user
+  validates :name, presence: true # A list should not exist without a name
+  validates :user_id, presence: true # A list should not exist without an id reference to its user
 
-  has_many :products, dependent: :destroy
+  has_many :products, dependent: :destroy # Each list owns a collection of products
 
-  scope :user, ->(user_id) { where(user_id: user_id) }
+  scope :user, ->(user_id) { where(user_id: user_id) } # A scope that only returns the lists owned by a user of specified user_id
 end
diff --git a/app/models/product.rb b/app/models/product.rb
index ab5c0d2..a49321e 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -1,8 +1,8 @@
 class Product < ApplicationRecord
-  belongs_to :list
-  validates :name, presence: true
-  validates :acquired, inclusion: {in: [true, false]}
-  validates :list_id, presence: true
+  belongs_to :list # Every product belongs to a list
+  validates :name, presence: true # A product should not exist without a name
+  validates :acquired, inclusion: {in: [true, false]} # The "acquired" field of a product should be either true or false
+  validates :list_id, presence: true # A product should not exist without reference to its parent list
 
-  scope :list, ->(list_id) { where(list_id: list_id) }
+  scope :list, ->(list_id) { where(list_id: list_id) } # A scope that returns all products in a specified list
 end
diff --git a/app/models/user.rb b/app/models/user.rb
index fb5729d..03095d0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,7 +1,7 @@
 class User < ApplicationRecord
-  validates :name, presence: true
-  validates :email, presence: true, uniqueness: true
-  validates :password, presence: true
+  validates :name, presence: true # A user should not exist without a name
+  validates :email, presence: true, uniqueness: true # A user should not exist without a unique email address
+  validates :password, presence: true # A user should not exist without a password
 
-  has_many :lists, dependent: :destroy
+  has_many :lists, dependent: :destroy # Each user owns a collection of lists
 end
-- 
GitLab