-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
// Place all the styles related to the Products controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ | ||
.products { | ||
table { | ||
border-collapse: collapse; | ||
} | ||
|
||
table tr td { | ||
padding: 5px; | ||
vertical-align: top; | ||
} | ||
|
||
.list_image { | ||
width: 60px; | ||
height: 70px; | ||
} | ||
|
||
.list_description { | ||
width: 60%; | ||
|
||
dl { | ||
margin: 0; | ||
} | ||
|
||
dt { | ||
color: #244; | ||
font-weight: bold; | ||
font-size: larger; | ||
} | ||
|
||
dd { | ||
margin: 0; | ||
} | ||
} | ||
|
||
.list_actions { | ||
font-size: x-small; | ||
text-align: right; | ||
padding-left: 1em; | ||
} | ||
|
||
.list_line_even { | ||
background: #e0f8f8; | ||
} | ||
|
||
.list_line_odd { | ||
background: #f8b0f8; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
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, :format => { | ||
:with => %r{\.(gif|jpg|png)$}i, | ||
:message => 'must be a URL for GIF, JPG or PNG image.' | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,51 @@ | ||
require 'test_helper' | ||
|
||
class ProductTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
test "product attributes must not be empty" do | ||
product = Product.new | ||
assert product.invalid? | ||
assert product.errors[:title].any? | ||
assert product.errors[:description].any? | ||
assert product.errors[:price].any? | ||
assert product.errors[:image_url].any? | ||
end | ||
|
||
test "product price must be positive" do | ||
product = Product.new(title: "My Book Title", | ||
description: "yyy", | ||
image_url: "zzz.jpg") | ||
product.price = -1 | ||
assert product.invalid? | ||
assert_equal "must be greater than or equal to 0.01", | ||
product.errors[:price].join('; ') | ||
|
||
product.price = 0 | ||
assert product.invalid? | ||
assert_equal "must be greater than or equal to 0.01", | ||
product.errors[:price].join('; ') | ||
|
||
product.price = 1 | ||
assert product.valid? | ||
end | ||
|
||
def new_product(image_url) | ||
Product.new(title: "My Book Title", | ||
description: "yyy", | ||
price: 1, | ||
image_url: image_url) | ||
end | ||
|
||
test "image url" do | ||
ok = %w{ fred.gif fred.jpg fred.png FRED.JPG FRED.Jpg | ||
http://a.b.c/x/y/z/fred.gif } | ||
bad = %w{ fred.doc fred.gif/more fred.gif.more } | ||
|
||
ok.each do |name| | ||
assert new_product(name).valid?, "#{name} shouldn't be invalid" | ||
end | ||
|
||
bad.each do |name| | ||
assert new_product(name).invalid?, "#{name} shouldn't be valid" | ||
end | ||
end | ||
end |