active_model-session 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/README.md +3 -3
- data/active_model-session.gemspec +2 -0
- data/lib/active_model/session/version.rb +1 -1
- data/test/session_with_user_model_test.rb +5 -5
- data/test/session_without_user_model_test.rb +3 -3
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1e361dbb8d00204306b1d22e7088e9d2b84a299
|
4
|
+
data.tar.gz: ef97b68bef1105728de9deff30ccf85d06165ad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d05d6039043638a7055e502e3390dfd594a056d2beb04bbf376d41ffd2dace3df7efea8807ccb585fc97dc7ece3ab56e47e1a3cb5cafdc06bc5e88fa163757ac
|
7
|
+
data.tar.gz: abd058d56c08cd8dbe4e7a577020f43073eaf9e5f6fe154acb36fa31cfa7dd0fac5f2dfa7ce5e72ac2c5bbf5bf5933d1fdd327ecbba32bb654fed883c2fac2a4
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveModel::Session
|
2
2
|
|
3
|
-
A simple session model implemented
|
3
|
+
A simple session model implemented on top of `ActiveModel::Model`.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -14,7 +14,7 @@ And then execute:
|
|
14
14
|
|
15
15
|
Or install it yourself as:
|
16
16
|
|
17
|
-
$ gem install
|
17
|
+
$ gem install active_model-session
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
@@ -47,7 +47,7 @@ provided normally by `has_secure_password` in `User` model. If you
|
|
47
47
|
need to authenticate a different type of user, you can do:
|
48
48
|
|
49
49
|
@session = ActiveModel::Session.new(session_params)
|
50
|
-
@session.user = Admin.find_by(email: session.email)
|
50
|
+
@session.user = Admin.find_by(email: @session.email)
|
51
51
|
if @session.valid?
|
52
52
|
# ...
|
53
53
|
|
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "activemodel", ">= 4.0.0"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
end
|
@@ -31,33 +31,33 @@ class SessionWithUserModelTest < Test::Unit::TestCase
|
|
31
31
|
@model = @session = ActiveModel::Session.new
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
def test_is_valid_with_valid_credentials
|
35
35
|
@session.email = "alice@example.com"
|
36
36
|
@session.password = "alicesecret"
|
37
37
|
assert @session.valid?
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
def test_returns_user_id_when_valid
|
41
41
|
@session.email = "bob@example.com"
|
42
42
|
@session.password = "bobsecret"
|
43
43
|
assert @session.valid?
|
44
44
|
assert_equal 2, @session.user_id
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
def test_is_invalid_when_user_does_not_exist
|
48
48
|
@session.email = "non-existing@example.com"
|
49
49
|
assert @session.invalid?
|
50
50
|
assert @session.errors[:password].present?
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
def test_is_invalid_with_incorrect_password
|
54
54
|
@session.email = "alice@example.com"
|
55
55
|
@session.password = "wrong-password"
|
56
56
|
assert @session.invalid?
|
57
57
|
assert @session.errors[:password].present?
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
def test_is_invalid_without_email
|
61
61
|
@session.email = nil
|
62
62
|
assert @session.invalid?
|
63
63
|
assert @session.errors[:email].present?
|
@@ -5,12 +5,12 @@ class SessionWithoutUserModelTest < Test::Unit::TestCase
|
|
5
5
|
Object.send(:remove_const, :User) if defined?(User)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
def test_is_invalid_when_user_model_is_nil
|
9
9
|
session = ActiveModel::Session.new(user: nil, email: "alice@example.com", password: "secret")
|
10
10
|
assert session.invalid?
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
def test_is_invalid_when_user_does_not_authenticate
|
14
14
|
user = Object.new
|
15
15
|
def user.authenticate(password)
|
16
16
|
password == "secret"
|
@@ -19,7 +19,7 @@ class SessionWithoutUserModelTest < Test::Unit::TestCase
|
|
19
19
|
assert session.invalid?
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
def test_is_valid_when_user_authenticates
|
23
23
|
user = Object.new
|
24
24
|
def user.authenticate(password)
|
25
25
|
password == "secret"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model-session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuba Kuźma
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2013-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|