paper_trail_without_deprecated 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +21 -0
  5. data/CHANGELOG.md +68 -0
  6. data/Gemfile +2 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +979 -0
  9. data/Rakefile +18 -0
  10. data/gemfiles/3.0.gemfile +31 -0
  11. data/lib/generators/paper_trail/USAGE +2 -0
  12. data/lib/generators/paper_trail/install_generator.rb +23 -0
  13. data/lib/generators/paper_trail/templates/add_object_changes_column_to_versions.rb +9 -0
  14. data/lib/generators/paper_trail/templates/create_versions.rb +18 -0
  15. data/lib/paper_trail.rb +115 -0
  16. data/lib/paper_trail/cleaner.rb +34 -0
  17. data/lib/paper_trail/config.rb +14 -0
  18. data/lib/paper_trail/frameworks/cucumber.rb +31 -0
  19. data/lib/paper_trail/frameworks/rails.rb +79 -0
  20. data/lib/paper_trail/frameworks/rspec.rb +24 -0
  21. data/lib/paper_trail/frameworks/rspec/extensions.rb +20 -0
  22. data/lib/paper_trail/frameworks/sinatra.rb +31 -0
  23. data/lib/paper_trail/has_paper_trail.rb +308 -0
  24. data/lib/paper_trail/serializers/json.rb +17 -0
  25. data/lib/paper_trail/serializers/yaml.rb +17 -0
  26. data/lib/paper_trail/version.rb +200 -0
  27. data/lib/paper_trail/version_number.rb +3 -0
  28. data/paper_trail.gemspec +36 -0
  29. data/spec/models/widget_spec.rb +13 -0
  30. data/spec/paper_trail_spec.rb +47 -0
  31. data/spec/spec_helper.rb +41 -0
  32. data/test/custom_json_serializer.rb +13 -0
  33. data/test/dummy/Rakefile +7 -0
  34. data/test/dummy/app/controllers/application_controller.rb +17 -0
  35. data/test/dummy/app/controllers/test_controller.rb +5 -0
  36. data/test/dummy/app/controllers/widgets_controller.rb +31 -0
  37. data/test/dummy/app/helpers/application_helper.rb +2 -0
  38. data/test/dummy/app/models/animal.rb +4 -0
  39. data/test/dummy/app/models/article.rb +16 -0
  40. data/test/dummy/app/models/authorship.rb +5 -0
  41. data/test/dummy/app/models/book.rb +5 -0
  42. data/test/dummy/app/models/cat.rb +2 -0
  43. data/test/dummy/app/models/document.rb +4 -0
  44. data/test/dummy/app/models/dog.rb +2 -0
  45. data/test/dummy/app/models/elephant.rb +3 -0
  46. data/test/dummy/app/models/fluxor.rb +3 -0
  47. data/test/dummy/app/models/foo_widget.rb +2 -0
  48. data/test/dummy/app/models/legacy_widget.rb +4 -0
  49. data/test/dummy/app/models/person.rb +28 -0
  50. data/test/dummy/app/models/post.rb +4 -0
  51. data/test/dummy/app/models/protected_widget.rb +3 -0
  52. data/test/dummy/app/models/song.rb +12 -0
  53. data/test/dummy/app/models/translation.rb +4 -0
  54. data/test/dummy/app/models/widget.rb +10 -0
  55. data/test/dummy/app/models/wotsit.rb +4 -0
  56. data/test/dummy/app/versions/post_version.rb +3 -0
  57. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  58. data/test/dummy/config.ru +4 -0
  59. data/test/dummy/config/application.rb +63 -0
  60. data/test/dummy/config/boot.rb +10 -0
  61. data/test/dummy/config/database.yml +22 -0
  62. data/test/dummy/config/environment.rb +5 -0
  63. data/test/dummy/config/environments/development.rb +40 -0
  64. data/test/dummy/config/environments/production.rb +73 -0
  65. data/test/dummy/config/environments/test.rb +37 -0
  66. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/test/dummy/config/initializers/inflections.rb +10 -0
  68. data/test/dummy/config/initializers/mime_types.rb +5 -0
  69. data/test/dummy/config/initializers/paper_trail.rb +5 -0
  70. data/test/dummy/config/initializers/secret_token.rb +7 -0
  71. data/test/dummy/config/initializers/session_store.rb +8 -0
  72. data/test/dummy/config/locales/en.yml +5 -0
  73. data/test/dummy/config/routes.rb +3 -0
  74. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +136 -0
  75. data/test/dummy/db/schema.rb +101 -0
  76. data/test/dummy/public/404.html +26 -0
  77. data/test/dummy/public/422.html +26 -0
  78. data/test/dummy/public/500.html +26 -0
  79. data/test/dummy/public/favicon.ico +0 -0
  80. data/test/dummy/public/javascripts/application.js +2 -0
  81. data/test/dummy/public/javascripts/controls.js +965 -0
  82. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  83. data/test/dummy/public/javascripts/effects.js +1123 -0
  84. data/test/dummy/public/javascripts/prototype.js +6001 -0
  85. data/test/dummy/public/javascripts/rails.js +175 -0
  86. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  87. data/test/dummy/script/rails +6 -0
  88. data/test/functional/controller_test.rb +90 -0
  89. data/test/functional/modular_sinatra_test.rb +44 -0
  90. data/test/functional/sinatra_test.rb +45 -0
  91. data/test/functional/thread_safety_test.rb +26 -0
  92. data/test/paper_trail_test.rb +27 -0
  93. data/test/test_helper.rb +40 -0
  94. data/test/unit/cleaner_test.rb +143 -0
  95. data/test/unit/inheritance_column_test.rb +43 -0
  96. data/test/unit/model_test.rb +1314 -0
  97. data/test/unit/protected_attrs_test.rb +46 -0
  98. data/test/unit/serializer_test.rb +117 -0
  99. data/test/unit/serializers/json_test.rb +40 -0
  100. data/test/unit/serializers/mixin_json_test.rb +36 -0
  101. data/test/unit/serializers/mixin_yaml_test.rb +49 -0
  102. data/test/unit/serializers/yaml_test.rb +40 -0
  103. data/test/unit/timestamp_test.rb +44 -0
  104. data/test/unit/version_test.rb +74 -0
  105. metadata +286 -0
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,40 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ # config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict if ::PaperTrail.active_record_protected_attributes?
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Debug mode disables concatenation and preprocessing of assets.
36
+ # This option may cause significant delays in view rendering with a large
37
+ # number of complex assets.
38
+ config.assets.debug = true
39
+ end
40
+
@@ -0,0 +1,73 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both thread web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Disable Rails's static asset server (Apache or nginx will already do this)
18
+ config.serve_static_assets = false
19
+
20
+ # Compress JavaScripts and CSS
21
+ config.assets.compress = true
22
+
23
+ # Don't fallback to assets pipeline if a precompiled asset is missed
24
+ config.assets.compile = false
25
+
26
+ # Generate digests for assets URLs
27
+ config.assets.digest = true
28
+
29
+ # Defaults to nil and saved in location specified by config.assets.prefix
30
+ # config.assets.manifest = YOUR_PATH
31
+
32
+ # Specifies the header that your server uses for sending files
33
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
34
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
35
+
36
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
37
+ # config.force_ssl = true
38
+
39
+ # See everything in the log (default is :info)
40
+ # config.log_level = :debug
41
+
42
+ # Prepend all log lines with the following tags
43
+ # config.log_tags = [ :subdomain, :uuid ]
44
+
45
+ # Use a different logger for distributed setups
46
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
47
+
48
+ # Use a different cache store in production
49
+ # config.cache_store = :mem_cache_store
50
+
51
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
52
+ # config.action_controller.asset_host = "http://assets.example.com"
53
+
54
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
55
+ # config.assets.precompile += %w( search.js )
56
+
57
+ # Disable delivery errors, bad email addresses will be ignored
58
+ # config.action_mailer.raise_delivery_errors = false
59
+
60
+ # Enable threaded mode
61
+ # config.threadsafe!
62
+
63
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
64
+ # the I18n.default_locale when a translation can not be found)
65
+ config.i18n.fallbacks = true
66
+
67
+ # Send deprecation notices to registered listeners
68
+ config.active_support.deprecation = :notify
69
+
70
+ # Log the query plan for queries taking more than this (works
71
+ # with SQLite, MySQL, and PostgreSQL)
72
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
73
+ end
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Eager loads all registered namespaces
11
+ config.eager_load = true
12
+
13
+ # Configure static asset server for tests with Cache-Control for performance
14
+ config.serve_static_assets = true
15
+ config.static_cache_control = "public, max-age=3600"
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ # config.action_mailer.delivery_method = :test
31
+
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict if ::PaperTrail.active_record_protected_attributes?
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,5 @@
1
+ module PaperTrail
2
+ class Version < ActiveRecord::Base
3
+ attr_accessible :created_at, :updated_at, :answer, :action, :question, :article_id, :ip, :user_agent, :title if ::PaperTrail.active_record_protected_attributes?
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '99c0312cf416079a8c7ccc63acb1e9f4f17741398ec8022a2f4fb509c57f55b72486573e9816a026f507efbcd452a9e954d45c93c95d5bacd87e664ad6805d3f'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,3 @@
1
+ Dummy::Application.routes.draw do
2
+ resources :widgets
3
+ end
@@ -0,0 +1,136 @@
1
+ class SetUpTestTables < ActiveRecord::Migration
2
+ def self.up
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.text :object_changes
25
+ t.datetime :created_at
26
+
27
+ # Metadata columns.
28
+ t.integer :answer
29
+ t.string :action
30
+ t.string :question
31
+ t.integer :article_id
32
+ t.string :title
33
+
34
+ # Controller info columns.
35
+ t.string :ip
36
+ t.string :user_agent
37
+ end
38
+ add_index :versions, [:item_type, :item_id]
39
+
40
+ create_table :post_versions, :force => true do |t|
41
+ t.string :item_type, :null => false
42
+ t.integer :item_id, :null => false
43
+ t.string :event, :null => false
44
+ t.string :whodunnit
45
+ t.text :object
46
+ t.datetime :created_at
47
+
48
+ # Controller info columns.
49
+ t.string :ip
50
+ t.string :user_agent
51
+ end
52
+ add_index :post_versions, [:item_type, :item_id]
53
+
54
+ create_table :wotsits, :force => true do |t|
55
+ t.integer :widget_id
56
+ t.string :name
57
+ t.datetime :created_at, :updated_at
58
+ end
59
+
60
+ create_table :fluxors, :force => true do |t|
61
+ t.integer :widget_id
62
+ t.string :name
63
+ end
64
+
65
+ create_table :articles, :force => true do |t|
66
+ t.string :title
67
+ t.string :content
68
+ t.string :abstract
69
+ t.string :file_upload
70
+ end
71
+
72
+ create_table :books, :force => true do |t|
73
+ t.string :title
74
+ end
75
+
76
+ create_table :authorships, :force => true do |t|
77
+ t.integer :book_id
78
+ t.integer :person_id
79
+ end
80
+
81
+ create_table :people, :force => true do |t|
82
+ t.string :name
83
+ t.string :time_zone
84
+ end
85
+
86
+ create_table :songs, :force => true do |t|
87
+ t.integer :length
88
+ end
89
+
90
+ create_table :posts, :force => true do |t|
91
+ t.string :title
92
+ t.string :content
93
+ end
94
+
95
+ create_table :animals, :force => true do |t|
96
+ t.string :name
97
+ t.string :species # single table inheritance column
98
+ end
99
+
100
+ create_table :documents, :force => true do |t|
101
+ t.string :name
102
+ end
103
+
104
+ create_table :legacy_widgets, :force => true do |t|
105
+ t.string :name
106
+ t.integer :version
107
+ end
108
+
109
+ create_table :translations, :force => true do |t|
110
+ t.string :headline
111
+ t.string :content
112
+ t.string :language_code
113
+ t.string :type
114
+ end
115
+ end
116
+
117
+ def self.down
118
+ drop_table :animals
119
+ drop_table :posts
120
+ drop_table :songs
121
+ drop_table :people
122
+ drop_table :authorships
123
+ drop_table :books
124
+ drop_table :articles
125
+ drop_table :fluxors
126
+ drop_table :wotsits
127
+ remove_index :post_versions, :column => [:item_type, :item_id]
128
+ drop_table :post_versions
129
+ remove_index :versions, :column => [:item_type, :item_id]
130
+ drop_table :versions
131
+ drop_table :widgets
132
+ drop_table :documents
133
+ drop_table :legacy_widgets
134
+ drop_table :translations
135
+ end
136
+ end
@@ -0,0 +1,101 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20110208155312) do
14
+
15
+ create_table "articles", :force => true do |t|
16
+ t.string "title"
17
+ t.string "content"
18
+ t.string "abstract"
19
+ end
20
+
21
+ create_table "authorships", :force => true do |t|
22
+ t.integer "book_id"
23
+ t.integer "person_id"
24
+ end
25
+
26
+ create_table "books", :force => true do |t|
27
+ t.string "title"
28
+ end
29
+
30
+ create_table "fluxors", :force => true do |t|
31
+ t.integer "widget_id"
32
+ t.string "name"
33
+ end
34
+
35
+ create_table "people", :force => true do |t|
36
+ t.string "name"
37
+ end
38
+
39
+ create_table "post_versions", :force => true do |t|
40
+ t.string "item_type", :null => false
41
+ t.integer "item_id", :null => false
42
+ t.string "event", :null => false
43
+ t.string "whodunnit"
44
+ t.text "object"
45
+ t.datetime "created_at"
46
+ t.string "ip"
47
+ t.string "user_agent"
48
+ end
49
+
50
+ add_index "post_versions", ["item_type", "item_id"], :name => "index_post_versions_on_item_type_and_item_id"
51
+
52
+ create_table "posts", :force => true do |t|
53
+ t.string "title"
54
+ t.string "content"
55
+ end
56
+
57
+ create_table "songs", :force => true do |t|
58
+ t.integer "length"
59
+ end
60
+
61
+ create_table "versions", :force => true do |t|
62
+ t.string "item_type", :null => false
63
+ t.integer "item_id", :null => false
64
+ t.string "event", :null => false
65
+ t.string "whodunnit"
66
+ t.text "object"
67
+ t.datetime "created_at"
68
+ t.integer "answer"
69
+ t.string "action"
70
+ t.string "question"
71
+ t.integer "article_id"
72
+ t.string "ip"
73
+ t.string "user_agent"
74
+ end
75
+
76
+ add_index "versions", ["item_type", "item_id"], :name => "index_versions_on_item_type_and_item_id"
77
+
78
+ create_table "widgets", :force => true do |t|
79
+ t.string "name"
80
+ t.text "a_text"
81
+ t.integer "an_integer"
82
+ t.float "a_float"
83
+ t.decimal "a_decimal"
84
+ t.datetime "a_datetime"
85
+ t.time "a_time"
86
+ t.date "a_date"
87
+ t.boolean "a_boolean"
88
+ t.datetime "created_at"
89
+ t.datetime "updated_at"
90
+ t.string "sacrificial_column"
91
+ t.string "type"
92
+ end
93
+
94
+ create_table "wotsits", :force => true do |t|
95
+ t.integer "widget_id"
96
+ t.string "name"
97
+ t.datetime "created_at"
98
+ t.datetime "updated_at"
99
+ end
100
+
101
+ end