More tests to check that user creation works, and the url in the e-mail is the same. Seems that we can only test that a particular page is loading fine in all locales in the integration tests, and not the functional tests.

This commit is contained in:
Shaun McDonald 2009-06-07 21:07:07 +00:00
parent 91bc3c9244
commit 887eba8c8d
4 changed files with 130 additions and 25 deletions

View file

@ -146,13 +146,9 @@ class DiaryEntryControllerTest < ActionController::TestCase
end end
def test_edit_diary_entry_i18n def test_edit_diary_entry_i18n
I18n.available_locales.each do |locale| get(:edit, {:id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id})
set_locale locale assert_response :success
assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
get(:edit, {:id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id})
assert_response :success
assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
end
end end
def test_create_diary_entry def test_create_diary_entry
@ -166,20 +162,16 @@ class DiaryEntryControllerTest < ActionController::TestCase
# Check that you can get the expected response and template for all available languages # Check that you can get the expected response and template for all available languages
# Should test that there are no <span class="translation_missing"> # Should test that there are no <span class="translation_missing">
def test_listing_diary_entries def test_listing_diary_entries
I18n.available_locales.each do |locale|
set_locale locale
get :list get :list
assert_response :success, "Should be able to list the diary entries in #{locale}" assert_response :success, "Should be able to list the diary entries in locale"
assert_template 'list', "Should use the list template in #{locale}" assert_template 'list', "Should use the list template in locale"
assert_select "span[class=translation_missing]", false, "Missing translation in list of diary entries" assert_select "span[class=translation_missing]", false, "Missing translation in list of diary entries"
# Now try to find a specific user's diary entry # Now try to find a specific user's diary entry
get :list, {:display_name => users(:normal_user).display_name} get :list, {:display_name => users(:normal_user).display_name}
assert_response :success, "Should be able to list the diary entries for a user in #{locale}" assert_response :success, "Should be able to list the diary entries for a user in locale"
assert_template 'list', "Should use the list template for a user in #{locale}" assert_template 'list', "Should use the list template for a user in locale"
assert_select "span[class=translation_missing]", false, "Missing translation in list of diary entries for user" assert_no_missing_translations
end
end end
def test_rss def test_rss

View file

@ -4,7 +4,7 @@ class UserControllerTest < ActionController::TestCase
fixtures :users fixtures :users
# The user creation page loads # The user creation page loads
def test_user_create def test_user_create_view
get :new get :new
assert_response :success assert_response :success
@ -27,6 +27,41 @@ class UserControllerTest < ActionController::TestCase
end end
end end
def test_user_create_success
new_email = "newtester@osm.org"
display_name = "new_tester"
assert_difference('User.count') do
assert_difference('ActionMailer::Base.deliveries.size') do
post :save, {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}}
end
end
# Check the e-mail
register_email = ActionMailer::Base.deliveries.first
assert_equal register_email.to[0], new_email
assert_match /#{@url}/, register_email.body
# Check the page
assert_redirected_to :action => 'login'
ActionMailer::Base.deliveries.clear
end
def test_user_create_submit_duplicate_email
dup_email = users(:public_user).email
display_name = "new_tester"
assert_difference('User.count', 0) do
assert_difference('ActionMailer::Base.deliveries.size', 0) do
post :save, :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}
end
end
assert_response :success
assert_template 'new'
assert_select "div#errorExplanation"
assert_select "table#loginForm > tr > td > div[class=fieldWithErrors] > input#user_email"
end
# Check that the user account page will display and contains some relevant # Check that the user account page will display and contains some relevant
# information for the user # information for the user
def test_view_user_account def test_view_user_account

View file

@ -1,10 +1,88 @@
require 'test_helper' require File.dirname(__FILE__) + '/../test_helper'
class UserCreationTest < ActionController::IntegrationTest class UserCreationTest < ActionController::IntegrationTest
fixtures :users fixtures :users
def test_create_user_duplicate def test_create_user_form
get '/user/new' I18n.available_locales.each do |locale|
assert_response :success get '/user/new', {}, {"accept_language" => locale.to_s}
assert_response :success
assert_template 'user/new'
end
end
def test_user_create_submit_duplicate_email
I18n.available_locales.each do |localer|
dup_email = users(:public_user).email
display_name = "#{localer.to_s}_new_tester"
assert_difference('User.count', 0) do
assert_difference('ActionMailer::Base.deliveries.size', 0) do
post '/user/save',
{:user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
{"accept_language" => localer.to_s}
end
end
assert_response :success
assert_template 'user/new'
assert_equal response.headers['Content-Language'][0..1], localer.to_s[0..1] unless localer == :root
assert_select "div#errorExplanation"
assert_select "table#loginForm > tr > td > div[class=fieldWithErrors] > input#user_email"
assert_no_missing_translations
end
end
def test_user_create_submit_duplicate_username
I18n.available_locales.each do |locale|
dup_display_name = users(:public_user).display_name
email = "#{locale.to_s}_new_tester"
assert_difference('User.count', 0) do
assert_difference('ActionMailer::Base.deliveries.size', 0) do
post '/user/save',
{:user => {:email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
{"accept_language" => locale.to_s}
end
end
assert_response :success
assert_template 'user/new'
assert_select "div#errorExplanation"
assert_select "table#loginForm > tr > td > div[class=fieldWithErrors] > input#user_display_name"
assert_no_missing_translations
end
end
def test_user_create_success
I18n.available_locales.each do |locale|
new_email = "#{locale.to_s}newtester@osm.org"
display_name = "#{locale.to_s}_new_tester"
assert_difference('User.count') do
assert_difference('ActionMailer::Base.deliveries.size', 1) do
post_via_redirect "/user/save",
{:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
{"accept_language" => "#{locale.to_s}"}
end
end
# Check the e-mail
register_email = ActionMailer::Base.deliveries.first
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
assert_match /#{@url}/, register_email.body
# Check the page
assert_response :success
assert_template 'login'
ActionMailer::Base.deliveries.clear
end
end
# Check that the user can successfully recover their password
def lost_password_recovery_success
# Open the lost password form
# Submit the lost password form
# Check the e-mail
# Submit the reset password token
# Check that the password has changed, and the user can login
end end
end end

View file

@ -123,10 +123,6 @@ class ActiveSupport::TestCase
@request.env["RAW_POST_DATA"] = c.to_s @request.env["RAW_POST_DATA"] = c.to_s
end end
def set_locale(l)
@request.env["HTTP_ACCEPT_LANGUAGE"] = l.to_s
end
# Used to check that the error header and the forbidden responses are given # Used to check that the error header and the forbidden responses are given
# when the owner of the changset has their data not marked as public # when the owner of the changset has their data not marked as public
def assert_require_public_data(msg = "Shouldn't be able to use API when the user's data is not public") def assert_require_public_data(msg = "Shouldn't be able to use API when the user's data is not public")
@ -140,5 +136,9 @@ class ActiveSupport::TestCase
#assert_equal @response.headers['Error'], "" #assert_equal @response.headers['Error'], ""
end end
def assert_no_missing_translations(msg="")
assert_select "span[class=translation_missing]", false, "Missing translation #{msg}"
end
# Add more helper methods to be used by all tests here... # Add more helper methods to be used by all tests here...
end end