sixarm_ruby_current_user 1.3.2 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,4 +1,5 @@
1
1
  CHANGELOG
2
2
 
3
- 2011-04-19 Add self and more tests
4
- 2011-04-18 Update for Ruby 1.9.2 and Rails 3.0.5
3
+ 2011-04-25 1.3.6 Add memoize and :reload => true
4
+ 2011-04-19 1.3.4 Add self and more tests
5
+ 2011-04-18 1.3.2 Update for Ruby 1.9.2 and Rails 3.0.5
@@ -10,13 +10,17 @@ module CurrentUser
10
10
  include CurrentUserId
11
11
 
12
12
 
13
- # Get the current user:
14
- # - if it is already set, then return it without doing a lookup
15
- # - otherwise, call User.find with the current_user_id
13
+ # Get the current user.
14
+ #
15
+ # This calls User.find with the current_user_id
16
16
  #
17
- # Return the current user, or nil if not found
17
+ # The current user is memoized as @current_user.
18
+ # To reload, pass :reload => true
19
+ #
20
+ # Return the current user, or raise an exception if not found
18
21
 
19
- def current_user
22
+ def current_user(ops={})
23
+ if ops[:reload] then @current_user=nil end
20
24
  @current_user ||= User.find(self.current_user_id)
21
25
  end
22
26
 
@@ -13,44 +13,41 @@ end
13
13
 
14
14
  class Testing < Test::Unit::TestCase
15
15
 
16
- include CurrentUser
17
-
18
- ANNE_ID=1
19
- BETH_ID=2
20
- CATE_ID=3
21
-
22
- ANNE = User.new(:id => ANNE_ID, :name => 'Anne')
23
- BETH = User.new(:id => BETH_ID, :name => 'Beth')
24
- CATE = User.new(:id => CATE_ID, :name => 'Cate')
25
-
16
+ # Mock session
26
17
  def session
27
- @session||=Hash.new
18
+ @session||={}
28
19
  end
29
20
 
21
+ include CurrentUser
22
+
23
+ ANNE = User.new(:id => 1, :name => 'Anne')
24
+ BETH = User.new(:id => 2, :name => 'Beth')
25
+ CATE = User.new(:id => 3, :name => 'Cate')
26
+
30
27
  def test_blank_slate
31
- assert_nil(self.current_user, "current_user")
32
- assert_nil(self.current_user_id, "current_user_id")
28
+ assert_nil(current_user, "current_user")
29
+ assert_nil(current_user_id, "current_user_id")
33
30
  end
34
31
 
35
32
  def test_current_user_question
36
- assert_equal(false, self.current_user?, "current_user is set, so current_user? should return false")
33
+ assert_equal(false, current_user?, "current_user is set, so current_user? should return false")
37
34
  self.current_user=BETH
38
- assert_equal(true, self.current_user?, "current_user is set, so current_user? should return true")
35
+ assert_equal(true, current_user?, "current_user is set, so current_user? should return true")
39
36
  end
40
37
 
41
38
  def test_current_user_equals
42
- current_user=BETH
39
+ self.current_user=BETH
43
40
  actual=current_user
44
41
  assert_equal(BETH, actual, "beth, actual:#{actual}")
45
- assert_not_equal(ANNE, actual, "anne, actual:#{actual}")
46
- assert_not_equal(CATE, actual, "cate, actual:#{actual}")
47
42
  end
48
43
 
49
- def test_current_user_clear
50
- current_user=ANNE
51
- assert_equal(ANNE, current_user, "current_user")
52
- current_user=nil
53
- assert_nil(current_user, "current_user")
44
+ def test_current_user_equals_then_reset
45
+ self.current_user=BETH
46
+ actual=current_user
47
+ assert_equal(BETH, actual, "beth, actual:#{actual}")
48
+ self.current_user=nil
49
+ actual=current_user
50
+ assert_equal(nil, actual, "current_user")
54
51
  end
55
52
 
56
53
  end
data.tar.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- m��`�zi����U��شA�YDwȪ�v�6׭Jr�k�fuɳ�[�x��t���Aw> ٲ��
2
- O���"
3
- �l�՝^�$|ugi|�o���F�&lm�"�\��y�]� �Ì�;t8�BE��
1
+ ?��߅�'M��O(
2
+ iR���(8ڻ�d.�@2Z<u�I����~�ړ��6�cϜ�H�[r�����/m�{��0
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.2
5
+ version: 1.3.6
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-19 00:00:00 -07:00
33
+ date: 2011-04-25 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.2
44
+ version: 1.3.6
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.3.2
55
+ version: 1.4.2
56
56
  type: :runtime
57
57
  version_requirements: *id002
58
58
  description:
metadata.gz.sig CHANGED
@@ -1 +1,2 @@
1
- #����%��!��LTF�
1
+ |pH�.
2
+ M��Ҵ��̄��e�*��8Z�:d�pzOd����$'%�YU���/%�44Gs�_�D� Q��s���2��2�nD�����a�#kT �9n���|Ҵ4�;5���Cvoñ��J"�/^�I��