simplest_auth 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,15 +38,13 @@ module SimplestAuth
38
38
  end
39
39
 
40
40
  def current_user
41
- if @current_user.nil?
42
- begin
43
- @current_user = user_class.find(current_user_id)
44
- rescue user_class::RecordNotFound
45
- clear_session
46
- @current_user = nil
41
+ @current_user ||= begin
42
+ if user_class.respond_to?(:find)
43
+ user_class.find(current_user_id)
44
+ else
45
+ user_class.first(:id => current_user_id)
47
46
  end
48
- end
49
- @current_user
47
+ end || clear_session
50
48
  end
51
49
 
52
50
  def current_user=(user)
@@ -3,7 +3,7 @@ module SimplestAuth
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 2
6
+ TINY = 3
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -97,8 +97,8 @@ class ControllerTest < Test::Unit::TestCase
97
97
  assert_equal "user", current_user
98
98
  end
99
99
 
100
- should "return nil for the current user if it doesn't exist" do
101
- User.stubs(:find).with('1').raises(User::RecordNotFound)
100
+ should "clear session and return nil for the current user if it doesn't exist" do
101
+ User.stubs(:find).with('1').returns(nil)
102
102
  stubs(:current_user_id).with().returns('1')
103
103
  stubs(:clear_session)
104
104
 
@@ -110,12 +110,12 @@ class ControllerTest < Test::Unit::TestCase
110
110
  clear_session
111
111
  end
112
112
 
113
- should "clear the :user_id from session if the user cannot be found" do
114
- User.stubs(:find).with('1').raises(User::RecordNotFound)
113
+ should "find with first when class doesn't respond to find" do
114
+ User.expects(:respond_to?).with(:find).returns(false)
115
+ User.stubs(:first).with(:id => '1').returns("user")
115
116
  stubs(:current_user_id).with().returns('1')
116
- expects(:clear_session).with()
117
117
 
118
- current_user
118
+ assert_equal "user", current_user
119
119
  end
120
120
 
121
121
  should "allow assigning to the current user" do
@@ -139,6 +139,13 @@ class ControllerTest < Test::Unit::TestCase
139
139
  should "have a default login error message" do
140
140
  assert_equal "Login or Registration Required", login_message
141
141
  end
142
+
143
+ should "return the current_user, repeatedly" do
144
+ User.expects(:find).with(1).returns("user")
145
+ expects(:current_user_id).returns(1)
146
+
147
+ assert_equal "user", current_user
148
+ end
142
149
  end
143
150
 
144
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplest_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-08 00:00:00 -04:00
12
+ date: 2009-05-09 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency