Permalink
Browse files

Fixing versions creation without controller.

Additionally fixing a leakage within the tests
  • Loading branch information...
1 parent 7fc9bb6 commit 13775e16a45a832d2be3518f2b4a33bdccda22cb @MSNexploder MSNexploder committed Apr 7, 2011
Showing with 30 additions and 1 deletion.
  1. +4 −1 lib/paper_trail.rb
  2. +20 −0 test/paper_trail_test.rb
  3. +6 −0 test/test_helper.rb
View
@@ -63,8 +63,11 @@ def self.controller_info=(value)
private
# Thread-safe hash to hold PaperTrail's data.
+ # Initializing with needed default values.
def self.paper_trail_store
- Thread.current[:paper_trail] ||= {}
+ Thread.current[:paper_trail] ||= {
+ :request_enabled_for_controller => true
+ }
end
# Returns PaperTrail's configuration object.
View
@@ -4,4 +4,24 @@ class PaperTrailTest < ActiveSupport::TestCase
test 'Sanity test' do
assert_kind_of Module, PaperTrail
end
+
+ test 'create with plain model class' do
+ widget = Widget.create
+ assert_equal 1, widget.versions.length
+ end
+
+ test 'update with plain model class' do
+ widget = Widget.create
+ assert_equal 1, widget.versions.length
+ widget.update_attributes(:name => 'Bugle')
+ assert_equal 2, widget.versions.length
+ end
+
+ test 'destroy with plain model class' do
+ widget = Widget.create
+ assert_equal 1, widget.versions.length
+ widget.destroy
+ versions_for_widget = Version.with_item_keys('Widget', widget.id)
+ assert_equal 2, versions_for_widget.length
+ end
end
View
@@ -29,6 +29,12 @@
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
+# global setup block resetting Thread.current
+class ActiveSupport::TestCase
+ teardown do
+ Thread.current[:paper_trail] = nil
+ end
+end
#
# Helpers

0 comments on commit 13775e1

Please sign in to comment.