sentient_user 0.3.1 → 0.3.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/lib/sentient_user.rb CHANGED
@@ -22,9 +22,14 @@ module SentientUser
22
22
 
23
23
  def self.do_as(user, &block)
24
24
  old_user = self.current
25
- self.current = user
26
- response = block.call unless block.nil?
27
- self.current = old_user
25
+
26
+ begin
27
+ self.current = user
28
+ response = block.call unless block.nil?
29
+ ensure
30
+ self.current = old_user
31
+ end
32
+
28
33
  response
29
34
  end
30
35
  }
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sentient_user}
8
+ s.version = "0.3.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["bokmann"]
12
+ s.date = %q{2011-01-17}
13
+ s.description = %q{lets the User model in most authentication frameworks know who is the current user"}
14
+ s.email = %q{dbock@codesherpas.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/sentient_user.rb",
26
+ "sentient_user.gemspec",
27
+ "test/helper.rb",
28
+ "test/test_sentient_user.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/bokmann/sentient_user}
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.7}
33
+ s.summary = %q{A trivial bit of common code}
34
+ s.test_files = [
35
+ "test/helper.rb",
36
+ "test/test_sentient_user.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
45
+ else
46
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
50
+ end
51
+ end
52
+
@@ -26,4 +26,24 @@ class TestSentientUser < Test::Unit::TestCase
26
26
  should "allow subclasses of user to be assigned to user.current" do
27
27
  User.current = AnonymousUser.new
28
28
  end
29
+
30
+ should "allow execution of a block as a specified user" do
31
+ p, p2 = Person.new, Person.new
32
+ p.make_current
33
+ Person.do_as(p2) { assert_equal Person.current, p2 }
34
+ end
35
+
36
+ should "should reset the original user after executing a block as a specified user" do
37
+ p, p2 = Person.new, Person.new
38
+ p.make_current
39
+
40
+ Person.do_as(p2) { }
41
+ assert_equal Person.current, p
42
+
43
+ begin
44
+ Person.do_as(p2) { raise "error" }
45
+ rescue
46
+ assert_equal Person.current, p
47
+ end
48
+ end
29
49
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentient_user
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 3
8
- - 1
9
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - bokmann
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-12-23 00:00:00 -05:00
18
+ date: 2011-01-17 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: shoulda
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 37
27
30
  segments:
28
31
  - 2
29
32
  - 11
@@ -47,6 +50,7 @@ files:
47
50
  - Rakefile
48
51
  - VERSION
49
52
  - lib/sentient_user.rb
53
+ - sentient_user.gemspec
50
54
  - test/helper.rb
51
55
  - test/test_sentient_user.rb
52
56
  has_rdoc: true
@@ -59,23 +63,27 @@ rdoc_options: []
59
63
  require_paths:
60
64
  - lib
61
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
62
67
  requirements:
63
68
  - - ">="
64
69
  - !ruby/object:Gem::Version
70
+ hash: 3
65
71
  segments:
66
72
  - 0
67
73
  version: "0"
68
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
69
76
  requirements:
70
77
  - - ">="
71
78
  - !ruby/object:Gem::Version
79
+ hash: 3
72
80
  segments:
73
81
  - 0
74
82
  version: "0"
75
83
  requirements: []
76
84
 
77
85
  rubyforge_project:
78
- rubygems_version: 1.3.6
86
+ rubygems_version: 1.3.7
79
87
  signing_key:
80
88
  specification_version: 3
81
89
  summary: A trivial bit of common code