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
# Changed but not updated:
# (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/fixtures/products.yml
# modified: test/functional/products_controller_test.rb
# modified: test/unit/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 05513cc] Validation!
4 files changed, 137 insertions(+), 6 deletions(-)
edit app/models/product.rb
class Product < ActiveRecord::Base
validates :title, :description, :image_url, presence: true
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :title, uniqueness: true
validates :image_url, allow_blank: true, format: {
with: %r{\.(gif|jpg|png)$}i,
message: 'must be a URL for GIF, JPG or PNG image.'
}
validates :title, length: {minimum: 10}
end
8.1 Iteration C1: Create the Catalog Listing 7.2 Iteration B2: Unit Testing