Created
November 18, 2011 11:54
-
-
Save cibernox/1376256 to your computer and use it in GitHub Desktop.
rspec problem with mocks and before_create
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
# The spec | |
let(:stamp){ mock_model(CompanyStamp) } | |
let(:signature){ mock_model(CompanyHandwrittenSignature) } | |
let(:account) { mock_model(Account, :company_handwritten_signature => signature, :company_stamp => stamp) } | |
it "should have signature if the account has signature" do | |
subject.account = account | |
subject.stub(:save).and_return(true) | |
subject.company_handwritten_signature.should == signature | |
end | |
# the model's code | |
before_create do |element| | |
puts "element.account ===> #{element.account.inspect}" # element has no account! why?!?!?!? | |
element.company_handwritten_signature ||= element.account.company_handwritten_signature | |
element.company_stamp ||= element.account.company_stamp | |
true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment