shield 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/shield.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Shield
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
 
4
4
  autoload :Password, "shield/password"
5
5
  autoload :Helpers, "shield/helpers"
@@ -1,10 +1,13 @@
1
1
  module Shield
2
2
  module Helpers
3
3
  def ensure_authenticated(model)
4
- return if authenticated(model)
5
-
6
- session[:return_to] = request.fullpath
7
- redirect_to_login
4
+ if authenticated(model)
5
+ return true
6
+ else
7
+ session[:return_to] = request.fullpath
8
+ redirect_to_login
9
+ return false
10
+ end
8
11
  end
9
12
 
10
13
  def authenticated(model)
@@ -37,5 +40,9 @@ module Shield
37
40
 
38
41
  @_authenticated.delete(model) if defined?(@_authenticated)
39
42
  end
43
+
44
+ def authenticate(user)
45
+ session[user.class.to_s] = user.id
46
+ end
40
47
  end
41
48
  end
data/test/shield_test.rb CHANGED
@@ -48,7 +48,7 @@ end
48
48
 
49
49
  test "ensure_authenticated when logged in" do |context|
50
50
  context.session["User"] = 1
51
- assert nil == context.ensure_authenticated(User)
51
+ assert true == context.ensure_authenticated(User)
52
52
  assert nil == context.redirect
53
53
  assert nil == context.session[:return_to]
54
54
  end
@@ -111,4 +111,10 @@ test "logout" do |context|
111
111
  assert nil == context.session["User"]
112
112
  assert nil == context.session[:return_to]
113
113
  assert nil == context.authenticated(User)
114
+ end
115
+
116
+ test "authenticate" do |context|
117
+ context.authenticate(User[1001])
118
+
119
+ assert User[1] == context.authenticated(User)
114
120
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michel Martens
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-19 00:00:00 +08:00
19
+ date: 2011-02-16 00:00:00 +08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency