]> git.openstreetmap.org Git - rails.git/blobdiff - test/integration/user_creation_test.rb
Use svg icons in first/last element version links
[rails.git] / test / integration / user_creation_test.rb
index 8ec0dc9bc049e2486458f50b650034e5d0f52beb..253f298a58f36493bb9e5bbca18c34586f75de30 100644 (file)
@@ -65,6 +65,26 @@ class UserCreationTest < ActionDispatch::IntegrationTest
     assert_select "form > div > input.is-invalid#user_display_name"
   end
 
+  def test_user_create_submit_mismatched_passwords
+    email = "newtester@osm.org"
+    display_name = "new_tester"
+    assert_difference("User.count", 0) do
+      assert_difference("ActionMailer::Base.deliveries.size", 0) do
+        perform_enqueued_jobs do
+          post "/user/new",
+               :params => { :user => { :email => email,
+                                       :email_confirmation => email,
+                                       :display_name => display_name,
+                                       :pass_crypt => "testtest",
+                                       :pass_crypt_confirmation => "blahblah" } }
+        end
+      end
+    end
+    assert_response :success
+    assert_template "users/new"
+    assert_select "form > div > input.is-invalid#user_pass_crypt_confirmation"
+  end
+
   def test_user_create_success
     new_email = "newtester@osm.org"
     display_name = "new_tester"
@@ -94,18 +114,29 @@ class UserCreationTest < ActionDispatch::IntegrationTest
       end
     end
 
-    # Check the e-mail
-    register_email = ActionMailer::Base.deliveries.first
-
-    assert_equal register_email.to.first, new_email
-    # Check that the confirm account url is correct
-    assert_match(/#{@url}/, register_email.body.to_s)
-
-    # Check the page
     assert_response :success
     assert_template "confirmations/confirm"
 
+    user = User.find_by(:email => "newtester@osm.org")
+    assert_not_nil user
+    assert_not_predicate user, :active?
+
+    register_email = ActionMailer::Base.deliveries.first
+    assert_equal register_email.to.first, new_email
+    found_confirmation_url = register_email.parts.first.parts.first.to_s =~ %r{\shttp://test.host(/\S+)\s}
+    assert found_confirmation_url
+    confirmation_url = Regexp.last_match(1)
     ActionMailer::Base.deliveries.clear
+
+    post confirmation_url
+
+    assert_response :redirect
+    assert_redirected_to welcome_path
+
+    user.reload
+    assert_predicate user, :active?
+
+    assert_equal user, User.authenticate(:username => new_email, :password => "testtest")
   end
 
   def test_user_create_no_tou_failure