Uninstall timecop

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.
This commit is contained in:
Jared Beck 2018-05-14 22:31:12 -04:00
parent e0fbe0d1b6
commit 812c306892
13 changed files with 25 additions and 120 deletions

View File

@ -66,7 +66,7 @@ DB=sqlite bundle exec rake prepare
# We can't use `appraisal` inside the dummy app, so we must set `BUNDLE_GEMFILE`.
# See spec/dummy_app/config/boot.rb for a complete explanation.
cd spec/dummy_app
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
export BUNDLE_GEMFILE=../../gemfiles/ar_5.2.gemfile
RAILS_ENV=test bundle exec rake db:environment:set db:setup
RAILS_ENV=foo bundle exec rake db:environment:set db:setup
RAILS_ENV=bar bundle exec rake db:environment:set db:setup
@ -74,7 +74,7 @@ unset BUNDLE_GEMFILE
cd ../..
# Run tests
DB=sqlite bundle exec appraisal ar-5.0 rake
DB=sqlite bundle exec appraisal ar-5.2 rake
```
### Test mysql, AR 5
@ -88,15 +88,15 @@ DB=mysql bundle exec rake prepare
# We can't use `appraisal` inside the dummy app, so we must set `BUNDLE_GEMFILE`.
# See spec/dummy_app/config/boot.rb for a complete explanation.
cd spec/dummy_app
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
RAILS_ENV=test bundle exec rake db:environment:set db:setup
RAILS_ENV=foo bundle exec rake db:environment:set db:setup
RAILS_ENV=bar bundle exec rake db:environment:set db:setup
export BUNDLE_GEMFILE=../../gemfiles/ar_5.2.gemfile
RAILS_ENV=test bundle exec rake db:setup db:environment:set
RAILS_ENV=foo bundle exec rake db:setup db:environment:set
RAILS_ENV=bar bundle exec rake db:setup db:environment:set
unset BUNDLE_GEMFILE
cd ../..
# Run tests
DB=mysql bundle exec appraisal ar-5.0 rake
DB=mysql bundle exec appraisal ar-5.2 rake
```
### Test postgres, AR 5
@ -111,7 +111,7 @@ DB=postgres bundle exec rake prepare
# We can't use `appraisal` inside the dummy app, so we must set `BUNDLE_GEMFILE`.
# See spec/dummy_app/config/boot.rb for a complete explanation.
cd spec/dummy_app
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
export BUNDLE_GEMFILE=../../gemfiles/ar_5.2.gemfile
DB=postgres RAILS_ENV=test bundle exec rake db:environment:set db:drop db:create db:migrate
DB=postgres RAILS_ENV=foo bundle exec rake db:environment:set db:drop db:create db:migrate
DB=postgres RAILS_ENV=bar bundle exec rake db:environment:set db:drop db:create db:migrate
@ -120,7 +120,7 @@ cd ../..
# Run tests
DB=postgres bundle exec rake
DB=postgres bundle exec appraisal ar-5.0 rake
DB=postgres bundle exec appraisal ar-5.2 rake
```
## Editing the migration

View File

@ -42,5 +42,4 @@ has been destroyed.
s.add_development_dependency "rubocop", "~> 0.56.0"
s.add_development_dependency "rubocop-rspec", "~> 1.25.1"
s.add_development_dependency "sqlite3", "~> 1.3"
s.add_development_dependency "timecop", "~> 0.9.1"
end

View File

@ -10,7 +10,6 @@ module Family
parent = described_class.new(name: "parent1")
parent.children.build(name: "child1")
parent.save!
Timecop.travel(1.second.since)
parent.update_attributes!(
name: "parent2",
children_attributes: { id: parent.children.first.id, name: "child2" }
@ -29,7 +28,6 @@ module Family
parent = described_class.new(name: "parent1")
parent.children.build(name: "child1")
parent.save!
Timecop.travel(1.second.since)
parent.name = "parent2"
parent.children.build(name: "child2")
parent.save!
@ -48,7 +46,6 @@ module Family
parent = described_class.new(name: "parent1")
parent.grandsons.build(name: "grandson1")
parent.save!
Timecop.travel(1.second.since)
parent.name = "parent2"
parent.grandsons.build(name: "grandson2")
parent.save!
@ -67,7 +64,6 @@ module Family
parent = described_class.new(name: "parent1")
parent.build_mentee(name: "partner1")
parent.save!
Timecop.travel(1.second.since)
parent.update_attributes(
name: "parent2",
mentee_attributes: { id: parent.mentee.id, name: "partner2" }

View File

@ -27,10 +27,7 @@ RSpec.describe NotOnUpdate, type: :model do
it "increments the `:updated_at` timestamp" do
before = record.updated_at
allow(::ActiveSupport::Deprecation).to receive(:warn)
# Travel 1 second because MySQL lacks sub-second resolution
Timecop.travel(1) do
record.paper_trail.touch_with_version
end
record.paper_trail.touch_with_version
expect(::ActiveSupport::Deprecation).to have_received(:warn).once
expect(record.updated_at).to be > before
end

View File

@ -36,7 +36,6 @@ RSpec.describe PostWithStatus, type: :model do
post = described_class.create(status: :draft)
expect(post.versions.count).to eq(1)
expect(post.status).to eq("draft")
Timecop.travel 1.second.since # because MySQL lacks fractional seconds precision
allow(::ActiveSupport::Deprecation).to receive(:warn)
post.paper_trail.touch_with_version
expect(::ActiveSupport::Deprecation).to have_received(:warn).once

View File

@ -42,10 +42,7 @@ RSpec.describe Widget, type: :model do
it "resets value for timestamp attrs for update so that value gets updated properly" do
widget.update_attributes!(name: "Foobar")
w = widget.versions.last.reify
# Travel 1 second because MySQL lacks sub-second resolution
Timecop.travel(1) do
expect { w.save! }.to change(w, :updated_at)
end
expect { w.save! }.to change(w, :updated_at)
end
end
@ -234,9 +231,7 @@ RSpec.describe Widget, type: :model do
it "creates a version" do
allow(::ActiveSupport::Deprecation).to receive(:warn)
count = widget.versions.size
Timecop.travel(1) do
widget.paper_trail.touch_with_version
end
widget.paper_trail.touch_with_version
expect(widget.versions.size).to eq(count + 1)
expect(::ActiveSupport::Deprecation).to have_received(:warn).once
end
@ -244,10 +239,7 @@ RSpec.describe Widget, type: :model do
it "increments the `:updated_at` timestamp" do
allow(::ActiveSupport::Deprecation).to receive(:warn)
time_was = widget.updated_at
# Travel 1 second because MySQL lacks sub-second resolution
Timecop.travel(1) do
widget.paper_trail.touch_with_version
end
widget.paper_trail.touch_with_version
expect(widget.updated_at).to be > time_was
expect(::ActiveSupport::Deprecation).to have_received(:warn).once
end
@ -275,13 +267,11 @@ RSpec.describe Widget, type: :model do
it "creates a version record" do
widget = Widget.create
expect(widget.versions.count).to eq(1)
Timecop.freeze Time.now do
widget.paper_trail.update_columns(name: "Bugle")
expect(widget.versions.count).to eq(2)
expect(widget.versions.last.event).to(eq("update"))
expect(widget.versions.last.changeset[:name]).to eq([nil, "Bugle"])
expect(widget.versions.last.created_at.to_i).to eq(Time.now.to_i)
end
widget.paper_trail.update_columns(name: "Bugle")
expect(widget.versions.count).to eq(2)
expect(widget.versions.last.event).to(eq("update"))
expect(widget.versions.last.changeset[:name]).to eq([nil, "Bugle"])
expect(widget.versions.last.created_at.to_i).to eq(Time.now.to_i)
end
end

View File

@ -3,17 +3,12 @@
require "spec_helper"
RSpec.describe(::PaperTrail, versioning: true) do
after do
Timecop.return
end
context "wotsit belongs_to widget" do
before { @widget = Widget.create(name: "widget_0") }
context "where the association is created between model versions" do
before do
@wotsit = Wotsit.create(name: "wotsit_0")
Timecop.travel(1.second.since)
@wotsit.update_attributes(widget_id: @widget.id, name: "wotsit_1")
end
@ -33,7 +28,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
before do
@widget.update_attributes(name: "widget_1")
@widget.update_attributes(name: "widget_2")
Timecop.travel(1.second.since)
@wotsit.update_attributes(name: "wotsit_2")
@widget.update_attributes(name: "widget_3")
end
@ -92,7 +86,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "and then the model is updated" do
before do
Timecop.travel(1.second.since)
@wotsit.update_attributes(name: "wotsit_3")
end
@ -110,7 +103,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "where the association is changed between model versions" do
before do
@wotsit = @widget.create_wotsit(name: "wotsit_0")
Timecop.travel(1.second.since)
@new_widget = Widget.create(name: "new_widget")
@wotsit.update_attributes(widget_id: @new_widget.id, name: "wotsit_1")
end

View File

@ -3,14 +3,9 @@
require "spec_helper"
RSpec.describe(::PaperTrail, versioning: true) do
after do
Timecop.return
end
context "foo and bar" do
before do
@foo = FooHabtm.create(name: "foo")
Timecop.travel(1.second.since)
end
context "where the association is created between model versions" do
@ -36,7 +31,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "where the association is changed between model versions" do
before do
@foo.update_attributes(name: "foo2", bar_habtms: [BarHabtm.create(name: "bar2")])
Timecop.travel(1.second.since)
@foo.update_attributes(name: "foo3", bar_habtms: [BarHabtm.create(name: "bar3")])
end
@ -66,7 +60,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "where the association is destroyed between model versions" do
before do
@foo.update_attributes(name: "foo2", bar_habtms: [BarHabtm.create(name: "bar2")])
Timecop.travel(1.second.since)
@foo.update_attributes(name: "foo3", bar_habtms: [])
end
@ -89,9 +82,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
before do
@bar = BarHabtm.create(name: "bar2")
@foo.update_attributes(name: "foo2", bar_habtms: [@bar])
Timecop.travel(1.second.since)
@foo.update_attributes(name: "foo3", bar_habtms: [BarHabtm.create(name: "bar4")])
Timecop.travel(1.second.since)
@bar.update_attributes(name: "bar3")
end
@ -114,7 +105,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "updated via nested attributes" do
before do
@foo = FooHabtm.create(name: "foo", bar_habtms_attributes: [{ name: "bar" }])
Timecop.travel(1.second.since)
@foo.update_attributes(
name: "foo2",
bar_habtms_attributes: [{ id: @foo.bar_habtms.first.id, name: "bar2" }]

View File

@ -3,10 +3,6 @@
require "spec_helper"
RSpec.describe(::PaperTrail, versioning: true) do
after do
Timecop.return
end
describe "customer, reified from version before order created" do
it "has no orders" do
customer = Customer.create(name: "customer_0")
@ -32,7 +28,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the expected order" do
customer = Customer.create(name: "customer_0")
customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
customer0 = customer.versions.last.reify(has_many: true)
expect(customer0.orders.map(&:order_date)).to(eq(["order_date_0"]))
@ -43,7 +38,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the expected line item" do
customer = Customer.create(name: "customer_0")
order = customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
order.line_items.create!(product: "product_0")
customer0 = customer.versions.last.reify(has_many: true)
@ -55,11 +49,9 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the updated order_date" do
customer = Customer.create(name: "customer_0")
order = customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
order.update_attributes(order_date: "order_date_1")
order.update_attributes(order_date: "order_date_2")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_2")
order.update_attributes(order_date: "order_date_3")
customer1 = customer.versions.last.reify(has_many: true)
@ -73,11 +65,9 @@ RSpec.describe(::PaperTrail, versioning: true) do
# TODO: This can be tested with fewer db records
customer = Customer.create(name: "customer_0")
order = customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
order.update_attributes(order_date: "order_date_1")
order.update_attributes(order_date: "order_date_2")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_2")
order.update_attributes(order_date: "order_date_3")
customer1 = customer.versions.last.reify(has_many: false)
@ -90,11 +80,9 @@ RSpec.describe(::PaperTrail, versioning: true) do
# TODO: This can be tested with fewer db records
customer = Customer.create(name: "customer_0")
order = customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
order.update_attributes(order_date: "order_date_1")
order.update_attributes(order_date: "order_date_2")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_2")
order.update_attributes(order_date: "order_date_3")
order.destroy
@ -108,7 +96,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the order" do
customer = Customer.create(name: "customer_0")
order = customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
order.destroy
customer1 = customer.versions.last.reify(has_many: true)
@ -121,10 +108,8 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "does not have the order" do
customer = Customer.create(name: "customer_0")
order = customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
order.destroy
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_2")
customer1 = customer.versions.last.reify(has_many: true)
expect(customer1.orders).to(eq([]))
@ -135,7 +120,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the old order_date" do
customer = Customer.create(name: "customer_0")
customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
customer.orders.create!(order_date: "order_date_1")
customer0 = customer.versions.last.reify(has_many: true)
@ -150,7 +134,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has both orders, and the second is marked for destruction" do
customer = Customer.create(name: "customer_0")
customer.orders.create!(order_date: "order_date_0")
Timecop.travel(1.second.since)
customer.update_attributes(name: "customer_1")
customer.orders.create!(order_date: "order_date_1")
customer0 = customer.versions.last.reify(has_many: true, mark_for_destruction: true)

View File

@ -18,10 +18,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
"Alice's Evidence"
].freeze
after do
Timecop.return
end
context "Books, Authors, and Authorships" do
before { @book = Book.create(title: "book_0") }
@ -61,7 +57,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "updated before it is associated with an existing one" do
before do
person_existing = Person.create(name: "person_existing")
Timecop.travel(1.second.since)
@book.update_attributes!(title: "book_1")
(@book.authors << person_existing)
end
@ -93,7 +88,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
before do
@author = @book.authors.create!(name: "author_0")
@person_existing = Person.create(name: "person_existing")
Timecop.travel(1.second.since)
@book.update_attributes!(title: "book_1")
end
@ -109,7 +103,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
before do
@author.update_attributes(name: "author_1")
@author.update_attributes(name: "author_2")
Timecop.travel(1.second.since)
@book.update_attributes(title: "book_2")
@author.update_attributes(name: "author_3")
end
@ -154,7 +147,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "and then the associated is destroyed between model versions" do
before do
@author.destroy
Timecop.travel(1.second.since)
@book.update_attributes(title: "book_2")
end
@ -170,7 +162,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "and then the associated is dissociated between model versions" do
before do
@book.authors = []
Timecop.travel(1.second.since)
@book.update_attributes(title: "book_2")
end
@ -281,13 +272,9 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "after the first has_many through relationship is created" do
before do
@chapter.update_attributes(name: CHAPTER_NAMES[1])
Timecop.travel(1.second.since)
@chapter.sections.create(name: "section 1")
Timecop.travel(1.second.since)
@chapter.sections.first.update_attributes(name: "section 2")
Timecop.travel(1.second.since)
@chapter.update_attributes(name: CHAPTER_NAMES[2])
Timecop.travel(1.second.since)
@chapter.sections.first.update_attributes(name: "section 3")
end
@ -310,9 +297,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "version 2, before the section was destroyed" do
before do
@chapter.update_attributes(name: CHAPTER_NAMES[2])
Timecop.travel(1.second.since)
@chapter.sections.destroy_all
Timecop.travel(1.second.since)
end
it "have the one section" do
@ -324,9 +309,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "version 3, after the section was destroyed" do
before do
@chapter.sections.destroy_all
Timecop.travel(1.second.since)
@chapter.update_attributes(name: CHAPTER_NAMES[3])
Timecop.travel(1.second.since)
end
it "have no sections" do
@ -338,7 +321,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "after creating a paragraph" do
before do
@section = @chapter.sections.first
Timecop.travel(1.second.since)
@paragraph = @section.paragraphs.create(name: "para1")
end
@ -346,10 +328,8 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "have one paragraph" do
initial_section_name = @section.name
initial_paragraph_name = @paragraph.name
Timecop.travel(1.second.since)
@chapter.update_attributes(name: CHAPTER_NAMES[4])
expect(@chapter.versions.size).to(eq(4))
Timecop.travel(1.second.since)
@paragraph.update_attributes(name: "para3")
chapter_v3 = @chapter.versions[3].reify(has_many: true)
expect(chapter_v3.sections.map(&:name)).to(eq([initial_section_name]))
@ -361,10 +341,8 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "the version before a section is destroyed" do
it "have the section and paragraph" do
Timecop.travel(1.second.since)
@chapter.update_attributes(name: CHAPTER_NAMES[3])
expect(@chapter.versions.size).to(eq(4))
Timecop.travel(1.second.since)
@section.destroy
expect(@chapter.versions.size).to(eq(4))
chapter_v3 = @chapter.versions[3].reify(has_many: true)
@ -378,7 +356,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "the version after a section is destroyed" do
it "not have any sections or paragraphs" do
@section.destroy
Timecop.travel(1.second.since)
@chapter.update_attributes(name: CHAPTER_NAMES[5])
expect(@chapter.versions.size).to(eq(4))
chapter_v3 = @chapter.versions[3].reify(has_many: true)
@ -390,9 +367,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "the version before a paragraph is destroyed" do
it "have the one paragraph" do
initial_paragraph_name = @section.paragraphs.first.name
Timecop.travel(1.second.since)
@chapter.update_attributes(name: CHAPTER_NAMES[5])
Timecop.travel(1.second.since)
@paragraph.destroy
chapter_v3 = @chapter.versions[3].reify(has_many: true)
paragraphs = chapter_v3.sections.first.paragraphs
@ -404,7 +379,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
context "the version after a paragraph is destroyed" do
it "have no paragraphs" do
@paragraph.destroy
Timecop.travel(1.second.since)
@chapter.update_attributes(name: CHAPTER_NAMES[5])
chapter_v3 = @chapter.versions[3].reify(has_many: true)
expect(chapter_v3.paragraphs.size).to(eq(0))
@ -421,7 +395,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
paragraph = Paragraph.create(name: "Paragraph One", section: section)
quotation = Quotation.create(chapter: chapter)
citation = Citation.create(quotation: quotation)
Timecop.travel(1.second.since)
chapter.update_attributes(name: CHAPTER_NAMES[1])
expect(chapter.versions.count).to(eq(2))
paragraph.destroy

View File

@ -3,10 +3,6 @@
require "spec_helper"
RSpec.describe(::PaperTrail, versioning: true) do
after do
Timecop.return
end
describe "widget, reified from a version prior to creation of wotsit" do
it "has a nil wotsit" do
widget = Widget.create(name: "widget_0")
@ -21,7 +17,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the expected wotsit" do
widget = Widget.create(name: "widget_0")
wotsit = widget.create_wotsit(name: "wotsit_0")
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_1")
widget0 = widget.versions.last.reify(has_one: true)
expect(widget0.wotsit.name).to(eq("wotsit_0"))
@ -33,11 +28,9 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the expected wotsit" do
widget = Widget.create(name: "widget_0")
wotsit = widget.create_wotsit(name: "wotsit_0")
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_1")
wotsit.update_attributes(name: "wotsit_1")
wotsit.update_attributes(name: "wotsit_2")
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_2")
wotsit.update_attributes(name: "wotsit_3")
widget1 = widget.versions.last.reify(has_one: true)
@ -50,11 +43,9 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the latest wotsit in the database" do
widget = Widget.create(name: "widget_0")
wotsit = widget.create_wotsit(name: "wotsit_0")
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_1")
wotsit.update_attributes(name: "wotsit_1")
wotsit.update_attributes(name: "wotsit_2")
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_2")
wotsit.update_attributes(name: "wotsit_3")
widget1 = widget.versions.last.reify(has_one: false)
@ -66,7 +57,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has the wotsit" do
widget = Widget.create(name: "widget_0")
wotsit = widget.create_wotsit(name: "wotsit_0")
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_1")
wotsit.destroy
widget1 = widget.versions.last.reify(has_one: true)
@ -79,10 +69,8 @@ RSpec.describe(::PaperTrail, versioning: true) do
it "has a nil wotsit" do
widget = Widget.create(name: "widget_0")
wotsit = widget.create_wotsit(name: "wotsit_0")
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_1")
wotsit.destroy
Timecop.travel(1.second.since)
widget.update_attributes(name: "widget_3")
widget2 = widget.versions.last.reify(has_one: true)
expect(widget2.wotsit).to be_nil

View File

@ -21,19 +21,18 @@ module PaperTrail
it "deletes oldest versions, when the database returns them in a different order" do
epoch = Date.new(2017, 1, 1)
widget = Timecop.freeze(epoch) { Widget.create }
widget = Widget.create(created_at: epoch)
# Sometimes a database will returns records in a different order than
# they were inserted. That's hard to get the database to do, so we'll
# just create them out-of-order:
(1..5).to_a.shuffle.each do |n|
Timecop.freeze(epoch + n.hours) do
PaperTrail::Version.create!(
item: widget,
event: "update",
object: { "id" => widget.id, "name" => "Name #{n}" }.to_yaml
)
end
PaperTrail::Version.create!(
created_at: epoch + n.hours,
item: widget,
event: "update",
object: { "id" => widget.id, "name" => "Name #{n}" }.to_yaml
)
end
expect(Widget.find(widget.id).versions.count).to eq(6) # 1 create + 5 updates

View File

@ -59,7 +59,6 @@ require File.expand_path("dummy_app/config/environment", __dir__)
require "rspec/rails"
require "paper_trail/frameworks/rspec"
require "ffaker"
require "timecop"
# Migrate
require_relative "support/paper_trail_spec_migrator"