I have a user_observer, code like this:
def after_create(user)
UserMailer.deliver_signup_notification(user)
user.random_key = random_key_method
user.save
end
before do
@user = mock_model(User)
@user_observer = UserObserver.instance
end
UserMailer.should_receive(:deliver_signup_notification).with(@user)
@user_observer.after_create(@user)
how can I test the random_key process?
On 26 Nov 2009, at 02:31, Zhenning G. wrote:
@user = mock_model(User)
@user_observer = UserObserver.instance
end
UserMailer.should_receive(:deliver_signup_notification).with(@user)
@user_observer.after_create(@user)
how can I test the random_key process?
You can do something like this to sense the value passed to the user
object:
it “should generate a key for the user which is 30 characters long” do
@user.should_receive(:random_key=) do |value|
value.length.should == 30
end
@user_observer.after_create(@user)
end
Obviously the precise specifications of the key are up to you and your
stakeholders, but that should show you how you can test it.
cheers,
Matt
+447974 430184