如何测试电子邮件是否已使用控制器规范中的 rspec2 发送和传递?
我在控制器规格中测试了我的观点。这也可以通过电子邮件实现吗? 如果是这样,有人可以给我举个例子吗?
我目前正在从事集成测试: 我从注册测试中获取了一些代码并将其转换,以便我可以测试我的重置密码,但停留在电子邮件部分。
describe "Reset Password" do
describe "success" do
it "should send the user reset password instructions" do
lambda do
visit reset_password_path
fill_in "password_reset[email]", :with => "[email protected]"
# click_button "password_reset_submit"
# response.should render_template :js => "window.location = '#{temp_success_path}'"
# end.should change(User, :count)
end
end
end
end
我已经设置了用于注册和重置密码的电子邮件。成功注册后,用户会收到一封电子邮件,欢迎他们访问该网站。密码重置时,用户会收到一封包含密码重置说明的电子邮件。
密码控制器的一部分:
class PasswordsController < ApplicationController
def new
end
def create
@user = User.find_by_email(params[:password_reset][:email])
@user.generate_and_store_password_reset_token && UserMailer.password_reset(@user).deliver if @user
redirect_to root_url, :notice => "Email sent with password reset instructions."
end
用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.join_confirmation(@user).deliver
format.js { render :js => "window.location = '#{temp_success_path}'" }
else
format.html { render :new }
format.js { render :form_errors }
end
end
end
end
I test my views in controller specs. Is this possible with email too?
If so can someone show me an example?
I'm currently working on integration tests:
I've taking some code from testing for signup and converting it so I can test my reset password but stuck on the email part.
describe "Reset Password" do
describe "success" do
it "should send the user reset password instructions" do
lambda do
visit reset_password_path
fill_in "password_reset[email]", :with => "[email protected]"
# click_button "password_reset_submit"
# response.should render_template :js => "window.location = '#{temp_success_path}'"
# end.should change(User, :count)
end
end
end
end
I've set up emails for signup and reset password. On successfuly signup user is sent an email to welcome them to the website. On password reset user is sent an email with password reset instructons.
Part of passwords controller:
class PasswordsController < ApplicationController
def new
end
def create
@user = User.find_by_email(params[:password_reset][:email])
@user.generate_and_store_password_reset_token && UserMailer.password_reset(@user).deliver if @user
redirect_to root_url, :notice => "Email sent with password reset instructions."
end
Users controller:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.join_confirmation(@user).deliver
format.js { render :js => "window.location = '#{temp_success_path}'" }
else
format.html { render :new }
format.js { render :form_errors }
end
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论