paper_trail 5.2.3 → 11.0.0

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 (198) hide show
  1. checksums.yaml +5 -5
  2. data/lib/generators/paper_trail/install/USAGE +3 -0
  3. data/lib/generators/paper_trail/install/install_generator.rb +75 -0
  4. data/lib/generators/paper_trail/{templates/add_object_changes_to_versions.rb → install/templates/add_object_changes_to_versions.rb.erb} +1 -1
  5. data/lib/generators/paper_trail/install/templates/create_versions.rb.erb +36 -0
  6. data/lib/generators/paper_trail/migration_generator.rb +38 -0
  7. data/lib/generators/paper_trail/update_item_subtype/USAGE +4 -0
  8. data/lib/generators/paper_trail/update_item_subtype/templates/update_versions_for_item_subtype.rb.erb +85 -0
  9. data/lib/generators/paper_trail/update_item_subtype/update_item_subtype_generator.rb +17 -0
  10. data/lib/paper_trail.rb +82 -130
  11. data/lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb +27 -0
  12. data/lib/paper_trail/attribute_serializers/cast_attribute_serializer.rb +15 -44
  13. data/lib/paper_trail/attribute_serializers/object_attribute.rb +2 -0
  14. data/lib/paper_trail/attribute_serializers/object_changes_attribute.rb +2 -0
  15. data/lib/paper_trail/cleaner.rb +3 -1
  16. data/lib/paper_trail/compatibility.rb +51 -0
  17. data/lib/paper_trail/config.rb +11 -49
  18. data/lib/paper_trail/events/base.rb +323 -0
  19. data/lib/paper_trail/events/create.rb +32 -0
  20. data/lib/paper_trail/events/destroy.rb +42 -0
  21. data/lib/paper_trail/events/update.rb +60 -0
  22. data/lib/paper_trail/frameworks/active_record.rb +2 -1
  23. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version.rb +8 -3
  24. data/lib/paper_trail/frameworks/cucumber.rb +5 -3
  25. data/lib/paper_trail/frameworks/rails.rb +2 -0
  26. data/lib/paper_trail/frameworks/rails/controller.rb +33 -43
  27. data/lib/paper_trail/frameworks/rails/engine.rb +34 -1
  28. data/lib/paper_trail/frameworks/rspec.rb +17 -4
  29. data/lib/paper_trail/frameworks/rspec/helpers.rb +2 -0
  30. data/lib/paper_trail/has_paper_trail.rb +22 -310
  31. data/lib/paper_trail/model_config.rb +157 -109
  32. data/lib/paper_trail/queries/versions/where_object.rb +65 -0
  33. data/lib/paper_trail/queries/versions/where_object_changes.rb +75 -0
  34. data/lib/paper_trail/record_history.rb +3 -9
  35. data/lib/paper_trail/record_trail.rb +169 -319
  36. data/lib/paper_trail/reifier.rb +53 -374
  37. data/lib/paper_trail/request.rb +166 -0
  38. data/lib/paper_trail/serializers/json.rb +9 -10
  39. data/lib/paper_trail/serializers/yaml.rb +15 -28
  40. data/lib/paper_trail/type_serializers/postgres_array_serializer.rb +48 -0
  41. data/lib/paper_trail/version_concern.rb +160 -155
  42. data/lib/paper_trail/version_number.rb +12 -4
  43. metadata +77 -372
  44. data/.github/CONTRIBUTING.md +0 -109
  45. data/.github/ISSUE_TEMPLATE.md +0 -13
  46. data/.gitignore +0 -23
  47. data/.rspec +0 -2
  48. data/.rubocop.yml +0 -99
  49. data/.rubocop_todo.yml +0 -22
  50. data/.travis.yml +0 -41
  51. data/Appraisals +0 -38
  52. data/CHANGELOG.md +0 -560
  53. data/Gemfile +0 -2
  54. data/MIT-LICENSE +0 -20
  55. data/README.md +0 -1654
  56. data/Rakefile +0 -30
  57. data/doc/bug_report_template.rb +0 -69
  58. data/doc/warning_about_not_setting_whodunnit.md +0 -32
  59. data/gemfiles/ar3.gemfile +0 -19
  60. data/gemfiles/ar4.gemfile +0 -8
  61. data/gemfiles/ar5.gemfile +0 -9
  62. data/lib/generators/paper_trail/USAGE +0 -2
  63. data/lib/generators/paper_trail/default_initializer.rb +0 -0
  64. data/lib/generators/paper_trail/install_generator.rb +0 -57
  65. data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb +0 -13
  66. data/lib/generators/paper_trail/templates/create_version_associations.rb +0 -22
  67. data/lib/generators/paper_trail/templates/create_versions.rb +0 -80
  68. data/lib/paper_trail/attribute_serializers/legacy_active_record_shim.rb +0 -48
  69. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb +0 -11
  70. data/lib/paper_trail/frameworks/sinatra.rb +0 -40
  71. data/lib/paper_trail/version_association_concern.rb +0 -17
  72. data/paper_trail.gemspec +0 -56
  73. data/spec/generators/install_generator_spec.rb +0 -66
  74. data/spec/generators/paper_trail/templates/create_versions_spec.rb +0 -51
  75. data/spec/models/animal_spec.rb +0 -36
  76. data/spec/models/boolit_spec.rb +0 -48
  77. data/spec/models/callback_modifier_spec.rb +0 -96
  78. data/spec/models/car_spec.rb +0 -13
  79. data/spec/models/custom_primary_key_record_spec.rb +0 -18
  80. data/spec/models/fluxor_spec.rb +0 -17
  81. data/spec/models/gadget_spec.rb +0 -68
  82. data/spec/models/joined_version_spec.rb +0 -47
  83. data/spec/models/json_version_spec.rb +0 -102
  84. data/spec/models/kitchen/banana_spec.rb +0 -14
  85. data/spec/models/not_on_update_spec.rb +0 -22
  86. data/spec/models/post_with_status_spec.rb +0 -50
  87. data/spec/models/skipper_spec.rb +0 -46
  88. data/spec/models/thing_spec.rb +0 -11
  89. data/spec/models/truck_spec.rb +0 -5
  90. data/spec/models/vehicle_spec.rb +0 -5
  91. data/spec/models/version_spec.rb +0 -272
  92. data/spec/models/widget_spec.rb +0 -343
  93. data/spec/modules/paper_trail_spec.rb +0 -27
  94. data/spec/modules/version_concern_spec.rb +0 -31
  95. data/spec/modules/version_number_spec.rb +0 -43
  96. data/spec/paper_trail/config_spec.rb +0 -33
  97. data/spec/paper_trail_spec.rb +0 -79
  98. data/spec/rails_helper.rb +0 -34
  99. data/spec/requests/articles_spec.rb +0 -34
  100. data/spec/spec_helper.rb +0 -114
  101. data/spec/support/alt_db_init.rb +0 -54
  102. data/test/custom_json_serializer.rb +0 -13
  103. data/test/dummy/Rakefile +0 -7
  104. data/test/dummy/app/controllers/application_controller.rb +0 -33
  105. data/test/dummy/app/controllers/articles_controller.rb +0 -20
  106. data/test/dummy/app/controllers/test_controller.rb +0 -5
  107. data/test/dummy/app/controllers/widgets_controller.rb +0 -32
  108. data/test/dummy/app/helpers/application_helper.rb +0 -2
  109. data/test/dummy/app/models/animal.rb +0 -6
  110. data/test/dummy/app/models/article.rb +0 -24
  111. data/test/dummy/app/models/authorship.rb +0 -5
  112. data/test/dummy/app/models/bar_habtm.rb +0 -4
  113. data/test/dummy/app/models/book.rb +0 -9
  114. data/test/dummy/app/models/boolit.rb +0 -4
  115. data/test/dummy/app/models/callback_modifier.rb +0 -45
  116. data/test/dummy/app/models/car.rb +0 -3
  117. data/test/dummy/app/models/cat.rb +0 -2
  118. data/test/dummy/app/models/chapter.rb +0 -9
  119. data/test/dummy/app/models/citation.rb +0 -5
  120. data/test/dummy/app/models/custom_primary_key_record.rb +0 -13
  121. data/test/dummy/app/models/customer.rb +0 -4
  122. data/test/dummy/app/models/document.rb +0 -4
  123. data/test/dummy/app/models/dog.rb +0 -2
  124. data/test/dummy/app/models/editor.rb +0 -4
  125. data/test/dummy/app/models/editorship.rb +0 -5
  126. data/test/dummy/app/models/elephant.rb +0 -3
  127. data/test/dummy/app/models/fluxor.rb +0 -3
  128. data/test/dummy/app/models/foo_habtm.rb +0 -5
  129. data/test/dummy/app/models/foo_widget.rb +0 -2
  130. data/test/dummy/app/models/fruit.rb +0 -5
  131. data/test/dummy/app/models/gadget.rb +0 -3
  132. data/test/dummy/app/models/kitchen/banana.rb +0 -5
  133. data/test/dummy/app/models/legacy_widget.rb +0 -4
  134. data/test/dummy/app/models/line_item.rb +0 -4
  135. data/test/dummy/app/models/not_on_update.rb +0 -4
  136. data/test/dummy/app/models/order.rb +0 -5
  137. data/test/dummy/app/models/paragraph.rb +0 -5
  138. data/test/dummy/app/models/person.rb +0 -38
  139. data/test/dummy/app/models/post.rb +0 -3
  140. data/test/dummy/app/models/post_with_status.rb +0 -8
  141. data/test/dummy/app/models/protected_widget.rb +0 -3
  142. data/test/dummy/app/models/quotation.rb +0 -5
  143. data/test/dummy/app/models/section.rb +0 -6
  144. data/test/dummy/app/models/skipper.rb +0 -6
  145. data/test/dummy/app/models/song.rb +0 -41
  146. data/test/dummy/app/models/thing.rb +0 -3
  147. data/test/dummy/app/models/translation.rb +0 -4
  148. data/test/dummy/app/models/truck.rb +0 -4
  149. data/test/dummy/app/models/vehicle.rb +0 -4
  150. data/test/dummy/app/models/whatchamajigger.rb +0 -4
  151. data/test/dummy/app/models/widget.rb +0 -16
  152. data/test/dummy/app/models/wotsit.rb +0 -8
  153. data/test/dummy/app/versions/custom_primary_key_record_version.rb +0 -3
  154. data/test/dummy/app/versions/joined_version.rb +0 -6
  155. data/test/dummy/app/versions/json_version.rb +0 -3
  156. data/test/dummy/app/versions/kitchen/banana_version.rb +0 -5
  157. data/test/dummy/app/versions/post_version.rb +0 -3
  158. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  159. data/test/dummy/config.ru +0 -4
  160. data/test/dummy/config/application.rb +0 -80
  161. data/test/dummy/config/boot.rb +0 -10
  162. data/test/dummy/config/database.mysql.yml +0 -19
  163. data/test/dummy/config/database.postgres.yml +0 -15
  164. data/test/dummy/config/database.sqlite.yml +0 -15
  165. data/test/dummy/config/environment.rb +0 -5
  166. data/test/dummy/config/environments/development.rb +0 -41
  167. data/test/dummy/config/environments/production.rb +0 -74
  168. data/test/dummy/config/environments/test.rb +0 -51
  169. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -9
  170. data/test/dummy/config/initializers/inflections.rb +0 -10
  171. data/test/dummy/config/initializers/mime_types.rb +0 -5
  172. data/test/dummy/config/initializers/paper_trail.rb +0 -9
  173. data/test/dummy/config/initializers/secret_token.rb +0 -9
  174. data/test/dummy/config/initializers/session_store.rb +0 -8
  175. data/test/dummy/config/locales/en.yml +0 -5
  176. data/test/dummy/config/routes.rb +0 -4
  177. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +0 -361
  178. data/test/dummy/db/schema.rb +0 -288
  179. data/test/dummy/script/rails +0 -8
  180. data/test/functional/controller_test.rb +0 -90
  181. data/test/functional/enabled_for_controller_test.rb +0 -28
  182. data/test/functional/modular_sinatra_test.rb +0 -46
  183. data/test/functional/sinatra_test.rb +0 -51
  184. data/test/functional/thread_safety_test.rb +0 -46
  185. data/test/test_helper.rb +0 -127
  186. data/test/time_travel_helper.rb +0 -1
  187. data/test/unit/associations_test.rb +0 -1016
  188. data/test/unit/cleaner_test.rb +0 -188
  189. data/test/unit/inheritance_column_test.rb +0 -43
  190. data/test/unit/model_test.rb +0 -1489
  191. data/test/unit/protected_attrs_test.rb +0 -52
  192. data/test/unit/serializer_test.rb +0 -119
  193. data/test/unit/serializers/json_test.rb +0 -95
  194. data/test/unit/serializers/mixin_json_test.rb +0 -37
  195. data/test/unit/serializers/mixin_yaml_test.rb +0 -53
  196. data/test/unit/serializers/yaml_test.rb +0 -54
  197. data/test/unit/timestamp_test.rb +0 -41
  198. data/test/unit/version_test.rb +0 -119
@@ -1,79 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe PaperTrail do
4
- context "when enabled" do
5
- it "affects all threads" do
6
- Thread.new { PaperTrail.enabled = false }.join
7
- assert_equal false, PaperTrail.enabled?
8
- end
9
-
10
- after do
11
- PaperTrail.enabled = true
12
- end
13
- end
14
-
15
- context "default" do
16
- it "should have versioning off by default" do
17
- expect(PaperTrail).not_to be_enabled
18
- end
19
-
20
- it "should turn versioning on in a `with_versioning` block" do
21
- expect(PaperTrail).not_to be_enabled
22
- with_versioning do
23
- expect(PaperTrail).to be_enabled
24
- end
25
- expect(PaperTrail).not_to be_enabled
26
- end
27
-
28
- context "error within `with_versioning` block" do
29
- it "should revert the value of `PaperTrail.enabled?` to it's previous state" do
30
- expect(PaperTrail).not_to be_enabled
31
- expect { with_versioning { raise } }.to raise_error(RuntimeError)
32
- expect(PaperTrail).not_to be_enabled
33
- end
34
- end
35
- end
36
-
37
- context "`versioning: true`", versioning: true do
38
- it "should have versioning on by default" do
39
- expect(PaperTrail).to be_enabled
40
- end
41
-
42
- it "should keep versioning on after a with_versioning block" do
43
- expect(PaperTrail).to be_enabled
44
- with_versioning do
45
- expect(PaperTrail).to be_enabled
46
- end
47
- expect(PaperTrail).to be_enabled
48
- end
49
- end
50
-
51
- context "`with_versioning` block at class level" do
52
- it { expect(PaperTrail).not_to be_enabled }
53
-
54
- with_versioning do
55
- it "should have versioning on by default" do
56
- expect(PaperTrail).to be_enabled
57
- end
58
- end
59
- it "should not leak the `enabled?` state into successive tests" do
60
- expect(PaperTrail).not_to be_enabled
61
- end
62
- end
63
-
64
- describe :whodunnit do
65
- before(:all) { PaperTrail.whodunnit = "foobar" }
66
-
67
- it "should get set to `nil` by default" do
68
- expect(PaperTrail.whodunnit).to be_nil
69
- end
70
- end
71
-
72
- describe :controller_info do
73
- before(:all) { ::PaperTrail.controller_info = { foo: "bar" } }
74
-
75
- it "should get set to an empty hash before each test" do
76
- expect(PaperTrail.controller_info).to eq({})
77
- end
78
- end
79
- end
@@ -1,34 +0,0 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV["RAILS_ENV"] ||= "test"
3
- ENV["DB"] ||= "sqlite"
4
-
5
- unless File.exist?(File.expand_path("../../test/dummy/config/database.yml", __FILE__))
6
- warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
7
- end
8
-
9
- require "spec_helper"
10
- require File.expand_path("../../test/dummy/config/environment", __FILE__)
11
- require "rspec/rails"
12
- require "paper_trail/frameworks/rspec"
13
- require "ffaker"
14
- require "timecop"
15
-
16
- # prevent Test::Unit's AutoRunner from executing during RSpec's rake task
17
- Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)
18
-
19
- # Checks for pending migrations before tests are run.
20
- # If you are not using ActiveRecord, you can remove this line.
21
- ActiveRecord::Migration.check_pending! if ActiveRecord::Migration.respond_to?(:check_pending!)
22
-
23
- RSpec.configure do |config|
24
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
25
-
26
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
27
- # examples within a transaction, remove the following line or assign false
28
- # instead of true.
29
- config.use_transactional_fixtures = true
30
-
31
- # The different available types are documented in the features, such as in
32
- # https://relishapp.com/rspec/rspec-rails/docs
33
- # config.infer_spec_type_from_file_location!
34
- end
@@ -1,34 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe "Articles management", type: :request, order: :defined do
4
- let(:valid_params) { { article: { title: "Doh", content: FFaker::Lorem.sentence } } }
5
-
6
- context "versioning disabled" do
7
- specify { expect(PaperTrail).not_to be_enabled }
8
-
9
- it "should not create a version" do
10
- expect(PaperTrail).to be_enabled_for_controller
11
- expect {
12
- post articles_path, params_wrapper(valid_params)
13
- }.to_not change(PaperTrail::Version, :count)
14
- end
15
-
16
- it "should not leak the state of the `PaperTrail.enabled_for_controller?` into the next test" do
17
- expect(PaperTrail).to be_enabled_for_controller
18
- end
19
- end
20
-
21
- with_versioning do
22
- let(:article) { Article.last }
23
-
24
- context "`current_user` method returns a `String`" do
25
- it "should set that value as the `whodunnit`" do
26
- expect {
27
- post articles_path, params_wrapper(valid_params)
28
- }.to change(PaperTrail::Version, :count).by(1)
29
- expect(article.title).to eq("Doh")
30
- expect(article.versions.last.whodunnit).to eq("foobar")
31
- end
32
- end
33
- end
34
- end
@@ -1,114 +0,0 @@
1
- require "pry-nav"
2
-
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
- # file to always be loaded, without a need to explicitly require it in any files.
7
- #
8
- # Given that it is always loaded, you are encouraged to keep this file as
9
- # light-weight as possible. Requiring heavyweight dependencies from this file
10
- # will add to the boot time of your test suite on EVERY test run, even for an
11
- # individual file that may not need all of that loaded. Instead, consider making
12
- # a separate helper file that requires the additional dependencies and performs
13
- # the additional setup, and require it from the spec files that actually need it.
14
- #
15
- # The `.rspec` file also contains a few flags that are not defaults but that
16
- # users commonly want.
17
- #
18
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
- RSpec.configure do |config|
20
- # rspec-expectations config goes here. You can use an alternate
21
- # assertion/expectation library such as wrong or the stdlib/minitest
22
- # assertions if you prefer.
23
- config.expect_with :rspec do |expectations|
24
- # This option will default to `true` in RSpec 4. It makes the `description`
25
- # and `failure_message` of custom matchers include text for helper methods
26
- # defined using `chain`, e.g.:
27
- # be_bigger_than(2).and_smaller_than(4).description
28
- # # => "be bigger than 2 and smaller than 4"
29
- # ...rather than:
30
- # # => "be bigger than 2"
31
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
- end
33
-
34
- # rspec-mocks config goes here. You can use an alternate test double
35
- # library (such as bogus or mocha) by changing the `mock_with` option here.
36
- config.mock_with :rspec do |mocks|
37
- # Prevents you from mocking or stubbing a method that does not exist on
38
- # a real object. This is generally recommended, and will default to
39
- # `true` in RSpec 4.
40
- mocks.verify_partial_doubles = true
41
- end
42
-
43
- # Support for disabling `verify_partial_doubles` on specific examples.
44
- config.around(:each, verify_stubs: false) do |ex|
45
- config.mock_with :rspec do |mocks|
46
- mocks.verify_partial_doubles = false
47
- ex.run
48
- mocks.verify_partial_doubles = true
49
- end
50
- end
51
-
52
- # The settings below are suggested to provide a good initial experience
53
- # with RSpec, but feel free to customize to your heart's content.
54
-
55
- # These two settings work together to allow you to limit a spec run
56
- # to individual examples or groups you care about by tagging them with
57
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
58
- # get run.
59
- # config.filter_run :focus
60
- # config.run_all_when_everything_filtered = true
61
-
62
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
63
- # For more details, see:
64
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
65
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
67
- # config.disable_monkey_patching!
68
-
69
- # This setting enables warnings. It's recommended, but in some cases may
70
- # be too noisy due to issues in dependencies.
71
- # config.warnings = true
72
-
73
- # Many RSpec users commonly either run the entire suite or an individual
74
- # file, and it's useful to allow more verbose output when running an
75
- # individual spec file.
76
- # if config.files_to_run.one?
77
- # # Use the documentation formatter for detailed output,
78
- # # unless a formatter has already been configured
79
- # # (e.g. via a command-line flag).
80
- # config.default_formatter = 'doc'
81
- # end
82
-
83
- # Print the 10 slowest examples and example groups at the
84
- # end of the spec run, to help surface which specs are running
85
- # particularly slow.
86
- # config.profile_examples = 10
87
-
88
- # Run specs in random order to surface order dependencies. If you find an
89
- # order dependency and want to debug it, you can fix the order by providing
90
- # the seed, which is printed after each run.
91
- # --seed 1234
92
- # config.order = :random
93
-
94
- # Seed global randomization in this process using the `--seed` CLI option.
95
- # Setting this allows you to use `--seed` to deterministically reproduce
96
- # test failures related to randomization by passing the same `--seed` value
97
- # as the one that triggered the failure.
98
- # Kernel.srand config.seed
99
- end
100
-
101
- def active_record_gem_version
102
- Gem::Version.new(ActiveRecord::VERSION::STRING)
103
- end
104
-
105
- # Wrap args in a hash to support the ActionController::TestCase and
106
- # ActionDispatch::Integration HTTP request method switch to keyword args
107
- # (see https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md)
108
- def params_wrapper(args)
109
- if defined?(::Rails) && active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
110
- { params: args }
111
- else
112
- args
113
- end
114
- end
@@ -1,54 +0,0 @@
1
- # This file copies the test database into locations for the `Foo` and `Bar` namespace,
2
- # then defines those namespaces, then establishes the sqlite3 connection for the namespaces
3
- # to simulate an application with multiple database connections.
4
-
5
- # Load database yaml to use
6
- configs = YAML.load_file("#{Rails.root}/config/database.yml")
7
-
8
- # If we are testing with sqlite make it quick
9
- db_directory = "#{Rails.root}/db"
10
-
11
- # Set up alternate databases
12
- if ENV["DB"] == "sqlite"
13
- FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
14
- FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
15
- end
16
-
17
- module Foo
18
- class Base < ActiveRecord::Base
19
- self.abstract_class = true
20
- end
21
-
22
- class Version < Base
23
- include PaperTrail::VersionConcern
24
- end
25
-
26
- class Document < Base
27
- has_paper_trail class_name: "Foo::Version"
28
- end
29
- end
30
-
31
- Foo::Base.configurations = configs
32
- Foo::Base.establish_connection(:foo)
33
- ActiveRecord::Base.establish_connection(:foo)
34
- ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__)
35
-
36
- module Bar
37
- class Base < ActiveRecord::Base
38
- self.abstract_class = true
39
- end
40
-
41
- class Version < Base
42
- include PaperTrail::VersionConcern
43
- end
44
-
45
- class Document < Base
46
- has_paper_trail class_name: "Bar::Version"
47
- end
48
- end
49
-
50
- Bar::Base.configurations = configs
51
- Bar::Base.establish_connection(:bar)
52
- ActiveRecord::Base.establish_connection(:bar)
53
-
54
- ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__)
@@ -1,13 +0,0 @@
1
- # This custom serializer excludes nil values
2
- module CustomJsonSerializer
3
- extend PaperTrail::Serializers::JSON
4
-
5
- def self.load(string)
6
- parsed_value = super(string)
7
- parsed_value.is_a?(Hash) ? parsed_value.reject { |k, v| k.blank? || v.blank? } : parsed_value
8
- end
9
-
10
- def self.dump(object)
11
- object.is_a?(Hash) ? super(object.reject { |_k, v| v.nil? }) : super
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path("../config/application", __FILE__)
5
- require "rake"
6
-
7
- Dummy::Application.load_tasks
@@ -1,33 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
-
4
- # Rails 5 deprecates `before_filter`
5
- name_of_before_callback = respond_to?(:before_action) ? :before_action : :before_filter
6
-
7
- # Some applications and libraries modify `current_user`. Their changes need
8
- # to be reflected in `whodunnit`, so the `set_paper_trail_whodunnit` below
9
- # must happen after this.
10
- send(name_of_before_callback, :modify_current_user)
11
-
12
- # Going forward, we'll no longer add this `before_filter`, requiring people
13
- # to do so themselves, allowing them to control the order in which this filter
14
- # happens.
15
- send(name_of_before_callback, :set_paper_trail_whodunnit)
16
-
17
- def rescue_action(e)
18
- raise e
19
- end
20
-
21
- # Returns id of hypothetical current user
22
- attr_reader :current_user
23
-
24
- def info_for_paper_trail
25
- { ip: request.remote_ip, user_agent: request.user_agent }
26
- end
27
-
28
- private
29
-
30
- def modify_current_user
31
- @current_user = OpenStruct.new(id: 153)
32
- end
33
- end
@@ -1,20 +0,0 @@
1
- class ArticlesController < ApplicationController
2
- def create
3
- @article = Article.create article_params
4
- head :ok
5
- end
6
-
7
- def current_user
8
- "foobar"
9
- end
10
-
11
- private
12
-
13
- def article_params
14
- if PaperTrail.active_record_protected_attributes?
15
- params[:article]
16
- else
17
- params.require(:article).permit!
18
- end
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- class TestController < ActionController::Base
2
- def user_for_paper_trail
3
- Thread.current.object_id
4
- end
5
- end
@@ -1,32 +0,0 @@
1
- class WidgetsController < ApplicationController
2
- def paper_trail_enabled_for_controller
3
- request.user_agent != "Disable User-Agent"
4
- end
5
-
6
- def create
7
- @widget = Widget.create widget_params
8
- head :ok
9
- end
10
-
11
- def update
12
- @widget = Widget.find params[:id]
13
- @widget.update_attributes widget_params
14
- head :ok
15
- end
16
-
17
- def destroy
18
- @widget = Widget.find params[:id]
19
- @widget.destroy
20
- head :ok
21
- end
22
-
23
- private
24
-
25
- def widget_params
26
- if PaperTrail.active_record_protected_attributes?
27
- params[:widget]
28
- else
29
- params[:widget].permit!
30
- end
31
- end
32
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,6 +0,0 @@
1
- class Animal < ActiveRecord::Base
2
- has_paper_trail
3
- self.inheritance_column = "species"
4
-
5
- attr_accessible :species, :name if ::PaperTrail.active_record_protected_attributes?
6
- end