revo-paper_trail 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class PaperTrailSchemaTest < ActiveSupport::TestCase
4
+ def setup
5
+ load_schema
6
+ end
7
+
8
+ def test_schema_has_loaded_correctly
9
+ assert_equal [], Widget.all
10
+ assert_equal [], Version.all
11
+ assert_equal [], Wotsit.all
12
+ assert_equal [], Fluxor.all
13
+ assert_equal [], Article.all
14
+ end
15
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,48 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+
3
+ create_table :widgets, :force => true do |t|
4
+ t.string :name
5
+ t.text :a_text
6
+ t.integer :an_integer
7
+ t.float :a_float
8
+ t.decimal :a_decimal
9
+ t.datetime :a_datetime
10
+ t.time :a_time
11
+ t.date :a_date
12
+ t.boolean :a_boolean
13
+ t.datetime :created_at, :updated_at
14
+ t.string :sacrificial_column
15
+ t.string :type
16
+ end
17
+
18
+ create_table :versions, :force => true do |t|
19
+ t.string :item_type, :null => false
20
+ t.integer :item_id, :null => false
21
+ t.string :event, :null => false
22
+ t.string :whodunnit
23
+ t.text :object
24
+ t.datetime :created_at
25
+
26
+ # Metadata columns.
27
+ t.integer :answer
28
+ t.string :question
29
+ t.integer :article_id
30
+ end
31
+ add_index :versions, [:item_type, :item_id]
32
+
33
+ create_table :wotsits, :force => true do |t|
34
+ t.integer :widget_id
35
+ t.string :name
36
+ end
37
+
38
+ create_table :fluxors, :force => true do |t|
39
+ t.integer :widget_id
40
+ t.string :name
41
+ end
42
+
43
+ create_table :articles, :force => true do |t|
44
+ t.integer :title
45
+ t.string :content
46
+ end
47
+
48
+ end
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Schema.define do
2
+ remove_column :widgets, :sacrificial_column
3
+ end
@@ -0,0 +1,43 @@
1
+ require 'test/unit'
2
+ RAILS_ROOT = File.join(File.dirname(__FILE__), %w{.. .. .. ..}) unless defined?(RAILS_ROOT)
3
+ $:.unshift(File.join(File.dirname(__FILE__), %w{.. lib}))
4
+
5
+ unless defined?(ActiveRecord)
6
+ if File.directory? RAILS_ROOT + 'config'
7
+ puts 'using config/boot.rb'
8
+ ENV['RAILS_ENV'] = 'test'
9
+ require File.join(RAILS_ROOT, 'config', 'boot.rb')
10
+ else
11
+ # simply use installed gems if available
12
+ puts 'using rubygems'
13
+ require 'rubygems'
14
+ gem 'actionpack'; gem 'activerecord'; gem 'activesupport'; gem 'rails'
15
+ end
16
+
17
+ %w(action_pack action_controller active_record active_support initializer).each {|f| require f}
18
+ end
19
+ require 'shoulda'
20
+ require 'paper_trail'
21
+
22
+ def connect_to_database
23
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
24
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
25
+
26
+ db_adapter = ENV['DB'] || 'sqlite3'
27
+
28
+ if db_adapter.nil?
29
+ raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
30
+ end
31
+
32
+ ActiveRecord::Base.establish_connection(config[db_adapter])
33
+ end
34
+
35
+ def load_schema
36
+ connect_to_database
37
+ load(File.dirname(__FILE__) + "/schema.rb")
38
+ require File.dirname(__FILE__) + '/../rails/init.rb'
39
+ end
40
+
41
+ def change_schema
42
+ load(File.dirname(__FILE__) + "/schema_change.rb")
43
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestController < ActionController::Base
4
+
5
+ def current_user
6
+ @current_user ||= ActiveSupport::SecureRandom.hex(32)
7
+ end
8
+
9
+ end
10
+
11
+ class ThreadSafeTest < Test::Unit::TestCase
12
+
13
+ should "is thread safe when dealing with audit logging" do
14
+ blocked = true
15
+
16
+ blocked_thread = Thread.new do
17
+ controller = TestController.new
18
+ controller.send(:set_whodunnit)
19
+ begin
20
+ puts "sleep for .001 sec"
21
+ sleep(0.001)
22
+ end while blocked
23
+ PaperTrail.whodunnit
24
+ end
25
+
26
+ fast_running_thread = Thread.new do
27
+ controller = TestController.new
28
+ controller.send(:set_whodunnit)
29
+ blocked = false
30
+ PaperTrail.whodunnit
31
+ end
32
+ assert_not_equal blocked_thread.value, fast_running_thread.value
33
+ end
34
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: revo-paper_trail
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.2
5
+ platform: ruby
6
+ authors:
7
+ - Andy Stewart
8
+ - Revo Developers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-03-04 00:00:00 +11:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: boss@airbladesoftware.com, ge_developers@playup.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README.md
25
+ files:
26
+ - .gitignore
27
+ - MIT-LICENSE
28
+ - README.md
29
+ - Rakefile
30
+ - VERSION
31
+ - generators/paper_trail/USAGE
32
+ - generators/paper_trail/paper_trail_generator.rb
33
+ - generators/paper_trail/templates/create_versions.rb
34
+ - init.rb
35
+ - install.rb
36
+ - lib/paper_trail.rb
37
+ - lib/paper_trail/has_paper_trail.rb
38
+ - lib/paper_trail/version.rb
39
+ - rails/init.rb
40
+ - revo-paper_trail.gemspec
41
+ - tasks/paper_trail_tasks.rake
42
+ - test/database.yml
43
+ - test/paper_trail_controller_test.rb
44
+ - test/paper_trail_model_test.rb
45
+ - test/paper_trail_schema_test.rb
46
+ - test/schema.rb
47
+ - test/schema_change.rb
48
+ - test/test_helper.rb
49
+ - test/thread_safe_test.rb
50
+ - uninstall.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/airblade/paper_trail
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Track changes to your models' data. Good for auditing or versioning.
79
+ test_files:
80
+ - test/paper_trail_controller_test.rb
81
+ - test/paper_trail_model_test.rb
82
+ - test/paper_trail_schema_test.rb
83
+ - test/schema.rb
84
+ - test/schema_change.rb
85
+ - test/test_helper.rb
86
+ - test/thread_safe_test.rb