paper_trail 4.0.2 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +27 -0
  4. data/CONTRIBUTING.md +78 -5
  5. data/README.md +328 -268
  6. data/doc/bug_report_template.rb +65 -0
  7. data/gemfiles/3.0.gemfile +7 -4
  8. data/lib/generators/paper_trail/templates/add_object_changes_to_versions.rb +1 -1
  9. data/lib/generators/paper_trail/templates/create_versions.rb +14 -0
  10. data/lib/paper_trail.rb +11 -9
  11. data/lib/paper_trail/attributes_serialization.rb +89 -0
  12. data/lib/paper_trail/cleaner.rb +8 -1
  13. data/lib/paper_trail/config.rb +15 -18
  14. data/lib/paper_trail/frameworks/rails/controller.rb +16 -2
  15. data/lib/paper_trail/has_paper_trail.rb +102 -99
  16. data/lib/paper_trail/record_history.rb +59 -0
  17. data/lib/paper_trail/reifier.rb +270 -0
  18. data/lib/paper_trail/version_association_concern.rb +3 -1
  19. data/lib/paper_trail/version_concern.rb +60 -226
  20. data/lib/paper_trail/version_number.rb +2 -2
  21. data/paper_trail.gemspec +7 -10
  22. data/spec/models/animal_spec.rb +17 -0
  23. data/spec/models/callback_modifier_spec.rb +96 -0
  24. data/spec/models/json_version_spec.rb +20 -17
  25. data/spec/paper_trail/config_spec.rb +52 -0
  26. data/spec/spec_helper.rb +6 -0
  27. data/test/dummy/app/models/callback_modifier.rb +45 -0
  28. data/test/dummy/app/models/chapter.rb +9 -0
  29. data/test/dummy/app/models/citation.rb +5 -0
  30. data/test/dummy/app/models/paragraph.rb +5 -0
  31. data/test/dummy/app/models/quotation.rb +5 -0
  32. data/test/dummy/app/models/section.rb +6 -0
  33. data/test/dummy/config/database.postgres.yml +1 -1
  34. data/test/dummy/config/initializers/paper_trail.rb +3 -1
  35. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +33 -0
  36. data/test/dummy/db/schema.rb +27 -0
  37. data/test/test_helper.rb +36 -0
  38. data/test/unit/associations_test.rb +726 -0
  39. data/test/unit/inheritance_column_test.rb +6 -6
  40. data/test/unit/model_test.rb +62 -594
  41. data/test/unit/protected_attrs_test.rb +3 -2
  42. data/test/unit/version_test.rb +87 -69
  43. metadata +38 -2
@@ -35,9 +35,10 @@ class ProtectedAttrsTest < ActiveSupport::TestCase
35
35
  end
36
36
 
37
37
  should 'the previous version should contain right attributes' do
38
- # For some reason this test seems to be broken in JRuby 1.9 mode in the test env even though it works in the console. WTF?
38
+ # For some reason this test seems to be broken in JRuby 1.9 mode in the
39
+ # test env even though it works in the console. WTF?
39
40
  unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION) && RUBY_VERSION >= '1.9'
40
- assert_equal @widget.previous_version.attributes, @initial_attributes
41
+ assert_attributes_equal @widget.previous_version.attributes, @initial_attributes
41
42
  end
42
43
  end
43
44
  end
@@ -1,100 +1,118 @@
1
1
  require 'test_helper'
2
2
 
3
- class PaperTrail::VersionTest < ActiveSupport::TestCase
4
- setup do
5
- change_schema
6
- @animal = Animal.create
7
- assert PaperTrail::Version.creates.present?
8
- end
3
+ module PaperTrail
4
+ class VersionTest < ActiveSupport::TestCase
5
+ setup do
6
+ change_schema
7
+ @animal = Animal.create
8
+ assert Version.creates.present?
9
+ end
9
10
 
10
- teardown do
11
- restore_schema
12
- Animal.connection.schema_cache.clear!
13
- Animal.reset_column_information
14
- end
11
+ teardown do
12
+ restore_schema
13
+ Animal.connection.schema_cache.clear!
14
+ Animal.reset_column_information
15
+ end
15
16
 
16
- context "PaperTrail::Version.creates" do
17
- should "return only create events" do
18
- PaperTrail::Version.creates.each do |version|
19
- assert_equal "create", version.event
17
+ context ".creates" do
18
+ should "return only create events" do
19
+ Version.creates.each do |version|
20
+ assert_equal "create", version.event
21
+ end
20
22
  end
21
23
  end
22
- end
23
24
 
24
- context "PaperTrail::Version.updates" do
25
- setup {
26
- @animal.update_attributes(:name => 'Animal')
27
- assert PaperTrail::Version.updates.present?
28
- }
25
+ context ".updates" do
26
+ setup {
27
+ @animal.update_attributes(:name => 'Animal')
28
+ assert Version.updates.present?
29
+ }
29
30
 
30
- should "return only update events" do
31
- PaperTrail::Version.updates.each do |version|
32
- assert_equal "update", version.event
31
+ should "return only update events" do
32
+ Version.updates.each do |version|
33
+ assert_equal "update", version.event
34
+ end
33
35
  end
34
36
  end
35
- end
36
37
 
37
- context "PaperTrail::Version.destroys" do
38
- setup {
39
- @animal.destroy
40
- assert PaperTrail::Version.destroys.present?
41
- }
38
+ context ".destroys" do
39
+ setup {
40
+ @animal.destroy
41
+ assert Version.destroys.present?
42
+ }
42
43
 
43
- should "return only destroy events" do
44
- PaperTrail::Version.destroys.each do |version|
45
- assert_equal "destroy", version.event
44
+ should "return only destroy events" do
45
+ Version.destroys.each do |version|
46
+ assert_equal "destroy", version.event
47
+ end
46
48
  end
47
49
  end
48
- end
49
50
 
50
- context "PaperTrail::Version.not_creates" do
51
- setup {
52
- @animal.update_attributes(:name => 'Animal')
53
- @animal.destroy
54
- assert PaperTrail::Version.not_creates.present?
55
- }
51
+ context ".not_creates" do
52
+ setup {
53
+ @animal.update_attributes(:name => 'Animal')
54
+ @animal.destroy
55
+ assert Version.not_creates.present?
56
+ }
56
57
 
57
- should "return all versions except create events" do
58
- PaperTrail::Version.not_creates.each do |version|
59
- assert_not_equal "create", version.event
58
+ should "return all versions except create events" do
59
+ Version.not_creates.each do |version|
60
+ assert_not_equal "create", version.event
61
+ end
60
62
  end
61
63
  end
62
- end
63
64
 
64
- context "PaperTrail::Version.subsequent" do
65
- setup { 2.times { @animal.update_attributes(:name => Faker::Lorem.word) } }
65
+ context ".subsequent" do
66
+ setup do
67
+ 2.times do
68
+ @animal.update_attributes(:name => Faker::Lorem.word)
69
+ end
70
+ end
66
71
 
67
- context "receiving a TimeStamp" do
68
- should "return all versions that were created before the Timestamp" do
69
- value = PaperTrail::Version.subsequent(1.hour.ago, true)
70
- assert_equal value, @animal.versions.to_a
71
- assert_not_nil value.to_sql.match(/ORDER BY #{PaperTrail::Version.arel_table[:created_at].asc.to_sql}/)
72
+ context "given a timestamp" do
73
+ should "return all versions that were created after the timestamp" do
74
+ value = Version.subsequent(1.hour.ago, true)
75
+ assert_equal @animal.versions.to_a, value
76
+ assert_match(
77
+ /ORDER BY #{Version.arel_table[:created_at].asc.to_sql}/,
78
+ value.to_sql
79
+ )
80
+ end
72
81
  end
73
- end
74
82
 
75
- context "receiving a `PaperTrail::Version`" do
76
- should "grab the Timestamp from the version and use that as the value" do
77
- value = PaperTrail::Version.subsequent(@animal.versions.first)
78
- assert_equal value, @animal.versions.to_a.tap { |assoc| assoc.shift }
83
+ context "given a Version" do
84
+ should "grab the timestamp from the version and use that as the value" do
85
+ expected = @animal.versions.to_a.tap { |assoc| assoc.shift }
86
+ actual = Version.subsequent(@animal.versions.first)
87
+ assert_equal expected, actual
88
+ end
79
89
  end
80
90
  end
81
- end
82
91
 
83
- context "PaperTrail::Version.preceding" do
84
- setup { 2.times { @animal.update_attributes(:name => Faker::Lorem.word) } }
92
+ context ".preceding" do
93
+ setup do
94
+ 2.times do
95
+ @animal.update_attributes(:name => Faker::Lorem.word)
96
+ end
97
+ end
85
98
 
86
- context "receiving a TimeStamp" do
87
- should "return all versions that were created before the Timestamp" do
88
- value = PaperTrail::Version.preceding(5.seconds.from_now, true)
89
- assert_equal value, @animal.versions.reverse
90
- assert_not_nil value.to_sql.match(/ORDER BY #{PaperTrail::Version.arel_table[:created_at].desc.to_sql}/)
99
+ context "given a timestamp" do
100
+ should "return all versions that were created before the timestamp" do
101
+ value = Version.preceding(5.seconds.from_now, true)
102
+ assert_equal @animal.versions.reverse, value
103
+ assert_match(
104
+ /ORDER BY #{Version.arel_table[:created_at].desc.to_sql}/,
105
+ value.to_sql
106
+ )
107
+ end
91
108
  end
92
- end
93
109
 
94
- context "receiving a `PaperTrail::Version`" do
95
- should "grab the Timestamp from the version and use that as the value" do
96
- value = PaperTrail::Version.preceding(@animal.versions.last)
97
- assert_equal value, @animal.versions.to_a.tap { |assoc| assoc.pop }.reverse
110
+ context "given a Version" do
111
+ should "grab the timestamp from the version and use that as the value" do
112
+ expected = @animal.versions.to_a.tap { |assoc| assoc.pop }.reverse
113
+ actual = Version.preceding(@animal.versions.last)
114
+ assert_equal expected, actual
115
+ end
98
116
  end
99
117
  end
100
118
  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: 4.0.2
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-19 00:00:00.000000000 Z
12
+ date: 2016-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -197,6 +197,20 @@ dependencies:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
199
  version: '1.2'
200
+ - !ruby/object:Gem::Dependency
201
+ name: pry-nav
202
+ requirement: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ type: :development
208
+ prerelease: false
209
+ version_requirements: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
200
214
  - !ruby/object:Gem::Dependency
201
215
  name: timecop
202
216
  requirement: !ruby/object:Gem::Requirement
@@ -268,6 +282,7 @@ files:
268
282
  - MIT-LICENSE
269
283
  - README.md
270
284
  - Rakefile
285
+ - doc/bug_report_template.rb
271
286
  - gemfiles/3.0.gemfile
272
287
  - lib/generators/paper_trail/USAGE
273
288
  - lib/generators/paper_trail/install_generator.rb
@@ -276,6 +291,7 @@ files:
276
291
  - lib/generators/paper_trail/templates/create_version_associations.rb
277
292
  - lib/generators/paper_trail/templates/create_versions.rb
278
293
  - lib/paper_trail.rb
294
+ - lib/paper_trail/attributes_serialization.rb
279
295
  - lib/paper_trail/cleaner.rb
280
296
  - lib/paper_trail/config.rb
281
297
  - lib/paper_trail/frameworks/active_record.rb
@@ -289,6 +305,8 @@ files:
289
305
  - lib/paper_trail/frameworks/rspec/helpers.rb
290
306
  - lib/paper_trail/frameworks/sinatra.rb
291
307
  - lib/paper_trail/has_paper_trail.rb
308
+ - lib/paper_trail/record_history.rb
309
+ - lib/paper_trail/reifier.rb
292
310
  - lib/paper_trail/serializers/json.rb
293
311
  - lib/paper_trail/serializers/yaml.rb
294
312
  - lib/paper_trail/version_association_concern.rb
@@ -298,6 +316,7 @@ files:
298
316
  - spec/generators/install_generator_spec.rb
299
317
  - spec/models/animal_spec.rb
300
318
  - spec/models/boolit_spec.rb
319
+ - spec/models/callback_modifier_spec.rb
301
320
  - spec/models/fluxor_spec.rb
302
321
  - spec/models/gadget_spec.rb
303
322
  - spec/models/joined_version_spec.rb
@@ -312,6 +331,7 @@ files:
312
331
  - spec/modules/paper_trail_spec.rb
313
332
  - spec/modules/version_concern_spec.rb
314
333
  - spec/modules/version_number_spec.rb
334
+ - spec/paper_trail/config_spec.rb
315
335
  - spec/paper_trail_spec.rb
316
336
  - spec/rails_helper.rb
317
337
  - spec/requests/articles_spec.rb
@@ -329,7 +349,10 @@ files:
329
349
  - test/dummy/app/models/authorship.rb
330
350
  - test/dummy/app/models/book.rb
331
351
  - test/dummy/app/models/boolit.rb
352
+ - test/dummy/app/models/callback_modifier.rb
332
353
  - test/dummy/app/models/cat.rb
354
+ - test/dummy/app/models/chapter.rb
355
+ - test/dummy/app/models/citation.rb
333
356
  - test/dummy/app/models/customer.rb
334
357
  - test/dummy/app/models/document.rb
335
358
  - test/dummy/app/models/dog.rb
@@ -345,10 +368,13 @@ files:
345
368
  - test/dummy/app/models/line_item.rb
346
369
  - test/dummy/app/models/not_on_update.rb
347
370
  - test/dummy/app/models/order.rb
371
+ - test/dummy/app/models/paragraph.rb
348
372
  - test/dummy/app/models/person.rb
349
373
  - test/dummy/app/models/post.rb
350
374
  - test/dummy/app/models/post_with_status.rb
351
375
  - test/dummy/app/models/protected_widget.rb
376
+ - test/dummy/app/models/quotation.rb
377
+ - test/dummy/app/models/section.rb
352
378
  - test/dummy/app/models/skipper.rb
353
379
  - test/dummy/app/models/song.rb
354
380
  - test/dummy/app/models/thing.rb
@@ -390,6 +416,7 @@ files:
390
416
  - test/paper_trail_test.rb
391
417
  - test/test_helper.rb
392
418
  - test/time_travel_helper.rb
419
+ - test/unit/associations_test.rb
393
420
  - test/unit/cleaner_test.rb
394
421
  - test/unit/inheritance_column_test.rb
395
422
  - test/unit/model_test.rb
@@ -429,6 +456,7 @@ test_files:
429
456
  - spec/generators/install_generator_spec.rb
430
457
  - spec/models/animal_spec.rb
431
458
  - spec/models/boolit_spec.rb
459
+ - spec/models/callback_modifier_spec.rb
432
460
  - spec/models/fluxor_spec.rb
433
461
  - spec/models/gadget_spec.rb
434
462
  - spec/models/joined_version_spec.rb
@@ -443,6 +471,7 @@ test_files:
443
471
  - spec/modules/paper_trail_spec.rb
444
472
  - spec/modules/version_concern_spec.rb
445
473
  - spec/modules/version_number_spec.rb
474
+ - spec/paper_trail/config_spec.rb
446
475
  - spec/paper_trail_spec.rb
447
476
  - spec/rails_helper.rb
448
477
  - spec/requests/articles_spec.rb
@@ -460,7 +489,10 @@ test_files:
460
489
  - test/dummy/app/models/authorship.rb
461
490
  - test/dummy/app/models/book.rb
462
491
  - test/dummy/app/models/boolit.rb
492
+ - test/dummy/app/models/callback_modifier.rb
463
493
  - test/dummy/app/models/cat.rb
494
+ - test/dummy/app/models/chapter.rb
495
+ - test/dummy/app/models/citation.rb
464
496
  - test/dummy/app/models/customer.rb
465
497
  - test/dummy/app/models/document.rb
466
498
  - test/dummy/app/models/dog.rb
@@ -476,10 +508,13 @@ test_files:
476
508
  - test/dummy/app/models/line_item.rb
477
509
  - test/dummy/app/models/not_on_update.rb
478
510
  - test/dummy/app/models/order.rb
511
+ - test/dummy/app/models/paragraph.rb
479
512
  - test/dummy/app/models/person.rb
480
513
  - test/dummy/app/models/post.rb
481
514
  - test/dummy/app/models/post_with_status.rb
482
515
  - test/dummy/app/models/protected_widget.rb
516
+ - test/dummy/app/models/quotation.rb
517
+ - test/dummy/app/models/section.rb
483
518
  - test/dummy/app/models/skipper.rb
484
519
  - test/dummy/app/models/song.rb
485
520
  - test/dummy/app/models/thing.rb
@@ -521,6 +556,7 @@ test_files:
521
556
  - test/paper_trail_test.rb
522
557
  - test/test_helper.rb
523
558
  - test/time_travel_helper.rb
559
+ - test/unit/associations_test.rb
524
560
  - test/unit/cleaner_test.rb
525
561
  - test/unit/inheritance_column_test.rb
526
562
  - test/unit/model_test.rb