mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
2b479a7f08
* Change update_attributes to update In Rails 6.0 update_attributes/update_attributes! is considered deprecated. Method update/update! is the replacement. * CI: Don't use Bundler 1.16.1 - Bundler 1.16.1 has bug where dependencies can't be resolved properly when a gem is a release candidate or an alpha version. The underlying bundler issue can be found here https://github.com/bundler/bundler/issues/6449 * Disable eager_load in test env: - In Rails 6.0, rails/rails@3b95478 made a change to eagerly define attribute methods of a Model when `eager_load` is enabled. This breaks our test suite because of the way we run migration. The TL;DR is that doing `People.attribute_names` will return an empty array instead of `[:id, time_zone, ...]`. You can find a failing build here https://travis-ci.org/paper-trail-gem/paper_trail/jobs/463369634 Basically what happens is: 1) The dummy app boot, attribute methods of each model are defined but since migration didn't run yet, the tables aren't even created resulting in a empty attribute set. 2) Migration runs, but it's already too late. In this commit I disabled eager_loading in test, AFAIT there isn't much benefit in eager_loading the dummy app anyway. Also renaming the `user.rb` file to `postgres_user.rb` in order for rails autoloading to work correctly.
44 lines
1.4 KiB
Ruby
44 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "spec_helper"
|
|
|
|
RSpec.describe Skipper, type: :model, versioning: true do
|
|
it { is_expected.to be_versioned }
|
|
|
|
describe "#update!", versioning: true do
|
|
context "updating a skipped attribute" do
|
|
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
|
|
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
|
|
|
|
it "does not create a version" do
|
|
skipper = Skipper.create!(another_timestamp: t1)
|
|
expect {
|
|
skipper.update!(another_timestamp: t2)
|
|
}.not_to(change { skipper.versions.length })
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#reify" do
|
|
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
|
|
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
|
|
|
|
context "without preserve (default)" do
|
|
it "has no timestamp" do
|
|
skipper = Skipper.create!(another_timestamp: t1)
|
|
skipper.update!(another_timestamp: t2, name: "Foobar")
|
|
skipper = skipper.versions.last.reify
|
|
expect(skipper.another_timestamp).to be(nil)
|
|
end
|
|
end
|
|
|
|
context "with preserve" do
|
|
it "preserves its timestamp" do
|
|
skipper = Skipper.create!(another_timestamp: t1)
|
|
skipper.update!(another_timestamp: t2, name: "Foobar")
|
|
skipper = skipper.versions.last.reify(unversioned_attributes: :preserve)
|
|
expect(skipper.another_timestamp).to eq(t2)
|
|
end
|
|
end
|
|
end
|
|
end
|