paper_trail_scrapbook 0.0.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.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +21 -0
  3. data/.rspec +5 -0
  4. data/.rubocop.yml +8 -0
  5. data/.ruby-gemset +1 -0
  6. data/Changelog.md +0 -0
  7. data/Gemfile +3 -0
  8. data/Gemfile.lock +141 -0
  9. data/LICENSE.md +21 -0
  10. data/README.md +77 -0
  11. data/Rakefile +24 -0
  12. data/circle.yml +10 -0
  13. data/lib/paper_trail_scrapbook/changes.rb +89 -0
  14. data/lib/paper_trail_scrapbook/chapter.rb +49 -0
  15. data/lib/paper_trail_scrapbook/config.rb +13 -0
  16. data/lib/paper_trail_scrapbook/life_history.rb +17 -0
  17. data/lib/paper_trail_scrapbook/version.rb +4 -0
  18. data/lib/paper_trail_scrapbook.rb +51 -0
  19. data/paper_trail_scrapbook.gemspec +38 -0
  20. data/spec/dummy_app/Rakefile +7 -0
  21. data/spec/dummy_app/app/models/animal.rb +4 -0
  22. data/spec/dummy_app/app/models/article.rb +24 -0
  23. data/spec/dummy_app/app/models/authorship.rb +5 -0
  24. data/spec/dummy_app/app/models/bar_habtm.rb +4 -0
  25. data/spec/dummy_app/app/models/book.rb +9 -0
  26. data/spec/dummy_app/app/models/boolit.rb +4 -0
  27. data/spec/dummy_app/app/models/callback_modifier.rb +45 -0
  28. data/spec/dummy_app/app/models/car.rb +3 -0
  29. data/spec/dummy_app/app/models/cat.rb +2 -0
  30. data/spec/dummy_app/app/models/chapter.rb +9 -0
  31. data/spec/dummy_app/app/models/citation.rb +5 -0
  32. data/spec/dummy_app/app/models/custom_primary_key_record.rb +15 -0
  33. data/spec/dummy_app/app/models/customer.rb +4 -0
  34. data/spec/dummy_app/app/models/document.rb +6 -0
  35. data/spec/dummy_app/app/models/dog.rb +2 -0
  36. data/spec/dummy_app/app/models/editor.rb +4 -0
  37. data/spec/dummy_app/app/models/editorship.rb +5 -0
  38. data/spec/dummy_app/app/models/elephant.rb +3 -0
  39. data/spec/dummy_app/app/models/fluxor.rb +3 -0
  40. data/spec/dummy_app/app/models/foo_habtm.rb +5 -0
  41. data/spec/dummy_app/app/models/foo_widget.rb +2 -0
  42. data/spec/dummy_app/app/models/fruit.rb +5 -0
  43. data/spec/dummy_app/app/models/gadget.rb +3 -0
  44. data/spec/dummy_app/app/models/kitchen/banana.rb +5 -0
  45. data/spec/dummy_app/app/models/legacy_widget.rb +3 -0
  46. data/spec/dummy_app/app/models/line_item.rb +4 -0
  47. data/spec/dummy_app/app/models/not_on_update.rb +4 -0
  48. data/spec/dummy_app/app/models/on/create.rb +6 -0
  49. data/spec/dummy_app/app/models/on/destroy.rb +6 -0
  50. data/spec/dummy_app/app/models/on/empty_array.rb +6 -0
  51. data/spec/dummy_app/app/models/on/update.rb +6 -0
  52. data/spec/dummy_app/app/models/order.rb +5 -0
  53. data/spec/dummy_app/app/models/paragraph.rb +5 -0
  54. data/spec/dummy_app/app/models/person.rb +39 -0
  55. data/spec/dummy_app/app/models/post.rb +3 -0
  56. data/spec/dummy_app/app/models/post_with_status.rb +7 -0
  57. data/spec/dummy_app/app/models/quotation.rb +5 -0
  58. data/spec/dummy_app/app/models/section.rb +6 -0
  59. data/spec/dummy_app/app/models/skipper.rb +3 -0
  60. data/spec/dummy_app/app/models/song.rb +37 -0
  61. data/spec/dummy_app/app/models/thing.rb +3 -0
  62. data/spec/dummy_app/app/models/translation.rb +6 -0
  63. data/spec/dummy_app/app/models/truck.rb +4 -0
  64. data/spec/dummy_app/app/models/vehicle.rb +4 -0
  65. data/spec/dummy_app/app/models/whatchamajigger.rb +4 -0
  66. data/spec/dummy_app/app/models/widget.rb +8 -0
  67. data/spec/dummy_app/app/models/wotsit.rb +8 -0
  68. data/spec/dummy_app/app/versions/custom_primary_key_record_version.rb +3 -0
  69. data/spec/dummy_app/app/versions/joined_version.rb +6 -0
  70. data/spec/dummy_app/app/versions/json_version.rb +3 -0
  71. data/spec/dummy_app/app/versions/kitchen/banana_version.rb +5 -0
  72. data/spec/dummy_app/app/versions/post_version.rb +3 -0
  73. data/spec/dummy_app/config/application.rb +37 -0
  74. data/spec/dummy_app/config/boot.rb +24 -0
  75. data/spec/dummy_app/config/database.sqlite.yml +15 -0
  76. data/spec/dummy_app/config/database.yml +15 -0
  77. data/spec/dummy_app/config/environment.rb +5 -0
  78. data/spec/dummy_app/config/environments/development.rb +36 -0
  79. data/spec/dummy_app/config/environments/production.rb +74 -0
  80. data/spec/dummy_app/config/environments/test.rb +46 -0
  81. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +9 -0
  82. data/spec/dummy_app/config/initializers/inflections.rb +10 -0
  83. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  84. data/spec/dummy_app/config/initializers/paper_trail.rb +1 -0
  85. data/spec/dummy_app/config/initializers/secret_token.rb +9 -0
  86. data/spec/dummy_app/config/initializers/session_store.rb +8 -0
  87. data/spec/dummy_app/config/locales/en.yml +5 -0
  88. data/spec/dummy_app/config/routes.rb +4 -0
  89. data/spec/dummy_app/config.ru +4 -0
  90. data/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb +344 -0
  91. data/spec/dummy_app/db/schema.rb +296 -0
  92. data/spec/dummy_app/db/test.sqlite3 +0 -0
  93. data/spec/paper_trail_scrapbook/changes_spec.rb +6 -0
  94. data/spec/paper_trail_scrapbook/chapter_spec.rb +6 -0
  95. data/spec/paper_trail_scrapbook/config_spec.rb +17 -0
  96. data/spec/paper_trail_scrapbook/life_history_spec.rb +6 -0
  97. data/spec/paper_trail_scrapbook/version_spec.rb +6 -0
  98. data/spec/paper_trail_scrapbook_spec.rb +4 -0
  99. data/spec/spec_helper.rb +73 -0
  100. metadata +363 -0
@@ -0,0 +1,46 @@
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
+ if config.respond_to?(:public_file_server)
14
+ config.public_file_server.enabled = true
15
+ elsif config.respond_to?(:serve_static_files=)
16
+ config.serve_static_files = true
17
+ else
18
+ config.serve_static_assets = true
19
+ end
20
+
21
+ if config.respond_to?(:public_file_server)
22
+ config.public_file_server.headers = {
23
+ 'Cache-Control' => 'public, max-age=3600'
24
+ }
25
+ else
26
+ config.static_cache_control = 'public, max-age=3600'
27
+ end
28
+
29
+ # Show full error reports and disable caching
30
+ config.consider_all_requests_local = true
31
+ config.action_controller.perform_caching = false
32
+
33
+ # Raise exceptions instead of rendering exception templates
34
+ config.action_dispatch.show_exceptions = false
35
+
36
+ # Disable request forgery protection in test environment
37
+ config.action_controller.allow_forgery_protection = false
38
+
39
+ # Tell Action Mailer not to deliver emails to the real world.
40
+ # The :test delivery method accumulates sent emails in the
41
+ # ActionMailer::Base.deliveries array.
42
+ # config.action_mailer.delivery_method = :test
43
+
44
+ # Print deprecation notices to the stderr
45
+ config.active_support.deprecation = :stderr
46
+ end
@@ -0,0 +1,9 @@
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
4
+ # to see in your backtraces.
5
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
6
+
7
+ # You can also remove all the silencers if you're trying to debug a problem that
8
+ # might stem from framework code.
9
+ # 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 @@
1
+ PaperTrail.config.track_associations = true
@@ -0,0 +1,9 @@
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 = '99c0312cf416079a8c7ccc63acb1e9f4f' \
8
+ '17741398ec8022a2f4fb509c57f55b72486573e9816a026f507efbcd452a9e954d45c93c' \
9
+ '95d5bacd87e664ad6805d3f'
@@ -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,4 @@
1
+ Dummy::Application.routes.draw do
2
+ resources :articles, only: [:create]
3
+ resources :widgets, only: %i[create update destroy]
4
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,344 @@
1
+ # Parts of this migration must be kept in sync with
2
+ # `lib/generators/paper_trail/templates/create_versions.rb`
3
+ #
4
+ # Starting with AR 5.1, we must specify which version of AR we are using.
5
+ # I tried using `const_get` but I got a `NameError`, then I learned about
6
+ # `::ActiveRecord::Migration::Current`.
7
+ class SetUpTestTables < (
8
+ if ::ActiveRecord::VERSION::MAJOR >= 5
9
+ ::ActiveRecord::Migration::Current
10
+ else
11
+ ::ActiveRecord::Migration
12
+ end
13
+ )
14
+ MYSQL_ADAPTERS = [
15
+ 'ActiveRecord::ConnectionAdapters::MysqlAdapter',
16
+ 'ActiveRecord::ConnectionAdapters::Mysql2Adapter'
17
+ ].freeze
18
+ TEXT_BYTES = 1_073_741_823
19
+
20
+ def up
21
+ create_table :on_create, force: true do |t|
22
+ t.string :name, null: false
23
+ end
24
+
25
+ create_table :on_destroy, force: true do |t|
26
+ t.string :name, null: false
27
+ end
28
+
29
+ create_table :on_empty_array, force: true do |t|
30
+ t.string :name, null: false
31
+ end
32
+
33
+ create_table :on_update, force: true do |t|
34
+ t.string :name, null: false
35
+ end
36
+
37
+ # Classes: Vehicle, Car, Truck
38
+ create_table :vehicles, force: true do |t|
39
+ t.string :name, null: false
40
+ t.string :type, null: false
41
+ t.timestamps null: false
42
+ end
43
+
44
+ create_table :skippers, force: true do |t|
45
+ t.string :name
46
+ t.datetime :another_timestamp
47
+ t.timestamps null: true
48
+ end
49
+
50
+ create_table :widgets, force: true do |t|
51
+ t.string :name
52
+ t.text :a_text
53
+ t.integer :an_integer
54
+ t.float :a_float
55
+ t.decimal :a_decimal, precision: 6, scale: 4
56
+ t.datetime :a_datetime
57
+ t.time :a_time
58
+ t.date :a_date
59
+ t.boolean :a_boolean
60
+ t.string :type
61
+ t.timestamps null: true
62
+ end
63
+
64
+ create_table :versions, versions_table_options do |t|
65
+ t.string :item_type, item_type_options
66
+ t.integer :item_id, null: false
67
+ t.string :event, null: false
68
+ t.string :whodunnit
69
+ t.text :object, limit: TEXT_BYTES
70
+ t.text :object_changes, limit: TEXT_BYTES
71
+ t.integer :transaction_id
72
+ t.datetime :created_at
73
+
74
+ # Metadata columns.
75
+ t.integer :answer
76
+ t.string :action
77
+ t.string :question
78
+ t.integer :article_id
79
+ t.string :title
80
+
81
+ # Controller info columns.
82
+ t.string :ip
83
+ t.string :user_agent
84
+ end
85
+ add_index :versions, %i[item_type item_id]
86
+
87
+ create_table :version_associations do |t|
88
+ t.integer :version_id
89
+ t.string :foreign_key_name, null: false
90
+ t.integer :foreign_key_id
91
+ end
92
+ add_index :version_associations, [:version_id]
93
+ add_index :version_associations,
94
+ %i[foreign_key_name foreign_key_id],
95
+ name: 'index_version_associations_on_foreign_key'
96
+
97
+ create_table :post_versions, force: true do |t|
98
+ t.string :item_type, null: false
99
+ t.integer :item_id, null: false
100
+ t.string :event, null: false
101
+ t.string :whodunnit
102
+ t.text :object
103
+ t.datetime :created_at
104
+
105
+ # Controller info columns.
106
+ t.string :ip
107
+ t.string :user_agent
108
+ end
109
+ add_index :post_versions, %i[item_type item_id]
110
+
111
+ if ENV['DB'] == 'postgres' && ::ActiveRecord::VERSION::MAJOR >= 4
112
+ create_table :json_versions, force: true do |t|
113
+ t.string :item_type, null: false
114
+ t.integer :item_id, null: false
115
+ t.string :event, null: false
116
+ t.string :whodunnit
117
+ t.json :object
118
+ t.json :object_changes
119
+ t.datetime :created_at
120
+ end
121
+ add_index :json_versions, %i[item_type item_id]
122
+ end
123
+
124
+ create_table :not_on_updates, force: true do |t|
125
+ t.timestamps null: true
126
+ end
127
+
128
+ create_table :bananas, force: true do |t|
129
+ t.timestamps null: true
130
+ end
131
+
132
+ create_table :banana_versions, force: true do |t|
133
+ t.string :item_type, null: false
134
+ t.integer :item_id, null: false
135
+ t.string :event, null: false
136
+ t.string :whodunnit
137
+ t.text :object
138
+ t.datetime :created_at
139
+ end
140
+ add_index :banana_versions, %i[item_type item_id]
141
+
142
+ create_table :wotsits, force: true do |t|
143
+ t.integer :widget_id
144
+ t.string :name
145
+ t.timestamps null: true
146
+ end
147
+
148
+ create_table :fluxors, force: true do |t|
149
+ t.integer :widget_id
150
+ t.string :name
151
+ end
152
+
153
+ create_table :whatchamajiggers, force: true do |t|
154
+ t.string :owner_type
155
+ t.integer :owner_id
156
+ t.string :name
157
+ end
158
+
159
+ create_table :articles, force: true do |t|
160
+ t.string :title
161
+ t.string :content
162
+ t.string :abstract
163
+ t.string :file_upload
164
+ end
165
+
166
+ create_table :books, force: true do |t|
167
+ t.string :title
168
+ end
169
+
170
+ create_table :authorships, force: true do |t|
171
+ t.integer :book_id
172
+ t.integer :author_id
173
+ end
174
+
175
+ create_table :people, force: true do |t|
176
+ t.string :name
177
+ t.string :time_zone
178
+ t.integer :mentor_id
179
+ end
180
+
181
+ create_table :editorships, force: true do |t|
182
+ t.integer :book_id
183
+ t.integer :editor_id
184
+ end
185
+
186
+ create_table :editors, force: true do |t|
187
+ t.string :name
188
+ end
189
+
190
+ create_table :songs, force: true do |t|
191
+ t.integer :length
192
+ end
193
+
194
+ create_table :posts, force: true do |t|
195
+ t.string :title
196
+ t.string :content
197
+ end
198
+
199
+ create_table :post_with_statuses, force: true do |t|
200
+ t.integer :status
201
+ t.timestamps null: false
202
+ end
203
+
204
+ create_table :animals, force: true do |t|
205
+ t.string :name
206
+ t.string :species # single table inheritance column
207
+ end
208
+
209
+ create_table :documents, force: true do |t|
210
+ t.string :name
211
+ end
212
+
213
+ create_table :legacy_widgets, force: true do |t|
214
+ t.string :name
215
+ t.integer :version
216
+ end
217
+
218
+ create_table :things, force: true do |t|
219
+ t.string :name
220
+ end
221
+
222
+ create_table :translations, force: true do |t|
223
+ t.string :headline
224
+ t.string :content
225
+ t.string :language_code
226
+ t.string :type
227
+ end
228
+
229
+ create_table :gadgets, force: true do |t|
230
+ t.string :name
231
+ t.string :brand
232
+ t.timestamps null: true
233
+ end
234
+
235
+ create_table :customers, force: true do |t|
236
+ t.string :name
237
+ end
238
+
239
+ create_table :orders, force: true do |t|
240
+ t.integer :customer_id
241
+ t.string :order_date
242
+ end
243
+
244
+ create_table :line_items, force: true do |t|
245
+ t.integer :order_id
246
+ t.string :product
247
+ end
248
+
249
+ create_table :fruits, force: true do |t|
250
+ t.string :name
251
+ t.string :color
252
+ end
253
+
254
+ create_table :boolits, force: true do |t|
255
+ t.string :name
256
+ t.boolean :scoped, default: true
257
+ end
258
+
259
+ create_table :callback_modifiers, force: true do |t|
260
+ t.string :some_content
261
+ t.boolean :deleted, default: false
262
+ end
263
+
264
+ create_table :chapters, force: true do |t|
265
+ t.string :name
266
+ end
267
+
268
+ create_table :sections, force: true do |t|
269
+ t.integer :chapter_id
270
+ t.string :name
271
+ end
272
+
273
+ create_table :paragraphs, force: true do |t|
274
+ t.integer :section_id
275
+ t.string :name
276
+ end
277
+
278
+ create_table :quotations, force: true do |t|
279
+ t.integer :chapter_id
280
+ end
281
+
282
+ create_table :citations, force: true do |t|
283
+ t.integer :quotation_id
284
+ end
285
+
286
+ create_table :foo_habtms, force: true do |t|
287
+ t.string :name
288
+ end
289
+
290
+ create_table :bar_habtms, force: true do |t|
291
+ t.string :name
292
+ end
293
+
294
+ create_table :bar_habtms_foo_habtms, force: true, id: false do |t|
295
+ t.integer :foo_habtm_id
296
+ t.integer :bar_habtm_id
297
+ end
298
+ add_index :bar_habtms_foo_habtms, [:foo_habtm_id]
299
+ add_index :bar_habtms_foo_habtms, [:bar_habtm_id]
300
+
301
+ # custom_primary_key_records use a uuid column (string)
302
+ create_table :custom_primary_key_records, id: false, force: true do |t|
303
+ t.column :uuid, :string, primary_key: true
304
+ t.string :name
305
+ t.timestamps null: true
306
+ end
307
+
308
+ # and custom_primary_key_record_versions stores the uuid in item_id, a string
309
+ create_table :custom_primary_key_record_versions, force: true do |t|
310
+ t.string :item_type, null: false
311
+ t.string :item_id, null: false
312
+ t.string :event, null: false
313
+ t.string :whodunnit
314
+ t.text :object
315
+ t.datetime :created_at
316
+ end
317
+ add_index :custom_primary_key_record_versions, %i[item_type item_id], name: 'idx_cust_pk_item'
318
+ end
319
+
320
+ def down
321
+ # Not actually irreversible, but there is no need to maintain this method.
322
+ raise ActiveRecord::IrreversibleMigration
323
+ end
324
+
325
+ private
326
+
327
+ def item_type_options
328
+ opt = { null: false }
329
+ opt[:limit] = 191 if mysql?
330
+ opt
331
+ end
332
+
333
+ def mysql?
334
+ MYSQL_ADAPTERS.include?(connection.class.name)
335
+ end
336
+
337
+ def versions_table_options
338
+ if mysql?
339
+ { options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci' }
340
+ else
341
+ {}
342
+ end
343
+ end
344
+ end