You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In an example such as the following, PT-AT fails to reify the students association, always returning the latest result as if .reify() was called without has_many: true.
This is demonstrated in the following bug report script:
Bug Report Script
### Bug Report Templaterequire"bundler/inline"# STEP ONE: What versions are you using?gemfile(true)doruby"2.6"source"https://rubygems.org"gem"activerecord","6.0.2"gem"minitest"gem"paper_trail","~>10.3.0"gem"paper_trail-association_tracking"gem"sqlite3"endrequire"active_record"require"minitest/autorun"require"logger"# Please use sqlite for your bug reports, if possible.ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=nilActiveRecord::Schema.definedo# STEP TWO: Define your tables here.create_table:individuals,force: truedo |t|
t.text:name,null: falset.text:flag,null: falset.string:type,null: falset.timestampsnull: falseendcreate_table:studentships,force: truedo |t|
t.integer:teacher_id,null: falset.integer:student_id,null: falset.timestampsnull: falseendcreate_table:versionsdo |t|
t.string:item_type,null: falset.integer:item_id,null: falset.string:event,null: falset.string:whodunnitt.text:object,limit: 1_073_741_823t.text:object_changes,limit: 1_073_741_823t.integer:transaction_idt.datetime:created_atendadd_index:versions,%i[item_typeitem_id]add_index:versions,[:transaction_id]create_table:version_associationsdo |t|
t.integer:version_idt.string:foreign_key_name,null: falset.integer:foreign_key_idt.string:foreign_type# NOTE: bug report template is out of date, this wasn't in there :) endadd_index:version_associations,[:version_id]add_index:version_associations,%i[foreign_key_nameforeign_key_idforeign_type],name: "index_version_associations_on_foreign_key"endActiveRecord::Base.logger=Logger.new(STDOUT)require"paper_trail"require"paper_trail-association_tracking"PaperTrail.config.track_associations=true# STEP FOUR: Define your AR models here.classIndividual < ActiveRecord::Basehas_paper_trailendclassTeacher < Individualhas_many:students,class_name: "Studentship"endclassProfessor < TeacherendclassStudent < IndividualendclassStudentship < ActiveRecord::Basebelongs_to:teacherbelongs_to:studenthas_paper_trailend# STEP FIVE: Please write a test that demonstrates your issue.classBugTest < ActiveSupport::TestCasedeftest_stiteach1=Professor.create!(name: "Prof. Alice",flag: "v1")# Flag is used to trigger a new versionstudent1=Student.create!(name: "Mr Student",flag: "v1")student2=Student.create!(name: "Miss Student",flag: "v1")teach1.students.create!(student: student1)teach1.updateflag: "v2"teach1.students.destroy_allteach1.updateflag: "v3"teach1.students.create!(student: student2)restore_version=->(idx){teach1.versions[idx].reify(has_many: true)}# v1 - Prof. Alice should have one student - Mr Studentv1=restore_version.call(1)assert_equal1,v1.students.sizeassert_equalstudent1,v1.students.first.student# v2 - Prof. Alice should have NO studentsv2=restore_version.call(2)assert_equal0,v2.students.size# v3 - Prof. Alice should have one student - Miss Studentv3=teach1assert_equal1,v3.students.sizeassert_equalstudent2,v3.students.first.studentendend# STEP SIX: Run this script using `ruby my_bug_report.rb`# Error log:# 1) Failure:# BugTest#test_sti [my_bug_report copy.rb:114]:# --- expected# +++ actual# @@ -1 +1 @@# -#<Student id: 2, name: "Mr Student", flag: "v1", type: "Student", created_at: "2021-01-01 11:10:53", updated_at: "2021-01-01 11:10:53"># +#<Student id: 3, name: "Miss Student", flag: "v1", type: "Student", created_at: "2021-01-01 11:10:53", updated_at: "2021-01-01 11:10:53">
I have a functional PR that addresses this issue that I will be submitting momentarily, just working on the tests.
The text was updated successfully, but these errors were encountered:
JaciBrunning
added a commit
to JaciBrunning/paper_trail-association_tracking
that referenced
this issue
Jan 1, 2021
In an example such as the following, PT-AT fails to reify the
students
association, always returning the latest result as if.reify()
was called withouthas_many: true
.This is demonstrated in the following bug report script:
Bug Report Script
I have a functional PR that addresses this issue that I will be submitting momentarily, just working on the tests.
The text was updated successfully, but these errors were encountered: