end
def test_edit_diary_entry_i18n
- I18n.available_locales.each do |locale|
- set_locale locale
-
- 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
+ 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
def test_create_diary_entry
# Check that you can get the expected response and template for all available languages
# Should test that there are no <span class="translation_missing">
def test_listing_diary_entries
- I18n.available_locales.each do |locale|
- set_locale locale
-
get :list
- assert_response :success, "Should be able to list the diary entries in #{locale}"
- assert_template 'list', "Should use the list template 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_select "span[class=translation_missing]", false, "Missing translation in list of diary entries"
# Now try to find a specific user's diary entry
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_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"
- end
+ 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_no_missing_translations
end
def test_rss
fixtures :users
# The user creation page loads
- def test_user_create
+ def test_user_create_view
get :new
assert_response :success
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
# information for the user
def test_view_user_account
-require 'test_helper'
+require File.dirname(__FILE__) + '/../test_helper'
class UserCreationTest < ActionController::IntegrationTest
fixtures :users
- def test_create_user_duplicate
- get '/user/new'
- assert_response :success
+ def test_create_user_form
+ I18n.available_locales.each do |locale|
+ 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
@request.env["RAW_POST_DATA"] = c.to_s
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
# 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")
#assert_equal @response.headers['Error'], ""
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...
end