8.1 Iteration C1: Create the Catalog Listing 7.2 Iteration B2: Unit Testing
Save our work
Show what files we changed.
git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: app/models/product.rb
modified: test/controllers/products_controller_test.rb
modified: test/fixtures/products.yml
modified: test/models/product_test.rb
no changes added to commit (use "git add" and/or "git commit -a")
Commit changes using -a shortcut
git commit -a -m 'Validation!'
[master 6c546fb] Validation!
4 files changed, 161 insertions(+), 8 deletions(-)
edit app/models/product.rb
class Product < ApplicationRecord
validates :title, :description, :image_url, presence: true
validates :title, uniqueness: true
validates :image_url, allow_blank: true, format: {
with: %r{\.(gif|jpg|png)\Z}i,
message: 'must be a URL for GIF, JPG or PNG image.'
}
validates :title, length: {minimum: 10}
validates :price, numericality: { greater_than_or_equal_to: 0.01 }
end
8.1 Iteration C1: Create the Catalog Listing 7.2 Iteration B2: Unit Testing