Sha256: 3119ed33fd41710a697914b33c79d6dc47c6621c2b97dc87406ba74053b47a11

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 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]
      blk = opts[:configurator] || proc{}

      Rack::Builder.new do
        use opts[:session] || Warden::Spec::Helpers::Session
        use Warden::Manager, opts, &blk
        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

10 entries across 10 versions & 3 rubygems

Version Path
devise_sociable-0.1.0 vendor/bundle/gems/warden-1.2.1/spec/helpers/request_helper.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/warden-1.2.1/spec/helpers/request_helper.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/helpers/request_helper.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/helpers/request_helper.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/helpers/request_helper.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/helpers/request_helper.rb
warden-1.2.1 spec/helpers/request_helper.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/helpers/request_helper.rb
warden-1.2.0 spec/helpers/request_helper.rb
warden-1.1.1 spec/helpers/request_helper.rb