Created
August 6, 2009 06:26
-
-
Save alvin2ye/163176 to your computer and use it in GitHub Desktop.
rspec model test
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.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
module FinanceRecordSpecHelper | |
def valid_attributes | |
{ | |
:item_type => "YinsouRecord", | |
:currency => "CNY", | |
:price => 500.12, | |
:loading_bill => LoadingBill.first, | |
:remark => "remark", | |
:state => "可付" | |
} | |
end | |
end | |
describe FinanceRecord do | |
include FinanceRecordSpecHelper | |
before(:each) do | |
@record = FinanceRecord.new | |
end | |
context "should be invalid" do | |
it "empty" do | |
@record.should_not be_valid | |
end | |
%w{currency loading_bill state}.each do |field| | |
it "require #{field}" do | |
@record.should_not be_valid | |
@record.errors.on(field.to_sym).should == I18n.t("activerecord.errors.messages.blank") | |
end | |
end | |
it "item_type" do | |
%w{error nil}.each do |value| | |
@record.attributes = valid_attributes.merge(:item_type => value) | |
@record.should_not be_valid | |
@record.errors.on(:item_type).should == I18n.t("activerecord.errors.messages.inclusion") | |
end | |
end | |
end | |
it "valid" do | |
@record.attributes = valid_attributes | |
@record.should be_valid | |
end | |
it "belongs to loading_bill" do | |
FinanceRecord.first.loading_bill.should be_a_kind_of LoadingBill | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment