Skip to content

Instantly share code, notes, and snippets.

@cibernox
Created November 18, 2011 11:54
Show Gist options
  • Save cibernox/1376256 to your computer and use it in GitHub Desktop.
Save cibernox/1376256 to your computer and use it in GitHub Desktop.
rspec problem with mocks and before_create
# 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