Sha256: 94f8d2b2f8c6bf69ce23c5da2b5212325fd6159abf1dde3d05e44937d57f1f13

Contents?: true

Size: 1.13 KB

Versions: 23

Compression:

Stored size: 1.13 KB

Contents

require 'rack'
require 'omniauth/test'

module OmniAuth
  module Test
    # Support for testing OmniAuth strategies.
    #
    # @example Usage
    #   class MyStrategyTest < Test::Unit::TestCase
    #     include OmniAuth::Test::StrategyTestCase
    #     def strategy
    #       # return the parameters to a Rack::Builder map call:
    #       [MyStrategy, :some, :configuration, :options => 'here']
    #     end
    #     setup do
    #       post '/auth/my_strategy/callback', :user => { 'name' => 'Dylan', 'id' => '445' }
    #     end
    #   end
    module StrategyTestCase
      def app
        strat = strategy
        resp = app_response
        Rack::Builder.new do
          use(OmniAuth::Test::PhonySession)
          use(*strat)
          run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
        end.to_app
      end

      def app_response
        nil
      end

      def session
        last_request.env['rack.session']
      end

      def strategy
        error = NotImplementedError.new('Including specs must define #strategy')
        raise(error)
      end
    end
  end
end

Version data entries

23 entries across 22 versions & 2 rubygems

Version Path
omniauth-2.1.2 lib/omniauth/test/strategy_test_case.rb
omniauth-2.1.1 lib/omniauth/test/strategy_test_case.rb
omniauth-1.9.2 lib/omniauth/test/strategy_test_case.rb
omniauth-2.1.0 lib/omniauth/test/strategy_test_case.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/omniauth-2.0.4/lib/omniauth/test/strategy_test_case.rb
omniauth-2.0.4 lib/omniauth/test/strategy_test_case.rb
omniauth-2.0.3 lib/omniauth/test/strategy_test_case.rb
omniauth-2.0.2 lib/omniauth/test/strategy_test_case.rb
omniauth-2.0.1 lib/omniauth/test/strategy_test_case.rb
omniauth-2.0.0 lib/omniauth/test/strategy_test_case.rb
omniauth-2.0.0.pre.rc1 lib/omniauth/test/strategy_test_case.rb
omniauth-1.9.1 lib/omniauth/test/strategy_test_case.rb
omniauth-1.9.0 lib/omniauth/test/strategy_test_case.rb
tdiary-5.0.8 vendor/bundle/gems/omniauth-1.8.1/lib/omniauth/test/strategy_test_case.rb
omniauth-1.8.1 lib/omniauth/test/strategy_test_case.rb
omniauth-1.8.0 lib/omniauth/test/strategy_test_case.rb
omniauth-1.7.1 lib/omniauth/test/strategy_test_case.rb
omniauth-1.7.0 lib/omniauth/test/strategy_test_case.rb
tdiary-5.0.5 vendor/bundle/gems/omniauth-1.6.1/lib/omniauth/test/strategy_test_case.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/omniauth-1.6.1/lib/omniauth/test/strategy_test_case.rb