Sha256: bf21a424b4c92619945849118a7f7428433e132b5a69b507161221cdd9dd155a

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

module Scrivito
  #
  # @api public
  #
  module TestRequest
    #
    # Make a test request to act as a CMS request.
    # This is necessary for testing controllers that include {Scrivito::ControllerActions}, because
    # these controllers do not have explicit routes by default.
    #
    # @api public
    # @param [Scrivito::BasicObj Obj] test_obj requested +Obj+
    #
    # @example
    #   class MyPageControllerTest < ActionController::TestCase
    #     test 'should respond with success' do
    #       request.for_scrivito_obj
    #       get :index
    #       assert_response :success
    #     end
    #   end
    #
    def for_scrivito_obj(test_obj = nil)
      # prepare the env as if the given obj was loaded by Scrivito::CmsEnv
      env[Scrivito::CmsEnv::OBJ_ENV_KEY] = test_obj if test_obj

      class << self
        def assign_parameters(routes, controller_path, action, parameters = {})
          super(routes, controller_path, action, parameters)
        rescue ActionController::RoutingError, AbstractController::ActionNotFound => e
          begin
            super(routes, "scrivito/cms_dispatch", action, parameters)
          rescue ActionController::RoutingError, AbstractController::ActionNotFound
            raise e
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scrivito_sdk-0.30.0 lib/scrivito/test_request.rb
scrivito_sdk-0.30.0.rc1 lib/scrivito/test_request.rb