warden 1.2.3 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/{History.rdoc → CHANGELOG.md} +16 -3
- data/Gemfile +3 -2
- data/Gemfile.lock +40 -0
- data/LICENSE +1 -1
- data/README.md +18 -0
- data/Rakefile +4 -8
- data/lib/warden/config.rb +3 -3
- data/lib/warden/errors.rb +2 -1
- data/lib/warden/hooks.rb +10 -9
- data/lib/warden/manager.rb +23 -10
- data/lib/warden/mixins/common.rb +2 -1
- data/lib/warden/proxy.rb +27 -11
- data/lib/warden/session_serializer.rb +1 -0
- data/lib/warden/strategies/base.rb +14 -8
- data/lib/warden/strategies.rb +1 -0
- data/lib/warden/test/helpers.rb +3 -2
- data/lib/warden/test/mock.rb +69 -0
- data/lib/warden/test/warden_helpers.rb +2 -1
- data/lib/warden/version.rb +2 -1
- data/lib/warden.rb +2 -0
- data/warden.gemspec +21 -18
- metadata +33 -50
- data/README.textile +0 -9
- data/spec/helpers/request_helper.rb +0 -51
- data/spec/helpers/strategies/failz.rb +0 -8
- data/spec/helpers/strategies/invalid.rb +0 -8
- data/spec/helpers/strategies/pass.rb +0 -8
- data/spec/helpers/strategies/pass_with_message.rb +0 -8
- data/spec/helpers/strategies/password.rb +0 -13
- data/spec/helpers/strategies/single.rb +0 -12
- data/spec/spec_helper.rb +0 -24
- data/spec/warden/authenticated_data_store_spec.rb +0 -114
- data/spec/warden/config_spec.rb +0 -48
- data/spec/warden/errors_spec.rb +0 -47
- data/spec/warden/hooks_spec.rb +0 -373
- data/spec/warden/manager_spec.rb +0 -316
- data/spec/warden/proxy_spec.rb +0 -1041
- data/spec/warden/scoped_session_serializer.rb +0 -123
- data/spec/warden/session_serializer_spec.rb +0 -53
- data/spec/warden/strategies/base_spec.rb +0 -313
- data/spec/warden/strategies_spec.rb +0 -93
- data/spec/warden/test/helpers_spec.rb +0 -93
- data/spec/warden/test/test_mode_spec.rb +0 -76
data/lib/warden/version.rb
CHANGED
data/lib/warden.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'forwardable'
|
3
4
|
|
4
5
|
require 'warden/mixins/common'
|
@@ -15,6 +16,7 @@ module Warden
|
|
15
16
|
module Test
|
16
17
|
autoload :WardenHelpers, 'warden/test/warden_helpers'
|
17
18
|
autoload :Helpers, 'warden/test/helpers'
|
19
|
+
autoload :Mock, 'warden/test/mock'
|
18
20
|
end
|
19
21
|
|
20
22
|
# Provides helper methods to warden for testing.
|
data/warden.gemspec
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
+
lib = File.expand_path("../lib", __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'warden/version'
|
4
7
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "warden"
|
10
|
+
spec.version = Warden::VERSION.dup
|
11
|
+
spec.authors = ["Daniel Neighman", "Justin Smestad", "Whitney Smestad", "José Valim"]
|
12
|
+
spec.email = %q{hasox.sox@gmail.com justin.smestad@gmail.com whitcolorado@gmail.com}
|
13
|
+
spec.homepage = "https://github.com/hassox/warden"
|
14
|
+
spec.summary = "An authentication library compatible with all Rack-based frameworks"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.extra_rdoc_files = [
|
12
17
|
"LICENSE",
|
13
|
-
|
18
|
+
"README.md"
|
14
19
|
]
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
s.add_dependency "rack", ">= 1.0"
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
spec.rdoc_options = ["--charset=UTF-8"]
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
spec.rubyforge_project = %q{warden}
|
26
|
+
spec.add_dependency "rack", ">= 2.0.6"
|
23
27
|
end
|
24
|
-
|
metadata
CHANGED
@@ -1,42 +1,50 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warden
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.2.3
|
4
|
+
version: 1.2.8
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Daniel Neighman
|
8
|
+
- Justin Smestad
|
9
|
+
- Whitney Smestad
|
10
|
+
- José Valim
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2018-11-15 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
17
|
+
name: rack
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
16
19
|
requirements:
|
17
|
-
- -
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
none: false
|
21
|
-
name: rack
|
22
|
+
version: 2.0.6
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
26
|
requirements:
|
26
|
-
- -
|
27
|
+
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
29
|
-
none: false
|
29
|
+
version: 2.0.6
|
30
30
|
description:
|
31
|
-
email:
|
31
|
+
email: hasox.sox@gmail.com justin.smestad@gmail.com whitcolorado@gmail.com
|
32
32
|
executables: []
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files:
|
35
35
|
- LICENSE
|
36
|
-
- README.
|
36
|
+
- README.md
|
37
37
|
files:
|
38
|
+
- ".gitignore"
|
39
|
+
- ".rspec"
|
40
|
+
- ".travis.yml"
|
41
|
+
- CHANGELOG.md
|
38
42
|
- Gemfile
|
39
|
-
-
|
43
|
+
- Gemfile.lock
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- lib/warden.rb
|
40
48
|
- lib/warden/config.rb
|
41
49
|
- lib/warden/errors.rb
|
42
50
|
- lib/warden/hooks.rb
|
@@ -44,61 +52,36 @@ files:
|
|
44
52
|
- lib/warden/mixins/common.rb
|
45
53
|
- lib/warden/proxy.rb
|
46
54
|
- lib/warden/session_serializer.rb
|
47
|
-
- lib/warden/strategies/base.rb
|
48
55
|
- lib/warden/strategies.rb
|
56
|
+
- lib/warden/strategies/base.rb
|
49
57
|
- lib/warden/test/helpers.rb
|
58
|
+
- lib/warden/test/mock.rb
|
50
59
|
- lib/warden/test/warden_helpers.rb
|
51
60
|
- lib/warden/version.rb
|
52
|
-
- lib/warden.rb
|
53
|
-
- LICENSE
|
54
|
-
- Rakefile
|
55
|
-
- README.textile
|
56
|
-
- spec/helpers/request_helper.rb
|
57
|
-
- spec/helpers/strategies/failz.rb
|
58
|
-
- spec/helpers/strategies/invalid.rb
|
59
|
-
- spec/helpers/strategies/pass.rb
|
60
|
-
- spec/helpers/strategies/pass_with_message.rb
|
61
|
-
- spec/helpers/strategies/password.rb
|
62
|
-
- spec/helpers/strategies/single.rb
|
63
|
-
- spec/spec_helper.rb
|
64
|
-
- spec/warden/authenticated_data_store_spec.rb
|
65
|
-
- spec/warden/config_spec.rb
|
66
|
-
- spec/warden/errors_spec.rb
|
67
|
-
- spec/warden/hooks_spec.rb
|
68
|
-
- spec/warden/manager_spec.rb
|
69
|
-
- spec/warden/proxy_spec.rb
|
70
|
-
- spec/warden/scoped_session_serializer.rb
|
71
|
-
- spec/warden/session_serializer_spec.rb
|
72
|
-
- spec/warden/strategies/base_spec.rb
|
73
|
-
- spec/warden/strategies_spec.rb
|
74
|
-
- spec/warden/test/helpers_spec.rb
|
75
|
-
- spec/warden/test/test_mode_spec.rb
|
76
61
|
- warden.gemspec
|
77
|
-
homepage:
|
62
|
+
homepage: https://github.com/hassox/warden
|
78
63
|
licenses:
|
79
64
|
- MIT
|
65
|
+
metadata: {}
|
80
66
|
post_install_message:
|
81
67
|
rdoc_options:
|
82
|
-
- --charset=UTF-8
|
68
|
+
- "--charset=UTF-8"
|
83
69
|
require_paths:
|
84
70
|
- lib
|
85
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- -
|
73
|
+
- - ">="
|
88
74
|
- !ruby/object:Gem::Version
|
89
75
|
version: '0'
|
90
|
-
none: false
|
91
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
77
|
requirements:
|
93
|
-
- -
|
78
|
+
- - ">="
|
94
79
|
- !ruby/object:Gem::Version
|
95
80
|
version: '0'
|
96
|
-
none: false
|
97
81
|
requirements: []
|
98
82
|
rubyforge_project: warden
|
99
|
-
rubygems_version:
|
83
|
+
rubygems_version: 2.7.6
|
100
84
|
signing_key:
|
101
|
-
specification_version:
|
102
|
-
summary:
|
85
|
+
specification_version: 4
|
86
|
+
summary: An authentication library compatible with all Rack-based frameworks
|
103
87
|
test_files: []
|
104
|
-
has_rdoc:
|
data/README.textile
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
Please see the "Warden Wiki":http://wiki.github.com/hassox/warden for overview documentation.
|
2
|
-
|
3
|
-
h2. Maintainers
|
4
|
-
|
5
|
-
* Daniel Neighman (hassox)
|
6
|
-
* José Valim (josevalim)
|
7
|
-
* Justin Smestad (jsmestad)
|
8
|
-
|
9
|
-
"A list of all contributors is available on Github.":https://github.com/hassox/warden/contributors
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Warden::Spec
|
3
|
-
module Helpers
|
4
|
-
FAILURE_APP = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }
|
5
|
-
|
6
|
-
def env_with_params(path = "/", params = {}, env = {})
|
7
|
-
method = params.delete(:method) || "GET"
|
8
|
-
env = { 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => "#{method}" }.merge(env)
|
9
|
-
Rack::MockRequest.env_for("#{path}?#{Rack::Utils.build_query(params)}", env)
|
10
|
-
end
|
11
|
-
|
12
|
-
def setup_rack(app = nil, opts = {}, &block)
|
13
|
-
app ||= block if block_given?
|
14
|
-
|
15
|
-
opts[:failure_app] ||= failure_app
|
16
|
-
opts[:default_strategies] ||= [:password]
|
17
|
-
opts[:default_serializers] ||= [:session]
|
18
|
-
blk = opts[:configurator] || proc{}
|
19
|
-
|
20
|
-
Rack::Builder.new do
|
21
|
-
use opts[:session] || Warden::Spec::Helpers::Session unless opts[:nil_session]
|
22
|
-
use Warden::Manager, opts, &blk
|
23
|
-
run app
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def valid_response
|
28
|
-
Rack::Response.new("OK").finish
|
29
|
-
end
|
30
|
-
|
31
|
-
def failure_app
|
32
|
-
Warden::Spec::Helpers::FAILURE_APP
|
33
|
-
end
|
34
|
-
|
35
|
-
def success_app
|
36
|
-
lambda{|e| [200, {"Content-Type" => "text/plain"}, ["You Win"]]}
|
37
|
-
end
|
38
|
-
|
39
|
-
class Session
|
40
|
-
attr_accessor :app
|
41
|
-
def initialize(app,configs = {})
|
42
|
-
@app = app
|
43
|
-
end
|
44
|
-
|
45
|
-
def call(e)
|
46
|
-
e['rack.session'] ||= {}
|
47
|
-
@app.call(e)
|
48
|
-
end
|
49
|
-
end # session
|
50
|
-
end
|
51
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
Warden::Strategies.add(:pass_with_message) do
|
3
|
-
def authenticate!
|
4
|
-
request.env['warden.spec.strategies'] ||= []
|
5
|
-
request.env['warden.spec.strategies'] << :pass_with_message
|
6
|
-
success!("Valid User", "The Success Strategy Has Accepted You") unless scope == :failz
|
7
|
-
end
|
8
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
Warden::Strategies.add(:password) do
|
3
|
-
def authenticate!
|
4
|
-
request.env['warden.spec.strategies'] ||= []
|
5
|
-
request.env['warden.spec.strategies'] << :password
|
6
|
-
if params["password"] || params["username"]
|
7
|
-
params["password"] == "sekrit" && params["username"] == "fred" ?
|
8
|
-
success!("Authenticated User") : fail!("Username or password is incorrect")
|
9
|
-
else
|
10
|
-
pass
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$TESTING=true
|
3
|
-
|
4
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
6
|
-
require 'warden'
|
7
|
-
|
8
|
-
require 'rubygems'
|
9
|
-
require 'rack'
|
10
|
-
|
11
|
-
Dir[File.join(File.dirname(__FILE__), "helpers", "**/*.rb")].each do |f|
|
12
|
-
require f
|
13
|
-
end
|
14
|
-
|
15
|
-
RSpec.configure do |config|
|
16
|
-
config.include(Warden::Spec::Helpers)
|
17
|
-
config.include(Warden::Test::Helpers)
|
18
|
-
|
19
|
-
def load_strategies
|
20
|
-
Dir[File.join(File.dirname(__FILE__), "helpers", "strategies", "**/*.rb")].each do |f|
|
21
|
-
load f
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe "authenticated data store" do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@env = env_with_params
|
8
|
-
@env['rack.session'] = {
|
9
|
-
"warden.user.foo.key" => "foo user",
|
10
|
-
"warden.user.default.key" => "default user",
|
11
|
-
:foo => "bar"
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should store data for the default scope" do
|
16
|
-
app = lambda do |e|
|
17
|
-
e['warden'].authenticate(:pass)
|
18
|
-
e['warden'].authenticate(:pass, :scope => :foo)
|
19
|
-
e['warden'].should be_authenticated
|
20
|
-
e['warden'].should be_authenticated(:foo)
|
21
|
-
|
22
|
-
# Store the data for :default
|
23
|
-
e['warden'].session[:key] = "value"
|
24
|
-
valid_response
|
25
|
-
end
|
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
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should store data for the foo user" do
|
32
|
-
app = lambda do |e|
|
33
|
-
e['warden'].session(:foo)[:key] = "value"
|
34
|
-
valid_response
|
35
|
-
end
|
36
|
-
setup_rack(app).call(@env)
|
37
|
-
@env['rack.session']['warden.user.foo.session'].should == {:key => "value"}
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should store the data seperately" do
|
41
|
-
app = lambda do |e|
|
42
|
-
e['warden'].session[:key] = "value"
|
43
|
-
e['warden'].session(:foo)[:key] = "another value"
|
44
|
-
valid_response
|
45
|
-
end
|
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"}
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should clear the foo scoped data when foo logs out" do
|
52
|
-
app = lambda do |e|
|
53
|
-
e['warden'].session[:key] = "value"
|
54
|
-
e['warden'].session(:foo)[:key] = "another value"
|
55
|
-
e['warden'].logout(:foo)
|
56
|
-
valid_response
|
57
|
-
end
|
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
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should clear out the default data when :default logs out" do
|
64
|
-
app = lambda do |e|
|
65
|
-
e['warden'].session[:key] = "value"
|
66
|
-
e['warden'].session(:foo)[:key] = "another value"
|
67
|
-
e['warden'].logout(:default)
|
68
|
-
valid_response
|
69
|
-
end
|
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"}
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should clear out all data when a general logout is performed" do
|
76
|
-
app = lambda do |e|
|
77
|
-
e['warden'].session[:key] = "value"
|
78
|
-
e['warden'].session(:foo)[:key] = "another value"
|
79
|
-
e['warden'].logout
|
80
|
-
valid_response
|
81
|
-
end
|
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
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should logout multuiple personas at once" do
|
88
|
-
@env['rack.session']['warden.user.bar.key'] = "bar user"
|
89
|
-
|
90
|
-
app = lambda do |e|
|
91
|
-
e['warden'].session[:key] = "value"
|
92
|
-
e['warden'].session(:foo)[:key] = "another value"
|
93
|
-
e['warden'].session(:bar)[:key] = "yet another"
|
94
|
-
e['warden'].logout(:bar, :default)
|
95
|
-
valid_response
|
96
|
-
end
|
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
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should not store data for a user who is not logged in" do
|
104
|
-
@env['rack.session']
|
105
|
-
app = lambda do |e|
|
106
|
-
e['warden'].session(:not_here)[:key] = "value"
|
107
|
-
valid_response
|
108
|
-
end
|
109
|
-
|
110
|
-
lambda do
|
111
|
-
setup_rack(app).call(@env)
|
112
|
-
end.should raise_error(Warden::NotAuthenticated)
|
113
|
-
end
|
114
|
-
end
|
data/spec/warden/config_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Warden::Config do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@config = Warden::Config.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should behave like a hash" do
|
11
|
-
@config[:foo] = :bar
|
12
|
-
@config[:foo].should == :bar
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should provide hash accessors" do
|
16
|
-
@config.failure_app = :foo
|
17
|
-
@config[:failure_app].should == :foo
|
18
|
-
@config[:failure_app] = :bar
|
19
|
-
@config.failure_app.should == :bar
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should allow to read and set default strategies" do
|
23
|
-
@config.default_strategies :foo, :bar
|
24
|
-
@config.default_strategies.should == [:foo, :bar]
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should allow to silence missing strategies" do
|
28
|
-
@config.silence_missing_strategies!
|
29
|
-
@config.silence_missing_strategies?.should be_true
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should set the default_scope" do
|
33
|
-
@config.default_scope.should == :default
|
34
|
-
@config.default_scope = :foo
|
35
|
-
@config.default_scope.should == :foo
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should merge given options on initialization" do
|
39
|
-
Warden::Config.new(:foo => :bar)[:foo].should == :bar
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should setup defaults with the scope_defaults method" do
|
43
|
-
c = Warden::Config.new
|
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}
|
47
|
-
end
|
48
|
-
end
|
data/spec/warden/errors_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Warden::Proxy::Errors do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@errors = Warden::Proxy::Errors.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should report that it is empty on first creation" do
|
11
|
-
@errors.empty?.should == true
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should continue to report that it is empty even after being checked" do
|
15
|
-
@errors.on(:foo)
|
16
|
-
@errors.empty?.should == true
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should add an error" do
|
20
|
-
@errors.add(:login, "Login or password incorrect")
|
21
|
-
@errors[:login].should == ["Login or password incorrect"]
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should allow many errors to be added to the same field" do
|
25
|
-
@errors.add(:login, "bad 1")
|
26
|
-
@errors.add(:login, "bad 2")
|
27
|
-
@errors.on(:login).should == ["bad 1", "bad 2"]
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should give the full messages for an error" do
|
31
|
-
@errors.add(:login, "login wrong")
|
32
|
-
@errors.add(:password, "password wrong")
|
33
|
-
["password wrong", "login wrong"].each do |msg|
|
34
|
-
@errors.full_messages.should include(msg)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return the error for a specific field / label" do
|
39
|
-
@errors.add(:login, "wrong")
|
40
|
-
@errors.on(:login).should == ["wrong"]
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return nil for a specific field if it's not been set" do
|
44
|
-
@errors.on(:not_there).should be_nil
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|