authentication-service 0.0.1.b → 0.0.2.b
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.
@@ -5,18 +5,32 @@ module AuthenticationService::Rails
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
+
# Using OptionsStore class to preserve values during rails code reload in development mode.
|
8
9
|
class OptionsStore
|
9
10
|
class << self
|
10
11
|
attr_accessor :account_class, :session_class
|
12
|
+
attr_accessor :accounts_repository, :sessions_repository
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
16
|
+
def store
|
17
|
+
OptionsStore
|
18
|
+
end
|
19
|
+
|
14
20
|
def account_class
|
15
|
-
|
21
|
+
store.account_class
|
16
22
|
end
|
17
23
|
|
18
24
|
def session_class
|
19
|
-
|
25
|
+
store.session_class
|
26
|
+
end
|
27
|
+
|
28
|
+
def accounts_repository
|
29
|
+
store.accounts_repository
|
30
|
+
end
|
31
|
+
|
32
|
+
def sessions_repository
|
33
|
+
store.sessions_repository
|
20
34
|
end
|
21
35
|
|
22
36
|
def authentication_service(options)
|
@@ -25,11 +39,14 @@ module AuthenticationService::Rails
|
|
25
39
|
:session => nil
|
26
40
|
}.merge(options)
|
27
41
|
|
28
|
-
raise "Account persistance model class not assigned" unless options[:account]
|
29
|
-
raise "Session persistance model class not assigned" unless options[:session]
|
42
|
+
raise "Account persistance model class not assigned" unless options[:account] || options[:accounts_repository]
|
43
|
+
raise "Session persistance model class not assigned" unless options[:session] || options[:sessions_repository]
|
30
44
|
|
31
45
|
OptionsStore.account_class = options[:account]
|
32
46
|
OptionsStore.session_class = options[:session]
|
47
|
+
|
48
|
+
OptionsStore.accounts_repository = options[:accounts_repository]
|
49
|
+
OptionsStore.sessions_repository = options[:sessions_repository]
|
33
50
|
end
|
34
51
|
|
35
52
|
def behave_as_sessins_controller
|
@@ -52,10 +69,14 @@ module AuthenticationService::Rails
|
|
52
69
|
|
53
70
|
def authentication_service
|
54
71
|
@authentication_service ||= begin
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
72
|
+
begin
|
73
|
+
raise "Authentication service not configured. Please use authentication_service to configure it."
|
74
|
+
end unless self.class.account_class || self.class.accounts_repository
|
75
|
+
begin
|
76
|
+
raise "Authentication service not configured. Please use authentication_service to configure it."
|
77
|
+
end unless self.class.session_class || self.class.sessions_repository
|
78
|
+
accounts_repository = self.class.accounts_repository || AuthenticationService::Persistance::AccountsRepository.new(self.class.account_class)
|
79
|
+
sessions_repository = self.class.sessions_repository || AuthenticationService::Persistance::SessionsRepository.new(self.class.session_class)
|
59
80
|
AuthenticationService::Base.new(accounts_repository, sessions_repository)
|
60
81
|
end
|
61
82
|
end
|
data/spec/lib/rails_spec.rb
CHANGED
@@ -31,30 +31,38 @@ describe AuthenticationService::Rails do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "self.class.authentication_service" do
|
34
|
-
it "should fail if options does not have account" do
|
34
|
+
it "should fail if options does not have account model class or accounts repository instance" do
|
35
35
|
session_class = mock(:session_class)
|
36
36
|
lambda {
|
37
|
-
AuthenticationSpecController.authentication_service :account => nil, :session => session_class
|
37
|
+
AuthenticationSpecController.authentication_service :account => nil, :accounts_repository => nil, :session => session_class
|
38
38
|
}.should raise_error(RuntimeError)
|
39
|
-
end
|
39
|
+
end
|
40
40
|
|
41
|
-
it "should fail if options does not have session" do
|
41
|
+
it "should fail if options does not have session model class or sessions repository instance" do
|
42
42
|
account_class = mock(:account_class)
|
43
43
|
lambda {
|
44
|
-
AuthenticationSpecController.authentication_service :
|
44
|
+
AuthenticationSpecController.authentication_service :session => nil, :sessions_repository => nil, :account => account_class
|
45
45
|
}.should raise_error(RuntimeError)
|
46
46
|
end
|
47
47
|
|
48
|
-
it "should assign account and session classes" do
|
48
|
+
it "should assign account and session model classes" do
|
49
49
|
account_class = mock(:account_class)
|
50
50
|
session_class = mock(:session_class)
|
51
51
|
AuthenticationSpecController.authentication_service :account => account_class, :session => session_class
|
52
52
|
AuthenticationSpecController.account_class.should be account_class
|
53
53
|
AuthenticationSpecController.session_class.should be session_class
|
54
54
|
end
|
55
|
+
|
56
|
+
it "should assign accounts and sessions repositories" do
|
57
|
+
accounts_repository = mock(:accounts_repository)
|
58
|
+
sessions_repository = mock(:sessions_repository)
|
59
|
+
AuthenticationSpecController.authentication_service :accounts_repository => accounts_repository, :sessions_repository => sessions_repository
|
60
|
+
AuthenticationSpecController.accounts_repository.should be accounts_repository
|
61
|
+
AuthenticationSpecController.sessions_repository.should be sessions_repository
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
|
-
describe "authentication_service
|
65
|
+
describe "authentication_service" do
|
58
66
|
it "should return instance with configured account and session classes" do
|
59
67
|
account_class = mock(:account_class)
|
60
68
|
session_class = mock(:session_class)
|
@@ -63,6 +71,15 @@ describe AuthenticationService::Rails do
|
|
63
71
|
@controller.authentication_service.accounts_repository.model_class.should be account_class
|
64
72
|
@controller.authentication_service.sessions_repository.model_class.should be session_class
|
65
73
|
end
|
74
|
+
|
75
|
+
it "should return instance with configured account and session repositories" do
|
76
|
+
accounts_repository = mock(:accounts_repository)
|
77
|
+
sessions_repository = mock(:sessions_repository)
|
78
|
+
AuthenticationSpecController.authentication_service :accounts_repository => accounts_repository, :sessions_repository => sessions_repository
|
79
|
+
@controller.authentication_service = nil
|
80
|
+
@controller.authentication_service.accounts_repository.should be accounts_repository
|
81
|
+
@controller.authentication_service.sessions_repository.should be sessions_repository
|
82
|
+
end
|
66
83
|
end
|
67
84
|
|
68
85
|
describe "authenticated?" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authentication-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.b
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70270526597480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70270526597480
|
25
25
|
description: Provides authentication related stuff.
|
26
26
|
email:
|
27
27
|
- evgeny.myasishchev@gmail.com
|