paper_trail 6.0.2 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +20 -0
  3. data/.rubocop.yml +30 -2
  4. data/.rubocop_todo.yml +20 -0
  5. data/.travis.yml +3 -5
  6. data/Appraisals +5 -6
  7. data/CHANGELOG.md +33 -0
  8. data/README.md +43 -81
  9. data/Rakefile +1 -1
  10. data/doc/bug_report_template.rb +4 -2
  11. data/gemfiles/ar_4.0.gemfile +7 -0
  12. data/gemfiles/ar_4.2.gemfile +0 -1
  13. data/lib/generators/paper_trail/templates/create_version_associations.rb +1 -1
  14. data/lib/generators/paper_trail/templates/create_versions.rb +1 -1
  15. data/lib/paper_trail.rb +7 -9
  16. data/lib/paper_trail/config.rb +0 -15
  17. data/lib/paper_trail/frameworks/rspec.rb +8 -2
  18. data/lib/paper_trail/model_config.rb +6 -2
  19. data/lib/paper_trail/record_trail.rb +3 -1
  20. data/lib/paper_trail/reifier.rb +43 -354
  21. data/lib/paper_trail/reifiers/belongs_to.rb +48 -0
  22. data/lib/paper_trail/reifiers/has_and_belongs_to_many.rb +50 -0
  23. data/lib/paper_trail/reifiers/has_many.rb +110 -0
  24. data/lib/paper_trail/reifiers/has_many_through.rb +90 -0
  25. data/lib/paper_trail/reifiers/has_one.rb +76 -0
  26. data/lib/paper_trail/serializers/yaml.rb +2 -25
  27. data/lib/paper_trail/version_concern.rb +5 -5
  28. data/lib/paper_trail/version_number.rb +7 -3
  29. data/paper_trail.gemspec +7 -34
  30. data/spec/controllers/articles_controller_spec.rb +1 -1
  31. data/spec/generators/install_generator_spec.rb +40 -34
  32. data/spec/models/animal_spec.rb +50 -25
  33. data/spec/models/boolit_spec.rb +8 -7
  34. data/spec/models/callback_modifier_spec.rb +13 -13
  35. data/spec/models/document_spec.rb +21 -0
  36. data/spec/models/gadget_spec.rb +35 -39
  37. data/spec/models/joined_version_spec.rb +4 -4
  38. data/spec/models/json_version_spec.rb +14 -15
  39. data/spec/models/not_on_update_spec.rb +1 -1
  40. data/spec/models/post_with_status_spec.rb +2 -2
  41. data/spec/models/skipper_spec.rb +4 -4
  42. data/spec/models/thing_spec.rb +1 -1
  43. data/spec/models/truck_spec.rb +1 -1
  44. data/spec/models/vehicle_spec.rb +1 -1
  45. data/spec/models/version_spec.rb +152 -168
  46. data/spec/models/widget_spec.rb +170 -196
  47. data/spec/modules/paper_trail_spec.rb +3 -3
  48. data/spec/modules/version_concern_spec.rb +5 -8
  49. data/spec/modules/version_number_spec.rb +11 -36
  50. data/spec/paper_trail/cleaner_spec.rb +152 -0
  51. data/spec/paper_trail/config_spec.rb +1 -1
  52. data/spec/paper_trail/serializers/custom_yaml_serializer_spec.rb +45 -0
  53. data/spec/paper_trail/serializers/json_spec.rb +57 -0
  54. data/spec/paper_trail/version_limit_spec.rb +55 -0
  55. data/spec/paper_trail_spec.rb +45 -32
  56. data/spec/requests/articles_spec.rb +4 -4
  57. data/test/dummy/app/models/custom_primary_key_record.rb +4 -2
  58. data/test/dummy/app/models/document.rb +1 -1
  59. data/test/dummy/app/models/not_on_update.rb +1 -1
  60. data/test/dummy/app/models/on/create.rb +6 -0
  61. data/test/dummy/app/models/on/destroy.rb +6 -0
  62. data/test/dummy/app/models/on/empty_array.rb +6 -0
  63. data/test/dummy/app/models/on/update.rb +6 -0
  64. data/test/dummy/app/models/person.rb +1 -0
  65. data/test/dummy/app/models/song.rb +19 -28
  66. data/test/dummy/config/application.rb +10 -43
  67. data/test/dummy/config/routes.rb +1 -1
  68. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +25 -51
  69. data/test/dummy/db/schema.rb +29 -19
  70. data/test/test_helper.rb +0 -16
  71. data/test/unit/associations_test.rb +81 -81
  72. data/test/unit/model_test.rb +48 -131
  73. data/test/unit/serializer_test.rb +34 -45
  74. data/test/unit/serializers/mixin_json_test.rb +3 -1
  75. data/test/unit/serializers/yaml_test.rb +1 -5
  76. metadata +44 -19
  77. data/lib/paper_trail/frameworks/sinatra.rb +0 -40
  78. data/test/functional/modular_sinatra_test.rb +0 -46
  79. data/test/functional/sinatra_test.rb +0 -51
  80. data/test/unit/cleaner_test.rb +0 -151
  81. data/test/unit/inheritance_column_test.rb +0 -41
  82. data/test/unit/serializers/json_test.rb +0 -95
  83. data/test/unit/serializers/mixin_yaml_test.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c23b36829183d413cfe6fa50f86b50dc5d5dd99a
4
- data.tar.gz: c1964749e5fb1f1d23d8d066558d8d61323a6b73
3
+ metadata.gz: c3a67c57c19665911311eab6dc66bd670e390f57
4
+ data.tar.gz: f74e8562ba1ac3e305d5785e50fc1357ee0a69ca
5
5
  SHA512:
6
- metadata.gz: 31692c33ac64c0322c894038b1a75c50ba5231a42ba7ebfa08a08517b721d0a08eba2e2e821566586da4a7bca7c7da92b7f74aee257bc5c698dbe8e8284a42dd
7
- data.tar.gz: 0fe50a103b744687e0e2acd02dbb24c5f32f82c0255a356e89f2a66a1c5bd4bd0b688ac7eb8394cb34fb08b856780cc8e55b53be6afbaea7f6f99c24cfc5d408
6
+ metadata.gz: 8e493b2ef87fb52d53c54cefa55369ee31ac82261d30dac5833bc4d010aeff5387fd9362deef390b97e7b646bc22fbbaeb5ea2620d63cc2369e5e9ddcd78744e
7
+ data.tar.gz: 4cb5a0c791d890011e9aff19d0e8119955e43d8aab22a2bd57f5c7c9457dd5dc60345d79494aedf87e254dd3dde524832b04e2baeeca4eaedc1b7e1f91b5b893
@@ -48,6 +48,10 @@ cd ../..
48
48
 
49
49
  # Run tests
50
50
  DB=sqlite bundle exec appraisal ar-4.2 rake
51
+
52
+ # Run a single test file
53
+ DB=sqlite bundle exec appraisal ar-4.2 ruby -I test test/unit/associations_test.rb
54
+ DB=sqlite bundle exec appraisal ar-4.2 rspec spec/paper_trail/serializers/json_spec.rb
51
55
  ```
52
56
 
53
57
  ### Test sqlite, AR 5
@@ -118,6 +122,22 @@ DB=postgres bundle exec rake
118
122
  DB=postgres bundle exec appraisal ar-5.0 rake
119
123
  ```
120
124
 
125
+ ## Editing the migration
126
+
127
+ After editing `test/dummy/db/migrate/20110208155312_set_up_test_tables.rb` ..
128
+
129
+ ```
130
+ cd test/dummy
131
+ export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
132
+ RAILS_ENV=test bundle exec rake db:environment:set db:drop db:create db:migrate
133
+ RAILS_ENV=foo bundle exec rake db:environment:set db:drop db:create db:migrate
134
+ RAILS_ENV=bar bundle exec rake db:environment:set db:drop db:create db:migrate
135
+ unset BUNDLE_GEMFILE
136
+ cd ../..
137
+ ```
138
+
139
+ Don't forget to commit changes to `schema.rb`.
140
+
121
141
  ## Releases
122
142
 
123
143
  1. Set the version in lib/paper_trail/version_number.rb
@@ -1,3 +1,6 @@
1
+ require:
2
+ - rubocop-rspec
3
+
1
4
  inherit_from: .rubocop_todo.yml
2
5
 
3
6
  # Please:
@@ -12,7 +15,7 @@ AllCops:
12
15
  - test/dummy/db/schema.rb # Generated, out of our control
13
16
 
14
17
  # Set to lowest supported version
15
- TargetRubyVersion: 1.9
18
+ TargetRubyVersion: 2.1
16
19
 
17
20
  # Migrations often contain long up/down methods, and extracting smaller methods
18
21
  # from these is of questionable value.
@@ -20,6 +23,10 @@ Metrics/AbcSize:
20
23
  Exclude:
21
24
  - 'test/dummy/db/migrate/*'
22
25
 
26
+ # Not a useful metric compared to, e.g. `AbcSize`.
27
+ Metrics/BlockLength:
28
+ Enabled: false
29
+
23
30
  # Not a useful metric compared to, e.g. `AbcSize`.
24
31
  Metrics/ClassLength:
25
32
  Enabled: false
@@ -40,6 +47,19 @@ Metrics/MethodLength:
40
47
  Metrics/ModuleLength:
41
48
  Enabled: false
42
49
 
50
+ # In an ideal world, each example has a single expectation. In the real world,
51
+ # sometimes setup is a pain and you don't want to duplicate setup in multiple
52
+ # examples, or make the specs more confusing with many nested `context`s, and
53
+ # the practical thing is to have multiple expectations.
54
+ RSpec/MultipleExpectations:
55
+ Enabled: false
56
+
57
+ # Yes, ideally examples would be short. Is it possible to pick a limit and say,
58
+ # "no example will ever be longer than this"? Hard to say. Sometimes they're
59
+ # quite long.
60
+ RSpec/ExampleLength:
61
+ Enabled: false
62
+
43
63
  Style/AlignParameters:
44
64
  EnforcedStyle: with_fixed_indentation
45
65
 
@@ -56,17 +76,25 @@ Style/DotPosition:
56
76
  Style/DoubleNegation:
57
77
  Enabled: false
58
78
 
79
+ Style/FileName:
80
+ Exclude:
81
+ - Appraisals
82
+
59
83
  # The decision of when to use a guard clause to improve readability is subtle,
60
84
  # and it's not clear that it can be linted. Certainly, the default
61
85
  # `MinBodyLength` of 1 can actually hurt readability.
62
86
  Style/GuardClause:
63
- MinBodyLength: 3
87
+ Enabled: false
64
88
 
65
89
  # Use postfix (modifier) conditionals for one-liners, unless doing so would
66
90
  # exceed 60 characters.
67
91
  Style/IfUnlessModifier:
68
92
  MaxLineLength: 60
69
93
 
94
+ Style/IndentHeredoc:
95
+ Exclude:
96
+ - paper_trail.gemspec
97
+
70
98
  # The Ruby Style Guide says:
71
99
  #
72
100
  # > Use \ instead of + or << to concatenate two string literals at line end.
@@ -1,3 +1,5 @@
1
+ require: rubocop-rspec
2
+
1
3
  # Remove these configuration records
2
4
  # one by one as the offenses are removed from the code base.
3
5
 
@@ -12,3 +14,21 @@ Metrics/PerceivedComplexity:
12
14
 
13
15
  Style/FrozenStringLiteralComment:
14
16
  Enabled: false
17
+
18
+ RSpec/BeforeAfterAll:
19
+ Enabled: false
20
+
21
+ RSpec/FilePath:
22
+ Enabled: false
23
+
24
+ RSpec/MessageSpies:
25
+ Enabled: false
26
+
27
+ RSpec/NamedSubject:
28
+ Enabled: false
29
+
30
+ RSpec/NestedGroups:
31
+ Max: 5 # goal: 3
32
+
33
+ Security/YAMLLoad:
34
+ Enabled: false
@@ -2,8 +2,7 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.3.1
5
- - 1.9.3
6
- - jruby-19mode
5
+ - 2.1.10
7
6
  env:
8
7
  global:
9
8
  - TRAVIS=true
@@ -25,6 +24,7 @@ before_script:
25
24
  - sh -c "if [ \"$DB\" = 'postgres' ]; then psql -c 'create database paper_trail_foo;' -U postgres; fi"
26
25
 
27
26
  gemfile:
27
+ - gemfiles/ar_4.0.gemfile
28
28
  - gemfiles/ar_4.2.gemfile
29
29
  - gemfiles/ar_5.0.gemfile
30
30
  - gemfiles/ar_master.gemfile
@@ -33,9 +33,7 @@ matrix:
33
33
  fast_finish: true
34
34
  exclude:
35
35
  - gemfile: gemfiles/ar_5.0.gemfile
36
- rvm: 1.9.3
37
- - gemfile: gemfiles/ar_5.0.gemfile
38
- rvm: jruby-19mode
36
+ rvm: 2.1.10
39
37
  allow_failures:
40
38
  - gemfile: gemfiles/ar_master.gemfile
41
39
 
data/Appraisals CHANGED
@@ -7,19 +7,18 @@
7
7
  # > the version from the appraisal takes precedence.
8
8
  # > https://github.com/thoughtbot/appraisal
9
9
 
10
+ appraise "ar-4.0" do
11
+ gem "activerecord", "~> 4.0"
12
+ end
13
+
10
14
  appraise "ar-4.2" do
11
15
  gem "activerecord", "~> 4.2"
12
- gem "sinatra", "~> 1.4.6"
13
16
  end
14
17
 
15
18
  appraise "ar-5.0" do
16
19
  gem "activerecord", "~> 5.0.0"
17
20
  gem "rspec-rails", "~> 3.5.1"
18
- gem 'rails-controller-testing'
19
-
20
- # The AR5 version of PaperTrail is not compatible with sinatra 2 yet.
21
- # Contributions welcome.
22
- # gem "sinatra", "2.0.0.beta2"
21
+ gem "rails-controller-testing"
23
22
  end
24
23
 
25
24
  appraise "ar_master" do
@@ -17,6 +17,35 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
17
17
 
18
18
  - None
19
19
 
20
+ ## 7.0.0 (2017-04-01)
21
+
22
+ ### Breaking Changes
23
+
24
+ - Drop support for ruby 1.9.3, whose EOL was 2015-02-23
25
+ - Drop support for ruby 2.0.0, whose EOL was 2016-02-24
26
+ - Remove deprecated config methods:
27
+ - PaperTrail.serialized_attributes?
28
+ - PaperTrail.config.serialized_attributes
29
+ - PaperTrail.config.serialized_attributes=
30
+ - Sinatra integration moved to
31
+ [paper_trail-sinatra](https://github.com/jaredbeck/paper_trail-sinatra) gem
32
+
33
+ ### Added
34
+
35
+ - `PaperTrail.gem_version` returns a `Gem::Version`, nice for comparisons.
36
+
37
+ ### Fixed
38
+
39
+ - [#925](https://github.com/airblade/paper_trail/pull/925) - Update RSpec
40
+ matchers to work with custom version association names
41
+ - [#929](https://github.com/airblade/paper_trail/pull/929) -
42
+ Fix error calling private method in rails 4.0
43
+ - [#938](https://github.com/airblade/paper_trail/pull/938) - Fix bug where
44
+ non-standard foreign key names broke belongs_to associations
45
+ - [#940](https://github.com/airblade/paper_trail/pull/940) - When destroying
46
+ versions to stay under version_limit, don't rely on the database to
47
+ implicitly return the versions in the right order
48
+
20
49
  ## 6.0.2 (2016-12-13)
21
50
 
22
51
  ### Breaking Changes
@@ -297,6 +326,10 @@ name conflict with your methods.
297
326
 
298
327
  ## 4.1.0 (2016-01-30)
299
328
 
329
+ ### Known Issues
330
+
331
+ - Version changesets now store ENUM values incorrectly (as nulls). Previously the values were stored as strings. This only affects Rails 4, not Rails 5. See [#926](https://github.com/airblade/paper_trail/pull/926)
332
+
300
333
  ### Breaking Changes
301
334
 
302
335
  - None
data/README.md CHANGED
@@ -11,6 +11,7 @@ has been destroyed.
11
11
  | Version | Documentation |
12
12
  | -------------- | ------------- |
13
13
  | Unreleased | https://github.com/airblade/paper_trail/blob/master/README.md |
14
+ | 7.0.0 | https://github.com/airblade/paper_trail/blob/v7.0.0/README.md |
14
15
  | 6.0.2 | https://github.com/airblade/paper_trail/blob/v6.0.2/README.md |
15
16
  | 5.2.3 | https://github.com/airblade/paper_trail/blob/v5.2.3/README.md |
16
17
  | 4.2.0 | https://github.com/airblade/paper_trail/blob/v4.2.0/README.md |
@@ -64,7 +65,9 @@ has been destroyed.
64
65
 
65
66
  | paper_trail | branch | tags | ruby | activerecord |
66
67
  | -------------- | ---------- | ------ | -------- | ------------- |
67
- | 6 | master | v6.x | >= 1.9.3 | >= 4.0, < 6 |
68
+ | unreleased | master | | >= 2.1.0 | >= 4.0, < 6 |
69
+ | 7 | 7-stable | v7.x | >= 2.1.0 | >= 4.0, < 6 |
70
+ | 6 | 6-stable | v6.x | >= 1.9.3 | >= 4.0, < 6 |
68
71
  | 5 | 5-stable | v5.x | >= 1.9.3 | >= 3.0, < 5.1 |
69
72
  | 4 | 4-stable | v4.x | >= 1.8.7 | >= 3.0, < 5.1 |
70
73
  | 3 | 3.0-stable | v3.x | >= 1.8.7 | >= 3.0, < 5 |
@@ -356,84 +359,88 @@ use attribute_name_was instead of attribute_name.
356
359
 
357
360
  ### 2.c. Choosing Attributes To Monitor
358
361
 
359
- You can ignore changes to certain attributes like this:
362
+ #### Ignore
363
+
364
+ You can `ignore` changes to certain attributes:
360
365
 
361
366
  ```ruby
362
367
  class Article < ActiveRecord::Base
363
- has_paper_trail :ignore => [:title, :rating]
368
+ has_paper_trail ignore: [:title, :rating]
364
369
  end
365
370
  ```
366
371
 
367
- This means that changes to just the `title` or `rating` will not store another
368
- version of the article. It does not mean that the `title` and `rating`
369
- attributes will be ignored if some other change causes a new
370
- `PaperTrail::Version` to be created. For example:
372
+ Changes to just the `title` or `rating` will not create a version record.
373
+ Changes to other attributes will create a version record.
371
374
 
372
375
  ```ruby
373
376
  a = Article.create
374
377
  a.versions.length # 1
375
- a.update_attributes :title => 'My Title', :rating => 3
378
+ a.update_attributes title: 'My Title', rating: 3
376
379
  a.versions.length # 1
377
- a.update_attributes :title => 'Greeting', :content => 'Hello'
380
+ a.update_attributes title: 'Greeting', content: 'Hello'
378
381
  a.versions.length # 2
379
382
  a.paper_trail.previous_version.title # 'My Title'
380
383
  ```
381
384
 
382
- Or, you can specify a list of all attributes you care about:
385
+ #### Only
386
+
387
+ Or, you can specify a list of the `only` attributes you care about:
383
388
 
384
389
  ```ruby
385
390
  class Article < ActiveRecord::Base
386
- has_paper_trail :only => [:title]
391
+ has_paper_trail only: [:title]
387
392
  end
388
393
  ```
389
394
 
390
- This means that only changes to the `title` will save a version of the article:
395
+ Only changes to the `title` will create a version record.
391
396
 
392
397
  ```ruby
393
398
  a = Article.create
394
399
  a.versions.length # 1
395
- a.update_attributes :title => 'My Title'
400
+ a.update_attributes title: 'My Title'
396
401
  a.versions.length # 2
397
- a.update_attributes :content => 'Hello'
402
+ a.update_attributes content: 'Hello'
398
403
  a.versions.length # 2
399
404
  a.paper_trail.previous_version.content # nil
400
405
  ```
401
406
 
402
- The `:ignore` and `:only` options can also accept `Hash` arguments, where the :
407
+ The `:ignore` and `:only` options can also accept `Hash` arguments.
403
408
 
404
409
  ```ruby
405
410
  class Article < ActiveRecord::Base
406
- has_paper_trail :only => [:title => Proc.new { |obj| !obj.title.blank? } ]
411
+ has_paper_trail only: { title: Proc.new { |obj| !obj.title.blank? } }
407
412
  end
408
413
  ```
409
414
 
410
- This means that if the `title` is not blank, then only changes to the `title`
411
- will save a version of the article:
415
+ If the `title` is not blank, then only changes to the `title`
416
+ will create a version record.
412
417
 
413
418
  ```ruby
414
419
  a = Article.create
415
420
  a.versions.length # 1
416
- a.update_attributes :content => 'Hello'
421
+ a.update_attributes content: 'Hello'
417
422
  a.versions.length # 2
418
- a.update_attributes :title => 'My Title'
423
+ a.update_attributes title: 'Title One'
419
424
  a.versions.length # 3
420
- a.update_attributes :content => 'Hai'
425
+ a.update_attributes content: 'Hai'
421
426
  a.versions.length # 3
422
427
  a.paper_trail.previous_version.content # "Hello"
423
- a.update_attributes :title => 'Dif Title'
428
+ a.update_attributes title: 'Title Two'
424
429
  a.versions.length # 4
425
430
  a.paper_trail.previous_version.content # "Hai"
426
431
  ```
427
432
 
428
- Passing both `:ignore` and `:only` options will result in the article being
429
- saved if a changed attribute is included in `:only` but not in `:ignore`.
433
+ Configuring both `:ignore` and `:only` is not recommended, but it should work as
434
+ expected. Passing both `:ignore` and `:only` options will result in the
435
+ article being saved if a changed attribute is included in `:only` but not in
436
+ `:ignore`.
430
437
 
431
- You can skip fields altogether with the `:skip` option. As with `:ignore`,
432
- updates to these fields will not create a new `PaperTrail::Version`. In
433
- addition, these fields will not be included in the serialized version of the
434
- object whenever a new `PaperTrail::Version` is created.
438
+ #### Skip
435
439
 
436
- For example:
440
+ You can skip attributes completely with the `:skip` option. As with `:ignore`,
441
+ updates to these attributes will not create a version record. In addition, if a
442
+ version record is created for some other reason, these attributes will not be
443
+ persisted.
437
444
 
438
445
  ```ruby
439
446
  class Article < ActiveRecord::Base
@@ -498,6 +505,9 @@ Or a block:
498
505
  end
499
506
  ```
500
507
 
508
+ PaperTrail is disabled for the whole model
509
+ (e.g. `Widget`), not just for the instance (e.g. `@widget`).
510
+
501
511
  ### 2.e. Limiting the Number of Versions Created
502
512
 
503
513
  Configure `version_limit` to cap the number of versions saved per record. This
@@ -545,7 +555,7 @@ widget = versions.last.reify # the widget as it was before destruction
545
555
  widget.save # the widget lives!
546
556
  ```
547
557
 
548
- You could even use PaperTrail to implement an undo system, [Ryan Bates has!][3]
558
+ You could even use PaperTrail to implement an undo system; [Ryan Bates has!][3]
549
559
 
550
560
  If your model uses [optimistic locking][1] don't forget to [increment your
551
561
  `lock_version`][2] before saving or you'll get a `StaleObjectError`.
@@ -1191,7 +1201,7 @@ there's no automatic way to migrate your data. The first (slow) option is to
1191
1201
  loop over every record and parse it in Ruby, then write to a temporary column:
1192
1202
 
1193
1203
  ```ruby
1194
- add_column :versions, :object, :new_object, :jsonb # or :json
1204
+ add_column :versions, :new_object, :jsonb # or :json
1195
1205
 
1196
1206
  PaperTrail::Version.reset_column_information
1197
1207
  PaperTrail::Version.find_each do |version|
@@ -1491,53 +1501,7 @@ require 'paper_trail/frameworks/rspec'
1491
1501
 
1492
1502
  ## 8. Sinatra
1493
1503
 
1494
- To configure PaperTrail for usage with [Sinatra][12], your `Sinatra`
1495
- app must be using `ActiveRecord` 3 or 4. There is no released version of sinatra yet
1496
- that is compatible with AR 5. We expect sinatra 2.0 to support AR 5, but it will have
1497
- breaking changes that will require changes to PaperTrail.
1498
-
1499
- It is also recommended to use the
1500
- [Sinatra ActiveRecord Extension][13] or something similar for managing your
1501
- applications `ActiveRecord` connection in a manner similar to the way `Rails`
1502
- does. If using the aforementioned `Sinatra ActiveRecord Extension`, steps for
1503
- setting up your app with PaperTrail will look something like this:
1504
-
1505
- 1. Add PaperTrail to your `Gemfile`.
1506
-
1507
- `gem 'paper_trail'`
1508
-
1509
- 2. Generate a migration to add a `versions` table to your database.
1510
-
1511
- `bundle exec rake db:create_migration NAME=create_versions`
1512
-
1513
- 3. Copy contents of [create_versions.rb][14]
1514
- into the `create_versions` migration that was generated into your `db/migrate` directory.
1515
-
1516
- 4. Run the migration.
1517
-
1518
- `bundle exec rake db:migrate`
1519
-
1520
- 5. Add `has_paper_trail` to the models you want to track.
1521
-
1522
-
1523
- PaperTrail provides a helper extension that acts similar to the controller mixin
1524
- it provides for `Rails` applications.
1525
-
1526
- It will set `PaperTrail.whodunnit` to whatever is returned by a method named
1527
- `user_for_paper_trail` which you can define inside your Sinatra Application. (by
1528
- default it attempts to invoke a method named `current_user`)
1529
-
1530
- If you're using the modular [`Sinatra::Base`][15] style of application, you will
1531
- need to register the extension:
1532
-
1533
- ```ruby
1534
- # bleh_app.rb
1535
- require 'sinatra/base'
1536
-
1537
- class BlehApp < Sinatra::Base
1538
- register PaperTrail::Sinatra
1539
- end
1540
- ```
1504
+ See [paper_trail-sinatra][41].
1541
1505
 
1542
1506
  ## Articles
1543
1507
 
@@ -1634,10 +1598,7 @@ Released under the MIT licence.
1634
1598
  [9]: https://github.com/airblade/paper_trail/tree/3.0-stable
1635
1599
  [10]: https://github.com/airblade/paper_trail/tree/2.7-stable
1636
1600
  [11]: https://github.com/airblade/paper_trail/tree/rails2
1637
- [12]: http://www.sinatrarb.com
1638
- [13]: https://github.com/janko-m/sinatra-activerecord
1639
1601
  [14]: https://raw.github.com/airblade/paper_trail/master/lib/generators/paper_trail/templates/create_versions.rb
1640
- [15]: http://www.sinatrarb.com/intro.html#Modular%20vs.%20Classic%20Style
1641
1602
  [16]: https://github.com/airblade/paper_trail/issues/113
1642
1603
  [17]: https://github.com/rails/protected_attributes
1643
1604
  [18]: https://github.com/rails/strong_parameters
@@ -1663,3 +1624,4 @@ Released under the MIT licence.
1663
1624
  [38]: https://github.com/sferik/rails_admin
1664
1625
  [39]: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#class-ActiveRecord::Base-label-Single+table+inheritance
1665
1626
  [40]: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Polymorphic+Associations
1627
+ [41]: https://github.com/jaredbeck/paper_trail-sinatra