diff --git a/lib/draper/test/rspec_integration.rb b/lib/draper/test/rspec_integration.rb index ae58ef88..277cd0b7 100755 --- a/lib/draper/test/rspec_integration.rb +++ b/lib/draper/test/rspec_integration.rb @@ -3,6 +3,39 @@ module DecoratorExampleGroup extend ActiveSupport::Concern included { metadata[:type] = :decorator } end + + module DeviseHelper + def sign_in(user) + warden.stub :authenticate! => user + controller.stub :current_user => user + user + end + + private + + def request + @request ||= ::ActionDispatch::TestRequest.new + end + + def controller + return @controller if @controller + @controller = ApplicationController.new + @controller.request = request + ::Draper::ViewContext.current = @controller.view_context + @controller + end + + # taken from Devise's helper but uses the request method instead of @request + # and we don't really need the rest of their helper + def warden + @warden ||= begin + manager = Warden::Manager.new(nil) do |config| + config.merge! Devise.warden_config + end + request.env['warden'] = Warden::Proxy.new(request.env, manager) + end + end + end end RSpec.configure do |config| @@ -11,7 +44,11 @@ module DecoratorExampleGroup :file_path => /spec[\\\/]decorators/ } + if defined?(Devise) + config.include Draper::DeviseHelper, :type => :decorator + end end + module Draper module RSpec class Railtie < Rails::Railtie