Skip to content

Commit

Permalink
Add a helper method sign_in for devise in decorator specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
vizjerai committed Dec 12, 2012
1 parent 059ecbc commit 66a3009
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/draper/test/rspec_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down

0 comments on commit 66a3009

Please sign in to comment.