simple_auth 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8682ca22a814e3257391a8c00f4133534f0fc10
|
4
|
+
data.tar.gz: 66f375cd6005a5e20236242b45c9e78746a622ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db21173167527172fdf0ccacaaa7551a0b1341742f75e3a2358391c2d844d4da16148ee920662d330fa23e3622c19783b16cdd288cdce5305aa9068c01391262
|
7
|
+
data.tar.gz: 7b9bdd103c1aa3e8222b29ade7fb0348b762df8508584384a3f9a46d97f75d22fe2bd219fefcd9f2bde0a76ceb1ab0caf5bfecc5ecc2bcfa60ebe893f6760358
|
@@ -21,7 +21,7 @@ module SimpleAuth
|
|
21
21
|
# end
|
22
22
|
# end
|
23
23
|
#
|
24
|
-
def authentication(&block)
|
24
|
+
def authentication(options = {}, &block)
|
25
25
|
SimpleAuth.setup(&block) if block_given?
|
26
26
|
SimpleAuth::Config.model ||= name.underscore.to_sym
|
27
27
|
|
@@ -29,12 +29,21 @@ module SimpleAuth
|
|
29
29
|
# So, just return.
|
30
30
|
return if respond_to?(:authenticate)
|
31
31
|
|
32
|
-
has_secure_password
|
32
|
+
macro = method(:has_secure_password)
|
33
|
+
|
34
|
+
if macro.arity.zero?
|
35
|
+
has_secure_password
|
36
|
+
else
|
37
|
+
has_secure_password(options)
|
38
|
+
end
|
33
39
|
|
34
40
|
extend ClassMethods
|
35
41
|
include InstanceMethods
|
36
42
|
|
37
|
-
|
43
|
+
if options.fetch(:validations, true)
|
44
|
+
validates_length_of :password, minimum: 4,
|
45
|
+
if: -> { password.present? }
|
46
|
+
end
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
data/lib/simple_auth/version.rb
CHANGED
@@ -32,31 +32,42 @@ describe SimpleAuth::ActiveRecord do
|
|
32
32
|
expect(subject).not_to be_valid
|
33
33
|
end
|
34
34
|
|
35
|
-
it "requires password" do
|
35
|
+
it "requires password", if: $rails_version >= "4.0" do
|
36
36
|
expect(subject.errors[:password]).not_to be_empty
|
37
37
|
end
|
38
38
|
|
39
|
+
it "requires password", if: $rails_version < "4.0" do
|
40
|
+
expect(subject.errors[:password_digest]).not_to be_empty
|
41
|
+
end
|
42
|
+
|
39
43
|
it "requires password to be at least 4-chars long" do
|
40
44
|
subject.password = "123"
|
41
45
|
expect(subject).not_to be_valid
|
42
46
|
expect(subject.errors[:password]).not_to be_empty
|
43
47
|
end
|
44
48
|
|
45
|
-
it "requires password confirmation", if:
|
49
|
+
it "requires password confirmation", if: $rails_version >= "4.0" do
|
46
50
|
user = User.create(password: "test", password_confirmation: "invalid")
|
47
51
|
expect(user.errors[:password_confirmation]).not_to be_empty
|
48
52
|
end
|
49
53
|
|
50
|
-
it "requires password confirmation", if:
|
54
|
+
it "requires password confirmation", if: $rails_version < "4.0" do
|
51
55
|
user = User.create(password: "test", password_confirmation: "invalid")
|
52
56
|
expect(user.errors[:password]).not_to be_empty
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
60
|
+
context "ignoring validations" do
|
61
|
+
it "ignores validations", if: $rails_version >= "4.0" do
|
62
|
+
person = Person.new
|
63
|
+
expect(person).to be_valid
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
56
67
|
context "existing record" do
|
57
68
|
before do
|
58
69
|
model.delete_all
|
59
|
-
model.create(
|
70
|
+
model.create!(
|
60
71
|
:email => "john@doe.com",
|
61
72
|
:login => "johndoe",
|
62
73
|
:password => "test",
|
@@ -67,11 +78,16 @@ describe SimpleAuth::ActiveRecord do
|
|
67
78
|
|
68
79
|
subject { model.first }
|
69
80
|
|
70
|
-
it "requires password" do
|
81
|
+
it "requires password", if: $rails_version >= "4.0" do
|
71
82
|
user = User.create(password: nil)
|
72
83
|
expect(user.errors[:password]).not_to be_empty
|
73
84
|
end
|
74
85
|
|
86
|
+
it "requires password", if: $rails_version < "4.0" do
|
87
|
+
user = User.create(password: nil)
|
88
|
+
expect(user.errors[:password_digest]).not_to be_empty
|
89
|
+
end
|
90
|
+
|
75
91
|
it "authenticates using email" do
|
76
92
|
expect(model.authenticate("john@doe.com", "test")).to eq(subject)
|
77
93
|
end
|
@@ -103,6 +119,25 @@ describe SimpleAuth::ActiveRecord do
|
|
103
119
|
}.to raise_error(SimpleAuth::RecordNotFound)
|
104
120
|
end
|
105
121
|
|
122
|
+
it "skips password length validation when no password is set" do
|
123
|
+
expect {
|
124
|
+
subject.username = "jd"
|
125
|
+
subject.save!
|
126
|
+
}.not_to raise_error
|
127
|
+
end
|
128
|
+
|
129
|
+
it "enforces password length when password is set" do
|
130
|
+
subject.password = "a"
|
131
|
+
subject.valid?
|
132
|
+
expect(subject.errors[:password]).to have(1).item
|
133
|
+
end
|
134
|
+
|
135
|
+
it "accepts valid password" do
|
136
|
+
subject.password = "test"
|
137
|
+
subject.valid?
|
138
|
+
expect(subject.errors[:password]).to be_empty
|
139
|
+
end
|
140
|
+
|
106
141
|
it "returns user" do
|
107
142
|
expect(model.find_by_credential(subject.email)).to eq(subject)
|
108
143
|
expect(model.find_by_credential!(subject.email)).to eq(subject)
|
@@ -31,6 +31,11 @@ describe SimpleAuth, "compatibility mode" do
|
|
31
31
|
|
32
32
|
it "assigns password_digest" do
|
33
33
|
customer = Customer.create(password: "test")
|
34
|
-
expect(customer.password_digest).
|
34
|
+
expect(customer.password_digest).to be_present
|
35
|
+
end
|
36
|
+
|
37
|
+
it "assigns password confirmation" do
|
38
|
+
customer = Customer.create(password: "test", password_confirmation: "test")
|
39
|
+
expect(customer.password_confirmation).to be_present
|
35
40
|
end
|
36
41
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- spec/spec_helper.rb
|
128
128
|
- spec/support/app/controllers/application_controller.rb
|
129
129
|
- spec/support/app/models/customer.rb
|
130
|
+
- spec/support/app/models/person.rb
|
130
131
|
- spec/support/app/models/user.rb
|
131
132
|
- spec/support/app/views/dashboard/index.erb
|
132
133
|
- spec/support/app/views/session/new.erb
|
@@ -170,6 +171,7 @@ test_files:
|
|
170
171
|
- spec/spec_helper.rb
|
171
172
|
- spec/support/app/controllers/application_controller.rb
|
172
173
|
- spec/support/app/models/customer.rb
|
174
|
+
- spec/support/app/models/person.rb
|
173
175
|
- spec/support/app/models/user.rb
|
174
176
|
- spec/support/app/views/dashboard/index.erb
|
175
177
|
- spec/support/app/views/session/new.erb
|