paper_trail 3.0.0.beta1 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -3
  3. data/CHANGELOG.md +15 -0
  4. data/README.md +113 -24
  5. data/Rakefile +2 -5
  6. data/lib/generators/paper_trail/install_generator.rb +1 -1
  7. data/lib/paper_trail.rb +16 -3
  8. data/lib/paper_trail/config.rb +1 -1
  9. data/lib/paper_trail/frameworks/cucumber.rb +22 -24
  10. data/lib/paper_trail/frameworks/rails.rb +1 -1
  11. data/lib/paper_trail/frameworks/rspec.rb +16 -18
  12. data/lib/paper_trail/frameworks/sinatra.rb +4 -4
  13. data/lib/paper_trail/has_paper_trail.rb +68 -39
  14. data/lib/paper_trail/serializers/json.rb +1 -1
  15. data/lib/paper_trail/serializers/yaml.rb +3 -3
  16. data/lib/paper_trail/version.rb +73 -78
  17. data/lib/paper_trail/version_number.rb +1 -1
  18. data/paper_trail.gemspec +4 -2
  19. data/spec/models/version_spec.rb +44 -0
  20. data/spec/models/widget_spec.rb +16 -6
  21. data/spec/modules/version_concern_spec.rb +50 -0
  22. data/spec/paper_trail_spec.rb +18 -20
  23. data/spec/spec_helper.rb +3 -1
  24. data/test/custom_json_serializer.rb +1 -1
  25. data/test/dummy/app/controllers/articles_controller.rb +10 -0
  26. data/test/dummy/app/models/article.rb +2 -2
  27. data/test/dummy/app/models/wotsit.rb +4 -0
  28. data/test/dummy/config/environments/development.rb +1 -1
  29. data/test/dummy/config/routes.rb +1 -0
  30. data/test/functional/enabled_for_controller_test.rb +29 -0
  31. data/test/functional/modular_sinatra_test.rb +1 -1
  32. data/test/functional/sinatra_test.rb +1 -1
  33. data/test/test_helper.rb +2 -7
  34. data/test/unit/model_test.rb +56 -2
  35. data/test/unit/serializer_test.rb +6 -6
  36. data/test/unit/serializers/json_test.rb +7 -7
  37. data/test/unit/serializers/mixin_yaml_test.rb +1 -1
  38. data/test/unit/serializers/yaml_test.rb +8 -8
  39. data/test/unit/version_test.rb +41 -12
  40. metadata +45 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b667567a3273c0c6d95a75068b7d4e0b5d5c71ba
4
- data.tar.gz: 83853768990c1f61e1c9149bc275126254b87415
3
+ metadata.gz: 9bf681540718f57e237227b7237dd75588325471
4
+ data.tar.gz: 53ca44944999542128882287cfeb7a2a0c3957e6
5
5
  SHA512:
6
- metadata.gz: ba6c131b28bb5a060acdd08839cc53d58407961633389d53775ca0ff47d034964a5d192f56dc3e2315fd0bcd040439b06640120b316e65bfdd68acb9783e0099
7
- data.tar.gz: 1e546deade76f16dfd47a2414cf9d0d4021c45fa7d5bf2d825e62f79ba22cc04f0235102fd4c7708ea4f121e8ddedacbc07450ca74dc58c152161887368dc4e8
6
+ metadata.gz: 0c71e183ad7347c6d2a4202b8f4c5a00cfda6c8945a91edf325d5dbbde3c1458bee5e06cbf135deb3f33446038de435e51682d29b68b0aaf9fba77925c5e839b
7
+ data.tar.gz: 49fc4e1bc5e418bf1565749e8853f6516dc937fca663638da0a011dd47d6284dc53338cf479f6e8ad3ff74a7f53a93f168708108ce76a93c0474161c49d156d1
@@ -6,9 +6,6 @@ rvm:
6
6
  - jruby-19mode
7
7
  - jruby-18mode
8
8
 
9
- before_install:
10
- - gem install bundler --version '~> 1.3'
11
-
12
9
  gemfile:
13
10
  - Gemfile
14
11
  - gemfiles/3.0.gemfile
@@ -1,5 +1,18 @@
1
1
  ## 3.0.0 (Unreleased)
2
2
 
3
+ - [#289](https://github.com/airblade/paper_trail/pull/289) - Use `ActiveSupport::Concern` for implementation of base functionality on
4
+ `PaperTrail::Version` class. Increases flexibility and makes it easier to use custom version classes with multiple `ActiveRecord` connections.
5
+ - [#288](https://github.com/airblade/paper_trail/issues/288) - Change all scope declarations to class methods on the `PaperTrail::Version`
6
+ class. Fixes usability when `PaperTrail::Version.abstract_class? == true`.
7
+ - [#287](https://github.com/airblade/paper_trail/issues/287) - Support for
8
+ [PostgreSQL's JSON Type](http://www.postgresql.org/docs/9.2/static/datatype-json.html) for storing `object` and `object_changes`.
9
+ - [#281](https://github.com/airblade/paper_trail/issues/281) - `Rails::Controller` helper will return `false` for the
10
+ `paper_trail_enabled_for_controller` method if `PaperTrail.enabled? == false`.
11
+ - [#280](https://github.com/airblade/paper_trail/pull/280) - Don't track virtual timestamp attributes.
12
+ - [#278](https://github.com/airblade/paper_trail/issues/278)/[#272](https://github.com/airblade/paper_trail/issues/272) -
13
+ Make RSpec and Cucumber helpers usable with [Spork](https://github.com/sporkrb/spork) and [Zeus](https://github.com/burke/zeus).
14
+ - [#273](https://github.com/airblade/paper_trail/pull/273) - Make the `only` and `ignore` options accept `Hash` arguments;
15
+ allows for conditional tracking.
3
16
  - [#264](https://github.com/airblade/paper_trail/pull/264) - Allow unwrapped symbol to be passed in to the `on` option.
4
17
  - [#224](https://github.com/airblade/paper_trail/issues/224)/[#236](https://github.com/airblade/paper_trail/pull/236) -
5
18
  Fixed compatibility with [ActsAsTaggableOn](https://github.com/mbleigh/acts-as-taggable-on).
@@ -12,6 +25,8 @@
12
25
  - [#199](https://github.com/airblade/paper_trail/pull/199) - Rails 4 compatibility.
13
26
  - [#165](https://github.com/airblade/paper_trail/pull/165) - Namespaced the `Version` class under the `PaperTrail` module.
14
27
  - [#119](https://github.com/airblade/paper_trail/issues/119) - Support for [Sinatra](http://www.sinatrarb.com/); decoupled gem from `Rails`.
28
+ - Renamed the default serializers from `PaperTrail::Serializers::Yaml` and `PaperTrail::Serializers::Json` to the capitalized forms,
29
+ `PaperTrail::Serializers::YAML` and `PaperTrail::Serializers::JSON`.
15
30
 
16
31
  ## 2.7.2
17
32
 
data/README.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  PaperTrail lets you track changes to your models' data. It's good for auditing or versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed.
4
4
 
5
- There's an excellent [Railscast on implementing Undo with Paper Trail](http://railscasts.com/episodes/255-undo-with-paper-trail).
6
-
5
+ There's an excellent [RailsCast on implementing Undo with Paper Trail](http://railscasts.com/episodes/255-undo-with-paper-trail).
7
6
 
8
7
  ## Features
9
8
 
@@ -42,9 +41,9 @@ The Rails 2.3 code is on the [`rails2`](https://github.com/airblade/paper_trail/
42
41
 
43
42
  ### Rails 3 & 4
44
43
 
45
- 1. Install PaperTrail as a gem via your `Gemfile`:
44
+ 1. Add `PaperTrail` to your `Gemfile`.
46
45
 
47
- `gem 'paper_trail', '~> 3.0'`
46
+ `gem 'paper_trail', '>= 3.0.0.rc1'`
48
47
 
49
48
  2. Generate a migration which will add a `versions` table to your database.
50
49
 
@@ -58,6 +57,29 @@ The Rails 2.3 code is on the [`rails2`](https://github.com/airblade/paper_trail/
58
57
 
59
58
  ### Sinatra
60
59
 
60
+ In order to configure `PaperTrail` for usage with [`Sinatra`](http://www.sinatrarb.com), your Sinatra app must be using `ActiveRecord` 3 or greater.
61
+ It is also recommended to use the [`Sinatra ActiveRecord Extension`](https://github.com/janko-m/sinatra-activerecord) or something similar for managing
62
+ your applications `ActiveRecord` connection in a manner similar to the way `Rails` does. If using the aforementioned `Sinatra ActiveRecord Extension`,
63
+ steps for setting up your app with `PaperTrail` will look something like this:
64
+
65
+ 1. Add `PaperTrail` to your `Gemfile`.
66
+
67
+ `gem 'paper_trail', '>= 3.0.0.beta1'`
68
+
69
+ 2. Generate a migration to add a `versions` table to your database.
70
+
71
+ `bundle exec rake db:create_migration NAME=create_versions`
72
+
73
+ 3. Copy contents of [create_versions.rb](https://raw.github.com/airblade/paper_trail/master/lib/generators/paper_trail/templates/create_versions.rb)
74
+ into the `create_versions` migration that was generated into your `db/migrate` directory.
75
+
76
+ 4. Run the migration.
77
+
78
+ `bundle exec rake db:migrate`
79
+
80
+ 5. Add `has_paper_trail` to the models you want to track.
81
+
82
+
61
83
  PaperTrail provides a helper extension that acts similar to the controller mixin it provides for `Rails` applications.
62
84
 
63
85
  It will set `PaperTrail.whodunnit` to whatever is returned by a method named `user_for_paper_trail` which you can define inside your Sinatra Application. (by default it attempts to invoke a method named `current_user`)
@@ -69,7 +91,7 @@ If you're using the modular [Sinatra::Base](http://www.sinatrarb.com/intro.html#
69
91
  require 'sinatra/base'
70
92
 
71
93
  class BlehApp < Sinatra::Base
72
- register Sinatra::PaperTrail
94
+ register PaperTrail::Sinatra
73
95
  end
74
96
  ```
75
97
 
@@ -123,6 +145,7 @@ version.originator
123
145
  # Returns who changed the item from the state it had in this version.
124
146
  version.terminator
125
147
  version.whodunnit
148
+ version.version_author
126
149
 
127
150
  # Returns the next version.
128
151
  version.next
@@ -304,6 +327,31 @@ This means that only changes to the `title` will save a version of the article:
304
327
  >> a.previous_version.content # nil
305
328
  ```
306
329
 
330
+ The `:ignore` and `:only` options can also accept `Hash` arguments, where the :
331
+
332
+ ```ruby
333
+ class Article < ActiveRecord::Base
334
+ has_paper_trail :only => [:title => Proc.new { |obj| !obj.title.blank? } ]
335
+ end
336
+ ```
337
+
338
+ This means that if the `title` is not blank, then only changes to the `title` will save a version of the article:
339
+
340
+ ```ruby
341
+ >> a = Article.create
342
+ >> a.versions.length # 1
343
+ >> a.update_attributes :content => 'Hello'
344
+ >> a.versions.length # 2
345
+ >> a.update_attributes :title => 'My Title'
346
+ >> a.versions.length # 3
347
+ >> a.update_attributes :content => 'Hai'
348
+ >> a.versions.length # 3
349
+ >> a.previous_version.content # "Hello"
350
+ >> a.update_attributes :title => 'Dif Title'
351
+ >> a.versions.length # 4
352
+ >> a.previous_version.content # "Hai"
353
+ ```
354
+
307
355
  Passing both `:ignore` and `:only` options will result in the article being saved if a changed attribute is included in `:only` but not in `:ignore`.
308
356
 
309
357
  You can skip fields altogether with the `:skip` option. As with `:ignore`, updates to these fields will not create a new `PaperTrail::Version`. In addition, these fields will not be included in the serialized version of the object whenever a new `PaperTrail::Version` is created.
@@ -343,7 +391,7 @@ Undeleting is just as simple:
343
391
  >> widget = Widget.find 42
344
392
  >> widget.destroy
345
393
  # Time passes....
346
- >> widget = PaperTrail::Version.find(153).reify # the widget as it was before it was destroyed
394
+ >> widget = PaperTrail::Version.find(153).reify # the widget as it was before destruction
347
395
  >> widget.save # the widget lives!
348
396
  ```
349
397
 
@@ -356,11 +404,11 @@ You can call `previous_version` and `next_version` on an item to get it as it wa
356
404
 
357
405
  ```ruby
358
406
  >> live_widget = Widget.find 42
359
- >> live_widget.versions.length # 4 for example
360
- >> widget = live_widget.previous_version # => widget == live_widget.versions.last.reify
361
- >> widget = widget.previous_version # => widget == live_widget.versions[-2].reify
362
- >> widget = widget.next_version # => widget == live_widget.versions.last.reify
363
- >> widget.next_version # nil
407
+ >> live_widget.versions.length # 4 for example
408
+ >> widget = live_widget.previous_version # => widget == live_widget.versions.last.reify
409
+ >> widget = widget.previous_version # => widget == live_widget.versions[-2].reify
410
+ >> widget = widget.next_version # => widget == live_widget.versions.last.reify
411
+ >> widget.next_version # nil
364
412
  ```
365
413
 
366
414
  As an aside, I'm undecided about whether `widget.previous_version.next_version` should return `nil` or `self` (i.e. `widget`). Let me know if you have a view.
@@ -547,7 +595,7 @@ The implementation is complicated by the edge case where the parent and child ar
547
595
  The correct solution is to make PaperTrail aware of requests or transactions (c.f. [Efficiency's transaction ID middleware](http://github.com/efficiency20/ops_middleware/blob/master/lib/e20/ops/middleware/transaction_id_middleware.rb)). In the meantime we work around the problem by finding the child as it was a few seconds before the parent was updated. By default we go 3 seconds before but you can change this by passing the desired number of seconds to the `:has_one` option:
548
596
 
549
597
  ```ruby
550
- >> t = treasure.versions.last.reify(:has_one => 1) # look back 1 second instead of 3
598
+ >> t = treasure.versions.last.reify(:has_one => 1) # look back 1 second instead of 3
551
599
  ```
552
600
 
553
601
  If you are shuddering, take solace from knowing PaperTrail opts out of these shenanigans by default. This means your `:has_one` associated objects will be the live ones, not the ones the user saw at the time. Since PaperTrail doesn't auto-restore `:has_many` associations (I can't get it to work) or `:belongs_to` (I ran out of time looking at `:has_many`), this at least makes your associations wrong consistently ;)
@@ -655,7 +703,7 @@ module PaperTrail
655
703
  end
656
704
  ```
657
705
 
658
- Why would you do this? In this example, `author_id` is an attribute of `Article` and PaperTrail will store it anyway in serialized (YAML) form in the `object` column of the `version` record. But let's say you wanted to pull out all versions for a particular author; without the metadata you would have to deserialize (reify) each `version` object to see if belonged to the author in question. Clearly this is inefficient. Using the metadata you can find just those versions you want:
706
+ Why would you do this? In this example, `author_id` is an attribute of `Article` and PaperTrail will store it anyway in a serialized form in the `object` column of the `version` record. But let's say you wanted to pull out all versions for a particular author; without the metadata you would have to deserialize (reify) each `version` object to see if belonged to the author in question. Clearly this is inefficient. Using the metadata you can find just those versions you want:
659
707
 
660
708
  ```ruby
661
709
  PaperTrail::Version.all(:conditions => ['author_id = ?', author_id])
@@ -759,7 +807,7 @@ end
759
807
 
760
808
  ### Per request
761
809
 
762
- You can turn PaperTrail on or off per request by adding a `paper_trail_enabled_for_controller` method to your controller which returns true or false:
810
+ You can turn PaperTrail on or off per request by adding a `paper_trail_enabled_for_controller` method to your controller which returns `true` or `false`:
763
811
 
764
812
  ```ruby
765
813
  class ApplicationController < ActionController::Base
@@ -801,7 +849,7 @@ end
801
849
 
802
850
  ## Using a custom serializer
803
851
 
804
- By default, PaperTrail stores your changes as a YAML dump. You can override this with the serializer config option:
852
+ By default, PaperTrail stores your changes as a `YAML` dump. You can override this with the serializer config option:
805
853
 
806
854
  ```ruby
807
855
  >> PaperTrail.serializer = MyCustomSerializer
@@ -809,8 +857,8 @@ By default, PaperTrail stores your changes as a YAML dump. You can override this
809
857
 
810
858
  A valid serializer is a `module` (or `class`) that defines a `load` and `dump` method. These serializers are included in the gem for your convenience:
811
859
 
812
- * [Yaml](https://github.com/airblade/paper_trail/blob/master/lib/paper_trail/serializers/yaml.rb) - Default
813
- * [Json](https://github.com/airblade/paper_trail/blob/master/lib/paper_trail/serializers/json.rb)
860
+ * [YAML](https://github.com/airblade/paper_trail/blob/master/lib/paper_trail/serializers/yaml.rb) - Default
861
+ * [JSON](https://github.com/airblade/paper_trail/blob/master/lib/paper_trail/serializers/json.rb)
814
862
 
815
863
  ## Limiting the number of versions created per object instance
816
864
 
@@ -819,7 +867,8 @@ there is a configuration option that can be set to cap the number of versions sa
819
867
  versions other than `create` events (which will always be preserved if they are stored).
820
868
 
821
869
  ```ruby
822
- # will make it so that a maximum of 4 versions will be stored for each object (the 3 most recent ones plus a `create` event)
870
+ # will make it so that a maximum of 4 versions will be stored for each object
871
+ # (the 3 most recent ones plus a `create` event)
823
872
  >> PaperTrail.config.version_limit = 3
824
873
  # disables/removes the version limit
825
874
  >> PaperTrail.config.version_limit = nil
@@ -839,13 +888,13 @@ sql> delete from versions where created_at < 2010-06-01;
839
888
 
840
889
  ## Testing
841
890
 
842
- You may want to turn PaperTrail off to speed up your tests. See the [Turning PaperTrail Off/On](#turning-papertrail-offon) section above.
891
+ You may want to turn PaperTrail off to speed up your tests. See the [Turning PaperTrail Off/On](#turning-papertrail-offon) section above for tips on usage with `Test::Unit`.
843
892
 
844
893
  ### RSpec
845
894
 
846
- PaperTrail provides a helper that works with RSpec to make it easier to control when `PaperTrail` during testing. By default, PaperTrail will be
847
- turned off for all tests. When you wish to enable PaperTrail for a test you can either wrap the test in a `with_versioning` block, or pass
848
- in `:versioning => true` option to a spec block, like so:
895
+ PaperTrail provides a helper that works with [RSpec](https://github.com/rspec/rspec) to make it easier to control when `PaperTrail` is enabled
896
+ during testing. By default, PaperTrail will be turned off for all tests.
897
+ When you wish to enable PaperTrail for a test you can either wrap the test in a `with_versioning` block, or pass in `:versioning => true` option to a spec block, like so:
849
898
 
850
899
  ```ruby
851
900
  describe "RSpec test group" do
@@ -891,7 +940,7 @@ end
891
940
 
892
941
  ### Cucumber
893
942
 
894
- PaperTrail provides a helper that works similar to the RSpec helper.
943
+ PaperTrail provides a helper for [Cucumber](http://cukes.info) that works similar to the RSpec helper.
895
944
  By default, PaperTrail will be turned off for all scenarios by a `before` hook added by the helper.
896
945
  When you wish to enable PaperTrail for a scenario, you can wrap code in a `with_versioning` block in a step, like so:
897
946
 
@@ -906,8 +955,46 @@ end
906
955
  The helper will also reset the `PaperTrail.whodunnit` value to `nil` before each test to help prevent data spillover between tests.
907
956
  If you are using PaperTrail with Rails, the helper will automatically set the `PaperTrail.controller_info` value to `{}` as well, again, to help prevent data spillover between tests.
908
957
 
958
+ ### Spork
959
+
960
+ If you wish to use the `RSpec` or `Cucumber` helpers with [Spork](https://github.com/sporkrb/spork), you will need to
961
+ manually require the helper(s) in your `prefork` block on your test helper, like so:
962
+
963
+ ```ruby
964
+ # spec/spec_helper.rb
965
+
966
+ require 'spork'
967
+
968
+ Spork.prefork do
969
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
970
+ ENV["RAILS_ENV"] ||= 'test'
971
+ require File.expand_path("../../config/environment", __FILE__)
972
+ require 'rspec/rails'
973
+ require 'rspec/autorun'
974
+ require 'paper_trail/frameworks/rspec'
975
+ require 'paper_trail/frameworks/cucumber'
976
+ ...
977
+ end
978
+ ```
979
+
980
+ ### Zeus
981
+
982
+ If you wish to use the `RSpec` or `Cucumber` heleprs with [Zeus](https://github.com/burke/zeus), you will need to
983
+ manually require the helper(s) in your test helper, like so:
984
+
985
+ ```ruby
986
+ # spec/spec_helper.rb
987
+
988
+ ENV["RAILS_ENV"] ||= 'test'
989
+ require File.expand_path("../../config/environment", __FILE__)
990
+ require 'rspec/rails'
991
+ require 'paper_trail/frameworks/rspec'
992
+ ```
993
+
909
994
  ## Articles
910
995
 
996
+ [Using PaperTrail to track stack traces](http://rubyrailsexpert.com/?p=36), T James Corcoran's blog, 1st October 2013.
997
+ [RailsCast #255 - Undo with PaperTrail](http://railscasts.com/episodes/255-undo-with-paper-trail), 28th February 2011.
911
998
  [Keep a Paper Trail with PaperTrail](http://www.linux-mag.com/id/7528), Linux Magazine, 16th September 2009.
912
999
 
913
1000
 
@@ -960,11 +1047,13 @@ Many thanks to:
960
1047
  * [Ben Morrall](https://github.com/bmorrall)
961
1048
  * [Yves Senn](https://github.com/senny)
962
1049
  * [Ben Atkins](https://github.com/fullbridge-batkins)
963
- * [Yves Senn](https://github.com/senny)
964
1050
  * [Tyler Rick](https://github.com/TylerRick)
965
1051
  * [Bradley Priest](https://github.com/bradleypriest)
966
1052
  * [David Butler](https://github.com/dwbutler)
967
1053
  * [Paul Belt](https://github.com/belt)
1054
+ * [Vlad Bokov](https://github.com/razum2um)
1055
+ * [Sean Marcia](https://github.com/SeanMarcia)
1056
+ * [Chulki Lee](https://github.com/chulkilee)
968
1057
 
969
1058
 
970
1059
  ## Inspirations
data/Rakefile CHANGED
@@ -14,8 +14,5 @@ require 'rspec/core/rake_task'
14
14
  desc 'Run PaperTrail specs for the RSpec helper.'
15
15
  RSpec::Core::RakeTask.new(:spec)
16
16
 
17
- desc 'Run all available test suites'
18
- task :run_all_tests => [:test, :spec]
19
-
20
- desc 'Default: run unit tests.'
21
- task :default => :run_all_tests
17
+ desc 'Default: run all available test suites'
18
+ task :default => [:test, :spec]
@@ -17,7 +17,7 @@ module PaperTrail
17
17
  end
18
18
 
19
19
  def self.next_migration_number(dirname)
20
- ActiveRecord::Generators::Base.next_migration_number(dirname)
20
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
21
21
  end
22
22
  end
23
23
  end
@@ -2,8 +2,7 @@ require 'paper_trail/config'
2
2
  require 'paper_trail/has_paper_trail'
3
3
  require 'paper_trail/cleaner'
4
4
 
5
- # Require all frameworks and serializers
6
- Dir[File.join(File.dirname(__FILE__), 'paper_trail', 'frameworks', '*.rb')].each { |file| require file }
5
+ # Require serializers
7
6
  Dir[File.join(File.dirname(__FILE__), 'paper_trail', 'serializers', '*.rb')].each { |file| require file }
8
7
 
9
8
  # PaperTrail's module methods can be called in both models and controllers.
@@ -80,7 +79,7 @@ module PaperTrail
80
79
  end
81
80
 
82
81
  def self.active_record_protected_attributes?
83
- @active_record_protected_attributes ||= ActiveRecord::VERSION::STRING.to_f < 4.0 || defined?(ProtectedAttributes)
82
+ @active_record_protected_attributes ||= ::ActiveRecord::VERSION::STRING.to_f < 4.0 || !!defined?(ProtectedAttributes)
84
83
  end
85
84
 
86
85
  private
@@ -102,8 +101,22 @@ module PaperTrail
102
101
 
103
102
  end
104
103
 
104
+ # Ensure `ProtectedAttributes` gem gets required if it is available before the `Version` class gets loaded in
105
+ unless PaperTrail.active_record_protected_attributes?
106
+ PaperTrail.send(:remove_instance_variable, :@active_record_protected_attributes)
107
+ begin
108
+ require 'protected_attributes'
109
+ rescue LoadError; end # will rescue if `ProtectedAttributes` gem is not available
110
+ end
111
+
105
112
  require 'paper_trail/version'
106
113
 
114
+ # Require frameworks
115
+ require 'paper_trail/frameworks/rails'
116
+ require 'paper_trail/frameworks/sinatra'
117
+ require 'paper_trail/frameworks/rspec' if defined? RSpec
118
+ require 'paper_trail/frameworks/cucumber' if defined? World
119
+
107
120
  ActiveSupport.on_load(:active_record) do
108
121
  include PaperTrail::Model
109
122
  end
@@ -8,7 +8,7 @@ module PaperTrail
8
8
  def initialize
9
9
  @enabled = true # Indicates whether PaperTrail is on or off.
10
10
  @timestamp_field = :created_at
11
- @serializer = PaperTrail::Serializers::Yaml
11
+ @serializer = PaperTrail::Serializers::YAML
12
12
  end
13
13
  end
14
14
  end
@@ -1,31 +1,29 @@
1
- if defined? World
2
- # before hook for Cucumber
3
- before do
4
- ::PaperTrail.enabled = false
5
- ::PaperTrail.whodunnit = nil
6
- ::PaperTrail.controller_info = {} if defined? ::Rails
7
- end
1
+ # before hook for Cucumber
2
+ before do
3
+ ::PaperTrail.enabled = false
4
+ ::PaperTrail.whodunnit = nil
5
+ ::PaperTrail.controller_info = {} if defined? ::Rails
6
+ end
8
7
 
9
- module PaperTrail
10
- module Cucumber
11
- module Extensions
12
- # :call-seq:
13
- # with_versioning
14
- #
15
- # enable versioning for specific blocks
8
+ module PaperTrail
9
+ module Cucumber
10
+ module Extensions
11
+ # :call-seq:
12
+ # with_versioning
13
+ #
14
+ # enable versioning for specific blocks
16
15
 
17
- def with_versioning
18
- was_enabled = ::PaperTrail.enabled?
19
- ::PaperTrail.enabled = true
20
- begin
21
- yield
22
- ensure
23
- ::PaperTrail.enabled = was_enabled
24
- end
16
+ def with_versioning
17
+ was_enabled = ::PaperTrail.enabled?
18
+ ::PaperTrail.enabled = true
19
+ begin
20
+ yield
21
+ ensure
22
+ ::PaperTrail.enabled = was_enabled
25
23
  end
26
24
  end
27
25
  end
28
26
  end
29
-
30
- World PaperTrail::Cucumber::Extensions
31
27
  end
28
+
29
+ World PaperTrail::Cucumber::Extensions
@@ -47,7 +47,7 @@ module PaperTrail
47
47
  # Override this method in your controller to specify when PaperTrail should
48
48
  # be off.
49
49
  def paper_trail_enabled_for_controller
50
- true
50
+ ::PaperTrail.enabled?
51
51
  end
52
52
 
53
53
  private