我在我的模型中测试 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.stub :account => account
subject.stub :save => 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! wtf!?
element.company_handwritten_signature ||= element.account.company_handwritten_signature
element.company_stamp ||= element.account.company_stamp
true
end
正在调用 before_filter 方法,但在该回调中,帐户方法的存根似乎不起作用。我测试过
主题.帐户 = 帐户结果相同。这是怎么回事?
顺便说一句,我正在使用 rails 2.3 和 rspec-rails 1.3.4