mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
812c306892
I'm hoping we don't actually need it because we explicitly enable fractional seconds precision in our `dummy_app` migration by specifying `limit(6)`. Works on my machine, but I use mariadb. We'll see how well it works on TravisCI, which runs mysql 5.6.33. MySQL added support for `limit(6)` in 5.6.4, so I'm hopeful.
81 lines
2.9 KiB
Ruby
81 lines
2.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "spec_helper"
|
|
|
|
module Family
|
|
RSpec.describe Family, type: :model, versioning: true do
|
|
describe "#reify" do
|
|
context "belongs_to" do
|
|
it "uses the correct item_type in queries" do
|
|
parent = described_class.new(name: "parent1")
|
|
parent.children.build(name: "child1")
|
|
parent.save!
|
|
parent.update_attributes!(
|
|
name: "parent2",
|
|
children_attributes: { id: parent.children.first.id, name: "child2" }
|
|
)
|
|
last_child_version = parent.children.first.versions.last
|
|
|
|
# We expect `reify` to look for item_type 'Family::Family', not
|
|
# '::Family::Family'. See PR #996
|
|
previous_children = last_child_version.reify(belongs_to: true)
|
|
expect(previous_children.parent.name).to eq "parent1"
|
|
end
|
|
end
|
|
|
|
context "has_many" do
|
|
it "uses the correct item_type in queries" do
|
|
parent = described_class.new(name: "parent1")
|
|
parent.children.build(name: "child1")
|
|
parent.save!
|
|
parent.name = "parent2"
|
|
parent.children.build(name: "child2")
|
|
parent.save!
|
|
|
|
# We expect `reify` to look for item_type 'Family::Family', not
|
|
# '::Family::Family'. See PR #996
|
|
previous_parent = parent.versions.last.reify(has_many: true)
|
|
previous_children = previous_parent.children
|
|
expect(previous_children.size).to eq 1
|
|
expect(previous_children.first.name).to eq "child1"
|
|
end
|
|
end
|
|
|
|
context "has_many through" do
|
|
it "uses the correct item_type in queries" do
|
|
parent = described_class.new(name: "parent1")
|
|
parent.grandsons.build(name: "grandson1")
|
|
parent.save!
|
|
parent.name = "parent2"
|
|
parent.grandsons.build(name: "grandson2")
|
|
parent.save!
|
|
|
|
# We expect `reify` to look for item_type 'Family::Family', not
|
|
# '::Family::Family'. See PR #996
|
|
previous_parent = parent.versions.last.reify(has_many: true)
|
|
previous_grandsons = previous_parent.grandsons
|
|
expect(previous_grandsons.size).to eq 1
|
|
expect(previous_grandsons.first.name).to eq "grandson1"
|
|
end
|
|
end
|
|
|
|
context "has_one" do
|
|
it "uses the correct item_type in queries" do
|
|
parent = described_class.new(name: "parent1")
|
|
parent.build_mentee(name: "partner1")
|
|
parent.save!
|
|
parent.update_attributes(
|
|
name: "parent2",
|
|
mentee_attributes: { id: parent.mentee.id, name: "partner2" }
|
|
)
|
|
|
|
# We expect `reify` to look for item_type 'Family::Family', not
|
|
# '::Family::Family'. See PR #996
|
|
previous_parent = parent.versions.last.reify(has_one: true)
|
|
previous_partner = previous_parent.mentee
|
|
expect(previous_partner.name).to eq "partner1"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|