fixing functional tests
This commit is contained in:
2
test/factories/user_password_reset_nonce.rb
Normal file
2
test/factories/user_password_reset_nonce.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
Factory.define(:user_password_reset_nonce) do |f|
|
||||
end
|
||||
11
test/fixtures/user_password_reset_nonces.yml
vendored
Normal file
11
test/fixtures/user_password_reset_nonces.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -15,7 +15,8 @@ class WikiPagesControllerTest < ActionController::TestCase
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
Factory.create(:wiki_page, :title => "abc")
|
||||
@wiki_page_abc = Factory.create(:wiki_page, :title => "abc")
|
||||
@wiki_page_def = Factory.create(:wiki_page, :title => "def")
|
||||
end
|
||||
|
||||
should "list all wiki_pages" do
|
||||
@@ -25,7 +26,7 @@ class WikiPagesControllerTest < ActionController::TestCase
|
||||
|
||||
should "list all wiki_pages (with search)" do
|
||||
get :index, {:search => {:title_matches => "abc"}}
|
||||
assert_response :success
|
||||
assert_redirected_to(wiki_page_path(@wiki_page_abc))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
18
test/unit/maintenance/user/login_reminder_mailer_test.rb
Normal file
18
test/unit/maintenance/user/login_reminder_mailer_test.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require "test_helper"
|
||||
|
||||
module Maintenance
|
||||
module User
|
||||
class LoginReminderMailerTest < ActionMailer::TestCase
|
||||
context "The login reminder mailer" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
end
|
||||
|
||||
should "send the notie" do
|
||||
LoginReminderMailer.notice(@user).deliver
|
||||
assert !ActionMailer::Base.deliveries.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
48
test/unit/user_password_reset_nonce_test.rb
Normal file
48
test/unit/user_password_reset_nonce_test.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserPasswordResetNonceTest < ActiveSupport::TestCase
|
||||
context "Creating a new nonce" do
|
||||
context "with a valid email" do
|
||||
setup do
|
||||
@user = Factory.create(:user, :email => "aaa@b.net")
|
||||
@nonce = Factory.create(:user_password_reset_nonce, :email => @user.email)
|
||||
end
|
||||
|
||||
should "validate" do
|
||||
assert_equal([], @nonce.errors.full_messages)
|
||||
end
|
||||
|
||||
should "populate the key with a random string" do
|
||||
assert_equal(32, @nonce.key.size)
|
||||
end
|
||||
|
||||
should "reset the password when reset" do
|
||||
@nonce.user.expects(:reset_password_and_deliver_notice)
|
||||
@nonce.reset_user!
|
||||
end
|
||||
end
|
||||
|
||||
context "with a blank email" do
|
||||
setup do
|
||||
@user = Factory.create(:user, :email => "")
|
||||
@nonce = UserPasswordResetNonce.new(:email => "")
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
@nonce.save
|
||||
assert_equal(["Email can't be blank", "Email is invalid"], @nonce.errors.full_messages.sort)
|
||||
end
|
||||
end
|
||||
|
||||
context "with an invalid email" do
|
||||
setup do
|
||||
@nonce = UserPasswordResetNonce.new(:email => "z@z.net")
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
@nonce.save
|
||||
assert_equal(["Email is invalid"], @nonce.errors.full_messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user