sixarm_ruby_current_user_id 1.3.8 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +2 -1
- data/README.rdoc +57 -0
- data/VERSION +1 -1
- data/lib/sixarm_ruby_current_user_id.rb +1 -1
- data/test/sixarm_ruby_current_user_id_test.rb +26 -2
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
data/CHANGELOG.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
|
3
|
-
2011-04-25 1.
|
3
|
+
2011-04-25 1.4.2 Add better memoize and fix bug in current_user_id text
|
4
|
+
2011-04-25 1.4.0 Add memoize and :reload => true
|
4
5
|
2011-04-22 1.3.4 Add self to protect from local variable masking
|
5
6
|
2011-04-19 1.3.2 Bump to match sixarm_ruby_current_user gem
|
6
7
|
2011-04-18 1.3.0 Public release of version for Ruby 1.9.2 and Rails 3.0.5
|
data/README.rdoc
CHANGED
@@ -6,5 +6,62 @@ License:: See LICENSE.txt file
|
|
6
6
|
|
7
7
|
Get and set the current user id in the Rails session array.
|
8
8
|
|
9
|
+
When you set the current user id:
|
10
|
+
- this sets session[:current_user_id] to the id
|
11
|
+
- this sets @current_user_id to the id
|
12
|
+
|
13
|
+
|
14
|
+
== Example code
|
15
|
+
|
16
|
+
self.current_user_id = 1
|
17
|
+
=> @current_user_id = session[:current_user_id] = 1
|
18
|
+
|
19
|
+
|
20
|
+
== Example controller
|
21
|
+
|
22
|
+
class MyController < ApplicationController
|
23
|
+
|
24
|
+
def sign_in(user)
|
25
|
+
self.current_user_id = user.id
|
26
|
+
end
|
27
|
+
|
28
|
+
def sign_out
|
29
|
+
self.current_user_id = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_anyone_using_this?
|
33
|
+
current_user_id?
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
== Example of reloading
|
40
|
+
|
41
|
+
For fast speed, we memoize the current_user_id:
|
42
|
+
we use the fast instance variable @current_user_id
|
43
|
+
rather than the slower session[:current_user_id].
|
44
|
+
|
45
|
+
To reload @current_user_id from session[:current_user_id],
|
46
|
+
we use the :reload parameter like this:
|
47
|
+
|
48
|
+
current_user_id(:reload => true)
|
49
|
+
|
50
|
+
|
51
|
+
== Why use the self prefix?
|
52
|
+
|
53
|
+
When we set variables, we must use the "self" prefix because Ruby uses this to do method dispatch.
|
54
|
+
|
55
|
+
Right:
|
56
|
+
self.current_user_id = 1
|
57
|
+
|
58
|
+
Wrong:
|
59
|
+
current_user_id = 1
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
9
66
|
|
10
67
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.2
|
@@ -16,14 +16,38 @@ class Testing < Test::Unit::TestCase
|
|
16
16
|
ID=1234
|
17
17
|
|
18
18
|
def test_current_user_id_default_is_nil
|
19
|
-
assert_nil(
|
19
|
+
assert_nil(current_user_id, "current_user_id is not set, so current_user_id should be nil")
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def test_current_user_id_equals
|
23
|
+
self.current_user_id=ID
|
24
|
+
assert_equal(ID, @current_user_id, "current_user_id is set, so @current_user_id should be an id")
|
25
|
+
assert_equal(ID, session[:current_user_id], "current_user_id is set, so session[:current_user_id] should be an id")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_current_user_id_equals_with_round_trip
|
23
29
|
self.current_user_id=ID
|
24
30
|
assert_equal(ID, current_user_id, "current_user_id is set, so current_user_id should be an id")
|
25
31
|
end
|
26
32
|
|
33
|
+
def test_current_user_id_with_memoize
|
34
|
+
self.current_user_id=ID
|
35
|
+
session[:current_user_id]=ID+1
|
36
|
+
assert_equal(ID, current_user_id, "current_user_id is memoized, so current_user_id should be an id")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_current_user_id_reload_false
|
40
|
+
self.current_user_id=ID
|
41
|
+
session[:current_user_id]=ID+1
|
42
|
+
assert_equal(ID, current_user_id(:reload=>false), "current_user_id reload => false, so current_user_id should be an id")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_current_user_id_reload_true
|
46
|
+
self.current_user_id=ID
|
47
|
+
session[:current_user_id]=ID+1
|
48
|
+
assert_equal(ID+1, current_user_id(:reload=>true), "current_user_id reload => true, so current_user_id should be an id")
|
49
|
+
end
|
50
|
+
|
27
51
|
def test_current_user_id_question_is_false
|
28
52
|
assert_equal(false, current_user_id?, "current_user_id is not set, so current_user_id? should be false")
|
29
53
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sixarm_ruby_current_user_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.4.2
|
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-
|
33
|
+
date: 2011-04-26 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
35
|
dependencies: []
|
36
36
|
|
metadata.gz.sig
CHANGED
Binary file
|