-
Notifications
You must be signed in to change notification settings - Fork 899
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
Fix get version data with full name of class #996
Fix get version data with full name of class #996
Conversation
Hi @chimame, thanks for the contribution! Please include:
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes requested
ad06cc2
to
ebe3766
Compare
ebe3766
to
3f714e7
Compare
It would be great if we could do a test without introducing any new AR models; we already have so many. |
Hi @jaredbeck, Thank you for reviewing. What's going on? Do you mean that we want you to create a test without creating a new AR? |
Yes. Currently this PR adds five new tables to the test suite. Please add fewer tables, if possible. Thanks! |
Let me know if you need help with getting the tests to pass. |
Thank you for following me. |
Please review once again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thanks! Only one minor change: "mentor" instead of "menter".
spec/dummy_app/app/models/family.rb
Outdated
module Family | ||
def self.table_name_prefix | ||
"family_" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! I didn't know about this method. I will be able to use this at work.
expect(previous_children.parent.name).to eq "parent1" | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for testing all four association types.
belongs_to :parent, class_name: "Family::Person", foreign_key: :parent_id | ||
end | ||
if ActiveRecord.gem_version >= Gem::Version.new("5.0") | ||
belongs_to :menter, class_name: "Family::Person", foreign_key: :partner_id, optional: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Mentor" is the correct spelling. English is silly.
Actually, I think we can delete the |
Hmmm ... bad news. I can apply the following patch and all tests pass, including your new tests. diff --git a/lib/paper_trail/reifiers/belongs_to.rb b/lib/paper_trail/reifiers/belongs_to.rb
index 483f791..3ff54b8 100644
--- a/lib/paper_trail/reifiers/belongs_to.rb
+++ b/lib/paper_trail/reifiers/belongs_to.rb
@@ -37,7 +37,7 @@ module PaperTrail
# @api private
def load_version(assoc, id, transaction_id, version_at)
assoc.klass.paper_trail.version_class.
- where("item_type = ?", assoc.klass.name).
+ where("item_type = ?", assoc.class_name).
where("item_id = ?", id).
where("created_at >= ? OR transaction_id = ?", version_at, transaction_id).
order("id").limit(1).first
diff --git a/lib/paper_trail/reifiers/has_many.rb b/lib/paper_trail/reifiers/has_many.rb
index 2c1c2c7..486acb2 100644
--- a/lib/paper_trail/reifiers/has_many.rb
+++ b/lib/paper_trail/reifiers/has_many.rb
@@ -98,7 +98,7 @@ module PaperTrail
select("MIN(version_id)").
where("foreign_key_name = ?", assoc.foreign_key).
where("foreign_key_id = ?", model.id).
- where("#{version_table}.item_type = ?", assoc.klass.name).
+ where("#{version_table}.item_type = ?", assoc.class_name).
where("created_at >= ? OR transaction_id = ?", version_at, tx_id).
group("item_id").
to_sql
diff --git a/lib/paper_trail/reifiers/has_many_through.rb b/lib/paper_trail/reifiers/has_many_through.rb
index af24206..fac4ef9 100644
--- a/lib/paper_trail/reifiers/has_many_through.rb
+++ b/lib/paper_trail/reifiers/has_many_through.rb
@@ -73,7 +73,7 @@ module PaperTrail
def load_versions_for_hmt_association(assoc, ids, tx_id, version_at)
version_id_subquery = assoc.klass.paper_trail.version_class.
select("MIN(id)").
- where("item_type = ?", assoc.klass.name).
+ where("item_type = ?", assoc.class_name).
where("item_id IN (?)", ids).
where(
"created_at >= ? OR transaction_id = ?",
diff --git a/lib/paper_trail/reifiers/has_one.rb b/lib/paper_trail/reifiers/has_one.rb
index 85b96b7..ad66112 100644
--- a/lib/paper_trail/reifiers/has_one.rb
+++ b/lib/paper_trail/reifiers/has_one.rb
@@ -36,7 +36,7 @@ module PaperTrail
model.class.paper_trail.version_class.joins(:version_associations).
where("version_associations.foreign_key_name = ?", assoc.foreign_key).
where("version_associations.foreign_key_id = ?", model.id).
- where("#{version_table_name}.item_type = ?", assoc.klass.name).
+ where("#{version_table_name}.item_type = ?", assoc.class_name).
where("created_at >= ? OR transaction_id = ?", version_at, transaction_id).
order("#{version_table_name}.id ASC").
first Assuming I'm running the test suite correctly, this means that your new tests do not actually demonstrate a problem. What am I missing? |
I'm sorry.
It can not be deleted. |
The directory name |
I want the tests to fail when I apply this patch. Are you ready for me to perform that experiment? Thanks! |
The test will fail if the specified patch is applied. please make sure. |
When I apply the patch, the tests fail. Thanks! |
Released as |
I avoid using `let` and `before` unless necessary.
When a record is inserted into the `versions` table, it is given an `item_type` like `Foo::Bar`, but the association reification queries were searching for an `item_type` like `::Foo::Bar`.
I avoid using `let` and `before` unless necessary.
Overview
Unable to acquire association history of model name including module name.
Impact point
It can be reproduced in the following cases.
This happens because
item_type
does not include the module name when acquiring an association.