uber_login 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGZjMzFmM2JhZGY0ZmJlZGE5MWY5ODc0ZWY4OTE1MDI4MjdkMTc0OA==
4
+ MWU0YWFkMDg3NjA3MzFiM2QxN2Y3NmQzODBlOTFjMDIxZGY1YzliYg==
5
5
  data.tar.gz: !binary |-
6
- MWQ3YTdhYzI1MzU2YTFlZjQxMjFhYzk4NjI2NTgyZDA5Y2E4MDVkNw==
6
+ ZGYxZmFmZjA0ZGEzOGIzY2RmODVmODczOWQ5OTc0MzlmYTM5NGQ4NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmIyNGE2MzhkYmE3NmI1OTk5MWU0OTM2Y2RmYTI3NWYzNDI2YzUxNDNmNTQy
10
- MmUxZTdhNjRiMDU0NmJjNDY5NjMxZGZlZWVkNTRmZDQwN2RjNGZmMWE5Mzcz
11
- YzU2NGRkZGQ0NGI5MWVmNTUzM2RjOGFkNzFiYWQzOGFjNmExYWI=
9
+ Mzc4YWVjYzM0ZmQ5N2YyMDdlOWYxOTMzMjAwMDVlNmIwNzdiODk4YjRmNjQ4
10
+ ZDhhY2FmZjg1ZmIwZDA4MDQyNGVjMjExMTE1MGQxMDE3Zjg2ZTQ3NjllMzE4
11
+ OGJjMWEwMjhlZjM5ZjUzYWFhNDM1Y2NhOTM3ZDY5NjE4NzQ0ZGY=
12
12
  data.tar.gz: !binary |-
13
- MWEyNzkzODc4ZGFiMGE3MDlkYTQyMWUxMDFjNTNhNTYwZWQyNTM0ODY5YzNk
14
- ZTNhNjkxZDc3YmJmNGI2NTkxZDRmYTk1MTVmNmNlYmMwNzZlNzNmM2E2MjA1
15
- MmE5MTQ4OWZlZDgxNDk1Njc0NzVmMjJlZTAwN2IwZTBhZTI0OTE=
13
+ Mjc0NGNiMGM4ZmU3ZTEzNjExOWQ2NGU4M2QyODExYTNhNGJkYzEwNWU2N2Yz
14
+ ZGZiMWY2ZWVjZTU0MDY5MTRiNzk2YWM0NzEzNTZlMWJiNTdhOWI2YjQ0ZWYx
15
+ YTA5YTc2NTFmYmJkZTAyMDJhNDU5ZTc5MDc3NGVlM2UzNTU4MTI=
@@ -1,3 +1,3 @@
1
1
  module UberLogin
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/uber_login.rb CHANGED
@@ -37,10 +37,14 @@ module UberLogin
37
37
  # Clears session[:uid]
38
38
  # If remember cookies were set they're cleared and the token is
39
39
  # removed from the database.
40
- def logout
41
- session.delete(:uid)
42
- delete_from_database if cookies[:uid]
43
- cookie_manager.clear
40
+ def logout(sequence = nil)
41
+ if sequence
42
+ delete_from_database(sequence)
43
+ else
44
+ session.delete(:uid)
45
+ delete_from_database if cookies[:uid]
46
+ cookie_manager.clear
47
+ end
44
48
  end
45
49
 
46
50
  ##
@@ -113,9 +117,10 @@ module UberLogin
113
117
  end
114
118
 
115
119
  ##
116
- # Removes a LoginToken with +uid+ and +sequence+ taken from the cookies
117
- def delete_from_database
118
- sequence = cookie_manager.sequence
120
+ # Removes a LoginToken with current +uid+ and given +sequence+
121
+ # If +sequence+ is nil it is taken from the cookies.
122
+ def delete_from_database(sequence = nil)
123
+ sequence = sequence || cookie_manager.sequence
119
124
  token = LoginToken.find_by(uid: cookies[:uid], sequence: sequence)
120
125
  token.destroy
121
126
  end
@@ -47,29 +47,56 @@ describe UberLogin do
47
47
  end
48
48
 
49
49
  describe '#logout' do
50
- it 'deletes session[:uid]' do
51
- controller.login(user)
52
- controller.logout
53
- expect(session[:uid]).to be_nil
50
+ context 'sequence is nil' do
51
+ it 'deletes session[:uid]' do
52
+ controller.login(user)
53
+ controller.logout
54
+ expect(session[:uid]).to be_nil
55
+ end
56
+
57
+ context 'persistent login was made' do
58
+ before { controller.login(user, true) }
59
+
60
+ it 'deletes session[:uid]' do
61
+ controller.logout
62
+ expect(session[:uid]).to be_nil
63
+ end
64
+
65
+ it 'deletes login cookies' do
66
+ controller.logout
67
+ expect(cookies[:uid]).to be_nil
68
+ expect(cookies[:ulogin]).to be_nil
69
+ end
70
+
71
+ it 'deletes a LoginToken row' do
72
+ expect {
73
+ controller.logout
74
+ }.to change{ LoginToken.count }.by -1
75
+ end
76
+ end
54
77
  end
55
78
 
56
- context 'persistent login was made' do
79
+ context 'sequence is not nil' do
57
80
  before { controller.login(user, true) }
58
81
 
59
- it 'deletes session[:uid]' do
60
- controller.logout
61
- expect(session[:uid]).to be_nil
82
+ it 'does not clear session[:uid]' do
83
+ controller.logout('sequence')
84
+ expect(session[:uid]).to_not be_nil
62
85
  end
63
86
 
64
- it 'deletes login cookies' do
65
- controller.logout
66
- expect(cookies[:uid]).to be_nil
67
- expect(cookies[:ulogin]).to be_nil
87
+ it 'does not clear cookies[:uid]' do
88
+ controller.logout('sequence')
89
+ expect(cookies[:uid]).to_not be_nil
90
+ end
91
+
92
+ it 'does not clear cookies[:ulogin]' do
93
+ controller.logout('sequence')
94
+ expect(cookies[:ulogin]).to_not be_nil
68
95
  end
69
96
 
70
97
  it 'deletes a LoginToken row' do
71
98
  expect {
72
- controller.logout
99
+ controller.logout('sequence')
73
100
  }.to change{ LoginToken.count }.by -1
74
101
  end
75
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uber_login
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Boffa