devise_custom_authenticatable 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/devise_custom_authenticatable.gemspec +2 -0
- data/lib/devise/models/custom_authenticatable.rb +7 -5
- data/lib/devise_custom_authenticatable/version.rb +1 -1
- data/spec/devise/models/custom_authenticatable_spec.rb +25 -18
- data/spec/support/helpers.rb +18 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e126cdae305f283e0598a29cf6c846b8c3eb06d
|
4
|
+
data.tar.gz: 9446a9ab199cece55d70a707b2512df695cd8a23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3db096d6c13521718d224149c2a6fd98cca58698d3773d7109817dc3388febbf1be9e50dc8c129817cb0c30e438585ca3b2f2c90dd5eb71f3aae904e92d343ae
|
7
|
+
data.tar.gz: f086ae0c2460d26275903f83f36d5674e6c0b3008bed69d7574e84bbc4d5a86611a69a5cbb2980ea823787b5555b381ef045d69eb0ff61219801ee89e08311f6
|
data/CHANGELOG.md
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "pry"
|
24
25
|
|
25
26
|
|
26
27
|
if defined?(RUBY_VERSION) && RUBY_VERSION >= "2.1" || defined?(JRUBY_VERSION) && JRUBY_VERSION >= "9000"
|
@@ -31,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
31
32
|
spec.add_development_dependency "activemodel", "< 5"
|
32
33
|
spec.add_development_dependency "activesupport", "< 5"
|
33
34
|
spec.add_development_dependency "rack", "~> 1.6.4"
|
35
|
+
spec.add_development_dependency "nokogiri", "~> 1.6.8.1"
|
34
36
|
|
35
37
|
spec.add_dependency "devise", ">= 2", "< 4"
|
36
38
|
end
|
@@ -5,7 +5,12 @@ module Devise::Models
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
|
8
|
+
attr_reader :password
|
9
|
+
end
|
10
|
+
|
11
|
+
def password=(password)
|
12
|
+
@password = password
|
13
|
+
super if defined?(super)
|
9
14
|
end
|
10
15
|
|
11
16
|
def authenticated_by_any_custom_strategy?(password, *strategies)
|
@@ -21,9 +26,6 @@ module Devise::Models
|
|
21
26
|
# A callback initiated after successfully authenticating. This can be
|
22
27
|
# used to insert your own logic that is only run after the user successfully
|
23
28
|
# authenticates.
|
24
|
-
def after_custom_authentication
|
25
|
-
|
26
|
-
end
|
27
|
-
|
29
|
+
def after_custom_authentication; end
|
28
30
|
end
|
29
31
|
end
|
@@ -1,38 +1,45 @@
|
|
1
1
|
RSpec.describe Devise::Models::CustomAuthenticatable do
|
2
|
-
|
3
|
-
|
2
|
+
subject(:resource) { CustomAuthenticatableTestClass.new }
|
3
|
+
|
4
|
+
it "defines password attribute accessors" do
|
5
|
+
resource.password = 'password'
|
6
|
+
expect(resource.password).to eq 'password'
|
4
7
|
end
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
context "when password setter already defined for resource model" do
|
10
|
+
subject(:resource) { CustomAuthenticatableTestClassWithPasswordWriter.new }
|
11
|
+
|
12
|
+
it "preserves original setter" do
|
13
|
+
resource.password = 'password'
|
14
|
+
expect(resource.password).to eq 'password'
|
15
|
+
expect(resource.encrypted_password).to eq 'password_encrypted'
|
16
|
+
end
|
9
17
|
end
|
10
18
|
|
11
19
|
describe "#authenticated_by_any_custom_strategy? helper" do
|
12
20
|
before(:each) do
|
13
|
-
allow(
|
14
|
-
allow(
|
21
|
+
allow(resource).to receive(:authenticated_by_test1_strategy?).and_return(true)
|
22
|
+
allow(resource).to receive(:authenticated_by_test2_strategy?).and_return(true)
|
15
23
|
end
|
16
24
|
|
17
25
|
context "should call all given strategy methods and" do
|
18
|
-
it "
|
19
|
-
expect(
|
20
|
-
expect(
|
26
|
+
it "returns false if all of them return false" do
|
27
|
+
expect(resource).to receive(:authenticated_by_test1_strategy?).with('password').and_return(false)
|
28
|
+
expect(resource).to receive(:authenticated_by_test2_strategy?).and_return(false)
|
21
29
|
|
22
|
-
expect(
|
30
|
+
expect(resource.authenticated_by_any_custom_strategy?('password', :test1, :test2)).to be_falsey
|
23
31
|
end
|
24
32
|
|
25
|
-
it "
|
26
|
-
expect(
|
27
|
-
expect(
|
33
|
+
it "returns true if any of them return true" do
|
34
|
+
expect(resource).to receive(:authenticated_by_test1_strategy?).with('password').and_return(false)
|
35
|
+
expect(resource).to receive(:authenticated_by_test2_strategy?).and_return(true)
|
28
36
|
|
29
|
-
expect(
|
37
|
+
expect(resource.authenticated_by_any_custom_strategy?('password', :test1, :test2)).to be_truthy
|
30
38
|
end
|
31
39
|
|
32
|
-
it "
|
33
|
-
expect(
|
40
|
+
it "returns true if all of them return true" do
|
41
|
+
expect(resource.authenticated_by_any_custom_strategy?('password', :test1, :test2)).to be_truthy
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
37
|
-
|
38
45
|
end
|
data/spec/support/helpers.rb
CHANGED
@@ -6,6 +6,24 @@ class CustomAuthenticatableTestClass
|
|
6
6
|
def authenticated_by_test2_strategy?(*args); end
|
7
7
|
end
|
8
8
|
|
9
|
+
module TestPasswordModule
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
included do
|
13
|
+
attr_accessor :encrypted_password
|
14
|
+
end
|
15
|
+
|
16
|
+
def password=(new_password)
|
17
|
+
@password = new_password
|
18
|
+
self.encrypted_password = "#{new_password}_encrypted" if @password.present?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class CustomAuthenticatableTestClassWithPasswordWriter
|
23
|
+
include TestPasswordModule
|
24
|
+
include Devise::Models::CustomAuthenticatable
|
25
|
+
end
|
26
|
+
|
9
27
|
def env_with_params(path = "/", params = {}, env = {})
|
10
28
|
method = params.delete(:method) || "GET"
|
11
29
|
env = { 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => "#{method}" }.merge(env)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_custom_authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artūrs Mekšs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activemodel
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|