Ensure method is always POST on new.html.erb forms, closes #365. Also, start to remove usage of assert_template.

This commit is contained in:
José Valim 2010-07-06 16:00:07 +02:00
parent e2a4ebce4a
commit 750560ae87
5 changed files with 28 additions and 15 deletions

View File

@ -1,6 +1,6 @@
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name)) do |f| %>
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />

View File

@ -1,6 +1,6 @@
<h2>Forgot your password?</h2>
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name)) do |f| %>
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />

View File

@ -1,6 +1,6 @@
<h2>Resend unlock instructions</h2>
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name)) do |f| %>
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />

View File

@ -16,16 +16,13 @@ class ConfirmationTest < ActionController::IntegrationTest
fill_in 'email', :with => user.email
click_button 'Resend confirmation instructions'
assert_template 'sessions/new'
assert_current_url '/users/sign_in'
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
assert_equal 1, ActionMailer::Base.deliveries.size
end
test 'user with invalid confirmation token should not be able to confirm an account' do
visit_user_confirmation_with_token('invalid_confirmation')
assert_response :success
assert_template 'confirmations/new'
assert_have_selector '#error_explanation'
assert_contain /Confirmation token(.*)invalid/
end
@ -33,26 +30,36 @@ class ConfirmationTest < ActionController::IntegrationTest
test 'user with valid confirmation token should be able to confirm an account' do
user = create_user(:confirm => false)
assert_not user.confirmed?
visit_user_confirmation_with_token(user.confirmation_token)
assert_template 'home/index'
assert_contain 'Your account was successfully confirmed.'
assert_current_url '/'
assert user.reload.confirmed?
end
test 'user already confirmed user should not be able to confirm the account again' do
test 'already confirmed user should not be able to confirm the account again' do
user = create_user(:confirm => false)
user.confirmed_at = Time.now
user.save
visit_user_confirmation_with_token(user.confirmation_token)
assert_template 'confirmations/new'
assert_have_selector '#error_explanation'
assert_contain 'already confirmed'
end
test 'already confirmed user should not be able to confirm the account again neither request confirmation' do
user = create_user(:confirm => false)
user.confirmed_at = Time.now
user.save
visit_user_confirmation_with_token(user.confirmation_token)
assert_contain 'already confirmed'
fill_in 'email', :with => user.email
click_button 'Resend confirmation instructions'
assert_contain 'already confirmed'
end
test 'sign in user automatically after confirming it\'s email' do
user = create_user(:confirm => false)
visit_user_confirmation_with_token(user.confirmation_token)

View File

@ -57,9 +57,15 @@ class ActionDispatch::IntegrationTest
assert [301, 302].include?(@integration_session.status),
"Expected status to be 301 or 302, got #{@integration_session.status}"
url = prepend_host(url)
location = prepend_host(@integration_session.headers["Location"])
assert_equal url, location
assert_url url, @integration_session.headers["Location"]
end
def assert_current_url(expected)
assert_url expected, current_url
end
def assert_url(expected, actual)
assert_equal prepend_host(expected), prepend_host(actual)
end
protected