]> git.openstreetmap.org Git - rails.git/commitdiff
More tests to check that user creation works, and the url in the e-mail is the same...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Sun, 7 Jun 2009 21:07:07 +0000 (21:07 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Sun, 7 Jun 2009 21:07:07 +0000 (21:07 +0000)
test/functional/diary_entry_controller_test.rb
test/functional/user_controller_test.rb
test/integration/user_creation_test.rb
test/test_helper.rb

index 709404045dbb1cb516d9444d40183557a69f31b2..d060af4167edecce21d5d91512a2efb5712a9a9a 100644 (file)
@@ -146,13 +146,9 @@ class DiaryEntryControllerTest < ActionController::TestCase
   end
   
   def test_edit_diary_entry_i18n
   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
   end
   
   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
   # Should test that there are no <span class="translation_missing">
   def test_listing_diary_entries
   # 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
       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_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
   end
   
   def test_rss
index 8d90b2bcfd84f8811f8cf5daca8a0d07be409949..5c1d6f47eb2d4743a5b80a3a149ccd7d6c2e53a1 100644 (file)
@@ -4,7 +4,7 @@ class UserControllerTest < ActionController::TestCase
   fixtures :users
   
   # The user creation page loads
   fixtures :users
   
   # The user creation page loads
-  def test_user_create
+  def test_user_create_view
     get :new
     assert_response :success
     
     get :new
     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
   # information for the user
   def test_view_user_account
   # Check that the user account page will display and contains some relevant
   # information for the user
   def test_view_user_account
index 5f664b5c8f4e15817b4dbe48099f18e7a31fa567..e6ac49e8d5579c82ec16aad6b0c868261f6c050f 100644 (file)
@@ -1,10 +1,88 @@
-require 'test_helper'
+require File.dirname(__FILE__) + '/../test_helper'
 
 class UserCreationTest < ActionController::IntegrationTest
   fixtures :users
 
 
 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
   end
 end
index c210315a96458a96b9b944e2f6c9d7c002c7e030..97c74900075def22db5e50c94a17d818b8b42334 100644 (file)
@@ -123,10 +123,6 @@ class ActiveSupport::TestCase
     @request.env["RAW_POST_DATA"] = c.to_s
   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")
   # 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")
@@ -140,5 +136,9 @@ class ActiveSupport::TestCase
     #assert_equal @response.headers['Error'], ""
   end
   
     #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
   # Add more helper methods to be used by all tests here...
 end