Created
January 30, 2014 23:17
-
-
Save novohispano/8722223 to your computer and use it in GitHub Desktop.
Example of Model Testing
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
require 'spec_helper' | |
describe Item do | |
it "should exist" do | |
item = Item.new | |
expect item | |
end | |
it "should have a name" do | |
item = Item.new(name: "hammer") | |
expect item.name.should eq "hammer" | |
end | |
it "should have a description" do | |
item = Item.new(description: "long") | |
expect item.description.should eq "long" | |
end | |
it "should not be valid without a name" do | |
item = Item.new(description: "short") | |
expect(item).not_to be_valid | |
end | |
it "should not be valid without a description" do | |
item = Item.new(name: "ball") | |
expect(item).not_to be_valid | |
end | |
it "should not create and item if the name exists" do | |
item1 = Item.create(name: "ball", description: "round") | |
item2 = Item.create(name: "ball", description: "red") | |
expect(item2).not_to be_valid | |
end | |
it "should have orders" do | |
item = Item.new | |
expect item.orders | |
end | |
it "should have order items" do | |
item = Item.new | |
expect item.order_items | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment