warden 1.2.3 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e2a3954f2157d76ec551f9c498a4e27e09a4a698
4
+ data.tar.gz: ea81f2cd654fbf09ebf9e2ef44d6836cd47bd920
5
+ SHA512:
6
+ metadata.gz: 74db07fcb955f8109cf57bd7e32868bb198f8c7c94a748ca450bfc7e281cacff1c869af942c1952a0ade3fb209bcd134dc7cf3a916d4d0a36417cc5e9a4790b2
7
+ data.tar.gz: 6d38527fbf7cbdf032ecf16ce5661584afe1d4fb9dbf4cb4c0d60a32b385b53f7e781eb92d4c1624b16de5fe688183af6f9a258cae079a942ca67bc3e69ddd9b
data/Gemfile CHANGED
@@ -6,6 +6,6 @@ gem 'rake'
6
6
  gem 'rack', '1.3'
7
7
 
8
8
  group :test do
9
- gem 'rspec', '~>2'
9
+ gem 'rspec', '~>3'
10
10
  gem 'rack-test'
11
11
  end
data/History.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == Version 1.2.5 / 2016-01-28
2
+ * Expands on the test helpers available to make it easier for testing gems
3
+
1
4
  == Version 1.2.3 / 2013-07-14
2
5
  * Fix an issue with lazy loaded sessions
3
6
 
data/lib/warden/config.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Warden
4
- # This is a class which is yielded on use Warden::Manager. If you have a plugin
5
- # and wants to add more configuration to warden, you just need to extend this
6
- # class.
4
+ # This class is yielded inside Warden::Manager. If you have a plugin and want to
5
+ # add more configuration to warden, you just need to extend this class.
7
6
  class Config < Hash
8
7
  # Creates an accessor that simply sets and reads a key in the hash:
9
8
  #
data/lib/warden/hooks.rb CHANGED
@@ -18,21 +18,21 @@ module Warden
18
18
  # A callback hook set to run every time after a user is set.
19
19
  # This callback is triggered the first time one of those three events happens
20
20
  # during a request: :authentication, :fetch (from session) and :set_user (when manually set).
21
- # You can supply as many hooks as you like, and they will be run in order of decleration.
21
+ # You can supply as many hooks as you like, and they will be run in order of declaration.
22
22
  #
23
23
  # If you want to run the callbacks for a given scope and/or event, you can specify them as options.
24
24
  # See parameters and example below.
25
25
  #
26
26
  # Parameters:
27
27
  # <options> Some options which specify when the callback should be executed
28
- # scope - Executes the callback only if it maches the scope(s) given
28
+ # scope - Executes the callback only if it matches the scope(s) given
29
29
  # only - Executes the callback only if it matches the event(s) given
30
30
  # except - Executes the callback except if it matches the event(s) given
31
31
  # <block> A block where you can set arbitrary logic to run every time a user is set
32
32
  # Block Parameters: |user, auth, opts|
33
33
  # user - The user object that is being set
34
34
  # auth - The raw authentication proxy object.
35
- # opts - any options passed into the set_user call includeing :scope
35
+ # opts - any options passed into the set_user call including :scope
36
36
  #
37
37
  # Example:
38
38
  # Warden::Manager.after_set_user do |user,auth,opts|
@@ -77,7 +77,7 @@ module Warden
77
77
  end
78
78
 
79
79
  # after_fetch is just a wrapper to after_set_user, which is only invoked
80
- # when the user is fetched from sesion. The options and yielded arguments
80
+ # when the user is fetched from session. The options and yielded arguments
81
81
  # are the same as in after_set_user.
82
82
  #
83
83
  # :api: public
@@ -85,18 +85,18 @@ module Warden
85
85
  after_set_user(options.merge(:event => :fetch), method, &block)
86
86
  end
87
87
 
88
- # A callback that runs just prior to the failur application being called.
88
+ # A callback that runs just prior to the failure application being called.
89
89
  # This callback occurs after PATH_INFO has been modified for the failure (default /unauthenticated)
90
90
  # In this callback you can mutate the environment as required by the failure application
91
91
  # If a Rails controller were used for the failure_app for example, you would need to set request[:params][:action] = :unauthenticated
92
92
  #
93
93
  # Parameters:
94
94
  # <options> Some options which specify when the callback should be executed
95
- # scope - Executes the callback only if it maches the scope(s) given
95
+ # scope - Executes the callback only if it matches the scope(s) given
96
96
  # <block> A block to contain logic for the callback
97
97
  # Block Parameters: |env, opts|
98
98
  # env - The rack env hash
99
- # opts - any options passed into the authenticate call includeing :scope
99
+ # opts - any options passed into the authenticate call including :scope
100
100
  #
101
101
  # Example:
102
102
  # Warden::Manager.before_failure do |env, opts|
@@ -121,7 +121,7 @@ module Warden
121
121
  #
122
122
  # Parameters:
123
123
  # <options> Some options which specify when the callback should be executed
124
- # scope - Executes the callback only if it maches the scope(s) given
124
+ # scope - Executes the callback only if it matches the scope(s) given
125
125
  # <block> A block to contain logic for the callback
126
126
  # Block Parameters: |user, auth, scope|
127
127
  # user - The authenticated user for the current scope
@@ -149,7 +149,7 @@ module Warden
149
149
  #
150
150
  # Parameters:
151
151
  # <options> Some options which specify when the callback should be executed
152
- # scope - Executes the callback only if it maches the scope(s) given
152
+ # scope - Executes the callback only if it matches the scope(s) given
153
153
  # <block> A block to contain logic for the callback
154
154
  # Block Parameters: |user, auth, scope|
155
155
  # user - The authenticated user for the current scope
@@ -4,7 +4,7 @@ require 'warden/config'
4
4
 
5
5
  module Warden
6
6
  # The middleware for Rack Authentication
7
- # The middlware requires that there is a session upstream
7
+ # The middleware requires that there is a session upstream
8
8
  # The middleware injects an authentication object into
9
9
  # the rack environment hash
10
10
  class Manager
@@ -19,7 +19,7 @@ module Warden
19
19
  default_strategies = options.delete(:default_strategies)
20
20
 
21
21
  @app, @config = app, Warden::Config.new(options)
22
- @config.default_strategies *default_strategies if default_strategies
22
+ @config.default_strategies(*default_strategies) if default_strategies
23
23
  yield @config if block_given?
24
24
  self
25
25
  end
@@ -38,13 +38,11 @@ module Warden
38
38
  result ||= {}
39
39
  case result
40
40
  when Array
41
- if result.first == 401 && intercept_401?(env)
42
- process_unauthenticated(env)
43
- else
44
- result
45
- end
41
+ handle_chain_result(result.first, result, env)
46
42
  when Hash
47
43
  process_unauthenticated(env, result)
44
+ when Rack::Response
45
+ handle_chain_result(result.status, result, env)
48
46
  end
49
47
  end
50
48
 
@@ -72,8 +70,8 @@ module Warden
72
70
  Warden::SessionSerializer.send :define_method, method_name, &block
73
71
  end
74
72
 
75
- # Reconstitues the user from the session.
76
- # Use the results of user_session_key to reconstitue the user from the session on requests after the initial login
73
+ # Reconstitutes the user from the session.
74
+ # Use the results of user_session_key to reconstitute the user from the session on requests after the initial login
77
75
  # You can supply different methods of de-serialization for different scopes by passing a scope symbol
78
76
  #
79
77
  # Example:
@@ -84,12 +82,25 @@ module Warden
84
82
  # :api: public
85
83
  def serialize_from_session(scope = nil, &block)
86
84
  method_name = scope.nil? ? :deserialize : "#{scope}_deserialize"
85
+
86
+ if Warden::SessionSerializer.method_defined? method_name
87
+ Warden::SessionSerializer.send :remove_method, method_name
88
+ end
89
+
87
90
  Warden::SessionSerializer.send :define_method, method_name, &block
88
91
  end
89
92
  end
90
93
 
91
94
  private
92
95
 
96
+ def handle_chain_result(status, result, env)
97
+ if status == 401 && intercept_401?(env)
98
+ process_unauthenticated(env)
99
+ else
100
+ result
101
+ end
102
+ end
103
+
93
104
  def intercept_401?(env)
94
105
  config[:intercept_401] && !env['warden'].custom_failure?
95
106
  end
@@ -113,6 +124,7 @@ module Warden
113
124
  when :custom
114
125
  proxy.custom_response
115
126
  else
127
+ options[:message] ||= proxy.message
116
128
  call_failure_app(env, options)
117
129
  end
118
130
  end
@@ -3,7 +3,7 @@ module Warden
3
3
  module Mixins
4
4
  module Common
5
5
 
6
- # Convinience method to access the session
6
+ # Convenience method to access the session
7
7
  # :api: public
8
8
  def session
9
9
  env['rack.session']
data/lib/warden/proxy.rb CHANGED
@@ -69,7 +69,7 @@ module Warden
69
69
  #
70
70
  # :api: public
71
71
  def clear_strategies_cache!(*args)
72
- scope, opts = _retrieve_scope_and_opts(args)
72
+ scope, _opts = _retrieve_scope_and_opts(args)
73
73
 
74
74
  @winning_strategies.delete(scope)
75
75
  @strategies[scope].each do |k, v|
@@ -87,7 +87,7 @@ module Warden
87
87
  @locked = true
88
88
  end
89
89
 
90
- # Run the authentiation strategies for the given strategies.
90
+ # Run the authentication strategies for the given strategies.
91
91
  # If there is already a user logged in for a given scope, the strategies are not run
92
92
  # This does not halt the flow of control and is a passive attempt to authenticate only
93
93
  # When scope is not specified, the default_scope is assumed.
@@ -101,7 +101,7 @@ module Warden
101
101
  #
102
102
  # :api: public
103
103
  def authenticate(*args)
104
- user, opts = _perform_authentication(*args)
104
+ user, _opts = _perform_authentication(*args)
105
105
  user
106
106
  end
107
107
 
@@ -181,7 +181,7 @@ module Warden
181
181
  @users[scope]
182
182
  end
183
183
 
184
- # Provides acccess to the user object in a given scope for a request.
184
+ # Provides access to the user object in a given scope for a request.
185
185
  # Will be nil if not logged in. Please notice that this method does not
186
186
  # perform strategies.
187
187
  #
@@ -280,7 +280,7 @@ module Warden
280
280
  winning_strategy && winning_strategy.message
281
281
  end
282
282
 
283
- # Provides a way to return a 401 without warden defering to the failure app
283
+ # Provides a way to return a 401 without warden deferring to the failure app
284
284
  # The result is a direct passthrough of your own response
285
285
  # :api: public
286
286
  def custom_failure!
@@ -290,7 +290,11 @@ module Warden
290
290
  # Check to see if the custom failure flag has been set
291
291
  # :api: public
292
292
  def custom_failure?
293
- !!@custom_failure
293
+ if instance_variable_defined?(:@custom_failure)
294
+ !!@custom_failure
295
+ else
296
+ false
297
+ end
294
298
  end
295
299
 
296
300
  # Check to see if this is an asset request
@@ -318,7 +322,7 @@ module Warden
318
322
  return user, opts if user = user(opts.merge(:scope => scope))
319
323
  _run_strategies_for(scope, args)
320
324
 
321
- if winning_strategy && winning_strategy.user
325
+ if winning_strategy && winning_strategy.successful?
322
326
  opts[:store] = opts.fetch(:store, winning_strategy.store?)
323
327
  set_user(winning_strategy.user, opts.merge!(:event => :authentication))
324
328
  end
@@ -356,7 +360,7 @@ module Warden
356
360
  end
357
361
  end
358
362
 
359
- # Fetchs strategies and keep them in a hash cache.
363
+ # Fetches strategies and keep them in a hash cache.
360
364
  def _fetch_strategy(name, scope)
361
365
  @strategies[scope][name] ||= if klass = Warden::Strategies[name]
362
366
  klass.new(@env, scope)
@@ -9,11 +9,11 @@ module Warden
9
9
  # You _may_ provide a @valid?@ method.
10
10
  # The valid method should return true or false depending on if the strategy is a valid one for the request.
11
11
  #
12
- # The parameters for Warden::Strategies.add method is:
12
+ # The parameters for Warden::Strategies.add method are:
13
13
  # <label: Symbol> The label is the name given to a strategy. Use the label to refer to the strategy when authenticating
14
- # <strategy: Class|nil> The optional stragtegy argument if set _must_ be a class that inherits from Warden::Strategies::Base and _must_
14
+ # <strategy: Class|nil> The optional strategy argument if set _must_ be a class that inherits from Warden::Strategies::Base and _must_
15
15
  # implement an @authenticate!@ method
16
- # <block> The block acts as a convinient way to declare your strategy. Inside is the class definition of a strategy.
16
+ # <block> The block acts as a convenient way to declare your strategy. Inside is the class definition of a strategy.
17
17
  #
18
18
  # Examples:
19
19
  #
@@ -108,8 +108,13 @@ module Warden
108
108
  # :api: public
109
109
  def pass; end
110
110
 
111
+ # Returns true only if the result is a success and a user was assigned.
112
+ def successful?
113
+ @result == :success && !user.nil?
114
+ end
115
+
111
116
  # Whenever you want to provide a user object as "authenticated" use the +success!+ method.
112
- # This will halt the strategy, and set the user in the approprieate scope.
117
+ # This will halt the strategy, and set the user in the appropriate scope.
113
118
  # It is the "login" method
114
119
  #
115
120
  # Parameters:
@@ -133,7 +138,7 @@ module Warden
133
138
  @result = :failure
134
139
  end
135
140
 
136
- # Casuses the strategy to fail, but not halt. The strategies will cascade after this failure and warden will check the next strategy. The last strategy to fail will have it's message displayed.
141
+ # Causes the strategy to fail, but not halt. The strategies will cascade after this failure and warden will check the next strategy. The last strategy to fail will have it's message displayed.
137
142
  # :api: public
138
143
  def fail(message = "Failed to Login")
139
144
  @message = message
@@ -144,8 +149,8 @@ module Warden
144
149
  #
145
150
  # Parameters:
146
151
  # url <String> - The string representing the URL to be redirected to
147
- # pararms <Hash> - Any parameters to encode into the URL
148
- # opts <Hash> - Any options to recirect with.
152
+ # params <Hash> - Any parameters to encode into the URL
153
+ # opts <Hash> - Any options to redirect with.
149
154
  # available options: permanent => (true || false)
150
155
  #
151
156
  # :api: public
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'rack'
4
+
3
5
  module Warden
4
6
  module Test
5
7
  # A collection of test helpers for testing full stack rack applications using Warden
@@ -10,7 +12,7 @@ module Warden
10
12
  ::Warden.test_mode!
11
13
  end
12
14
 
13
- # A helper method that will peform a login of a user in warden for the next request
15
+ # A helper method that will perform a login of a user in warden for the next request.
14
16
  # Provide it the same options as you would to Warden::Proxy#set_user
15
17
  # @see Warden::Proxy#set_user
16
18
  # @api public
@@ -31,6 +33,59 @@ module Warden
31
33
  proxy.logout(*scopes)
32
34
  end
33
35
  end
36
+
37
+ # A helper method that provides the warden object by mocking the env variable.
38
+ # @api public
39
+ def warden
40
+ @warden ||= begin
41
+ env['warden']
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def env
48
+ @env ||= begin
49
+ request = Rack::MockRequest.env_for(
50
+ "/?#{Rack::Utils.build_query({})}",
51
+ { 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => 'GET' }
52
+ )
53
+ app.call(request)
54
+
55
+ request
56
+ end
57
+ end
58
+
59
+ def app
60
+ @app ||= begin
61
+ opts = {
62
+ failure_app: lambda {
63
+ [401, { 'Content-Type' => 'text/plain' }, ['You Fail!']]
64
+ },
65
+ default_strategies: :password,
66
+ default_serializers: :session
67
+ }
68
+ Rack::Builder.new do
69
+ use Warden::Test::Helpers::Session
70
+ use Warden::Manager, opts, &proc {}
71
+ run lambda { |e|
72
+ [200, { 'Content-Type' => 'text/plain' }, ['You Win']]
73
+ }
74
+ end
75
+ end
76
+ end
77
+
78
+ class Session
79
+ attr_accessor :app
80
+ def initialize(app,configs = {})
81
+ @app = app
82
+ end
83
+
84
+ def call(e)
85
+ e['rack.session'] ||= {}
86
+ @app.call(e)
87
+ end
88
+ end # session
34
89
  end
35
90
  end
36
91
  end
@@ -32,7 +32,7 @@ module Warden
32
32
  _on_next_request.clear
33
33
  end
34
34
 
35
- # A containter for the on_next_request items.
35
+ # A container for the on_next_request items.
36
36
  # @api private
37
37
  def _on_next_request
38
38
  @_on_next_request ||= []
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Warden
3
- VERSION = "1.2.3".freeze
3
+ VERSION = "1.2.5".freeze
4
4
  end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ Warden::Strategies.add(:fail_with_user) do
3
+ def authenticate!
4
+ request.env['warden.spec.strategies'] ||= []
5
+ request.env['warden.spec.strategies'] << :fail_with_user
6
+ self.user = 'Valid User'
7
+ fail!
8
+ end
9
+ end
10
+
@@ -5,4 +5,4 @@ Warden::Strategies.add(:invalid) do
5
5
  end
6
6
 
7
7
  def authenticate!; end
8
- end
8
+ end
@@ -16,16 +16,16 @@ describe "authenticated data store" do
16
16
  app = lambda do |e|
17
17
  e['warden'].authenticate(:pass)
18
18
  e['warden'].authenticate(:pass, :scope => :foo)
19
- e['warden'].should be_authenticated
20
- e['warden'].should be_authenticated(:foo)
19
+ expect(e['warden']).to be_authenticated
20
+ expect(e['warden']).to be_authenticated(:foo)
21
21
 
22
22
  # Store the data for :default
23
23
  e['warden'].session[:key] = "value"
24
24
  valid_response
25
25
  end
26
26
  setup_rack(app).call(@env)
27
- @env['rack.session']['warden.user.default.session'].should == {:key => "value"}
28
- @env['rack.session']['warden.user.foo.session'].should be_nil
27
+ expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
28
+ expect(@env['rack.session']['warden.user.foo.session']).to be_nil
29
29
  end
30
30
 
31
31
  it "should store data for the foo user" do
@@ -34,18 +34,18 @@ describe "authenticated data store" do
34
34
  valid_response
35
35
  end
36
36
  setup_rack(app).call(@env)
37
- @env['rack.session']['warden.user.foo.session'].should == {:key => "value"}
37
+ expect(@env['rack.session']['warden.user.foo.session']).to eq(key: "value")
38
38
  end
39
39
 
40
- it "should store the data seperately" do
40
+ it "should store the data separately" do
41
41
  app = lambda do |e|
42
42
  e['warden'].session[:key] = "value"
43
43
  e['warden'].session(:foo)[:key] = "another value"
44
44
  valid_response
45
45
  end
46
46
  setup_rack(app).call(@env)
47
- @env['rack.session']['warden.user.default.session'].should == {:key => "value"}
48
- @env['rack.session']['warden.user.foo.session' ].should == {:key => "another value"}
47
+ expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
48
+ expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
49
49
  end
50
50
 
51
51
  it "should clear the foo scoped data when foo logs out" do
@@ -56,8 +56,8 @@ describe "authenticated data store" do
56
56
  valid_response
57
57
  end
58
58
  setup_rack(app).call(@env)
59
- @env['rack.session']['warden.user.default.session'].should == {:key => "value"}
60
- @env['rack.session']['warden.user.foo.session' ].should be_nil
59
+ expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
60
+ expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil
61
61
  end
62
62
 
63
63
  it "should clear out the default data when :default logs out" do
@@ -68,8 +68,8 @@ describe "authenticated data store" do
68
68
  valid_response
69
69
  end
70
70
  setup_rack(app).call(@env)
71
- @env['rack.session']['warden.user.default.session'].should be_nil
72
- @env['rack.session']['warden.user.foo.session' ].should == {:key => "another value"}
71
+ expect(@env['rack.session']['warden.user.default.session']).to be_nil
72
+ expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
73
73
  end
74
74
 
75
75
  it "should clear out all data when a general logout is performed" do
@@ -80,11 +80,11 @@ describe "authenticated data store" do
80
80
  valid_response
81
81
  end
82
82
  setup_rack(app).call(@env)
83
- @env['rack.session']['warden.user.default.session'].should be_nil
84
- @env['rack.session']['warden.user.foo.session' ].should be_nil
83
+ expect(@env['rack.session']['warden.user.default.session']).to be_nil
84
+ expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil
85
85
  end
86
86
 
87
- it "should logout multuiple personas at once" do
87
+ it "should logout multiple persons at once" do
88
88
  @env['rack.session']['warden.user.bar.key'] = "bar user"
89
89
 
90
90
  app = lambda do |e|
@@ -95,9 +95,9 @@ describe "authenticated data store" do
95
95
  valid_response
96
96
  end
97
97
  setup_rack(app).call(@env)
98
- @env['rack.session']['warden.user.default.session'].should be_nil
99
- @env['rack.session']['warden.user.foo.session' ].should == {:key => "another value"}
100
- @env['rack.session']['warden.user.bar.session' ].should be_nil
98
+ expect(@env['rack.session']['warden.user.default.session']).to be_nil
99
+ expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
100
+ expect(@env['rack.session']['warden.user.bar.session' ]).to be_nil
101
101
  end
102
102
 
103
103
  it "should not store data for a user who is not logged in" do
@@ -107,8 +107,8 @@ describe "authenticated data store" do
107
107
  valid_response
108
108
  end
109
109
 
110
- lambda do
110
+ expect {
111
111
  setup_rack(app).call(@env)
112
- end.should raise_error(Warden::NotAuthenticated)
112
+ }.to raise_error(Warden::NotAuthenticated)
113
113
  end
114
114
  end
@@ -9,40 +9,40 @@ describe Warden::Config do
9
9
 
10
10
  it "should behave like a hash" do
11
11
  @config[:foo] = :bar
12
- @config[:foo].should == :bar
12
+ expect(@config[:foo]).to eq(:bar)
13
13
  end
14
14
 
15
15
  it "should provide hash accessors" do
16
16
  @config.failure_app = :foo
17
- @config[:failure_app].should == :foo
17
+ expect(@config[:failure_app]).to eq(:foo)
18
18
  @config[:failure_app] = :bar
19
- @config.failure_app.should == :bar
19
+ expect(@config.failure_app).to eq(:bar)
20
20
  end
21
21
 
22
22
  it "should allow to read and set default strategies" do
23
23
  @config.default_strategies :foo, :bar
24
- @config.default_strategies.should == [:foo, :bar]
24
+ expect(@config.default_strategies).to eq([:foo, :bar])
25
25
  end
26
26
 
27
27
  it "should allow to silence missing strategies" do
28
28
  @config.silence_missing_strategies!
29
- @config.silence_missing_strategies?.should be_true
29
+ expect(@config.silence_missing_strategies?).to eq(true)
30
30
  end
31
31
 
32
32
  it "should set the default_scope" do
33
- @config.default_scope.should == :default
33
+ expect(@config.default_scope).to eq(:default)
34
34
  @config.default_scope = :foo
35
- @config.default_scope.should == :foo
35
+ expect(@config.default_scope).to eq(:foo)
36
36
  end
37
37
 
38
38
  it "should merge given options on initialization" do
39
- Warden::Config.new(:foo => :bar)[:foo].should == :bar
39
+ expect(Warden::Config.new(:foo => :bar)[:foo]).to eq(:bar)
40
40
  end
41
41
 
42
42
  it "should setup defaults with the scope_defaults method" do
43
43
  c = Warden::Config.new
44
44
  c.scope_defaults :foo, :strategies => [:foo, :bar], :store => false
45
- c.default_strategies(:scope => :foo).should == [:foo, :bar]
46
- c.scope_defaults(:foo).should == {:store => false}
45
+ expect(c.default_strategies(:scope => :foo)).to eq([:foo, :bar])
46
+ expect(c.scope_defaults(:foo)).to eq(store: false)
47
47
  end
48
48
  end
@@ -8,40 +8,40 @@ describe Warden::Proxy::Errors do
8
8
  end
9
9
 
10
10
  it "should report that it is empty on first creation" do
11
- @errors.empty?.should == true
11
+ expect(@errors).to be_empty
12
12
  end
13
13
 
14
14
  it "should continue to report that it is empty even after being checked" do
15
15
  @errors.on(:foo)
16
- @errors.empty?.should == true
16
+ expect(@errors).to be_empty
17
17
  end
18
18
 
19
19
  it "should add an error" do
20
20
  @errors.add(:login, "Login or password incorrect")
21
- @errors[:login].should == ["Login or password incorrect"]
21
+ expect(@errors[:login]).to eq(["Login or password incorrect"])
22
22
  end
23
23
 
24
24
  it "should allow many errors to be added to the same field" do
25
25
  @errors.add(:login, "bad 1")
26
26
  @errors.add(:login, "bad 2")
27
- @errors.on(:login).should == ["bad 1", "bad 2"]
27
+ expect(@errors.on(:login)).to eq(["bad 1", "bad 2"])
28
28
  end
29
29
 
30
30
  it "should give the full messages for an error" do
31
31
  @errors.add(:login, "login wrong")
32
32
  @errors.add(:password, "password wrong")
33
33
  ["password wrong", "login wrong"].each do |msg|
34
- @errors.full_messages.should include(msg)
34
+ expect(@errors.full_messages).to include(msg)
35
35
  end
36
36
  end
37
37
 
38
38
  it "should return the error for a specific field / label" do
39
39
  @errors.add(:login, "wrong")
40
- @errors.on(:login).should == ["wrong"]
40
+ expect(@errors.on(:login)).to eq(["wrong"])
41
41
  end
42
42
 
43
43
  it "should return nil for a specific field if it's not been set" do
44
- @errors.on(:not_there).should be_nil
44
+ expect(@errors.on(:not_there)).to be_nil
45
45
  end
46
46
 
47
47
  end