モデルにメソッドがあります
(ユーザーモデル)
def create_reset_code
self.attributes = {:reset_code => Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )}
save(:validate=>false)
UserMailer.reset_password_email(self).deliver
end
RSpecでテストするにはどうすればよいですか?コード生成をテストして、電子メールを送信したい
PS:Googleを使用していますが、の例は見つかりませんでした
UPD
私は2つのテストを書きます:
it "should create reset code" do
@user.create_reset_code
@user.reset_code.should_not be_nil
end
it "should send reset code by email" do
@user.create_reset_code
@email_confirmation = ActionMailer::Base.deliveries.first
@email_confirmation.to.should == [@user.email]
@email_confirmation.subject.should == I18n.t('emailer.pass_reset.subject')
@email_confirmation.body.should match(/#{@user.reset_code}/)
end
しかし、これ--- @ email_confirmation.body.should match(/#{@ user.reset_code} /)----動作しません
手紙の中で私はreset_password_url(@ user.reset_code)のようにreset_codeでURLを与えます
修繕
it "should send reset code by email" do
@user.create_reset_code
@email_confirmation = ActionMailer::Base.deliveries.last
@email_confirmation.to.should == [@user.email]
@email_confirmation.subject.should == I18n.t('emailer.pass_reset.subject')
@email_confirmation.html_part.body.should match /#{@user.reset_code}/
end
仕事です!
みなさん、ありがとうございました。質問は締め切らせていただきました