mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract common controllers to abstract_unit
This commit is contained in:
parent
0dd24728a0
commit
546497d027
3 changed files with 33 additions and 45 deletions
|
@ -349,3 +349,32 @@ module RoutingTestHelpers
|
|||
set.send(:url_for, options.merge(:only_path => true, :_recall => recall))
|
||||
end
|
||||
end
|
||||
|
||||
class ResourcesController < ActionController::Base
|
||||
def index() render :nothing => true end
|
||||
alias_method :show, :index
|
||||
end
|
||||
|
||||
class ThreadsController < ResourcesController; end
|
||||
class MessagesController < ResourcesController; end
|
||||
class CommentsController < ResourcesController; end
|
||||
class AuthorsController < ResourcesController; end
|
||||
class LogosController < ResourcesController; end
|
||||
|
||||
class AccountsController < ResourcesController; end
|
||||
class AdminController < ResourcesController; end
|
||||
class ProductsController < ResourcesController; end
|
||||
class ImagesController < ResourcesController; end
|
||||
class PreferencesController < ResourcesController; end
|
||||
|
||||
module Backoffice
|
||||
class ProductsController < ResourcesController; end
|
||||
class TagsController < ResourcesController; end
|
||||
class ManufacturersController < ResourcesController; end
|
||||
class ImagesController < ResourcesController; end
|
||||
|
||||
module Admin
|
||||
class ProductsController < ResourcesController; end
|
||||
class ImagesController < ResourcesController; end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,35 +2,6 @@ require 'abstract_unit'
|
|||
require 'active_support/core_ext/object/try'
|
||||
require 'active_support/core_ext/object/with_options'
|
||||
|
||||
class ResourcesController < ActionController::Base
|
||||
def index() render :nothing => true end
|
||||
alias_method :show, :index
|
||||
end
|
||||
|
||||
class ThreadsController < ResourcesController; end
|
||||
class MessagesController < ResourcesController; end
|
||||
class CommentsController < ResourcesController; end
|
||||
class AuthorsController < ResourcesController; end
|
||||
class LogosController < ResourcesController; end
|
||||
|
||||
class AccountsController < ResourcesController; end
|
||||
class AdminController < ResourcesController; end
|
||||
class ProductsController < ResourcesController; end
|
||||
class ImagesController < ResourcesController; end
|
||||
class PreferencesController < ResourcesController; end
|
||||
|
||||
module Backoffice
|
||||
class ProductsController < ResourcesController; end
|
||||
class TagsController < ResourcesController; end
|
||||
class ManufacturersController < ResourcesController; end
|
||||
class ImagesController < ResourcesController; end
|
||||
|
||||
module Admin
|
||||
class ProductsController < ResourcesController; end
|
||||
class ImagesController < ResourcesController; end
|
||||
end
|
||||
end
|
||||
|
||||
class ResourcesTest < ActionController::TestCase
|
||||
def test_default_restful_routes
|
||||
with_restful_routing :messages do
|
||||
|
|
|
@ -1,17 +1,5 @@
|
|||
require 'abstract_unit'
|
||||
|
||||
class CommentsController < ActionController::Base
|
||||
def index
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
|
||||
class ImageAttachmentsController < ActionController::Base
|
||||
def index
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
|
||||
class RoutingConcernsTest < ActionDispatch::IntegrationTest
|
||||
Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
|
||||
app.draw do
|
||||
|
@ -20,7 +8,7 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
concern :image_attachable do
|
||||
resources :image_attachments, only: :index
|
||||
resources :images, only: :index
|
||||
end
|
||||
|
||||
resources :posts, concerns: [:commentable, :image_attachable] do
|
||||
|
@ -65,13 +53,13 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_accessing_concern_from_resources_with_more_than_one_concern
|
||||
get "/posts/1/image_attachments"
|
||||
get "/posts/1/images"
|
||||
assert_equal "200", @response.code
|
||||
assert_equal "/posts/1/image_attachments", post_image_attachments_path(post_id: 1)
|
||||
assert_equal "/posts/1/images", post_images_path(post_id: 1)
|
||||
end
|
||||
|
||||
def test_accessing_concern_from_resources_using_only_option
|
||||
get "/posts/1/image_attachment/1"
|
||||
get "/posts/1/image/1"
|
||||
assert_equal "404", @response.code
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue