Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The slow and gentle removal of PT-AT is complete #1221

Merged
merged 1 commit into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ RSpec/DescribedClass:
RSpec/ExampleLength:
Enabled: false

RSpec/FilePath:
Exclude:
- spec/paper_trail/association_reify_error_behaviour/error.rb
- spec/paper_trail/association_reify_error_behaviour/warn.rb
- spec/paper_trail/association_reify_error_behaviour/ignore.rb

# In an ideal world, each example has a single expectation. In the real world,
# sometimes setup is a pain and you don't want to duplicate setup in multiple
# examples, or make the specs more confusing with many nested `context`s, and
Expand Down
9 changes: 0 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,8 @@ RSpec/HooksBeforeExamples:
- spec/paper_trail/request_spec.rb
- spec/paper_trail_spec.rb

RSpec/InstanceVariable:
Exclude:
- spec/paper_trail/associations/belongs_to_spec.rb
- spec/paper_trail/associations/habtm_spec.rb
- spec/paper_trail/associations/has_many_through_spec.rb

RSpec/NestedGroups:
Exclude:
- spec/paper_trail/associations/belongs_to_spec.rb
- spec/paper_trail/associations/habtm_spec.rb
- spec/paper_trail/associations/has_many_through_spec.rb
- spec/paper_trail/model_spec.rb

# It may be possible for us to use safe_load, but we'd have to pass the
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ are welcome.
| 2 | 2.7-stable | >= 1.8.7 | >= 3.0, < 4 |
| 1 | rails2 | >= 1.8.7 | >= 2.3, < 3 |

Experts: to install incompatible versions of activerecord, see
Experts: to install incompatible versions of activerecord, see
`paper_trail/compatibility.rb`.

### 1.b. Installation
Expand All @@ -109,7 +109,7 @@ Experts: to install incompatible versions of activerecord, see
1. Add a `versions` table to your database:

```
bundle exec rails generate paper_trail:install [--with-changes] [--with-associations]
bundle exec rails generate paper_trail:install [--with-changes]
```

For more information on this generator, see [section 5.c.
Expand Down Expand Up @@ -889,17 +889,19 @@ string, please try the [paper_trail-globalid][37] gem.

To track and reify associations, use [paper_trail-association_tracking][6] (PT-AT).

From 2014 to 2018, association tracking was part of PT core as an experimental
feature, but many issues were discovered. To attract new volunteers to address
these issues, PT-AT was extracted (see
https://github.com/paper-trail-gem/paper_trail/issues/1070).
From 2014 to 2018, association tracking was an experimental feature, but many
issues were discovered. To attract new volunteers to address these issues, PT-AT
was extracted (see https://github.com/paper-trail-gem/paper_trail/issues/1070).

Even though this has always been an experimental feature, we don't want the
extraction of PT-AT to be a breaking change. In PT 9, PT-AT was kept as a
runtime dependency. In PT 10, it is a development dependency, so if you use it
you must add it to your own `Gemfile`. We will keep PT-AT as a development
dependency and continue running the existing tests related to association
tracking for as long as is practical.
Even though it had always been an experimental feature, we didn't want the
extraction of PT-AT to be a breaking change, so great care was taken to remove
it slowly.

- In PT 9, PT-AT was kept as a runtime dependency.
- In PT 10, it became a development dependency (If you use it you must add it to
your own `Gemfile`) and we kept running all of its tests.
- In PT 11, it will no longer be a development dependency, and it is responsible
for its own tests.

#### 4.b.1 The optional `item_subtype` column

Expand Down Expand Up @@ -1225,7 +1227,7 @@ add_column :versions, :new_object, :jsonb # or :json

PaperTrail::Version.where.not(object: nil).find_each do |version|
version.update_column(:new_object, YAML.load(version.object))

# if version.object_changes
# version.update_column(
# :new_object_changes,
Expand Down
33 changes: 0 additions & 33 deletions lib/paper_trail/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ module PaperTrail
class Config
include Singleton

E_PT_AT_REMOVED = <<-EOS.squish
Association Tracking for PaperTrail has been extracted to a separate gem.
To use it, please add `paper_trail-association_tracking` to your Gemfile.
If you don't use it (most people don't, that's the default) and you set
`track_associations = false` somewhere (probably a rails initializer) you
can remove that line now.
EOS

attr_accessor(
:association_reify_error_behaviour,
:object_changes_adapter,
Expand All @@ -43,30 +35,5 @@ def enabled
def enabled=(enable)
@mutex.synchronize { @enabled = enable }
end

# In PT 10, the paper_trail-association_tracking gem was changed from a
# runtime dependency to a development dependency. We raise an error about
# this for the people who don't read changelogs.
#
# We raise a generic RuntimeError instead of a specific PT error class
# because there is no known use case where someone would want to rescue
# this. If we think of such a use case in the future we can revisit this
# decision.
#
# @override If PT-AT is `require`d, it will replace this method with its
# own implementation.
def track_associations=(value)
if value
raise E_PT_AT_REMOVED
else
::Kernel.warn(E_PT_AT_REMOVED)
end
end

# @override If PT-AT is `require`d, it will replace this method with its
# own implementation.
def track_associations?
raise E_PT_AT_REMOVED
end
end
end
10 changes: 0 additions & 10 deletions lib/paper_trail/version_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,8 @@ def object_deserialized

# Restore the item from this version.
#
# Optionally this can also restore all :has_one and :has_many (including
# has_many :through) associations as they were "at the time", if they are
# also being versioned by PaperTrail.
#
# Options:
#
# - :has_one
# - `true` - Also reify has_one associations.
# - `false - Default.
# - :has_many
# - `true` - Also reify has_many and has_many :through associations.
# - `false` - Default.
# - :mark_for_destruction
# - `true` - Mark the has_one/has_many associations that did not exist in
# the reified version for destruction, instead of removing them.
Expand Down
6 changes: 0 additions & 6 deletions spec/dummy_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
Bundler.require(:default, Rails.env)
require "paper_trail"

# As of PT 10, PT-AT is a development dependency in paper_trail.gemspec
# https://github.com/paper-trail-gem/paper_trail/issues/1070
# https://github.com/westonganger/paper_trail-association_tracking/issues/2
# https://github.com/westonganger/paper_trail-association_tracking/issues/7
require "paper_trail-association_tracking"

module Dummy
class Application < Rails::Application
config.encoding = "utf-8"
Expand Down
3 changes: 0 additions & 3 deletions spec/dummy_app/config/initializers/paper_trail.rb

This file was deleted.

11 changes: 0 additions & 11 deletions spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ def up
end
add_index :versions, %i[item_type item_id]

create_table :version_associations do |t|
t.integer :version_id
t.string :foreign_key_name, null: false
t.integer :foreign_key_id
t.string :foreign_type, null: false
end
add_index :version_associations, [:version_id]
add_index :version_associations,
%i[foreign_key_name foreign_key_id foreign_type],
name: "index_version_associations_on_foreign_key"

create_table :post_versions, force: true do |t|
t.string :item_type, null: false
t.integer :item_id, null: false
Expand Down
81 changes: 0 additions & 81 deletions spec/models/family/family_spec.rb

This file was deleted.

20 changes: 0 additions & 20 deletions spec/models/pet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@
person.update(name: "Peter")

expect(person.reload.versions.length).to(eq(3))

second_version = person.reload.versions.second.reify(has_many: true)
expect(second_version.pets.length).to(eq(2))
expect(second_version.animals.length).to(eq(2))
expect(second_version.animals.map { |a| a.class.name }).to(eq(%w[Dog Cat]))
expect(second_version.pets.map { |p| p.animal.class.name }).to(eq(%w[Dog Cat]))
expect(second_version.animals.first.name).to(eq("Snoopy"))
expect(second_version.dogs.first.name).to(eq("Snoopy"))
expect(second_version.animals.second.name).to(eq("Garfield"))
expect(second_version.cats.first.name).to(eq("Garfield"))

last_version = person.reload.versions.last.reify(has_many: true)
expect(last_version.pets.length).to(eq(2))
expect(last_version.animals.length).to(eq(2))
expect(last_version.animals.map { |a| a.class.name }).to(eq(%w[Dog Cat]))
expect(last_version.pets.map { |p| p.animal.class.name }).to(eq(%w[Dog Cat]))
expect(last_version.animals.first.name).to(eq("Beethoven"))
expect(last_version.dogs.first.name).to(eq("Beethoven"))
expect(last_version.animals.second.name).to(eq("Sylvester"))
expect(last_version.cats.first.name).to(eq("Sylvester"))
end

context "Older version entry present where item_type refers to the base_class" do
Expand Down
40 changes: 0 additions & 40 deletions spec/paper_trail/association_reify_error_behaviour/error_spec.rb

This file was deleted.

40 changes: 0 additions & 40 deletions spec/paper_trail/association_reify_error_behaviour/ignore_spec.rb

This file was deleted.

Loading