2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/core_ext/object/try"
|
|
|
|
require "active_support/core_ext/object/with_options"
|
|
|
|
require "active_support/core_ext/array/extract_options"
|
2006-07-31 14:59:58 -04:00
|
|
|
|
2016-05-31 11:21:30 -04:00
|
|
|
class AdminController < ResourcesController; end
|
|
|
|
class MessagesController < ResourcesController; end
|
|
|
|
class ProductsController < ResourcesController; end
|
|
|
|
class ThreadsController < ResourcesController; end
|
|
|
|
|
|
|
|
module Backoffice
|
|
|
|
class ProductsController < ResourcesController; end
|
|
|
|
class ImagesController < ResourcesController; end
|
2013-11-27 16:44:19 -05:00
|
|
|
|
2016-05-31 11:21:30 -04:00
|
|
|
module Admin
|
|
|
|
class ProductsController < ResourcesController; end
|
|
|
|
class ImagesController < ResourcesController; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ResourcesTest < ActionController::TestCase
|
2006-07-31 14:59:58 -04:00
|
|
|
def test_default_restful_routes
|
|
|
|
with_restful_routing :messages do
|
2006-07-31 16:00:18 -04:00
|
|
|
assert_simply_restful_for :messages
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-09 02:28:29 -04:00
|
|
|
def test_override_paths_for_member_and_collection_methods
|
2016-08-06 13:35:13 -04:00
|
|
|
collection_methods = { rss: :get, reorder: :post, csv: :post }
|
2016-10-28 23:05:58 -04:00
|
|
|
member_methods = { rss: :get, atom: :get, upload: :post, fix: :post }
|
2016-08-16 03:30:11 -04:00
|
|
|
path_names = { new: "nuevo", rss: "canal", fix: "corrigir" }
|
2009-08-09 02:28:29 -04:00
|
|
|
|
|
|
|
with_restful_routing :messages,
|
2016-08-06 13:35:13 -04:00
|
|
|
collection: collection_methods,
|
|
|
|
member: member_methods,
|
|
|
|
path_names: path_names do
|
2009-08-09 02:28:29 -04:00
|
|
|
|
|
|
|
assert_restful_routes_for :messages,
|
2016-08-06 13:35:13 -04:00
|
|
|
collection: collection_methods,
|
|
|
|
member: member_methods,
|
|
|
|
path_names: path_names do |options|
|
2009-08-09 02:28:29 -04:00
|
|
|
member_methods.each do |action, method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: action.to_s, id: "1"),
|
|
|
|
path: "/messages/1/#{path_names[action] || action}",
|
|
|
|
method: method)
|
2009-08-09 02:28:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
collection_methods.each do |action, method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: action.to_s),
|
|
|
|
path: "/messages/#{path_names[action] || action}",
|
|
|
|
method: method)
|
2009-08-09 02:28:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_restful_named_routes_for :messages,
|
2016-08-06 13:35:13 -04:00
|
|
|
collection: collection_methods,
|
|
|
|
member: member_methods,
|
|
|
|
path_names: path_names do |options|
|
2009-08-09 02:28:29 -04:00
|
|
|
|
2014-09-29 10:07:18 -04:00
|
|
|
collection_methods.each_key do |action|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "/messages/#{path_names[action] || action}", "#{action}_messages_path", action: action
|
2009-08-09 02:28:29 -04:00
|
|
|
end
|
|
|
|
|
2014-09-29 10:07:18 -04:00
|
|
|
member_methods.each_key do |action|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "/messages/1/#{path_names[action] || action}", "#{action}_message_path", action: action, id: "1"
|
2009-08-09 02:28:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 16:32:48 -04:00
|
|
|
def test_multiple_default_restful_routes
|
|
|
|
with_restful_routing :messages, :comments do
|
|
|
|
assert_simply_restful_for :messages
|
|
|
|
assert_simply_restful_for :comments
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-28 14:00:48 -04:00
|
|
|
def test_multiple_resources_with_options
|
2016-08-16 03:30:11 -04:00
|
|
|
expected_options = { controller: "threads", action: "index" }
|
2011-07-28 14:00:48 -04:00
|
|
|
|
|
|
|
with_restful_routing :messages, :comments, expected_options.slice(:controller) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(expected_options, path: "comments")
|
|
|
|
assert_recognizes(expected_options, path: "messages")
|
2011-07-28 14:00:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-07-24 22:47:21 -04:00
|
|
|
def test_with_custom_conditions
|
2016-08-06 13:35:13 -04:00
|
|
|
with_restful_routing :messages, conditions: { subdomain: "app" } do
|
|
|
|
assert @routes.recognize_path("/messages", method: :get, subdomain: "app")
|
2007-07-24 22:47:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-05 09:44:23 -04:00
|
|
|
def test_irregular_id_with_no_constraints_should_raise_error
|
2016-08-16 03:30:11 -04:00
|
|
|
expected_options = { controller: "messages", action: "show", id: "1.1.1" }
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2007-02-25 15:13:19 -05:00
|
|
|
with_restful_routing :messages do
|
2012-05-19 17:28:14 -04:00
|
|
|
assert_raise(Assertion) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(expected_options, path: "messages/1.1.1", method: :get)
|
2007-02-25 15:13:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2010-08-05 09:44:23 -04:00
|
|
|
def test_irregular_id_with_constraints_should_pass
|
2016-08-16 03:30:11 -04:00
|
|
|
expected_options = { controller: "messages", action: "show", id: "1.1.1" }
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
with_restful_routing(:messages, constraints: { id: /[0-9]\.[0-9]\.[0-9]/ }) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(expected_options, path: "messages/1.1.1", method: :get)
|
2007-02-25 15:13:19 -05:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2010-08-05 09:44:23 -04:00
|
|
|
def test_with_path_prefix_constraints
|
2016-08-16 03:30:11 -04:00
|
|
|
expected_options = { controller: "messages", action: "show", thread_id: "1.1.1", id: "1" }
|
|
|
|
with_restful_routing :messages, path_prefix: "/thread/:thread_id", constraints: { thread_id: /[0-9]\.[0-9]\.[0-9]/ } do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(expected_options, path: "thread/1.1.1/messages/1", method: :get)
|
2007-02-25 15:13:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-05 09:44:23 -04:00
|
|
|
def test_irregular_id_constraints_should_get_passed_to_member_actions
|
2016-08-16 03:30:11 -04:00
|
|
|
expected_options = { controller: "messages", action: "custom", id: "1.1.1" }
|
2009-05-01 16:49:18 -04:00
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
with_restful_routing(:messages, member: { custom: :get }, constraints: { id: /[0-9]\.[0-9]\.[0-9]/ }) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(expected_options, path: "messages/1.1.1/custom", method: :get)
|
2009-05-01 16:49:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 14:59:58 -04:00
|
|
|
def test_with_path_prefix
|
2016-08-06 13:35:13 -04:00
|
|
|
with_restful_routing :messages, path_prefix: "/thread/:thread_id" do
|
|
|
|
assert_simply_restful_for :messages, path_prefix: "thread/5/", options: { thread_id: "5" }
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-06-27 04:38:55 -04:00
|
|
|
def test_multiple_with_path_prefix
|
2016-08-06 13:35:13 -04:00
|
|
|
with_restful_routing :messages, :comments, path_prefix: "/thread/:thread_id" do
|
|
|
|
assert_simply_restful_for :messages, path_prefix: "thread/5/", options: { thread_id: "5" }
|
|
|
|
assert_simply_restful_for :comments, path_prefix: "thread/5/", options: { thread_id: "5" }
|
2006-07-31 16:32:48 -04:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2007-01-17 01:46:02 -05:00
|
|
|
def test_with_name_prefix
|
2016-08-06 13:35:13 -04:00
|
|
|
with_restful_routing :messages, as: "post_messages" do
|
|
|
|
assert_simply_restful_for :messages, name_prefix: "post_"
|
2007-01-17 01:46:02 -05:00
|
|
|
end
|
|
|
|
end
|
2006-07-31 16:32:48 -04:00
|
|
|
|
2007-06-27 04:38:55 -04:00
|
|
|
def test_with_collection_actions
|
2016-08-06 12:54:50 -04:00
|
|
|
actions = { "a" => :get, "b" => :put, "c" => :post, "d" => :delete, "e" => :patch }
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resources :messages do
|
2016-08-06 13:35:13 -04:00
|
|
|
get :a, on: :collection
|
|
|
|
put :b, on: :collection
|
|
|
|
post :c, on: :collection
|
|
|
|
delete :d, on: :collection
|
|
|
|
patch :e, on: :collection
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 14:59:58 -04:00
|
|
|
assert_restful_routes_for :messages do |options|
|
2006-09-14 15:53:04 -04:00
|
|
|
actions.each do |action, method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: action), path: "/messages/#{action}", method: method)
|
2006-09-14 15:53:04 -04:00
|
|
|
end
|
2006-07-31 16:00:18 -04:00
|
|
|
end
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2015-08-25 01:05:18 -04:00
|
|
|
assert_restful_named_routes_for :messages do
|
2014-09-29 10:07:18 -04:00
|
|
|
actions.each_key do |action|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "/messages/#{action}", "#{action}_messages_path", action: action
|
2006-09-14 15:53:04 -04:00
|
|
|
end
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-06-27 04:38:55 -04:00
|
|
|
def test_with_collection_actions_and_name_prefix
|
2016-08-06 12:54:50 -04:00
|
|
|
actions = { "a" => :get, "b" => :put, "c" => :post, "d" => :delete, "e" => :patch }
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope "/threads/:thread_id" do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :messages, as: "thread_messages" do
|
|
|
|
get :a, on: :collection
|
|
|
|
put :b, on: :collection
|
|
|
|
post :c, on: :collection
|
|
|
|
delete :d, on: :collection
|
|
|
|
patch :e, on: :collection
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options|
|
2007-06-27 04:38:55 -04:00
|
|
|
actions.each do |action, method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: action), path: "/threads/1/messages/#{action}", method: method)
|
2007-06-27 04:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do
|
2014-09-29 10:07:18 -04:00
|
|
|
actions.each_key do |action|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", action: action
|
2007-06-27 04:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-14 11:06:00 -04:00
|
|
|
def test_with_collection_actions_and_name_prefix_and_member_action_with_same_name
|
2016-08-06 12:54:50 -04:00
|
|
|
actions = { "a" => :get }
|
2009-03-14 11:06:00 -04:00
|
|
|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope "/threads/:thread_id" do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :messages, as: "thread_messages" do
|
|
|
|
get :a, on: :collection
|
|
|
|
get :a, on: :member
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options|
|
2009-03-14 11:06:00 -04:00
|
|
|
actions.each do |action, method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: action), path: "/threads/1/messages/#{action}", method: method)
|
2009-03-14 11:06:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do
|
2014-09-29 10:07:18 -04:00
|
|
|
actions.each_key do |action|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", action: action
|
2009-03-14 11:06:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-06-27 04:38:55 -04:00
|
|
|
def test_with_collection_action_and_name_prefix_and_formatted
|
2016-08-06 12:54:50 -04:00
|
|
|
actions = { "a" => :get, "b" => :put, "c" => :post, "d" => :delete, "e" => :patch }
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope "/threads/:thread_id" do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :messages, as: "thread_messages" do
|
|
|
|
get :a, on: :collection
|
|
|
|
put :b, on: :collection
|
|
|
|
post :c, on: :collection
|
|
|
|
delete :d, on: :collection
|
|
|
|
patch :e, on: :collection
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options|
|
2007-06-27 04:38:55 -04:00
|
|
|
actions.each do |action, method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: action, format: "xml"), path: "/threads/1/messages/#{action}.xml", method: method)
|
2007-06-27 04:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do
|
2014-09-29 10:07:18 -04:00
|
|
|
actions.each_key do |action|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "/threads/1/messages/#{action}.xml", "#{action}_thread_messages_path", action: action, format: "xml"
|
2007-06-27 04:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 14:59:58 -04:00
|
|
|
def test_with_member_action
|
2011-05-06 17:03:55 -04:00
|
|
|
[:patch, :put, :post].each do |method|
|
2016-08-06 13:35:13 -04:00
|
|
|
with_restful_routing :messages, member: { mark: method } do
|
2016-08-16 03:30:11 -04:00
|
|
|
mark_options = { action: "mark", id: "1" }
|
2007-03-28 17:55:40 -04:00
|
|
|
mark_path = "/messages/1/mark"
|
2006-07-31 14:59:58 -04:00
|
|
|
assert_restful_routes_for :messages do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(mark_options), path: mark_path, method: method)
|
2006-07-31 16:00:18 -04:00
|
|
|
end
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2015-08-25 01:05:18 -04:00
|
|
|
assert_restful_named_routes_for :messages do
|
2006-07-31 16:00:18 -04:00
|
|
|
assert_named_route mark_path, :mark_message_path, mark_options
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-14 11:06:00 -04:00
|
|
|
def test_with_member_action_and_requirement
|
2016-08-16 03:30:11 -04:00
|
|
|
expected_options = { controller: "messages", action: "mark", id: "1.1.1" }
|
2009-10-20 13:31:23 -04:00
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
with_restful_routing(:messages, constraints: { id: /[0-9]\.[0-9]\.[0-9]/ }, member: { mark: :get }) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(expected_options, path: "messages/1.1.1/mark", method: :get)
|
2009-03-14 11:06:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-04-18 07:45:33 -04:00
|
|
|
def test_member_when_override_paths_for_default_restful_actions_with
|
2011-05-06 17:03:55 -04:00
|
|
|
[:patch, :put, :post].each do |method|
|
2016-08-16 03:30:11 -04:00
|
|
|
with_restful_routing :messages, member: { mark: method }, path_names: { new: "nuevo" } do
|
|
|
|
mark_options = { action: "mark", id: "1", controller: "messages" }
|
2008-04-18 07:45:33 -04:00
|
|
|
mark_path = "/messages/1/mark"
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_restful_routes_for :messages, path_names: { new: "nuevo" } do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(mark_options), path: mark_path, method: method)
|
2008-04-18 07:45:33 -04:00
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_restful_named_routes_for :messages, path_names: { new: "nuevo" } do
|
2008-04-18 07:45:33 -04:00
|
|
|
assert_named_route mark_path, :mark_message_path, mark_options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 17:57:59 -04:00
|
|
|
def test_with_two_member_actions_with_same_method
|
2011-05-06 17:03:55 -04:00
|
|
|
[:patch, :put, :post].each do |method|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resources :messages do
|
|
|
|
member do
|
2016-08-06 13:35:13 -04:00
|
|
|
match :mark , via: method
|
|
|
|
match :unmark, via: method
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 17:57:59 -04:00
|
|
|
%w(mark unmark).each do |action|
|
2016-08-16 03:30:11 -04:00
|
|
|
action_options = { action: action, id: "1" }
|
2007-03-28 17:55:40 -04:00
|
|
|
action_path = "/messages/1/#{action}"
|
2006-07-31 17:57:59 -04:00
|
|
|
assert_restful_routes_for :messages do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action_options), path: action_path, method: method)
|
2006-07-31 17:57:59 -04:00
|
|
|
end
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2015-08-25 01:05:18 -04:00
|
|
|
assert_restful_named_routes_for :messages do
|
2006-07-31 17:57:59 -04:00
|
|
|
assert_named_route action_path, "#{action}_message_path".to_sym, action_options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-08-28 07:35:00 -04:00
|
|
|
def test_array_as_collection_or_member_method_value
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resources :messages do
|
|
|
|
collection do
|
2016-08-06 13:35:13 -04:00
|
|
|
match :search, via: [:post, :get]
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
member do
|
2016-08-06 13:35:13 -04:00
|
|
|
match :toggle, via: [:post, :get]
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-08-28 07:35:00 -04:00
|
|
|
assert_restful_routes_for :messages do |options|
|
|
|
|
[:get, :post].each do |method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: "search"), path: "/messages/search", method: method)
|
2008-08-28 07:35:00 -04:00
|
|
|
end
|
|
|
|
[:get, :post].each do |method|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: "toggle", id: "1"), path: "/messages/1/toggle", method: method)
|
2008-08-28 07:35:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 14:59:58 -04:00
|
|
|
def test_with_new_action
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resources :messages do
|
2016-08-06 13:35:13 -04:00
|
|
|
post :preview, on: :new
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
preview_options = { action: "preview" }
|
2007-03-28 17:55:40 -04:00
|
|
|
preview_path = "/messages/new/preview"
|
2006-07-31 14:59:58 -04:00
|
|
|
assert_restful_routes_for :messages do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(preview_options), path: preview_path, method: :post)
|
2006-07-31 16:00:18 -04:00
|
|
|
end
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2015-08-25 01:05:18 -04:00
|
|
|
assert_restful_named_routes_for :messages do
|
2006-07-31 16:00:18 -04:00
|
|
|
assert_named_route preview_path, :preview_new_message_path, preview_options
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2007-06-27 04:38:55 -04:00
|
|
|
def test_with_new_action_with_name_prefix
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope("/threads/:thread_id") do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :messages, as: "thread_messages" do
|
|
|
|
post :preview, on: :new
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
preview_options = { action: "preview", thread_id: "1" }
|
2007-06-27 04:38:55 -04:00
|
|
|
preview_path = "/threads/1/messages/new/preview"
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options|
|
|
|
|
assert_recognizes(options.merge(preview_options), path: preview_path, method: :post)
|
2007-06-27 04:38:55 -04:00
|
|
|
end
|
2006-07-31 14:59:58 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do
|
2007-06-27 04:38:55 -04:00
|
|
|
assert_named_route preview_path, :preview_new_thread_message_path, preview_options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2007-06-27 04:38:55 -04:00
|
|
|
def test_with_formatted_new_action_with_name_prefix
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope("/threads/:thread_id") do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :messages, as: "thread_messages" do
|
|
|
|
post :preview, on: :new
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
preview_options = { action: "preview", thread_id: "1", format: "xml" }
|
2007-06-27 04:38:55 -04:00
|
|
|
preview_path = "/threads/1/messages/new/preview.xml"
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options|
|
|
|
|
assert_recognizes(options.merge(preview_options), path: preview_path, method: :post)
|
2007-06-27 04:38:55 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do
|
2008-11-24 02:24:19 -05:00
|
|
|
assert_named_route preview_path, :preview_new_thread_message_path, preview_options
|
2007-06-27 04:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2006-09-26 18:45:09 -04:00
|
|
|
def test_override_new_method
|
|
|
|
with_restful_routing :messages do
|
|
|
|
assert_restful_routes_for :messages do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: "new"), path: "/messages/new", method: :get)
|
2009-12-11 01:01:22 -05:00
|
|
|
assert_raise(ActionController::RoutingError) do
|
2016-08-06 13:35:13 -04:00
|
|
|
@routes.recognize_path("/messages/new", method: :post)
|
2006-09-26 18:45:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resources :messages do
|
2016-08-06 13:35:13 -04:00
|
|
|
match :new, via: [:post, :get], on: :new
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-09-26 18:45:09 -04:00
|
|
|
assert_restful_routes_for :messages do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: "new"), path: "/messages/new", method: :post)
|
|
|
|
assert_recognizes(options.merge(action: "new"), path: "/messages/new", method: :get)
|
2006-09-26 18:45:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 20:29:02 -04:00
|
|
|
def test_nested_restful_routes
|
2006-07-31 14:59:58 -04:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
resources :threads do
|
|
|
|
resources :messages do
|
|
|
|
resources :comments
|
2006-07-31 21:23:06 -04:00
|
|
|
end
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-31 21:23:06 -04:00
|
|
|
assert_simply_restful_for :threads
|
|
|
|
assert_simply_restful_for :messages,
|
2016-08-06 13:35:13 -04:00
|
|
|
name_prefix: "thread_",
|
|
|
|
path_prefix: "threads/1/",
|
|
|
|
options: { thread_id: "1" }
|
2006-07-31 21:23:06 -04:00
|
|
|
assert_simply_restful_for :comments,
|
2016-08-06 13:35:13 -04:00
|
|
|
name_prefix: "thread_message_",
|
|
|
|
path_prefix: "threads/1/messages/2/",
|
|
|
|
options: { thread_id: "1", message_id: "2" }
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
|
|
|
end
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2008-08-30 09:58:16 -04:00
|
|
|
def test_shallow_nested_restful_routes
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :threads, shallow: true do
|
2010-08-05 12:10:53 -04:00
|
|
|
resources :messages do
|
|
|
|
resources :comments
|
2008-08-30 09:58:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_simply_restful_for :threads,
|
2016-08-06 13:35:13 -04:00
|
|
|
shallow: true
|
2008-08-30 09:58:16 -04:00
|
|
|
assert_simply_restful_for :messages,
|
2016-08-06 13:35:13 -04:00
|
|
|
name_prefix: "thread_",
|
|
|
|
path_prefix: "threads/1/",
|
|
|
|
shallow: true,
|
|
|
|
options: { thread_id: "1" }
|
2008-08-30 09:58:16 -04:00
|
|
|
assert_simply_restful_for :comments,
|
2016-08-06 13:35:13 -04:00
|
|
|
name_prefix: "message_",
|
|
|
|
path_prefix: "messages/2/",
|
|
|
|
shallow: true,
|
|
|
|
options: { message_id: "2" }
|
2008-08-30 09:58:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-07 17:50:58 -05:00
|
|
|
def test_shallow_nested_restful_routes_with_namespaces
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
namespace :backoffice do
|
|
|
|
namespace :admin do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, shallow: true do
|
2010-08-05 12:10:53 -04:00
|
|
|
resources :images
|
2009-03-07 17:50:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_simply_restful_for :products,
|
2016-08-06 13:35:13 -04:00
|
|
|
controller: "backoffice/admin/products",
|
|
|
|
namespace: "backoffice/admin/",
|
|
|
|
name_prefix: "backoffice_admin_",
|
|
|
|
path_prefix: "backoffice/admin/",
|
|
|
|
shallow: true
|
2009-03-07 17:50:58 -05:00
|
|
|
assert_simply_restful_for :images,
|
2016-08-06 13:35:13 -04:00
|
|
|
controller: "backoffice/admin/images",
|
|
|
|
namespace: "backoffice/admin/",
|
|
|
|
name_prefix: "backoffice_admin_product_",
|
|
|
|
path_prefix: "backoffice/admin/products/1/",
|
|
|
|
shallow: true,
|
|
|
|
options: { product_id: "1" }
|
2009-03-07 17:50:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-09-06 10:28:32 -04:00
|
|
|
def test_restful_routes_dont_generate_duplicates
|
|
|
|
with_restful_routing :messages do
|
2010-03-30 15:05:42 -04:00
|
|
|
routes = @routes.routes
|
2007-09-06 10:28:32 -04:00
|
|
|
routes.each do |route|
|
|
|
|
routes.each do |r|
|
2015-08-17 19:30:53 -04:00
|
|
|
next if route == r # skip the comparison instance
|
2015-08-17 19:36:31 -04:00
|
|
|
assert_not_equal [route.conditions, route.path.spec.to_s, route.verb], [r.conditions, r.path.spec.to_s, r.verb]
|
2007-09-06 10:28:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2006-07-31 14:59:58 -04:00
|
|
|
|
2006-12-07 10:36:08 -05:00
|
|
|
def test_should_create_singleton_resource_routes
|
|
|
|
with_singleton_resources :account do
|
|
|
|
assert_singleton_restful_for :account
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_create_multiple_singleton_resource_routes
|
2015-08-23 12:08:49 -04:00
|
|
|
with_singleton_resources :account, :product do
|
2006-12-07 10:36:08 -05:00
|
|
|
assert_singleton_restful_for :account
|
2015-08-23 12:08:49 -04:00
|
|
|
assert_singleton_restful_for :product
|
2006-12-07 10:36:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_create_nested_singleton_resource_routes
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :admin, controller: "admin" do
|
2010-08-05 09:44:23 -04:00
|
|
|
resource :account
|
2006-12-07 10:36:08 -05:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_restful_for :admin, controller: "admin"
|
|
|
|
assert_singleton_restful_for :account, name_prefix: "admin_", path_prefix: "admin/"
|
2006-12-07 10:36:08 -05:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2006-12-07 10:36:08 -05:00
|
|
|
def test_singleton_resource_with_member_action
|
2011-05-06 17:03:55 -04:00
|
|
|
[:patch, :put, :post].each do |method|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resource :account do
|
2016-08-06 13:35:13 -04:00
|
|
|
match :reset, on: :member, via: method
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
reset_options = { action: "reset" }
|
2007-03-28 17:55:40 -04:00
|
|
|
reset_path = "/account/reset"
|
2006-12-07 10:36:08 -05:00
|
|
|
assert_singleton_routes_for :account do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(reset_options), path: reset_path, method: method)
|
2006-12-07 10:36:08 -05:00
|
|
|
end
|
|
|
|
|
2015-08-25 01:05:18 -04:00
|
|
|
assert_singleton_named_routes_for :account do
|
2006-12-07 10:36:08 -05:00
|
|
|
assert_named_route reset_path, :reset_account_path, reset_options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_singleton_resource_with_two_member_actions_with_same_method
|
2011-05-06 17:03:55 -04:00
|
|
|
[:patch, :put, :post].each do |method|
|
2010-08-05 12:10:53 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resource :account do
|
2016-08-06 13:35:13 -04:00
|
|
|
match :reset, on: :member, via: method
|
|
|
|
match :disable, on: :member, via: method
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-12-07 10:36:08 -05:00
|
|
|
%w(reset disable).each do |action|
|
2016-08-16 03:30:11 -04:00
|
|
|
action_options = { action: action }
|
2007-03-28 17:55:40 -04:00
|
|
|
action_path = "/account/#{action}"
|
2006-12-07 10:36:08 -05:00
|
|
|
assert_singleton_routes_for :account do |options|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action_options), path: action_path, method: method)
|
2006-12-07 10:36:08 -05:00
|
|
|
end
|
|
|
|
|
2015-08-25 01:05:18 -04:00
|
|
|
assert_singleton_named_routes_for :account do
|
2006-12-07 10:36:08 -05:00
|
|
|
assert_named_route action_path, "#{action}_account_path".to_sym, action_options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2006-12-07 11:31:41 -05:00
|
|
|
|
|
|
|
def test_should_nest_resources_in_singleton_resource
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
resource :account do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources :messages
|
2006-12-07 11:31:41 -05:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2006-12-07 11:31:41 -05:00
|
|
|
assert_singleton_restful_for :account
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_simply_restful_for :messages, name_prefix: "account_", path_prefix: "account/"
|
2006-12-07 11:31:41 -05:00
|
|
|
end
|
|
|
|
end
|
2007-01-07 20:07:48 -05:00
|
|
|
|
2010-08-05 12:10:53 -04:00
|
|
|
def test_should_nest_resources_in_singleton_resource_with_path_scope
|
2007-01-07 20:07:48 -05:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope ":site_id" do
|
2010-08-05 12:10:53 -04:00
|
|
|
resource(:account) do
|
|
|
|
resources :messages
|
|
|
|
end
|
2007-01-07 20:07:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_restful_for :account, path_prefix: "7/", options: { site_id: "7" }
|
|
|
|
assert_simply_restful_for :messages, name_prefix: "account_", path_prefix: "7/account/", options: { site_id: "7" }
|
2007-01-07 20:07:48 -05:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2006-12-07 11:31:41 -05:00
|
|
|
def test_should_nest_singleton_resource_in_resources
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
resources :threads do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :admin, controller: "admin"
|
2006-12-07 11:31:41 -05:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2006-12-07 11:31:41 -05:00
|
|
|
assert_simply_restful_for :threads
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_restful_for :admin, controller: "admin", name_prefix: "thread_", path_prefix: "threads/5/", options: { thread_id: "5" }
|
2006-12-07 11:31:41 -05:00
|
|
|
end
|
|
|
|
end
|
2006-12-07 10:36:08 -05:00
|
|
|
|
2011-05-06 17:03:55 -04:00
|
|
|
def test_should_not_allow_delete_or_patch_or_put_on_collection_path
|
2007-01-28 03:20:04 -05:00
|
|
|
controller_name = :messages
|
|
|
|
with_restful_routing controller_name do
|
2016-08-06 13:35:13 -04:00
|
|
|
options = { controller: controller_name.to_s }
|
2007-01-28 03:20:04 -05:00
|
|
|
collection_path = "/#{controller_name}"
|
|
|
|
|
2012-05-19 17:28:14 -04:00
|
|
|
assert_raise(Assertion) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: "update"), path: collection_path, method: :patch)
|
2011-05-06 17:03:55 -04:00
|
|
|
end
|
|
|
|
|
2012-05-19 17:28:14 -04:00
|
|
|
assert_raise(Assertion) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: "update"), path: collection_path, method: :put)
|
2007-01-28 03:20:04 -05:00
|
|
|
end
|
|
|
|
|
2012-05-19 17:28:14 -04:00
|
|
|
assert_raise(Assertion) do
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(options.merge(action: "destroy"), path: collection_path, method: :delete)
|
2007-01-28 03:20:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-09-06 10:28:32 -04:00
|
|
|
def test_new_style_named_routes_for_resource
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope "/threads/:thread_id" do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :messages, as: "thread_messages" do
|
|
|
|
get :search, on: :collection
|
|
|
|
get :preview, on: :new
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
2007-09-06 10:28:32 -04:00
|
|
|
end
|
2010-08-05 12:10:53 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_simply_restful_for :messages, name_prefix: "thread_", path_prefix: "threads/1/", options: { thread_id: "1" }
|
2007-09-06 10:28:32 -04:00
|
|
|
assert_named_route "/threads/1/messages/search", "search_thread_messages_path", {}
|
|
|
|
assert_named_route "/threads/1/messages/new", "new_thread_message_path", {}
|
|
|
|
assert_named_route "/threads/1/messages/new/preview", "preview_new_thread_message_path", {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_style_named_routes_for_singleton_resource
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope "/admin" do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :account, as: :admin_account do
|
|
|
|
get :login, on: :member
|
|
|
|
get :preview, on: :new
|
2010-08-05 12:10:53 -04:00
|
|
|
end
|
|
|
|
end
|
2007-09-06 10:28:32 -04:00
|
|
|
end
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_restful_for :account, name_prefix: "admin_", path_prefix: "admin/"
|
2007-09-06 10:28:32 -04:00
|
|
|
assert_named_route "/admin/account/login", "login_admin_account_path", {}
|
|
|
|
assert_named_route "/admin/account/new", "new_admin_account_path", {}
|
|
|
|
assert_named_route "/admin/account/new/preview", "preview_new_admin_account_path", {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-04-27 12:58:36 -04:00
|
|
|
def test_resources_in_namespace
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
namespace :backoffice do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources :products
|
2007-04-27 12:58:36 -04:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_simply_restful_for :products, controller: "backoffice/products", name_prefix: "backoffice_", path_prefix: "backoffice/"
|
2007-04-27 12:58:36 -04:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:37:07 -04:00
|
|
|
|
2007-05-16 21:27:54 -04:00
|
|
|
def test_resources_in_nested_namespace
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
namespace :backoffice do
|
|
|
|
namespace :admin do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources :products
|
2007-05-16 21:27:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_simply_restful_for :products, controller: "backoffice/admin/products", name_prefix: "backoffice_admin_", path_prefix: "backoffice/admin/"
|
2007-05-16 21:27:54 -04:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2007-04-27 12:58:36 -04:00
|
|
|
def test_resources_using_namespace
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
namespace :backoffice, path: nil, as: nil do
|
2010-08-05 12:10:53 -04:00
|
|
|
resources :products
|
|
|
|
end
|
2007-04-27 12:58:36 -04:00
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_simply_restful_for :products, controller: "backoffice/products"
|
2007-04-27 12:58:36 -04:00
|
|
|
end
|
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2007-09-10 10:31:44 -04:00
|
|
|
def test_nested_resources_using_namespace
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
namespace :backoffice do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources :products do
|
2010-08-05 12:10:53 -04:00
|
|
|
resources :images
|
2007-09-10 10:31:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_simply_restful_for :images, controller: "backoffice/images", name_prefix: "backoffice_product_", path_prefix: "backoffice/products/1/", options: { product_id: "1" }
|
2007-09-10 10:31:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_nested_resources_in_nested_namespace
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
namespace :backoffice do
|
|
|
|
namespace :admin do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources :products do
|
2010-08-05 12:10:53 -04:00
|
|
|
resources :images
|
2007-09-10 10:31:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_simply_restful_for :images, controller: "backoffice/admin/images", name_prefix: "backoffice_admin_product_", path_prefix: "backoffice/admin/products/1/", options: { product_id: "1" }
|
2007-09-10 10:31:44 -04:00
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2008-02-02 00:57:16 -05:00
|
|
|
def test_with_path_segment
|
2009-03-03 18:40:39 -05:00
|
|
|
with_restful_routing :messages do
|
|
|
|
assert_simply_restful_for :messages
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_recognizes({ controller: "messages", action: "index" }, "/messages")
|
|
|
|
assert_recognizes({ controller: "messages", action: "index" }, "/messages/")
|
2008-02-02 00:57:16 -05:00
|
|
|
end
|
2009-03-03 18:40:39 -05:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
resources :messages, path: "reviews"
|
|
|
|
end
|
|
|
|
assert_simply_restful_for :messages, as: "reviews"
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_recognizes({ controller: "messages", action: "index" }, "/reviews")
|
|
|
|
assert_recognizes({ controller: "messages", action: "index" }, "/reviews/")
|
2016-08-06 13:55:02 -04:00
|
|
|
end
|
2008-02-02 00:57:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_multiple_with_path_segment_and_controller
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:55:02 -04:00
|
|
|
resources :products do
|
|
|
|
resources :product_reviews, path: "reviews", controller: "messages"
|
|
|
|
end
|
|
|
|
resources :tutors do
|
|
|
|
resources :tutor_reviews, path: "reviews", controller: "comments"
|
|
|
|
end
|
2008-02-02 00:57:16 -05:00
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_simply_restful_for :product_reviews, controller: "messages", as: "reviews", name_prefix: "product_", path_prefix: "products/1/", options: { product_id: "1" }
|
2016-10-28 23:05:58 -04:00
|
|
|
assert_simply_restful_for :tutor_reviews, controller: "comments", as: "reviews", name_prefix: "tutor_", path_prefix: "tutors/1/", options: { tutor_id: "1" }
|
2008-02-02 00:57:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-05 09:44:23 -04:00
|
|
|
def test_with_path_segment_path_prefix_constraints
|
2016-08-16 03:30:11 -04:00
|
|
|
expected_options = { controller: "messages", action: "show", thread_id: "1.1.1", id: "1" }
|
2010-08-05 09:44:23 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
scope "/thread/:thread_id", constraints: { thread_id: /[0-9]\.[0-9]\.[0-9]/ } do
|
|
|
|
resources :messages, path: "comments"
|
2010-08-05 09:44:23 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes(expected_options, path: "thread/1.1.1/comments/1", method: :get)
|
2008-02-02 00:57:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-12 06:00:17 -05:00
|
|
|
def test_resource_has_only_show_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: :show
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("products", {}, { id: "1" }, :show, [:index, :new, :create, :edit, :update, :destroy])
|
|
|
|
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :show, [:index, :new, :create, :edit, :update, :destroy])
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_singleton_resource_has_only_show_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :account, only: :show
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", {}, :show, [:index, :new, :create, :edit, :update, :destroy])
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :show, [:index, :new, :create, :edit, :update, :destroy])
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_resource_does_not_have_destroy_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, except: :destroy
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("products", {}, { id: "1" }, [:index, :new, :create, :show, :edit, :update], :destroy)
|
|
|
|
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [:index, :new, :create, :show, :edit, :update], :destroy)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_singleton_resource_does_not_have_destroy_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :account, except: :destroy
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", {}, [:new, :create, :show, :edit, :update], :destroy)
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, [:new, :create, :show, :edit, :update], :destroy)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-13 09:31:36 -05:00
|
|
|
def test_resource_has_only_create_action_and_named_route
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: :create
|
2008-11-13 09:31:36 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("products", {}, { id: "1" }, :create, [:index, :new, :show, :edit, :update, :destroy])
|
|
|
|
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :create, [:index, :new, :show, :edit, :update, :destroy])
|
2008-11-13 09:31:36 -05:00
|
|
|
|
|
|
|
assert_not_nil set.named_routes[:products]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_resource_has_only_update_action_and_named_route
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: :update
|
2008-11-13 09:31:36 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("products", {}, { id: "1" }, :update, [:index, :new, :create, :show, :edit, :destroy])
|
|
|
|
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :update, [:index, :new, :create, :show, :edit, :destroy])
|
2008-11-13 09:31:36 -05:00
|
|
|
|
|
|
|
assert_not_nil set.named_routes[:product]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_resource_has_only_destroy_action_and_named_route
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: :destroy
|
2008-11-13 09:31:36 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("products", {}, { id: "1" }, :destroy, [:index, :new, :create, :show, :edit, :update])
|
|
|
|
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :destroy, [:index, :new, :create, :show, :edit, :update])
|
2008-11-13 09:31:36 -05:00
|
|
|
|
|
|
|
assert_not_nil set.named_routes[:product]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_singleton_resource_has_only_create_action_and_named_route
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :account, only: :create
|
2008-11-13 09:31:36 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", {}, :create, [:new, :show, :edit, :update, :destroy])
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :create, [:new, :show, :edit, :update, :destroy])
|
2008-11-13 09:31:36 -05:00
|
|
|
|
|
|
|
assert_not_nil set.named_routes[:account]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_singleton_resource_has_only_update_action_and_named_route
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :account, only: :update
|
2008-11-13 09:31:36 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", {}, :update, [:new, :create, :show, :edit, :destroy])
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :update, [:new, :create, :show, :edit, :destroy])
|
2008-11-13 09:31:36 -05:00
|
|
|
|
|
|
|
assert_not_nil set.named_routes[:account]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_singleton_resource_has_only_destroy_action_and_named_route
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :account, only: :destroy
|
2008-11-13 09:31:36 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", {}, :destroy, [:new, :create, :show, :edit, :update])
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :destroy, [:new, :create, :show, :edit, :update])
|
2008-11-13 09:31:36 -05:00
|
|
|
|
|
|
|
assert_not_nil set.named_routes[:account]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-12 06:00:17 -05:00
|
|
|
def test_resource_has_only_collection_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: [] do
|
|
|
|
get :sale, on: :collection
|
2010-08-05 17:16:08 -04:00
|
|
|
end
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("products", {}, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
|
|
|
|
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
|
2008-11-12 06:00:17 -05:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes({ controller: "products", action: "sale" }, path: "products/sale", method: :get)
|
|
|
|
assert_recognizes({ controller: "products", action: "sale", format: "xml" }, path: "products/sale.xml", method: :get)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_resource_has_only_member_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: [] do
|
|
|
|
get :preview, on: :member
|
2010-08-05 17:16:08 -04:00
|
|
|
end
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("products", {}, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
|
|
|
|
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
|
2008-11-12 06:00:17 -05:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes({ controller: "products", action: "preview", id: "1" }, path: "products/1/preview", method: :get)
|
|
|
|
assert_recognizes({ controller: "products", action: "preview", id: "1", format: "xml" }, path: "products/1/preview.xml", method: :get)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_singleton_resource_has_only_member_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resource :account, only: [] do
|
2010-08-05 12:10:53 -04:00
|
|
|
member do
|
|
|
|
get :signup
|
|
|
|
end
|
|
|
|
end
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", {}, [], [:new, :create, :show, :edit, :update, :destroy])
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, [], [:new, :create, :show, :edit, :update, :destroy])
|
2008-11-12 06:00:17 -05:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes({ controller: "accounts", action: "signup" }, path: "account/signup", method: :get)
|
|
|
|
assert_recognizes({ controller: "accounts", action: "signup", format: "xml" }, path: "account/signup.xml", method: :get)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_nested_resource_has_only_show_and_member_action
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: [:index, :show] do
|
|
|
|
resources :images, only: :show do
|
|
|
|
get :thumbnail, on: :member
|
2010-08-05 17:16:08 -04:00
|
|
|
end
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images")
|
|
|
|
assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images")
|
2008-11-12 06:00:17 -05:00
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2" }, path: "products/1/images/2/thumbnail", method: :get)
|
|
|
|
assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2", format: "jpg" }, path: "products/1/images/2/thumbnail.jpg", method: :get)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-30 06:37:59 -05:00
|
|
|
def test_nested_resource_does_not_inherit_only_option
|
2008-11-13 15:00:11 -05:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: :show do
|
|
|
|
resources :images, except: :destroy
|
2008-11-13 15:00:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update], :destroy, "products/1/images")
|
|
|
|
assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update], :destroy, "products/1/images")
|
2008-11-13 15:00:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-30 06:37:59 -05:00
|
|
|
def test_nested_resource_does_not_inherit_only_option_by_default
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, only: :show do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources :images
|
2009-01-30 06:37:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images")
|
|
|
|
assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images")
|
2009-01-30 06:37:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_nested_resource_does_not_inherit_except_option
|
2008-11-13 15:00:11 -05:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, except: :show do
|
|
|
|
resources :images, only: :destroy
|
2008-11-13 15:00:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, :destroy, [:index, :new, :create, :show, :edit, :update], "products/1/images")
|
|
|
|
assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, :destroy, [:index, :new, :create, :show, :edit, :update], "products/1/images")
|
2008-11-13 15:00:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-30 06:37:59 -05:00
|
|
|
def test_nested_resource_does_not_inherit_except_option_by_default
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 13:35:13 -04:00
|
|
|
resources :products, except: :show do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources :images
|
2009-01-30 06:37:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images")
|
|
|
|
assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images")
|
2009-01-30 06:37:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-24 07:23:27 -05:00
|
|
|
def test_default_singleton_restful_route_uses_get
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2010-08-05 12:10:53 -04:00
|
|
|
resource :product
|
2008-11-24 07:23:27 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_routing "/product", controller: "products", action: "show"
|
|
|
|
assert set.recognize_path("/product", method: :get)
|
2008-11-24 07:23:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-23 17:59:11 -05:00
|
|
|
def test_assert_routing_accepts_all_as_a_valid_method
|
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
match "/products", to: "products#show", via: :all
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:44:11 -04:00
|
|
|
assert_routing({ method: "all", path: "/products" }, controller: "products", action: "show")
|
2015-01-23 17:59:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_routing_fails_when_not_all_http_methods_are_recognized
|
|
|
|
with_routing do |set|
|
|
|
|
set.draw do
|
|
|
|
match "/products", to: "products#show", via: [:get, :post, :put]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises(Minitest::Assertion) do
|
2016-08-06 13:44:11 -04:00
|
|
|
assert_routing({ method: "all", path: "/products" }, controller: "products", action: "show")
|
2015-01-23 17:59:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-15 10:45:29 -04:00
|
|
|
def test_singleton_resource_name_is_not_singularized
|
2015-08-23 12:08:49 -04:00
|
|
|
with_singleton_resources(:products) do
|
|
|
|
assert_singleton_restful_for :products
|
2010-03-15 10:45:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-23 09:40:07 -05:00
|
|
|
private
|
2006-07-31 16:32:48 -04:00
|
|
|
def with_restful_routing(*args)
|
2010-08-05 09:44:23 -04:00
|
|
|
options = args.extract_options!
|
|
|
|
collection_methods = options.delete(:collection)
|
|
|
|
member_methods = options.delete(:member)
|
|
|
|
path_prefix = options.delete(:path_prefix)
|
|
|
|
args.push(options)
|
|
|
|
|
2006-07-31 14:59:58 -04:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-08-06 12:54:50 -04:00
|
|
|
scope(path_prefix || "") do
|
2010-08-05 09:44:23 -04:00
|
|
|
resources(*args) do
|
|
|
|
if collection_methods
|
|
|
|
collection do
|
|
|
|
collection_methods.each do |name, method|
|
|
|
|
send(method, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if member_methods
|
|
|
|
member do
|
|
|
|
member_methods.each do |name, method|
|
|
|
|
send(method, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2006-07-31 14:59:58 -04:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2007-05-22 05:38:54 -04:00
|
|
|
|
2006-12-07 10:36:08 -05:00
|
|
|
def with_singleton_resources(*args)
|
|
|
|
with_routing do |set|
|
2016-08-16 03:30:11 -04:00
|
|
|
set.draw { resource(*args) }
|
2006-12-07 10:36:08 -05:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2006-07-31 16:00:18 -04:00
|
|
|
|
|
|
|
# runs assert_restful_routes_for and assert_restful_named_routes for on the controller_name and options, without passing a block.
|
|
|
|
def assert_simply_restful_for(controller_name, options = {})
|
|
|
|
assert_restful_routes_for controller_name, options
|
2007-04-27 12:58:36 -04:00
|
|
|
assert_restful_named_routes_for controller_name, nil, options
|
2006-07-31 16:00:18 -04:00
|
|
|
end
|
|
|
|
|
2006-12-07 10:36:08 -05:00
|
|
|
def assert_singleton_restful_for(singleton_name, options = {})
|
|
|
|
assert_singleton_routes_for singleton_name, options
|
|
|
|
assert_singleton_named_routes_for singleton_name, options
|
|
|
|
end
|
|
|
|
|
2006-07-31 14:59:58 -04:00
|
|
|
def assert_restful_routes_for(controller_name, options = {})
|
2015-08-08 11:44:11 -04:00
|
|
|
route_options = (options[:options] ||= {}).dup
|
|
|
|
route_options[:controller] = options[:controller] || controller_name.to_s
|
2006-07-31 14:59:58 -04:00
|
|
|
|
2008-08-30 09:58:16 -04:00
|
|
|
if options[:shallow]
|
|
|
|
options[:shallow_options] ||= {}
|
2015-08-08 11:44:11 -04:00
|
|
|
options[:shallow_options][:controller] = route_options[:controller]
|
2008-08-30 09:58:16 -04:00
|
|
|
else
|
2015-08-08 11:44:11 -04:00
|
|
|
options[:shallow_options] = route_options
|
2008-08-30 09:58:16 -04:00
|
|
|
end
|
|
|
|
|
2010-03-30 15:05:42 -04:00
|
|
|
new_action = @routes.resources_path_names[:new] || "new"
|
|
|
|
edit_action = @routes.resources_path_names[:edit] || "edit"
|
2010-02-23 22:53:52 -05:00
|
|
|
|
2008-04-18 07:45:33 -04:00
|
|
|
if options[:path_names]
|
2008-05-05 03:53:30 -04:00
|
|
|
new_action = options[:path_names][:new] if options[:path_names][:new]
|
|
|
|
edit_action = options[:path_names][:edit] if options[:path_names][:edit]
|
2008-04-18 07:45:33 -04:00
|
|
|
end
|
|
|
|
|
2008-08-30 09:58:16 -04:00
|
|
|
path = "#{options[:as] || controller_name}"
|
|
|
|
collection_path = "/#{options[:path_prefix]}#{path}"
|
2009-03-07 17:50:58 -05:00
|
|
|
shallow_path = "/#{options[:shallow] ? options[:namespace] : options[:path_prefix]}#{path}"
|
2008-08-30 09:58:16 -04:00
|
|
|
member_path = "#{shallow_path}/1"
|
2008-04-18 07:45:33 -04:00
|
|
|
new_path = "#{collection_path}/#{new_action}"
|
|
|
|
edit_member_path = "#{member_path}/#{edit_action}"
|
|
|
|
formatted_edit_member_path = "#{member_path}/#{edit_action}.xml"
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
with_options(route_options) do |controller|
|
2016-08-06 13:35:13 -04:00
|
|
|
controller.assert_routing collection_path, action: "index"
|
|
|
|
controller.assert_routing new_path, action: "new"
|
|
|
|
controller.assert_routing "#{collection_path}.xml", action: "index", format: "xml"
|
|
|
|
controller.assert_routing "#{new_path}.xml", action: "new", format: "xml"
|
2008-08-30 09:58:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
with_options(options[:shallow_options]) do |controller|
|
2016-08-06 13:35:13 -04:00
|
|
|
controller.assert_routing member_path, action: "show", id: "1"
|
|
|
|
controller.assert_routing edit_member_path, action: "edit", id: "1"
|
|
|
|
controller.assert_routing "#{member_path}.xml", action: "show", id: "1", format: "xml"
|
|
|
|
controller.assert_routing formatted_edit_member_path, action: "edit", id: "1", format: "xml"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_recognizes(route_options.merge(action: "index"), path: collection_path, method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "new"), path: new_path, method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "create"), path: collection_path, method: :post)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "show", id: "1"), path: member_path, method: :get)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "edit", id: "1"), path: edit_member_path, method: :get)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "update", id: "1"), path: member_path, method: :put)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "destroy", id: "1"), path: member_path, method: :delete)
|
|
|
|
|
|
|
|
assert_recognizes(route_options.merge(action: "index", format: "xml"), path: "#{collection_path}.xml", method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "new", format: "xml"), path: "#{new_path}.xml", method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "create", format: "xml"), path: "#{collection_path}.xml", method: :post)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "show", id: "1", format: "xml"), path: "#{member_path}.xml", method: :get)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "edit", id: "1", format: "xml"), path: formatted_edit_member_path, method: :get)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "update", id: "1", format: "xml"), path: "#{member_path}.xml", method: :put)
|
|
|
|
assert_recognizes(options[:shallow_options].merge(action: "destroy", id: "1", format: "xml"), path: "#{member_path}.xml", method: :delete)
|
2006-07-31 16:00:18 -04:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
yield route_options if block_given?
|
2006-07-31 16:00:18 -04:00
|
|
|
end
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2006-07-31 16:00:18 -04:00
|
|
|
# test named routes like foo_path and foos_path map to the correct options.
|
|
|
|
def assert_restful_named_routes_for(controller_name, singular_name = nil, options = {})
|
|
|
|
if singular_name.is_a?(Hash)
|
|
|
|
options = singular_name
|
|
|
|
singular_name = nil
|
|
|
|
end
|
|
|
|
singular_name ||= controller_name.to_s.singularize
|
2007-04-27 12:58:36 -04:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
route_options = (options[:options] ||= {}).dup
|
|
|
|
route_options[:controller] = options[:controller] || controller_name.to_s
|
2007-04-27 12:58:36 -04:00
|
|
|
|
2008-08-30 09:58:16 -04:00
|
|
|
if options[:shallow]
|
|
|
|
options[:shallow_options] ||= {}
|
2015-08-08 11:44:11 -04:00
|
|
|
options[:shallow_options][:controller] = route_options[:controller]
|
2008-08-30 09:58:16 -04:00
|
|
|
else
|
2015-08-08 11:44:11 -04:00
|
|
|
options[:shallow_options] = route_options
|
2008-08-30 09:58:16 -04:00
|
|
|
end
|
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
@controller = "#{route_options[:controller].camelize}Controller".constantize.new
|
2015-01-31 23:12:37 -05:00
|
|
|
@controller.singleton_class.include(@routes.url_helpers)
|
2015-08-08 11:44:11 -04:00
|
|
|
get :index, params: route_options
|
|
|
|
route_options.delete :action
|
2006-07-31 16:00:18 -04:00
|
|
|
|
2008-08-30 09:58:16 -04:00
|
|
|
path = "#{options[:as] || controller_name}"
|
2009-03-07 17:50:58 -05:00
|
|
|
shallow_path = "/#{options[:shallow] ? options[:namespace] : options[:path_prefix]}#{path}"
|
2008-08-30 09:58:16 -04:00
|
|
|
full_path = "/#{options[:path_prefix]}#{path}"
|
2007-01-17 01:46:02 -05:00
|
|
|
name_prefix = options[:name_prefix]
|
2016-08-06 12:54:50 -04:00
|
|
|
shallow_prefix = options[:shallow] ? options[:namespace].try(:gsub, /\//, "_") : options[:name_prefix]
|
2008-02-02 00:57:16 -05:00
|
|
|
|
2008-04-18 07:45:33 -04:00
|
|
|
new_action = "new"
|
|
|
|
edit_action = "edit"
|
|
|
|
if options[:path_names]
|
|
|
|
new_action = options[:path_names][:new] || "new"
|
|
|
|
edit_action = options[:path_names][:edit] || "edit"
|
|
|
|
end
|
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
assert_named_route "#{full_path}", "#{name_prefix}#{controller_name}_path", route_options
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "#{full_path}.xml", "#{name_prefix}#{controller_name}_path", route_options.merge(format: "xml")
|
|
|
|
assert_named_route "#{shallow_path}/1", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1")
|
|
|
|
assert_named_route "#{shallow_path}/1.xml", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1", format: "xml")
|
2007-06-27 04:38:55 -04:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
assert_named_route "#{full_path}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", route_options
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "#{full_path}/#{new_action}.xml", "new_#{name_prefix}#{singular_name}_path", route_options.merge(format: "xml")
|
|
|
|
assert_named_route "#{shallow_path}/1/#{edit_action}", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1")
|
|
|
|
assert_named_route "#{shallow_path}/1/#{edit_action}.xml", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1", format: "xml")
|
2007-06-27 04:38:55 -04:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
yield route_options if block_given?
|
2006-07-31 14:59:58 -04:00
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2006-12-07 10:36:08 -05:00
|
|
|
def assert_singleton_routes_for(singleton_name, options = {})
|
2015-08-08 11:44:11 -04:00
|
|
|
route_options = (options[:options] ||= {}).dup
|
|
|
|
route_options[:controller] = options[:controller] || singleton_name.to_s.pluralize
|
2007-01-28 03:20:04 -05:00
|
|
|
|
2008-02-02 00:57:16 -05:00
|
|
|
full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}"
|
2007-01-28 03:20:04 -05:00
|
|
|
new_path = "#{full_path}/new"
|
2007-03-28 17:55:40 -04:00
|
|
|
edit_path = "#{full_path}/edit"
|
|
|
|
formatted_edit_path = "#{full_path}/edit.xml"
|
2007-01-28 03:20:04 -05:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
with_options route_options do |controller|
|
2016-08-06 13:35:13 -04:00
|
|
|
controller.assert_routing full_path, action: "show"
|
|
|
|
controller.assert_routing new_path, action: "new"
|
|
|
|
controller.assert_routing edit_path, action: "edit"
|
|
|
|
controller.assert_routing "#{full_path}.xml", action: "show", format: "xml"
|
|
|
|
controller.assert_routing "#{new_path}.xml", action: "new", format: "xml"
|
|
|
|
controller.assert_routing formatted_edit_path, action: "edit", format: "xml"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_recognizes(route_options.merge(action: "show"), path: full_path, method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "new"), path: new_path, method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "edit"), path: edit_path, method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "create"), path: full_path, method: :post)
|
|
|
|
assert_recognizes(route_options.merge(action: "update"), path: full_path, method: :put)
|
|
|
|
assert_recognizes(route_options.merge(action: "destroy"), path: full_path, method: :delete)
|
|
|
|
|
|
|
|
assert_recognizes(route_options.merge(action: "show", format: "xml"), path: "#{full_path}.xml", method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "new", format: "xml"), path: "#{new_path}.xml", method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "edit", format: "xml"), path: formatted_edit_path, method: :get)
|
|
|
|
assert_recognizes(route_options.merge(action: "create", format: "xml"), path: "#{full_path}.xml", method: :post)
|
|
|
|
assert_recognizes(route_options.merge(action: "update", format: "xml"), path: "#{full_path}.xml", method: :put)
|
|
|
|
assert_recognizes(route_options.merge(action: "destroy", format: "xml"), path: "#{full_path}.xml", method: :delete)
|
2007-01-28 03:20:04 -05:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
yield route_options if block_given?
|
2006-12-07 10:36:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def assert_singleton_named_routes_for(singleton_name, options = {})
|
2015-08-08 11:44:11 -04:00
|
|
|
route_options = (options[:options] ||= {}).dup
|
|
|
|
controller_name = route_options[:controller] || options[:controller] || singleton_name.to_s.pluralize
|
|
|
|
@controller = "#{controller_name.camelize}Controller".constantize.new
|
2015-01-31 23:12:37 -05:00
|
|
|
@controller.singleton_class.include(@routes.url_helpers)
|
2015-08-08 11:44:11 -04:00
|
|
|
get :show, params: route_options
|
|
|
|
route_options.delete :action
|
2007-01-28 03:20:04 -05:00
|
|
|
|
2008-02-02 00:57:16 -05:00
|
|
|
full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}"
|
2007-04-27 01:06:38 -04:00
|
|
|
name_prefix = options[:name_prefix]
|
2007-01-28 03:20:04 -05:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", route_options
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "#{full_path}.xml", "#{name_prefix}#{singleton_name}_path", route_options.merge(format: "xml")
|
2007-06-27 04:38:55 -04:00
|
|
|
|
2015-08-08 11:44:11 -04:00
|
|
|
assert_named_route "#{full_path}/new", "new_#{name_prefix}#{singleton_name}_path", route_options
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "#{full_path}/new.xml", "new_#{name_prefix}#{singleton_name}_path", route_options.merge(format: "xml")
|
2015-08-08 11:44:11 -04:00
|
|
|
assert_named_route "#{full_path}/edit", "edit_#{name_prefix}#{singleton_name}_path", route_options
|
2016-08-06 13:35:13 -04:00
|
|
|
assert_named_route "#{full_path}/edit.xml", "edit_#{name_prefix}#{singleton_name}_path", route_options.merge(format: "xml")
|
2006-12-07 10:36:08 -05:00
|
|
|
end
|
|
|
|
|
2006-07-31 16:00:18 -04:00
|
|
|
def assert_named_route(expected, route, options)
|
2016-10-28 23:05:58 -04:00
|
|
|
actual = @controller.send(route, options) rescue $!.class.name
|
2006-07-31 16:00:18 -04:00
|
|
|
assert_equal expected, actual, "Error on route: #{route}(#{options.inspect})"
|
|
|
|
end
|
2008-07-11 12:44:24 -04:00
|
|
|
|
2006-07-31 17:57:59 -04:00
|
|
|
def assert_resource_methods(expected, resource, action_method, method)
|
|
|
|
assert_equal expected.length, resource.send("#{action_method}_methods")[method].size, "#{resource.send("#{action_method}_methods")[method].inspect}"
|
|
|
|
expected.each do |action|
|
2016-09-16 12:44:05 -04:00
|
|
|
assert_includes resource.send("#{action_method}_methods")[method], action,
|
2016-08-07 17:11:06 -04:00
|
|
|
"#{method} not in #{action_method} methods: #{resource.send("#{action_method}_methods")[method].inspect}"
|
2006-07-31 17:57:59 -04:00
|
|
|
end
|
|
|
|
end
|
2006-09-14 15:53:04 -04:00
|
|
|
|
2008-11-12 06:00:17 -05:00
|
|
|
def assert_resource_allowed_routes(controller, options, shallow_options, allowed, not_allowed, path = controller)
|
|
|
|
shallow_path = "#{path}/#{shallow_options[:id]}"
|
|
|
|
format = options[:format] && ".#{options[:format]}"
|
2016-08-06 13:35:13 -04:00
|
|
|
options.merge!(controller: controller)
|
2008-11-12 06:00:17 -05:00
|
|
|
shallow_options.merge!(options)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "index", "#{path}#{format}", :get)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "new", "#{path}/new#{format}", :get)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "create", "#{path}#{format}", :post)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, shallow_options, "show", "#{shallow_path}#{format}", :get)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, shallow_options, "edit", "#{shallow_path}/edit#{format}", :get)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, shallow_options, "update", "#{shallow_path}#{format}", :put)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, shallow_options, "destroy", "#{shallow_path}#{format}", :delete)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def assert_singleton_resource_allowed_routes(controller, options, allowed, not_allowed, path = controller.singularize)
|
|
|
|
format = options[:format] && ".#{options[:format]}"
|
2016-08-06 13:35:13 -04:00
|
|
|
options.merge!(controller: controller)
|
2008-11-12 06:00:17 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "new", "#{path}/new#{format}", :get)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "create", "#{path}#{format}", :post)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "show", "#{path}#{format}", :get)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "edit", "#{path}/edit#{format}", :get)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "update", "#{path}#{format}", :put)
|
|
|
|
assert_whether_allowed(allowed, not_allowed, options, "destroy", "#{path}#{format}", :delete)
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def assert_whether_allowed(allowed, not_allowed, options, action, path, method)
|
|
|
|
action = action.to_sym
|
2016-08-06 13:35:13 -04:00
|
|
|
options = options.merge(action: action.to_s)
|
|
|
|
path_options = { path: path, method: method }
|
2008-11-12 06:00:17 -05:00
|
|
|
|
2012-08-05 18:27:56 -04:00
|
|
|
if Array(allowed).include?(action)
|
2008-11-12 06:00:17 -05:00
|
|
|
assert_recognizes options, path_options
|
2012-08-05 18:27:56 -04:00
|
|
|
elsif Array(not_allowed).include?(action)
|
2008-11-12 06:00:17 -05:00
|
|
|
assert_not_recognizes options, path_options
|
2013-11-27 16:44:19 -05:00
|
|
|
else
|
2016-08-06 12:54:50 -04:00
|
|
|
raise Assertion, "Invalid Action has passed"
|
2008-11-12 06:00:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_not_recognizes(expected_options, path)
|
2012-05-19 17:28:14 -04:00
|
|
|
assert_raise Assertion do
|
2008-11-12 06:00:17 -05:00
|
|
|
assert_recognizes(expected_options, path)
|
|
|
|
end
|
|
|
|
end
|
2008-01-05 08:32:06 -05:00
|
|
|
end
|