module ActiveDecorator::RSpec

Constants

VERSION

Public Class Methods

enable(example) click to toggle source
# File lib/active_decorator/rspec.rb, line 9
def self.enable(example)
  example.extend self

  base_class = begin
                 ApplicationController
               rescue NameError
                 ActionController::Base
               end
  controller = Class.new(base_class).new
  controller.request = if ActionController::TestRequest.respond_to?(:create)
                         if ActionPack.version.release >= Gem::Version.new('5.1.0')
                           ActionController::TestRequest.create(controller.class)
                         else
                           ActionController::TestRequest.create
                         end
                       else
                         ActionController::TestRequest.new
                       end
  if ActiveDecorator::ViewContext.respond_to?(:current=)
    ActiveDecorator::ViewContext.current = controller.view_context
  else
    ActiveDecorator::ViewContext.push controller.view_context
  end

  self
end

Public Instance Methods

decorate(obj) click to toggle source
# File lib/active_decorator/rspec.rb, line 36
def decorate(obj)
  ActiveDecorator::Decorator.instance.decorate(obj)
  obj
end