sixarm_ruby_current_user 1.3.6 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  CHANGELOG
2
2
 
3
- 2011-04-25 1.3.6 Add memoize and :reload => true
3
+ 2011-04-25 1.4.0 Add memoize and :reload => true
4
4
  2011-04-19 1.3.4 Add self and more tests
5
5
  2011-04-18 1.3.2 Update for Ruby 1.9.2 and Rails 3.0.5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.2
1
+ 1.4.0
@@ -7,9 +7,6 @@ require 'sixarm_ruby_current_user_id'
7
7
 
8
8
  module CurrentUser
9
9
 
10
- include CurrentUserId
11
-
12
-
13
10
  # Get the current user.
14
11
  #
15
12
  # This calls User.find with the current_user_id
@@ -17,11 +14,13 @@ module CurrentUser
17
14
  # The current user is memoized as @current_user.
18
15
  # To reload, pass :reload => true
19
16
  #
20
- # Return the current user, or raise an exception if not found
17
+ # Return the current user,
18
+ # or nil if the current user id is not set,
19
+ # or raise an exception if the current iser id is invalid
21
20
 
22
21
  def current_user(ops={})
23
22
  if ops[:reload] then @current_user=nil end
24
- @current_user ||= User.find(self.current_user_id)
23
+ @current_user ||= (current_user_id ? User.find(current_user_id) : nil)
25
24
  end
26
25
 
27
26
 
@@ -6,11 +6,9 @@ require 'sixarm_ruby_active_record_mock'
6
6
  require 'simplecov'
7
7
  SimpleCov.start
8
8
 
9
-
10
9
  class User < ActiveRecordMock
11
10
  end
12
11
 
13
-
14
12
  class Testing < Test::Unit::TestCase
15
13
 
16
14
  # Mock session
@@ -19,16 +17,42 @@ class Testing < Test::Unit::TestCase
19
17
  end
20
18
 
21
19
  include CurrentUser
20
+ include CurrentUserId
22
21
 
23
22
  ANNE = User.new(:id => 1, :name => 'Anne')
24
23
  BETH = User.new(:id => 2, :name => 'Beth')
25
24
  CATE = User.new(:id => 3, :name => 'Cate')
26
25
 
26
+
27
27
  def test_blank_slate
28
28
  assert_nil(current_user, "current_user")
29
29
  assert_nil(current_user_id, "current_user_id")
30
30
  end
31
31
 
32
+ def test_return_nil_if_not_found
33
+ self.current_user_id=0
34
+ assert_equal(0, current_user_id, "current_user_id")
35
+ assert_nil(current_user, "current_user")
36
+ end
37
+
38
+ def test_current_user_memoize
39
+ self.current_user=BETH
40
+ self.current_user_id=CATE.id
41
+ assert_equal(BETH, current_user, "current_user is memoized, so current_user should be beth")
42
+ end
43
+
44
+ def test_current_user_id_reload_false
45
+ self.current_user=BETH
46
+ self.current_user_id=CATE.id
47
+ assert_equal(BETH, current_user(:reload=>false), "current_user reload => false, so current_user should be beth")
48
+ end
49
+
50
+ def test_current_user_id_reload_true
51
+ self.current_user=BETH
52
+ self.current_user_id=CATE.id
53
+ assert_equal(CATE, current_user(:reload=>true), "current_user reload => true, so current_user should be cate")
54
+ end
55
+
32
56
  def test_current_user_question
33
57
  assert_equal(false, current_user?, "current_user is set, so current_user? should return false")
34
58
  self.current_user=BETH
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sixarm_ruby_current_user
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.6
5
+ version: 1.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - SixArm
@@ -30,7 +30,7 @@ cert_chain:
30
30
  eabwpCbAopo=
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2011-04-25 00:00:00 -07:00
33
+ date: 2011-04-26 00:00:00 -07:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -41,7 +41,7 @@ dependencies:
41
41
  requirements:
42
42
  - - "="
43
43
  - !ruby/object:Gem::Version
44
- version: 1.3.6
44
+ version: 1.4.0
45
45
  type: :runtime
46
46
  version_requirements: *id001
47
47
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,7 @@ dependencies:
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 1.4.2
55
+ version: 1.4.4
56
56
  type: :runtime
57
57
  version_requirements: *id002
58
58
  description:
metadata.gz.sig CHANGED
Binary file