Permalink
Browse files

using product fixtures

  • Loading branch information...
1 parent d847641 commit 03260d0316fc1f468f127d354882422e6a638a79 @tomcz tomcz committed Mar 10, 2010
Showing with 20 additions and 6 deletions.
  1. +20 −6 spec/models/product_spec.rb
View
26 spec/models/product_spec.rb
@@ -2,16 +2,18 @@
describe Product do
+ fixtures :products
+
it 'is invalid with empty attributes' do
product = Product.new
product.should_not be_valid
- product.errors.should be_invalid(:title)
- product.errors.should be_invalid(:description)
- product.errors.should be_invalid(:price)
- product.errors.should be_invalid(:image_url)
+ product.should have(1).error_on(:title)
+ product.should have(1).error_on(:description)
+ product.should have(1).error_on(:price)
+ product.should have(2).errors_on(:image_url)
end
- describe 'price validation' do
+ context 'price validation' do
before(:each) do
@product = Product.new(:title => "My Book Title", :description => "yyy", :image_url => "zzz.jpg")
end
@@ -31,7 +33,7 @@
end
end
- describe 'image url validation' do
+ context 'image url validation' do
before(:each) do
@product = Product.new(:title => "My Book Title", :description => "yyy", :price => 1)
end
@@ -40,15 +42,27 @@
ok.each do |url|
@product.image_url = url
@product.should be_valid
+ @product.should have(:no).errors_on(:image_url)
end
end
it 'is invalid with unknown image extension' do
bad = %w{ fred.doc fred.gif/more fred.gif.more }
bad.each do |url|
@product.image_url = url
@product.should_not be_valid
+ @product.should have(1).error_on(:image_url)
end
end
end
+ context 'title validation' do
+ it 'validates that the title is unique' do
+ title = products(:ruby_book).title
+ product = Product.new(:title => title, :description => "yyy", :price => 1, :image_url => "fred.gif")
+ product.should_not be_valid
+ product.should have(1).error_on(:title)
+ product.errors_on(:title).should == ['has already been taken']
+ end
+ end
+
end

0 comments on commit 03260d0

Please sign in to comment.