fixing functional tests

This commit is contained in:
albert
2011-07-17 16:42:26 -04:00
parent 04ab2f4701
commit 72e9da01b5
26 changed files with 446 additions and 46 deletions

View File

@@ -0,0 +1,44 @@
require "test_helper"
module Maintenance
module User
class LoginRemindersControllerTest < ActionController::TestCase
context "A login reminder controller" do
setup do
@user = Factory.create(:user)
@blank_email_user = Factory.create(:user, :email => "")
CurrentUser.user = nil
CurrentUser.ip_addr = "127.0.0.1"
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.deliveries.clear
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "render the new page" do
get :new
assert_response :success
end
should "deliver an email with the login to the user" do
post :create, {:user => {:email => @user.email}}
assert_equal(flash[:notice], "Email sent")
assert_equal(1, ActionMailer::Base.deliveries.size)
end
context "for a user with a blank email" do
should "fail" do
post :create, {:user => {:email => ""}}
assert_equal("Email address not found", flash[:notice])
@blank_email_user.reload
assert_equal(@blank_email_user.created_at, @blank_email_user.updated_at)
assert_equal(0, ActionMailer::Base.deliveries.size)
end
end
end
end
end
end

View File

@@ -0,0 +1,98 @@
require "test_helper"
module Maintenance
module User
class PasswordResetsControllerTest < ActionController::TestCase
context "A password resets controller" do
setup do
@user = Factory.create(:user, :email => "abc@com.net")
CurrentUser.user = nil
CurrentUser.ip_addr = "127.0.0.1"
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.deliveries.clear
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "render the new page" do
get :new
assert_response :success
end
context "create action" do
context "given invalid parameters" do
setup do
post :create, {:nonce => {:email => ""}}
end
should "not create a new nonce" do
assert_equal(0, UserPasswordResetNonce.count)
end
should "redirect to the new page" do
assert_redirected_to new_maintenance_user_password_reset_path
end
should "not deliver an email" do
assert_equal(0, ActionMailer::Base.deliveries.size)
end
end
context "given valid parameters" do
setup do
post :create, {:nonce => {:email => @user.email}}
end
should "create a new nonce" do
assert_equal(1, UserPasswordResetNonce.where(:email => @user.email).count)
end
should "redirect to the new page" do
assert_redirected_to new_maintenance_user_password_reset_path
end
should "deliver an email to the supplied email address" do
assert_equal(1, ActionMailer::Base.deliveries.size)
end
end
end
context "edit action" do
context "with invalid parameters" do
setup do
get :edit, :email => "a@b.c"
end
should "succeed silently" do
assert_response :success
end
end
context "with valid parameters" do
setup do
@user = Factory.create(:user)
@nonce = Factory.create(:user_password_reset_nonce, :email => @user.email)
ActionMailer::Base.deliveries.clear
post :update, :email => @nonce.email, :key => @nonce.key
end
should "succeed" do
assert_redirected_to new_maintenance_user_password_reset_path
end
should "send an email" do
assert_equal(1, ActionMailer::Base.deliveries.size)
end
should "delete the nonce" do
assert_equal(0, UserPasswordResetNonce.count)
end
end
end
end
end
end
end