Skip to content

Commit

Permalink
Merge pull request #2 from mspanc/master
Browse files Browse the repository at this point in the history
Updated helpers to work with RoR 4.1 & RSpec 3
  • Loading branch information
ajsharp committed Jan 22, 2016
2 parents 3415dde + ffab9b7 commit d44e129
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/warden/test/controller_helpers.rb
@@ -1,19 +1,14 @@
# test/test_helpers/warden.rb

# Based on http://stackoverflow.com/questions/13420923/configuring-warden-for-use-in-rspec-controller-specs
module Warden
# Warden::Test::ControllerHelpers provides a facility to test controllers in isolation
# Most of the code was extracted from Devise's Devise::TestHelpers.
module Test
module ControllerHelpers
def self.included(base)
base.class_eval do
before(:each) do
setup_controller_for_warden
end

before(:each) do
warden
end
setup :setup_controller_for_warden, :warden if respond_to?(:setup)
end
end

Expand All @@ -31,7 +26,7 @@ def setup_controller_for_warden
# Quick access to Warden::Proxy.
def warden
@warden ||= begin
manager = Warden::Manager.new(nil, &Rails.application.config.middleware.detect{|m| m.name == 'RailsWarden::Manager'}.block)
manager = Warden::Manager.new(nil, &Rails.application.config.middleware.detect{|m| m.name == 'Warden::Manager'}.block)
@request.env['warden'] = Warden::Proxy.new(@request.env, manager)
end
end
Expand Down Expand Up @@ -62,4 +57,4 @@ def _catch_warden(&block)
end
end
end
end
end

0 comments on commit d44e129

Please sign in to comment.