test/integration/authenticatable_test.rb in devise-3.2.3 vs test/integration/authenticatable_test.rb in devise-3.2.4
- old
+ new
@@ -25,43 +25,43 @@
assert warden.authenticated?(:user)
assert warden.authenticated?(:admin)
end
test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
- swap Devise, :sign_out_all_scopes => false do
+ swap Devise, sign_out_all_scopes: false do
sign_in_as_user
sign_in_as_admin
get destroy_user_session_path
assert_not warden.authenticated?(:user)
assert warden.authenticated?(:admin)
end
end
test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
- swap Devise, :sign_out_all_scopes => false do
+ swap Devise, sign_out_all_scopes: false do
sign_in_as_user
sign_in_as_admin
get destroy_admin_session_path
assert_not warden.authenticated?(:admin)
assert warden.authenticated?(:user)
end
end
test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
- swap Devise, :sign_out_all_scopes => true do
+ swap Devise, sign_out_all_scopes: true do
sign_in_as_user
sign_in_as_admin
get destroy_user_session_path
assert_not warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
end
end
test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
- swap Devise, :sign_out_all_scopes => true do
+ swap Devise, sign_out_all_scopes: true do
sign_in_as_user
sign_in_as_admin
get destroy_admin_session_path
assert_not warden.authenticated?(:admin)
@@ -160,21 +160,21 @@
assert_template 'home/private'
assert_contain 'Private!'
end
test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
- sign_in_as_admin(:active => false)
+ sign_in_as_admin(active: false)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
assert_raises ActionController::RoutingError do
get "/private/active"
end
end
test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
- sign_in_as_admin(:active => true)
+ sign_in_as_admin(active: true)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get private_active_path
@@ -212,21 +212,21 @@
get dashboard_path
end
end
test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
- sign_in_as_admin(:active => false)
+ sign_in_as_admin(active: false)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
assert_raises ActionController::RoutingError do
get "/dashboard/active"
end
end
test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
- sign_in_as_admin(:active => true)
+ sign_in_as_admin(active: true)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get dashboard_active_path
@@ -275,11 +275,11 @@
get users_path
assert_redirected_to new_user_session_path
assert_equal users_path, session[:"user_return_to"]
follow_redirect!
- sign_in_as_user :visit => false
+ sign_in_as_user visit: false
assert_current_url '/users'
assert_nil session[:"user_return_to"]
end
@@ -291,11 +291,11 @@
get users_path
assert_redirected_to new_user_session_path
assert_equal users_path, session[:"user_return_to"]
follow_redirect!
- sign_in_as_user :visit => false
+ sign_in_as_user visit: false
assert_current_url '/users'
assert_nil session[:"user_return_to"]
end
@@ -390,11 +390,11 @@
end
end
class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
test 'renders the scoped view if turned on and view is available' do
- swap Devise, :scoped_views => true do
+ swap Devise, scoped_views: true do
assert_raise Webrat::NotFoundError do
sign_in_as_user
end
assert_match /Special user view/, response.body
end
@@ -413,29 +413,29 @@
Devise::SessionsController.send :remove_instance_variable, :@scoped_views
end
end
test 'does not render the scoped view if turned off' do
- swap Devise, :scoped_views => false do
+ swap Devise, scoped_views: false do
assert_nothing_raised do
sign_in_as_user
end
end
end
test 'does not render the scoped view if not available' do
- swap Devise, :scoped_views => true do
+ swap Devise, scoped_views: true do
assert_nothing_raised do
sign_in_as_admin
end
end
end
end
class AuthenticationOthersTest < ActionDispatch::IntegrationTest
test 'handles unverified requests gets rid of caches' do
- swap ApplicationController, :allow_forgery_protection => true do
+ swap ApplicationController, allow_forgery_protection: true do
post exhibit_user_url(1)
assert_not warden.authenticated?(:user)
sign_in_as_user
assert warden.authenticated?(:user)
@@ -471,63 +471,63 @@
end
test 'sign in with script name' do
assert_nothing_raised do
get new_user_session_path, {}, "SCRIPT_NAME" => "/omg"
- fill_in "email", :with => "user@test.com"
+ fill_in "email", with: "user@test.com"
end
end
test 'sign in stub in xml format' do
- get new_user_session_path(:format => 'xml')
+ get new_user_session_path(format: 'xml')
assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
assert_match /<user>.*<\/user>/m, response.body
assert_match '<email></email>', response.body
assert_match '<password nil="true"', response.body
end
test 'sign in stub in json format' do
- get new_user_session_path(:format => 'json')
+ get new_user_session_path(format: 'json')
assert_match '{"user":{', response.body
assert_match '"email":""', response.body
assert_match '"password":null', response.body
end
test 'sign in stub in json with non attribute key' do
- swap Devise, :authentication_keys => [:other_key] do
- get new_user_session_path(:format => 'json')
+ swap Devise, authentication_keys: [:other_key] do
+ get new_user_session_path(format: 'json')
assert_match '{"user":{', response.body
assert_match '"other_key":null', response.body
assert_match '"password":null', response.body
end
end
test 'uses the mapping from router' do
- sign_in_as_user :visit => "/as/sign_in"
+ sign_in_as_user visit: "/as/sign_in"
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
end
test 'sign in with xml format returns xml response' do
create_user
- post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
+ post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign in with xml format is idempotent' do
- get new_user_session_path(:format => 'xml')
+ get new_user_session_path(format: 'xml')
assert_response :success
create_user
- post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
+ post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
assert_response :success
- get new_user_session_path(:format => 'xml')
+ get new_user_session_path(format: 'xml')
assert_response :success
- post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
+ post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign out with html redirects' do
@@ -535,79 +535,79 @@
get destroy_user_session_path
assert_response :redirect
assert_current_url '/'
sign_in_as_user
- get destroy_user_session_path(:format => 'html')
+ get destroy_user_session_path(format: 'html')
assert_response :redirect
assert_current_url '/'
end
test 'sign out with xml format returns no content' do
sign_in_as_user
- get destroy_user_session_path(:format => 'xml')
+ get destroy_user_session_path(format: 'xml')
assert_response :no_content
assert_not warden.authenticated?(:user)
end
test 'sign out with json format returns no content' do
sign_in_as_user
- get destroy_user_session_path(:format => 'json')
+ get destroy_user_session_path(format: 'json')
assert_response :no_content
assert_not warden.authenticated?(:user)
end
test 'sign out with non-navigational format via XHR does not redirect' do
- swap Devise, :navigational_formats => ['*/*', :html] do
+ swap Devise, navigational_formats: ['*/*', :html] do
sign_in_as_user
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
assert_response :no_content
assert_not warden.authenticated?(:user)
end
end
# Belt and braces ... Perhaps this test is not necessary?
test 'sign out with navigational format via XHR does redirect' do
- swap Devise, :navigational_formats => ['*/*', :html] do
+ swap Devise, navigational_formats: ['*/*', :html] do
sign_in_as_user
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" }
assert_response :redirect
assert_not warden.authenticated?(:user)
end
end
end
class AuthenticationKeysTest < ActionDispatch::IntegrationTest
test 'missing authentication keys cause authentication to abort' do
- swap Devise, :authentication_keys => [:subdomain] do
+ swap Devise, authentication_keys: [:subdomain] do
sign_in_as_user
assert_contain "Invalid email or password."
assert_not warden.authenticated?(:user)
end
end
test 'missing authentication keys cause authentication to abort unless marked as not required' do
- swap Devise, :authentication_keys => { :email => true, :subdomain => false } do
+ swap Devise, authentication_keys: { email: true, subdomain: false } do
sign_in_as_user
assert warden.authenticated?(:user)
end
end
end
class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
test 'request keys are used on authentication' do
host! 'foo.bar.baz'
- swap Devise, :request_keys => [:subdomain] do
- User.expects(:find_for_authentication).with(:subdomain => 'foo', :email => 'user@test.com').returns(create_user)
+ swap Devise, request_keys: [:subdomain] do
+ User.expects(:find_for_authentication).with(subdomain: 'foo', email: 'user@test.com').returns(create_user)
sign_in_as_user
assert warden.authenticated?(:user)
end
end
test 'invalid request keys raises NoMethodError' do
- swap Devise, :request_keys => [:unknown_method] do
+ swap Devise, request_keys: [:unknown_method] do
assert_raise NoMethodError do
sign_in_as_user
end
assert_not warden.authenticated?(:user)
@@ -615,30 +615,30 @@
end
test 'blank request keys cause authentication to abort' do
host! 'test.com'
- swap Devise, :request_keys => [:subdomain] do
+ swap Devise, request_keys: [:subdomain] do
sign_in_as_user
assert_contain "Invalid email or password."
assert_not warden.authenticated?(:user)
end
end
test 'blank request keys cause authentication to abort unless if marked as not required' do
host! 'test.com'
- swap Devise, :request_keys => { :subdomain => false } do
+ swap Devise, request_keys: { subdomain: false } do
sign_in_as_user
assert warden.authenticated?(:user)
end
end
end
class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
def sign_in!(scope)
- sign_in_as_admin(:visit => send("new_#{scope}_session_path"))
+ sign_in_as_admin(visit: send("new_#{scope}_session_path"))
assert warden.authenticated?(scope)
end
test 'allow sign out via delete when sign_out_via provides only delete' do
sign_in!(:sign_out_via_delete)
@@ -690,24 +690,24 @@
end
class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest
test 'signed in as user redirects when visiting user sign in page' do
sign_in_as_user
- get new_user_session_path(:format => :html)
+ get new_user_session_path(format: :html)
assert_redirected_to '/'
end
test 'signed in as admin redirects when visiting admin sign in page' do
sign_in_as_admin
- get new_admin_session_path(:format => :html)
+ get new_admin_session_path(format: :html)
assert_redirected_to '/admin_area/home'
end
test 'signed in as both user and admin redirects when visiting admin sign in page' do
sign_in_as_user
sign_in_as_admin
- get new_user_session_path(:format => :html)
+ get new_user_session_path(format: :html)
assert_redirected_to '/'
- get new_admin_session_path(:format => :html)
+ get new_admin_session_path(format: :html)
assert_redirected_to '/admin_area/home'
end
end