モデルで 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 メソッドが呼び出されていますが、そのコールバック内でアカウント メソッドのスタブ化が機能していないようです。私はテストしました
subject.account = アカウント同じ結果で。どうしたの?
ちなみに、Rails 2.3 と rspec-Rails 1.3.4 を使っています。