webget-current_user_id 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/current_user_id.rb +29 -0
- data/test/unit/current_user_id_test.rb +27 -0
- metadata +53 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# = CurrentUserId
|
2
|
+
#
|
3
|
+
# Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
|
4
|
+
# Copyright:: Copyright (c) 2006-2009 Joel Parker Henderson
|
5
|
+
# License:: CreativeCommons License, Non-commercial Share Alike
|
6
|
+
# License:: LGPL, GNU Lesser General Public License
|
7
|
+
#
|
8
|
+
# Get and set the current user id in the Rails session array.
|
9
|
+
#
|
10
|
+
# We get and set the user id, instead of the entire user model,
|
11
|
+
# because this is typically faster for typical user models.
|
12
|
+
##
|
13
|
+
|
14
|
+
module CurrentUserId
|
15
|
+
|
16
|
+
# Get the current user id in the Rails session array
|
17
|
+
|
18
|
+
def current_user_id
|
19
|
+
session[:current_user_id]
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Set the current user id in the Rails session array
|
24
|
+
|
25
|
+
def current_user_id=(id)
|
26
|
+
session[:current_user_id]=id
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'current_user_id'
|
3
|
+
require 'session_mock'
|
4
|
+
|
5
|
+
class CurrentUserIdTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include CurrentUserId
|
8
|
+
|
9
|
+
def session
|
10
|
+
@session||=SessionMock.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_without_current_user_id
|
14
|
+
assert_not_nil(session,"session")
|
15
|
+
assert_nil(current_user_id,"current_user_id")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_id
|
19
|
+
assert_not_nil(session,"session")
|
20
|
+
id=1234
|
21
|
+
current_user_id=1234
|
22
|
+
out=current_user_id
|
23
|
+
assert_equal(id,out,"id:#{id}, out:#{out}")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webget-current_user_id
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- WebGet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-05 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: webget@webget.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/current_user_id.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage: http://webget.com/
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: "0"
|
38
|
+
version:
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
requirements: []
|
46
|
+
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.2.0
|
49
|
+
signing_key:
|
50
|
+
specification_version: 2
|
51
|
+
summary: get/set a user in a rails app session
|
52
|
+
test_files:
|
53
|
+
- test/unit/current_user_id_test.rb
|