Skip to content
Browse files

Updating the library to handle Warden version 0.8

  • Loading branch information...
1 parent 675e33f commit 17865a4e8c58989b745de97f92028230f59b07dc @roman committed Jan 9, 2010
View
2 lib/warden_oauth.rb
@@ -12,7 +12,7 @@ module OAuth
autoload :StrategyBuilder, base_path + '/strategy_builder'
autoload :Strategy, base_path + '/strategy'
autoload :Config, base_path + "/config"
- require base_path + "/manager"
+ require base_path + "/config_extension"
end
View
18 lib/warden_oauth/manager.rb → lib/warden_oauth/config_extension.rb
@@ -2,10 +2,10 @@ module Warden
module OAuth
#
- # Holds all the extensions made to Warden::Manager in order to create OAuth
+ # Holds all the extensions made to Warden::Config in order to create OAuth
# consumers.
#
- module Manager
+ module ConfigExtension
#
# Helps to setup a new OAuth client authentication, to get started you need to define
@@ -14,11 +14,12 @@ module Manager
# @param [Symbol] service An identifier of the OAuth service
#
# @example
- #
- # Warden::Manager.oauth(:twitter) do
- # consumer_key "<YOUR CONSUMER KEY>"
- # consumer_secret "<YOUR CONSUMER SECRET>"
- # options :site => 'http://twitter.com'
+ # use Warden::Manager do |config|
+ # config.oauth(:twitter) do
+ # consumer_key "<YOUR CONSUMER KEY>"
+ # consumer_secret "<YOUR CONSUMER SECRET>"
+ # options :site => 'http://twitter.com'
+ # end
# end
#
def oauth(service, &block)
@@ -40,4 +41,5 @@ def oauth(service, &block)
end
end
-Warden::Manager.send(:include, Warden::OAuth::Manager)
+Warden::Config.send(:include, Warden::OAuth::ConfigExtension)
+
View
16 spec/warden_oauth/manager_spec.rb → spec/warden_oauth/config_extension_spec.rb
@@ -1,14 +1,18 @@
require File.dirname(__FILE__) + "/../spec_helper"
-describe Warden::Manager do
+describe Warden::Config do
before(:each) do
failure_app = lambda { |env| "Failure" }
- @manager = Warden::Manager.new(nil, :failure_app => failure_app)
+ config = nil
+ Warden::Manager.new(nil, :failure_app => failure_app) do |_config|
+ config = _config
+ end
+ @config = config
end
it "should respond to an `oauth` message" do
- @manager.should respond_to(:oauth)
+ @config.should respond_to(:oauth)
end
describe "#oauth" do
@@ -17,22 +21,22 @@
it "should require setting the consumer_key" do
lambda do
- @manager.oauth(:service) do |service|
+ @config.oauth(:service) do |service|
service.consumer_secret "ABC"
end
end.should raise_error(Warden::OAuth::ConfigError, "You need to specify the consumer key and the consumer secret")
end
it "should require setting the consumer_secret" do
lambda do
- @manager.oauth(:service) do |service|
+ @config.oauth(:service) do |service|
service.consumer_key "ABC"
end
end.should raise_error(Warden::OAuth::ConfigError, "You need to specify the consumer key and the consumer secret")
end
it "should create a new instance of strategy" do
- @manager.oauth(:service) do |service|
+ @config.oauth(:service) do |service|
service.consumer_key "ABC"
service.consumer_secret "123"
end
View
14 spec/warden_oauth/strategy_spec.rb
@@ -60,8 +60,8 @@ def fixture_response(name)
before(:each) do
FakeWeb.register_uri(:post, 'http://localhost:3000/oauth/request_token',
:body => fixture_response("unauthorized_request_token"))
- @response = @request.get("/", :input => 'warden_oauth_provider=example')
- end
+ @response = @request.get("/", :params => { 'warden_oauth_provider' => 'example' })
+ end
it "should redirect to the authorize url" do
@response.headers['Location'].should =~ %r"http://localhost:3000/oauth/authorize"
@@ -76,7 +76,12 @@ def app
$app
end
- describe "and the access_token_finder hasn't been declared" do
+ before(:each) do
+ Warden::Strategies.clear!
+ Warden::OAuth::Strategy.send(:remove_const, "Example") if Warden::OAuth::Strategy.const_defined?("Example")
+ end
+
+ describe "and the access_token_user_finder hasn't been declared" do
before(:each) do
FakeWeb.register_uri(:post, 'http://localhost:3000/oauth/request_token',
@@ -95,9 +100,10 @@ def app
end
- describe "and the access_token_finder has been declared" do
+ describe "and the access_token_user_finder has been declared" do
before(:each) do
+ get "/initialize_strategies"
Warden::Strategies[:example_oauth].access_token_user_finder do |access_token|
Object.new if access_token.token == 'ABC' && access_token.secret == '123'
end

0 comments on commit 17865a4

Please sign in to comment.
Something went wrong with that request. Please try again.