Stabilize the build 💚 #37
Conversation
|
@chubchenko This is a great PR, thank you! I'm new to this repo but PTAT is currently preventing me from upgrading to Rails 7 so I was looking into this specific issue. @westonganger has a WIP PR (#36) which overlaps a lot with this one. In case this helps getting either PR merged, here are two key differences: # lib/paper_trail-association_tracking.rb
if defined?(Rails)
require "paper_trail/frameworks/active_record"
require "paper_trail_association_tracking/frameworks/rails"
+ elsif defined?(ActiveRecord)
+ require "paper_trail/frameworks/active_record"
+ require "paper_trail_association_tracking/frameworks/active_record"Any idea why is needed? @chubchenko's PR doesn't add these 3 lines: is the test suite supposed to catch an issue or are these lines superfluous? In if ActiveRecord::VERSION::MAJOR >= 7
callback = lambda do |*args|
update_habtm_state(assoc_name, :"before_#{verb}", args[-2], args.last)
end
)It seems like the way @chubchenko rewrote |
|
@KevinBongart Good catch 👍. Regarding callbacks, actually, it stays the same: Before # verb => `add` and `remove`
lambda do |*args|
update_habtm_state(assoc_name, :"before_#{verb}", args[-2], args.last)
endAfter before_add_callback = lambda do |*args|
update_habtm_state(association_name, :before_add, args[-2], args.last)
end
before_remove_callback = lambda do |*args|
update_habtm_state(association_name, :before_remove, args[-2], args.last)
endNot so long ago I have tried the same solution as in the @westonganger PR but my build was failed because of those lines @model_class.send(
assoc.macro, assoc_name, **assoc.options.merge("before_{verb}" => callback)
)Those lines declare the same association one more time but with additional options (callback). In rails way it will be something like this: class User < ApplicationRecord
# defined by the application
has_many :posts
# defined by ptat
has_many :posts, before_add: callback
endTo fix that problem I have found the |
|
This is great, thank you so much for the detailed explanation! I'll take a look at adding tests for a Rails-less ActiveRecord app. In the meantime, I've created this PR for updating the appraisal config: chubchenko#4 |
|
@chubchenko thank you so much for your explanation of the build issue #37 (comment) I have decided to go with my existing PR (#36) because of how I had already structured the test suite. Sorry I did not want to go through curating all those changes once again. Once again big thanks to @chubchenko for your stellar work here! The community will be forever in your debt. |
#to_prepare(ofPaperTrailAssociationTracking::VersionConcern) instead ofincludepaper_trail_association_trackingafterpaper_trailsetup_habtm_change_callbacksmethod to make it compatible with all versions of rails (due to this fix rails/rails@bfcac13)Sorry I haven't tested this in my application and probably and I won't be able to do it in the near future due to the war in Ukraine 🇺🇦
Feel free to add all needed changes