sixarm_ruby_current_user 1.2.6 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt ADDED
@@ -0,0 +1,4 @@
1
+ CHANGELOG
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
data/README.rdoc CHANGED
@@ -1,10 +1,8 @@
1
+ = SixArm.com » Ruby » CurrentUser module with current_user methods
1
2
 
2
- = SixArm Ruby Gem: CurrentUser module with current_user methods
3
-
4
- Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
5
- Copyright:: Copyright (c) 2005-2010 Joel Parker Henderson
6
- License:: CreativeCommons License, Non-commercial Share Alike
7
- License:: LGPL, GNU Lesser General Public License
3
+ Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
4
+ Copyright:: Copyright (c) 2005-2011 Joel Parker Henderson
5
+ License:: See LICENSE.txt file
8
6
 
9
7
  Simple gem to get and set the current user,
10
8
  using the related gem for current_user_id.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.3.2
@@ -12,30 +12,28 @@ module CurrentUser
12
12
 
13
13
  # Get the current user:
14
14
  # - if it is already set, then return it without doing a lookup
15
- # - otherwise, find the user via #current_user_find
15
+ # - otherwise, call User.find with the current_user_id
16
16
  #
17
- # If the current user is not set, and the current user id is nil,
18
- # then this returns nil because current_user_find returns nil.
17
+ # Return the current user, or nil if not found
19
18
 
20
19
  def current_user
21
- @current_user ||= current_user_find_by_id(current_user_id)
20
+ @current_user ||= User.find(self.current_user_id)
22
21
  end
23
22
 
24
23
 
25
- # Set the current user and also set the current user id.
24
+ # Is there a current user in the Rails session?
26
25
 
27
- def current_user=(user)
28
- @current_user = user
29
- return current_user_id = (user ? user.id : nil)
26
+ def current_user?
27
+ !!self.current_user
30
28
  end
31
-
32
29
 
33
- # Return the current user by calling User.find with a user id.
34
- # If the user id is nil, then return nil for the current user.
30
+
31
+ # Set the current user
32
+ # Return the current user
35
33
 
36
- def current_user_find_by_id(id)
37
- return id ? User.find(id) : nil
34
+ def current_user=(user)
35
+ self.current_user_id = (user ? user.id : nil)
36
+ @current_user = user
38
37
  end
39
-
40
38
 
41
39
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'test/unit'
2
3
  require 'sixarm_ruby_current_user'
3
4
  require 'sixarm_ruby_current_user_id'
@@ -17,7 +18,7 @@ class Testing < Test::Unit::TestCase
17
18
  ANNE_ID=1
18
19
  BETH_ID=2
19
20
  CATE_ID=3
20
-
21
+
21
22
  ANNE = User.new(:id => ANNE_ID, :name => 'Anne')
22
23
  BETH = User.new(:id => BETH_ID, :name => 'Beth')
23
24
  CATE = User.new(:id => CATE_ID, :name => 'Cate')
@@ -27,8 +28,14 @@ class Testing < Test::Unit::TestCase
27
28
  end
28
29
 
29
30
  def test_blank_slate
30
- assert_nil(current_user, "current_user")
31
- assert_nil(current_user_id, "current_user_id")
31
+ assert_nil(self.current_user, "current_user")
32
+ assert_nil(self.current_user_id, "current_user_id")
33
+ end
34
+
35
+ def test_current_user_question
36
+ assert_equal(false, self.current_user?, "current_user is set, so current_user? should return false")
37
+ self.current_user=BETH
38
+ assert_equal(true, self.current_user?, "current_user is set, so current_user? should return true")
32
39
  end
33
40
 
34
41
  def test_current_user_equals
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- ��[2������>8֡>H���.cPnVFZ���յSke�>�@ڶ�𥑙*���8�9�k�������ӭ�c˞.@
2
- _ Eb/C�+rb��e;�&N���Z�q�gV�_( J�5��B�+n�7�
1
+ m��`�zi����U��شAYDwȪ�v�6׭Jr�k�fuɳ�[�x��t���Aw> ٲ��
2
+ O���"
3
+ �l�՝^�$|ugi|�o���F�&lm�"�\��y�]� �Ì�;t8�BE��
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.2.6
5
+ version: 1.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - SixArm
@@ -41,7 +41,7 @@ dependencies:
41
41
  requirements:
42
42
  - - "="
43
43
  - !ruby/object:Gem::Version
44
- version: 1.2.6
44
+ version: 1.3.2
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.0
55
+ version: 1.3.2
56
56
  type: :runtime
57
57
  version_requirements: *id002
58
58
  description:
@@ -65,10 +65,12 @@ extra_rdoc_files: []
65
65
 
66
66
  files:
67
67
  - .gemtest
68
- - Rakefile
69
- - README.rdoc
68
+ - CHANGELOG.txt
70
69
  - INSTALL.txt
71
70
  - LICENSE.txt
71
+ - Rakefile
72
+ - README.rdoc
73
+ - VERSION
72
74
  - lib/sixarm_ruby_current_user.rb
73
75
  - test/sixarm_ruby_current_user_test.rb
74
76
  has_rdoc: true
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- sRT�+�2(J[��=z����Y
2
- ���5Y��2 ��.��$�U��-���n��> la�"�j-�8(��Г�|��e��m��|2wks�P;��由���ɀ�)��Y�B�g��狆��c����
1
+ #����%��!��LTF