साथ after_create हुक मैं (आरओआर 3.0.x) है कि कम या ज्यादा इस तरह अपने मॉडल में कोड है:परीक्षण rspec
class Message
after_create :notify
protected
def notify
if visible?
Notifier.message_from_portfolio(user, self).deliver
else
Notifier.invisible_message_from_portfolio(user, self).deliver
end
end
end
और मैं यह परीक्षण करने के लिए नवीनतम rspec मणि उपयोग कर रहा हूँ। समस्या यह है कि मैं अधिसूचना विधि का परीक्षण करने में सक्षम नहीं हूं: अगर मैं इसे सीधे जांचता हूं तो मैं नहीं कर सकता क्योंकि यह सुरक्षित है, अगर मैं एक संदेश बनाता हूं और उम्मीदों को सेट करता हूं तो यह काम नहीं करता है क्योंकि स्पष्ट रूप से आरएसपीईसी अधिसूचना चलाता है मेटोड मैं समय पर कॉल पकड़ने में सक्षम नहीं हूं।
मेरे कल्पना है:
describe :notification do
it "should send the whole message by email when visible" do
u = Factory.create(:user, :account_type => 1)
message = u.messages.build(:body => "Whatever", :author => "Nobody", :email => "[email protected]")
Notifier.should_receive(:message_from_portfolio)
message.save
end
end
वस्तु सूचक message_from_portfolio कभी नहीं प्राप्त करता है। मैं क्या गलत कर रहा हूं? सुझाव?
लेकिन 'u.messages.build' का उपयोग किया गया था। क्या आप यही सुझाव नहीं देते? – lulalala