Sha256: 09ba05e70bcf2d1f8825ff3b920c80a8a6bcd31475f017ec987cd9169da9f694

Contents?: true

Size: 1.25 KB

Versions: 8

Compression:

Stored size: 1.25 KB

Contents

# encoding: utf-8
module Warden::Spec
  module Helpers
    FAILURE_APP = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }

    def env_with_params(path = "/", params = {}, env = {})
      method = params.delete(:method) || "GET"
      env = { 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => "#{method}" }.merge(env)
      Rack::MockRequest.env_for("#{path}?#{Rack::Utils.build_query(params)}", env)
    end

    def setup_rack(app = nil, opts = {}, &block)
      app ||= block if block_given?

      opts[:failure_app]         ||= failure_app
      opts[:default_strategies]  ||= [:password]
      opts[:default_serializers] ||= [:session]

      Rack::Builder.new do
        use opts[:session] || Warden::Spec::Helpers::Session
        use Warden::Manager, opts
        run app
      end
    end

    def valid_response
      Rack::Response.new("OK").finish
    end

    def failure_app
      Warden::Spec::Helpers::FAILURE_APP
    end

    def success_app
      lambda{|e| [200, {"Content-Type" => "text/plain"}, ["You Win"]]}
    end

    class Session
      attr_accessor :app
      def initialize(app,configs = {})
        @app = app
      end

      def call(e)
        e['rack.session'] ||= {}
        @app.call(e)
      end
    end # session
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
devise_sociable-0.1.0 vendor/bundle/gems/warden-1.0.6/spec/helpers/request_helper.rb
warden-1.0.6 spec/helpers/request_helper.rb
warden-1.0.5 spec/helpers/request_helper.rb
warden-1.0.4 spec/helpers/request_helper.rb
warden-1.0.3 spec/helpers/request_helper.rb
warden-1.0.2 spec/helpers/request_helper.rb
warden-1.0.1 spec/helpers/request_helper.rb
warden-1.0.0 spec/helpers/request_helper.rb