Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #383 from vizjerai/devise

Add a helper method sign_in for devise in decorator specs.
  • Loading branch information...
commit 0e51d1df57d260c4f8c22b81ef024f6914ed9ce9 2 parents 9609156 + 66a3009
@steveklabnik steveklabnik authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 lib/draper/test/rspec_integration.rb
View
37 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
Please sign in to comment.
Something went wrong with that request. Please try again.