2017-12-21 17:36:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-03-26 10:27:19 +00:00
|
|
|
require 'test_helper'
|
2009-10-10 00:11:58 +00:00
|
|
|
|
2015-08-18 23:42:56 +00:00
|
|
|
class RoutesTest < Devise::ControllerTestCase
|
2009-10-10 00:11:58 +00:00
|
|
|
tests ApplicationController
|
|
|
|
|
2010-03-26 10:27:19 +00:00
|
|
|
def assert_path_and_url(name, prepend_path=nil)
|
2009-10-10 00:11:58 +00:00
|
|
|
@request.path = '/users/session'
|
|
|
|
prepend_path = "#{prepend_path}_" if prepend_path
|
2009-10-11 11:15:48 +00:00
|
|
|
|
2009-10-16 16:44:51 +00:00
|
|
|
# Resource param
|
2009-10-12 02:24:57 +00:00
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user),
|
2009-10-10 11:37:22 +00:00
|
|
|
send(:"#{prepend_path}user_#{name}_path")
|
2009-10-12 02:24:57 +00:00
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
2009-10-10 11:37:22 +00:00
|
|
|
send(:"#{prepend_path}user_#{name}_url")
|
2009-10-10 00:11:58 +00:00
|
|
|
|
2014-08-23 13:33:08 +00:00
|
|
|
# With string
|
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", "user"),
|
|
|
|
send(:"#{prepend_path}user_#{name}_path")
|
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", "user"),
|
|
|
|
send(:"#{prepend_path}user_#{name}_url")
|
|
|
|
|
2009-10-11 11:15:48 +00:00
|
|
|
# Default url params
|
2014-02-25 16:42:55 +00:00
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
|
|
|
|
send(:"#{prepend_path}user_#{name}_path", param: 123)
|
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, param: 123),
|
|
|
|
send(:"#{prepend_path}user_#{name}_url", param: 123)
|
2009-10-10 00:11:58 +00:00
|
|
|
|
2009-10-10 11:37:22 +00:00
|
|
|
@request.path = nil
|
2010-07-16 11:42:13 +00:00
|
|
|
# With an object
|
2009-10-10 11:37:22 +00:00
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
|
|
|
send(:"#{prepend_path}user_#{name}_path")
|
|
|
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
|
|
|
send(:"#{prepend_path}user_#{name}_url")
|
2009-10-10 00:11:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test 'should alias session to mapped user session' do
|
2010-03-26 10:27:19 +00:00
|
|
|
assert_path_and_url :session
|
|
|
|
assert_path_and_url :session, :new
|
|
|
|
assert_path_and_url :session, :destroy
|
2009-10-10 00:11:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should alias password to mapped user password' do
|
2010-03-26 10:27:19 +00:00
|
|
|
assert_path_and_url :password
|
|
|
|
assert_path_and_url :password, :new
|
|
|
|
assert_path_and_url :password, :edit
|
2009-10-10 00:11:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should alias confirmation to mapped user confirmation' do
|
2010-03-26 10:27:19 +00:00
|
|
|
assert_path_and_url :confirmation
|
|
|
|
assert_path_and_url :confirmation, :new
|
2009-10-10 00:11:58 +00:00
|
|
|
end
|
2010-07-04 09:53:12 +00:00
|
|
|
|
|
|
|
test 'should alias unlock to mapped user unlock' do
|
|
|
|
assert_path_and_url :unlock
|
|
|
|
assert_path_and_url :unlock, :new
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should alias registration to mapped user registration' do
|
|
|
|
assert_path_and_url :registration
|
|
|
|
assert_path_and_url :registration, :new
|
|
|
|
assert_path_and_url :registration, :edit
|
2010-07-15 20:00:20 +00:00
|
|
|
assert_path_and_url :registration, :cancel
|
2010-07-04 09:53:12 +00:00
|
|
|
end
|
2009-10-10 00:11:58 +00:00
|
|
|
end
|