Created
November 15, 2008 08:09
-
-
Save motdotla/25215 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 File.join( File.dirname(__FILE__), '..', "spec_helper" ) | |
describe Stock do | |
it "should be valid when new" do | |
stock = Stock.new(:symbol => 'GOOG') | |
stock.should be_valid | |
end | |
it "should be invalid when symbol is empty" do | |
stock = Stock.new(:symbol => '') | |
stock.should_not be_valid | |
end | |
it "should have symbol in all uppercase" do | |
stock = Stock.create(:symbol => 'GOOG') | |
stock.symbol.should equal(stock.symbol.upcase) | |
stock = Stock.create(:symbol => 'goog') | |
stock.symbol.should equal(stock.symbol.upcase) | |
end | |
end |
This file contains hidden or 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 File.join( File.dirname(__FILE__), '..', "spec_helper" ) | |
describe Comment do | |
it "should be valid when new" do | |
comment = Comment.new(:body => "Yesterday the market rose by 5%. I was happy.", :stock_id => '1') | |
comment.should be_valid | |
end | |
it "should not be valid if body is empty" do | |
comment = Comment.new(:body => '') | |
comment.should_not be_valid | |
end | |
it "should not be valid if stock_id is empty" do | |
comment = Comment.new(:body => 'Yesterday the market rose by 5%. I was happy.', :stock_id => '') | |
comment.should_not be_valid | |
end | |
it "should not be valid if stock_id does not exist" do | |
stock = Stock.find(:all) # this is failing because i need fixtures or a stub | |
non_existant_stock_id = stock.id.to_i + 1 | |
comment = Comment.create(:body => 'Yseterday the market rose by 5%. I was happy.', :stock_id => non_existant_stock_id) | |
comment.non_existant_stock_id should_not equal(stock.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment