paper_trail 1.4.1 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,6 +18,7 @@ PaperTrail lets you track changes to your models' data. It's good for auditing
18
18
  * No configuration necessary.
19
19
  * Stores everything in a single database table (generates migration for you).
20
20
  * Thoroughly tested.
21
+ * Threadsafe.
21
22
 
22
23
 
23
24
  ## Rails Version
@@ -206,7 +207,7 @@ And on again like this:
206
207
 
207
208
  ## Testing
208
209
 
209
- PaperTrail has a thorough suite of tests. Thanks to [Zachery Hostens](http://github.com/zacheryph) for making them able to run standalone, i.e. without needing PaperTrail to be sitting in a Rails app.
210
+ PaperTrail has a thorough suite of tests.
210
211
 
211
212
 
212
213
  ## Articles
@@ -225,6 +226,8 @@ Many thanks to:
225
226
 
226
227
  * [Zachery Hostens](http://github.com/zacheryph)
227
228
  * [Jeremy Weiskotten](http://github.com/jeremyw)
229
+ * [Phan Le](http://github.com/revo)
230
+ * [jdrucza](http://github.com/jdrucza)
228
231
 
229
232
 
230
233
  ## Inspirations
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.1
1
+ 1.4.3
data/lib/paper_trail.rb CHANGED
@@ -3,26 +3,29 @@ require 'paper_trail/has_paper_trail'
3
3
  require 'paper_trail/version'
4
4
 
5
5
  module PaperTrail
6
- @@whodunnit = nil
7
6
 
8
7
  def self.included(base)
9
8
  base.before_filter :set_whodunnit
10
9
  end
11
10
 
12
11
  def self.whodunnit
13
- @@whodunnit.respond_to?(:call) ? @@whodunnit.call : @@whodunnit
12
+ Thread.current[:whodunnit]
14
13
  end
15
14
 
15
+ # Sets who is responsible for any changes that occur.
16
+ # You would normally use this in a migration or on the console,
17
+ # when working with models directly. In a controller it is set
18
+ # automatically to the `current_user`.
16
19
  def self.whodunnit=(value)
17
- @@whodunnit = value
20
+ Thread.current[:whodunnit] = value
18
21
  end
19
22
 
20
- private
23
+ protected
21
24
 
25
+ # Sets who is responsible for any changes that occur: the controller's
26
+ # `current_user`.
22
27
  def set_whodunnit
23
- @@whodunnit = lambda {
24
- self.send :current_user rescue nil
25
- }
28
+ Thread.current[:whodunnit] = self.send :current_user rescue nil
26
29
  end
27
30
  end
28
31
 
data/paper_trail.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{paper_trail}
8
- s.version = "1.4.1"
8
+ s.version = "1.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Stewart"]
12
- s.date = %q{2010-03-18}
12
+ s.date = %q{2010-03-19}
13
13
  s.email = %q{boss@airbladesoftware.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.md"
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "test/schema.rb",
37
37
  "test/schema_change.rb",
38
38
  "test/test_helper.rb",
39
+ "test/thread_safe_test.rb",
39
40
  "uninstall.rb"
40
41
  ]
41
42
  s.homepage = %q{http://github.com/airblade/paper_trail}
@@ -49,7 +50,8 @@ Gem::Specification.new do |s|
49
50
  "test/paper_trail_schema_test.rb",
50
51
  "test/schema.rb",
51
52
  "test/schema_change.rb",
52
- "test/test_helper.rb"
53
+ "test/test_helper.rb",
54
+ "test/thread_safe_test.rb"
53
55
  ]
54
56
 
55
57
  if s.respond_to? :specification_version then
@@ -1,5 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
+ ActionController::Routing::Routes.draw do |map|
4
+ map.resources :widgets
5
+ end
6
+
3
7
  class ApplicationController < ActionController::Base
4
8
  def rescue_action(e)
5
9
  raise e
@@ -30,18 +34,8 @@ class WidgetsController < ApplicationController
30
34
  end
31
35
  end
32
36
 
33
-
34
- class PaperTrailControllerTest < ActionController::TestCase #Test::Unit::TestCase
37
+ class PaperTrailControllerTest < ActionController::TestCase
35
38
  tests WidgetsController
36
- def setup
37
- #@controller = WidgetsController.new
38
- #@request = ActionController::TestRequest.new
39
- #@response = ActionController::TestResponse.new
40
-
41
- ActionController::Routing::Routes.draw do |map|
42
- map.resources :widgets
43
- end
44
- end
45
39
 
46
40
  test 'create' do
47
41
  post :create, :widget => { :name => 'Flugel' }
@@ -68,4 +62,3 @@ class PaperTrailControllerTest < ActionController::TestCase #Test::Unit::TestCas
68
62
  assert_equal 153, widget.versions.last.whodunnit.to_i
69
63
  end
70
64
  end
71
-
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class TestController < ActionController::Base
4
+ def current_user
5
+ Thread.current.object_id
6
+ end
7
+ end
8
+
9
+ class ThreadSafeTest < Test::Unit::TestCase
10
+ should "be thread safe" do
11
+ blocked = true
12
+
13
+ slow_thread = Thread.new do
14
+ controller = TestController.new
15
+ controller.send :set_whodunnit
16
+ begin
17
+ sleep 0.001
18
+ end while blocked
19
+ PaperTrail.whodunnit
20
+ end
21
+
22
+ fast_thread = Thread.new do
23
+ controller = TestController.new
24
+ controller.send :set_whodunnit
25
+ who = PaperTrail.whodunnit
26
+ blocked = false
27
+ who
28
+ end
29
+
30
+ assert_not_equal slow_thread.value, fast_thread.value
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-18 00:00:00 +00:00
12
+ date: 2010-03-19 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,6 +43,7 @@ files:
43
43
  - test/schema.rb
44
44
  - test/schema_change.rb
45
45
  - test/test_helper.rb
46
+ - test/thread_safe_test.rb
46
47
  - uninstall.rb
47
48
  has_rdoc: true
48
49
  homepage: http://github.com/airblade/paper_trail
@@ -79,3 +80,4 @@ test_files:
79
80
  - test/schema.rb
80
81
  - test/schema_change.rb
81
82
  - test/test_helper.rb
83
+ - test/thread_safe_test.rb