Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not raise undefined method base fixes #59 #69

Merged
merged 3 commits into from Mar 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,4 +1,4 @@
source :rubygems
source 'https://rubygems.org'

gemspec

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -5,7 +5,7 @@ PATH
rack (>= 1.0)

GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
diff-lcs (1.1.3)
rack (1.3.0)
Expand Down
3 changes: 2 additions & 1 deletion lib/warden/strategies.rb
Expand Up @@ -11,7 +11,8 @@ def add(label, strategy = nil, &block)
raise NoMethodError, "authenticate! is not declared in the #{label.inspect} strategy"
end

unless strategy.ancestors.include?(Warden::Strategies::Base)
base = Warden::Strategies::Base
unless strategy.ancestors.include?(base)
raise "#{label.inspect} is not a #{base}"
end

Expand Down
11 changes: 5 additions & 6 deletions spec/warden/proxy_spec.rb
Expand Up @@ -2,7 +2,6 @@
require 'spec_helper'

describe Warden::Proxy do

before(:all) do
load_strategies
end
Expand Down Expand Up @@ -340,7 +339,6 @@
end
setup_rack(app).call(@env)
end

end

describe "set user" do
Expand Down Expand Up @@ -512,7 +510,6 @@
end

describe "logout" do

before(:each) do
@env['rack.session'] = {"warden.user.default.key" => "default key", "warden.user.foo.key" => "foo key", :foo => "bar"}
@app = lambda do |e|
Expand Down Expand Up @@ -665,7 +662,7 @@
app = lambda do |e|
e['warden'].should be_authenticated
end
result = setup_rack(app).call(@env)
setup_rack(app).call(@env)
end

it "should yield to a block when the block is passed and authenticated" do
Expand Down Expand Up @@ -700,7 +697,7 @@
app = lambda do |e|
e['warden'].should_not be_authenticated
end
result = setup_rack(app).call(@env)
setup_rack(app).call(@env)
end

it "should return false if scope cannot be retrieved from session" do
Expand Down Expand Up @@ -786,7 +783,7 @@
app = lambda do |e|
e['warden'].should be_unauthenticated
end
result = setup_rack(app).call(@env)
setup_rack(app).call(@env)
end

it "should yield to a block when the block is passed and authenticated" do
Expand Down Expand Up @@ -828,6 +825,8 @@ def def_app(&blk)

describe "dynamic default_strategies" do
before(:all) do
load_strategies

class ::DynamicDefaultStrategies
def initialize(app, &blk)
@app, @blk = app, blk
Expand Down
12 changes: 11 additions & 1 deletion spec/warden/strategies_spec.rb
Expand Up @@ -11,13 +11,23 @@ def authenticate!
Warden::Strategies[:strategy1].ancestors.should include(Warden::Strategies::Base)
end

it "should raise an error if I add a strategy via a block, that does not have an autheniticate! method" do
it "should raise an error if I add a strategy via a block, that does not have an authenticate! method" do
lambda do
Warden::Strategies.add(:strategy2) do
end
end.should raise_error
end

it "should raise an error if I add a strategy that does not extend Warden::Strategies::Base" do
non_base = Class.new do
def authenticate!
end
end
expect do
Warden::Strategies.add(:strategy_non_base, non_base)
end.to raise_error(/is not a Warden::Strategies::Base/)
end

it "should allow me to get access to a particular strategy" do
Warden::Strategies.add(:strategy3) do
def authenticate!; end
Expand Down