paper_trail 7.1.0 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/paper_trail/record_trail.rb +1 -1
- data/lib/paper_trail/version_number.rb +1 -1
- metadata +3 -274
- data/.github/CONTRIBUTING.md +0 -151
- data/.github/ISSUE_TEMPLATE.md +0 -13
- data/.gitignore +0 -23
- data/.rspec +0 -2
- data/.rubocop.yml +0 -135
- data/.rubocop_todo.yml +0 -41
- data/.travis.yml +0 -41
- data/Appraisals +0 -26
- data/CHANGELOG.md +0 -739
- data/Gemfile +0 -2
- data/MIT-LICENSE +0 -20
- data/README.md +0 -1613
- data/Rakefile +0 -38
- data/doc/bug_report_template.rb +0 -73
- data/doc/triage.md +0 -27
- data/doc/warning_about_not_setting_whodunnit.md +0 -33
- data/gemfiles/ar_4.0.gemfile +0 -7
- data/gemfiles/ar_4.2.gemfile +0 -7
- data/gemfiles/ar_5.0.gemfile +0 -8
- data/gemfiles/ar_5.1.gemfile +0 -8
- data/gemfiles/ar_master.gemfile +0 -9
- data/lib/generators/paper_trail/default_initializer.rb +0 -0
- data/paper_trail.gemspec +0 -49
- data/spec/controllers/articles_controller_spec.rb +0 -28
- data/spec/controllers/widgets_controller_spec.rb +0 -85
- data/spec/dummy_app/Rakefile +0 -7
- data/spec/dummy_app/app/controllers/application_controller.rb +0 -30
- data/spec/dummy_app/app/controllers/articles_controller.rb +0 -16
- data/spec/dummy_app/app/controllers/test_controller.rb +0 -5
- data/spec/dummy_app/app/controllers/widgets_controller.rb +0 -28
- data/spec/dummy_app/app/models/animal.rb +0 -4
- data/spec/dummy_app/app/models/article.rb +0 -25
- data/spec/dummy_app/app/models/authorship.rb +0 -5
- data/spec/dummy_app/app/models/bar_habtm.rb +0 -4
- data/spec/dummy_app/app/models/book.rb +0 -9
- data/spec/dummy_app/app/models/boolit.rb +0 -4
- data/spec/dummy_app/app/models/callback_modifier.rb +0 -45
- data/spec/dummy_app/app/models/car.rb +0 -3
- data/spec/dummy_app/app/models/cat.rb +0 -2
- data/spec/dummy_app/app/models/chapter.rb +0 -9
- data/spec/dummy_app/app/models/citation.rb +0 -5
- data/spec/dummy_app/app/models/custom_primary_key_record.rb +0 -15
- data/spec/dummy_app/app/models/customer.rb +0 -4
- data/spec/dummy_app/app/models/document.rb +0 -8
- data/spec/dummy_app/app/models/dog.rb +0 -2
- data/spec/dummy_app/app/models/editor.rb +0 -4
- data/spec/dummy_app/app/models/editorship.rb +0 -5
- data/spec/dummy_app/app/models/elephant.rb +0 -3
- data/spec/dummy_app/app/models/fluxor.rb +0 -3
- data/spec/dummy_app/app/models/foo_habtm.rb +0 -5
- data/spec/dummy_app/app/models/foo_widget.rb +0 -2
- data/spec/dummy_app/app/models/fruit.rb +0 -5
- data/spec/dummy_app/app/models/gadget.rb +0 -3
- data/spec/dummy_app/app/models/kitchen/banana.rb +0 -5
- data/spec/dummy_app/app/models/legacy_widget.rb +0 -6
- data/spec/dummy_app/app/models/line_item.rb +0 -4
- data/spec/dummy_app/app/models/not_on_update.rb +0 -4
- data/spec/dummy_app/app/models/on/create.rb +0 -6
- data/spec/dummy_app/app/models/on/destroy.rb +0 -6
- data/spec/dummy_app/app/models/on/empty_array.rb +0 -6
- data/spec/dummy_app/app/models/on/update.rb +0 -6
- data/spec/dummy_app/app/models/order.rb +0 -5
- data/spec/dummy_app/app/models/paragraph.rb +0 -5
- data/spec/dummy_app/app/models/person.rb +0 -39
- data/spec/dummy_app/app/models/post.rb +0 -3
- data/spec/dummy_app/app/models/post_with_status.rb +0 -7
- data/spec/dummy_app/app/models/quotation.rb +0 -5
- data/spec/dummy_app/app/models/section.rb +0 -6
- data/spec/dummy_app/app/models/skipper.rb +0 -3
- data/spec/dummy_app/app/models/song.rb +0 -37
- data/spec/dummy_app/app/models/thing.rb +0 -3
- data/spec/dummy_app/app/models/translation.rb +0 -11
- data/spec/dummy_app/app/models/truck.rb +0 -4
- data/spec/dummy_app/app/models/vehicle.rb +0 -4
- data/spec/dummy_app/app/models/whatchamajigger.rb +0 -4
- data/spec/dummy_app/app/models/widget.rb +0 -8
- data/spec/dummy_app/app/models/wotsit.rb +0 -8
- data/spec/dummy_app/app/versions/custom_primary_key_record_version.rb +0 -3
- data/spec/dummy_app/app/versions/joined_version.rb +0 -6
- data/spec/dummy_app/app/versions/json_version.rb +0 -3
- data/spec/dummy_app/app/versions/kitchen/banana_version.rb +0 -5
- data/spec/dummy_app/app/versions/post_version.rb +0 -3
- data/spec/dummy_app/config.ru +0 -4
- data/spec/dummy_app/config/application.rb +0 -39
- data/spec/dummy_app/config/boot.rb +0 -24
- data/spec/dummy_app/config/database.mysql.yml +0 -19
- data/spec/dummy_app/config/database.postgres.yml +0 -15
- data/spec/dummy_app/config/database.sqlite.yml +0 -15
- data/spec/dummy_app/config/environment.rb +0 -5
- data/spec/dummy_app/config/environments/development.rb +0 -36
- data/spec/dummy_app/config/environments/production.rb +0 -74
- data/spec/dummy_app/config/environments/test.rb +0 -46
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +0 -9
- data/spec/dummy_app/config/initializers/inflections.rb +0 -10
- data/spec/dummy_app/config/initializers/mime_types.rb +0 -5
- data/spec/dummy_app/config/initializers/paper_trail.rb +0 -1
- data/spec/dummy_app/config/initializers/secret_token.rb +0 -9
- data/spec/dummy_app/config/initializers/session_store.rb +0 -8
- data/spec/dummy_app/config/locales/en.yml +0 -5
- data/spec/dummy_app/config/routes.rb +0 -4
- data/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb +0 -344
- data/spec/dummy_app/db/schema.rb +0 -298
- data/spec/generators/install_generator_spec.rb +0 -88
- data/spec/models/animal_spec.rb +0 -61
- data/spec/models/article_spec.rb +0 -186
- data/spec/models/boolit_spec.rb +0 -41
- data/spec/models/callback_modifier_spec.rb +0 -92
- data/spec/models/car_spec.rb +0 -13
- data/spec/models/custom_primary_key_record_spec.rb +0 -18
- data/spec/models/document_spec.rb +0 -57
- data/spec/models/gadget_spec.rb +0 -63
- data/spec/models/joined_version_spec.rb +0 -41
- data/spec/models/json_version_spec.rb +0 -101
- data/spec/models/kitchen/banana_spec.rb +0 -14
- data/spec/models/legacy_widget_spec.rb +0 -40
- data/spec/models/not_on_update_spec.rb +0 -22
- data/spec/models/on/create_spec.rb +0 -27
- data/spec/models/on/destroy_spec.rb +0 -27
- data/spec/models/on/empty_array_spec.rb +0 -30
- data/spec/models/on/update_spec.rb +0 -27
- data/spec/models/post_with_status_spec.rb +0 -46
- data/spec/models/skipper_spec.rb +0 -42
- data/spec/models/thing_spec.rb +0 -11
- data/spec/models/translation_spec.rb +0 -70
- data/spec/models/vehicle_spec.rb +0 -5
- data/spec/models/version_spec.rb +0 -282
- data/spec/models/widget_spec.rb +0 -338
- data/spec/modules/paper_trail_spec.rb +0 -27
- data/spec/modules/version_concern_spec.rb +0 -28
- data/spec/modules/version_number_spec.rb +0 -18
- data/spec/paper_trail/associations_spec.rb +0 -965
- data/spec/paper_trail/cleaner_spec.rb +0 -152
- data/spec/paper_trail/config_spec.rb +0 -45
- data/spec/paper_trail/model_spec.rb +0 -992
- data/spec/paper_trail/serializer_spec.rb +0 -85
- data/spec/paper_trail/serializers/custom_json_serializer_spec.rb +0 -18
- data/spec/paper_trail/serializers/custom_yaml_serializer_spec.rb +0 -45
- data/spec/paper_trail/serializers/json_spec.rb +0 -57
- data/spec/paper_trail/serializers/yaml_spec.rb +0 -42
- data/spec/paper_trail/thread_safety_spec.rb +0 -44
- data/spec/paper_trail/version_limit_spec.rb +0 -55
- data/spec/paper_trail/version_spec.rb +0 -96
- data/spec/paper_trail_spec.rb +0 -122
- data/spec/requests/articles_spec.rb +0 -34
- data/spec/spec_helper.rb +0 -78
- data/spec/support/alt_db_init.rb +0 -54
- data/spec/support/custom_json_serializer.rb +0 -13
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require_dependency "on/update"
|
|
3
|
-
|
|
4
|
-
module On
|
|
5
|
-
RSpec.describe Update, type: :model, versioning: true do
|
|
6
|
-
describe "#versions" do
|
|
7
|
-
it "only creates one version record, for the update event" do
|
|
8
|
-
record = described_class.create(name: "Alice")
|
|
9
|
-
record.update_attributes(name: "blah")
|
|
10
|
-
record.destroy
|
|
11
|
-
expect(record.versions.length).to(eq(1))
|
|
12
|
-
expect(record.versions.last.event).to(eq("update"))
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context "#paper_trail_event" do
|
|
17
|
-
it "rembembers the custom event name" do
|
|
18
|
-
record = described_class.create(name: "Alice")
|
|
19
|
-
record.paper_trail_event = "banana"
|
|
20
|
-
record.update_attributes(name: "blah")
|
|
21
|
-
record.destroy
|
|
22
|
-
expect(record.versions.length).to(eq(1))
|
|
23
|
-
expect(record.versions.last.event).to(eq("banana"))
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe PostWithStatus, type: :model do
|
|
4
|
-
with_versioning do
|
|
5
|
-
let(:post) { described_class.create!(status: "draft") }
|
|
6
|
-
|
|
7
|
-
it "saves the enum value in versions" do
|
|
8
|
-
post.published!
|
|
9
|
-
post.archived!
|
|
10
|
-
expect(post.paper_trail.previous_version.published?).to be true
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "can read enums in version records written by PT 4" do
|
|
14
|
-
post = described_class.create(status: "draft")
|
|
15
|
-
post.published!
|
|
16
|
-
version = post.versions.last
|
|
17
|
-
# Simulate behavior PT 4, which used to save the string version of
|
|
18
|
-
# enums to `object_changes`
|
|
19
|
-
version.update(object_changes: "---\nid:\n- \n- 1\nstatus:\n- draft\n- published\n")
|
|
20
|
-
assert_equal %w[draft published], version.changeset["status"]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context "storing enum object_changes" do
|
|
24
|
-
subject { post.versions.last }
|
|
25
|
-
|
|
26
|
-
it "saves the enum value properly in versions object_changes" do
|
|
27
|
-
post.published!
|
|
28
|
-
post.archived!
|
|
29
|
-
expect(subject.changeset["status"]).to eql %w[published archived]
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "#touch_with_version" do
|
|
34
|
-
it "preserves the enum value (and all other attributes)" do
|
|
35
|
-
post = described_class.create(status: :draft)
|
|
36
|
-
expect(post.versions.count).to eq(1)
|
|
37
|
-
expect(post.status).to eq("draft")
|
|
38
|
-
Timecop.travel 1.second.since # because MySQL lacks fractional seconds precision
|
|
39
|
-
post.paper_trail.touch_with_version
|
|
40
|
-
expect(post.versions.count).to eq(2)
|
|
41
|
-
expect(post.versions.last[:object]).to include("status: 0")
|
|
42
|
-
expect(post.paper_trail.previous_version.status).to eq("draft")
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
data/spec/models/skipper_spec.rb
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Skipper, type: :model, versioning: true do
|
|
4
|
-
it { is_expected.to be_versioned }
|
|
5
|
-
|
|
6
|
-
describe "#update_attributes!", versioning: true do
|
|
7
|
-
context "updating a skipped attribute" do
|
|
8
|
-
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
|
|
9
|
-
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
|
|
10
|
-
|
|
11
|
-
it "does not create a version" do
|
|
12
|
-
skipper = Skipper.create!(another_timestamp: t1)
|
|
13
|
-
expect {
|
|
14
|
-
skipper.update_attributes!(another_timestamp: t2)
|
|
15
|
-
}.not_to(change { skipper.versions.length })
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "#reify" do
|
|
21
|
-
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
|
|
22
|
-
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
|
|
23
|
-
|
|
24
|
-
context "without preserve (default)" do
|
|
25
|
-
it "has no timestamp" do
|
|
26
|
-
skipper = Skipper.create!(another_timestamp: t1)
|
|
27
|
-
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
|
|
28
|
-
skipper = skipper.versions.last.reify
|
|
29
|
-
expect(skipper.another_timestamp).to be(nil)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "with preserve" do
|
|
34
|
-
it "preserves its timestamp" do
|
|
35
|
-
skipper = Skipper.create!(another_timestamp: t1)
|
|
36
|
-
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
|
|
37
|
-
skipper = skipper.versions.last.reify(unversioned_attributes: :preserve)
|
|
38
|
-
expect(skipper.another_timestamp).to eq(t2)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
data/spec/models/thing_spec.rb
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Thing, type: :model do
|
|
4
|
-
it { is_expected.to be_versioned }
|
|
5
|
-
|
|
6
|
-
describe "does not store object_changes", versioning: true do
|
|
7
|
-
let(:thing) { Thing.create(name: "pencil") }
|
|
8
|
-
|
|
9
|
-
it { expect(thing.versions.last.object_changes).to be_nil }
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Translation, type: :model, versioning: true do
|
|
4
|
-
context "for non-US translations" do
|
|
5
|
-
it "not change the number of versions" do
|
|
6
|
-
described_class.create!(headline: "Headline")
|
|
7
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "after update" do
|
|
11
|
-
it "not change the number of versions" do
|
|
12
|
-
translation = described_class.create!(headline: "Headline")
|
|
13
|
-
translation.update_attributes(content: "Content")
|
|
14
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "after destroy" do
|
|
19
|
-
it "not change the number of versions" do
|
|
20
|
-
translation = described_class.create!(headline: "Headline")
|
|
21
|
-
translation.destroy
|
|
22
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "for US translations" do
|
|
28
|
-
context "that are drafts" do
|
|
29
|
-
it "creation does not change the number of versions" do
|
|
30
|
-
translation = described_class.new(headline: "Headline")
|
|
31
|
-
translation.language_code = "US"
|
|
32
|
-
translation.type = "DRAFT"
|
|
33
|
-
translation.save!
|
|
34
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "update does not change the number of versions" do
|
|
38
|
-
translation = described_class.new(headline: "Headline")
|
|
39
|
-
translation.language_code = "US"
|
|
40
|
-
translation.type = "DRAFT"
|
|
41
|
-
translation.save!
|
|
42
|
-
translation.update_attributes(content: "Content")
|
|
43
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context "that are not drafts" do
|
|
48
|
-
it "create changes the number of versions" do
|
|
49
|
-
described_class.create!(headline: "Headline", language_code: "US")
|
|
50
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "update does not change the number of versions" do
|
|
54
|
-
translation = described_class.create!(headline: "Headline", language_code: "US")
|
|
55
|
-
translation.update_attributes(content: "Content")
|
|
56
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
57
|
-
expect(translation.versions.size).to(eq(2))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "destroy does not change the number of versions" do
|
|
61
|
-
translation = described_class.new(headline: "Headline")
|
|
62
|
-
translation.language_code = "US"
|
|
63
|
-
translation.save!
|
|
64
|
-
translation.destroy
|
|
65
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
66
|
-
expect(translation.versions.size).to(eq(2))
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
data/spec/models/vehicle_spec.rb
DELETED
data/spec/models/version_spec.rb
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
module PaperTrail
|
|
4
|
-
::RSpec.describe Version, type: :model do
|
|
5
|
-
describe "object_changes column", versioning: true do
|
|
6
|
-
let(:widget) { Widget.create!(name: "Dashboard") }
|
|
7
|
-
let(:value) { widget.versions.last.object_changes }
|
|
8
|
-
|
|
9
|
-
context "serializer is YAML" do
|
|
10
|
-
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
|
11
|
-
|
|
12
|
-
it "store out as a plain hash" do
|
|
13
|
-
expect(value =~ /HashWithIndifferentAccess/).to be_nil
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "serializer is JSON" do
|
|
18
|
-
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
|
19
|
-
|
|
20
|
-
it "store out as a plain hash" do
|
|
21
|
-
expect(value =~ /HashWithIndifferentAccess/).to be_nil
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe "#paper_trail_originator" do
|
|
29
|
-
context "no previous versions" do
|
|
30
|
-
it "returns nil" do
|
|
31
|
-
expect(PaperTrail::Version.new.paper_trail_originator).to be_nil
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context "has previous version", versioning: true do
|
|
36
|
-
it "returns name of whodunnit" do
|
|
37
|
-
name = FFaker::Name.name
|
|
38
|
-
widget = Widget.create!(name: FFaker::Name.name)
|
|
39
|
-
widget.versions.first.update_attributes!(whodunnit: name)
|
|
40
|
-
widget.update_attributes!(name: FFaker::Name.first_name)
|
|
41
|
-
expect(widget.versions.last.paper_trail_originator).to eq(name)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe "#previous" do
|
|
47
|
-
context "no previous versions" do
|
|
48
|
-
it "returns nil" do
|
|
49
|
-
expect(PaperTrail::Version.new.previous).to be_nil
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "has previous version", versioning: true do
|
|
54
|
-
it "returns a PaperTrail::Version" do
|
|
55
|
-
name = FFaker::Name.name
|
|
56
|
-
widget = Widget.create!(name: FFaker::Name.name)
|
|
57
|
-
widget.versions.first.update_attributes!(whodunnit: name)
|
|
58
|
-
widget.update_attributes!(name: FFaker::Name.first_name)
|
|
59
|
-
expect(widget.versions.last.previous).to be_instance_of(PaperTrail::Version)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "#originator" do
|
|
65
|
-
it "sets the invoke `paper_trail_originator`" do
|
|
66
|
-
allow(ActiveSupport::Deprecation).to receive(:warn)
|
|
67
|
-
subject = PaperTrail::Version.new
|
|
68
|
-
expect(subject).to receive(:paper_trail_originator)
|
|
69
|
-
subject.originator
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "displays a deprecation warning" do
|
|
73
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
|
74
|
-
with(/Use paper_trail_originator instead of originator/)
|
|
75
|
-
subject = PaperTrail::Version.new
|
|
76
|
-
subject.originator
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe "#terminator" do
|
|
81
|
-
it "is an alias for the `whodunnit` attribute" do
|
|
82
|
-
attributes = { whodunnit: FFaker::Name.first_name }
|
|
83
|
-
subject = PaperTrail::Version.new(attributes)
|
|
84
|
-
expect(subject.terminator).to eq(attributes[:whodunnit])
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe "#version_author" do
|
|
89
|
-
it "is an alias for the `terminator` method" do
|
|
90
|
-
subject = PaperTrail::Version.new
|
|
91
|
-
expect(subject.method(:version_author)).to eq(subject.method(:terminator))
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
describe "Methods" do
|
|
96
|
-
# TODO: Changing the data type of these database columns in the middle
|
|
97
|
-
# of the test suite adds a fair amount of complication. Is there a better
|
|
98
|
-
# way? We already have a `json_versions` table in our tests, maybe we
|
|
99
|
-
# could use that and add a `jsonb_versions` table?
|
|
100
|
-
column_overrides = [false]
|
|
101
|
-
if ENV["DB"] == "postgres" && ::ActiveRecord::VERSION::MAJOR >= 4
|
|
102
|
-
column_overrides << "json"
|
|
103
|
-
# 'jsonb' column types are only supported for ActiveRecord 4.2+
|
|
104
|
-
column_overrides << "jsonb" if ::ActiveRecord::VERSION::STRING >= "4.2"
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
column_overrides.shuffle.each do |override|
|
|
108
|
-
context "with a #{override || 'text'} column" do
|
|
109
|
-
before do
|
|
110
|
-
if override
|
|
111
|
-
# In rails < 5, we use truncation, ie. there is no transaction
|
|
112
|
-
# around the tests, so we can't use a savepoint.
|
|
113
|
-
if active_record_gem_version >= ::Gem::Version.new("5")
|
|
114
|
-
ActiveRecord::Base.connection.execute("SAVEPOINT pgtest;")
|
|
115
|
-
end
|
|
116
|
-
%w[object object_changes].each do |column|
|
|
117
|
-
ActiveRecord::Base.connection.execute(
|
|
118
|
-
"ALTER TABLE versions DROP COLUMN #{column};"
|
|
119
|
-
)
|
|
120
|
-
ActiveRecord::Base.connection.execute(
|
|
121
|
-
"ALTER TABLE versions ADD COLUMN #{column} #{override};"
|
|
122
|
-
)
|
|
123
|
-
end
|
|
124
|
-
PaperTrail::Version.reset_column_information
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
after do
|
|
129
|
-
if override
|
|
130
|
-
# In rails < 5, we use truncation, ie. there is no transaction
|
|
131
|
-
# around the tests, so we can't use a savepoint.
|
|
132
|
-
if active_record_gem_version >= ::Gem::Version.new("5")
|
|
133
|
-
ActiveRecord::Base.connection.execute("ROLLBACK TO SAVEPOINT pgtest;")
|
|
134
|
-
else
|
|
135
|
-
%w[object object_changes].each do |column|
|
|
136
|
-
ActiveRecord::Base.connection.execute(
|
|
137
|
-
"ALTER TABLE versions DROP COLUMN #{column};"
|
|
138
|
-
)
|
|
139
|
-
ActiveRecord::Base.connection.execute(
|
|
140
|
-
"ALTER TABLE versions ADD COLUMN #{column} text;"
|
|
141
|
-
)
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
PaperTrail::Version.reset_column_information
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
describe "#where_object", versioning: true do
|
|
149
|
-
let(:widget) { Widget.new }
|
|
150
|
-
let(:name) { FFaker::Name.first_name }
|
|
151
|
-
let(:int) { rand(10) + 1 }
|
|
152
|
-
|
|
153
|
-
before do
|
|
154
|
-
widget.update_attributes!(name: name, an_integer: int)
|
|
155
|
-
widget.update_attributes!(name: "foobar", an_integer: 100)
|
|
156
|
-
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "requires its argument to be a Hash" do
|
|
160
|
-
expect {
|
|
161
|
-
PaperTrail::Version.where_object(:foo)
|
|
162
|
-
}.to raise_error(ArgumentError)
|
|
163
|
-
expect {
|
|
164
|
-
PaperTrail::Version.where_object([])
|
|
165
|
-
}.to raise_error(ArgumentError)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
context "`serializer == YAML`" do
|
|
169
|
-
specify do
|
|
170
|
-
expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it "locates versions according to their `object` contents" do
|
|
174
|
-
expect(
|
|
175
|
-
PaperTrail::Version.where_object(name: name)
|
|
176
|
-
).to eq([widget.versions[1]])
|
|
177
|
-
expect(
|
|
178
|
-
PaperTrail::Version.where_object(an_integer: 100)
|
|
179
|
-
).to eq([widget.versions[2]])
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
context "JSON serializer" do
|
|
184
|
-
before(:all) do
|
|
185
|
-
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
specify do
|
|
189
|
-
expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
it "locates versions according to their `object` contents" do
|
|
193
|
-
expect(
|
|
194
|
-
PaperTrail::Version.where_object(name: name)
|
|
195
|
-
).to eq([widget.versions[1]])
|
|
196
|
-
expect(
|
|
197
|
-
PaperTrail::Version.where_object(an_integer: 100)
|
|
198
|
-
).to eq([widget.versions[2]])
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
after(:all) do
|
|
202
|
-
PaperTrail.serializer = PaperTrail::Serializers::YAML
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
describe "#where_object_changes", versioning: true do
|
|
208
|
-
let(:widget) { Widget.new }
|
|
209
|
-
let(:name) { FFaker::Name.first_name }
|
|
210
|
-
let(:int) { rand(5) + 2 }
|
|
211
|
-
|
|
212
|
-
before do
|
|
213
|
-
widget.update_attributes!(name: name, an_integer: 0)
|
|
214
|
-
widget.update_attributes!(name: "foobar", an_integer: 77)
|
|
215
|
-
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: int)
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
it "requires its argument to be a Hash" do
|
|
219
|
-
expect {
|
|
220
|
-
PaperTrail::Version.where_object_changes(:foo)
|
|
221
|
-
}.to raise_error(ArgumentError)
|
|
222
|
-
expect {
|
|
223
|
-
PaperTrail::Version.where_object_changes([])
|
|
224
|
-
}.to raise_error(ArgumentError)
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
context "YAML serializer" do
|
|
228
|
-
it "locates versions according to their `object_changes` contents" do
|
|
229
|
-
expect(
|
|
230
|
-
widget.versions.where_object_changes(name: name)
|
|
231
|
-
).to eq(widget.versions[0..1])
|
|
232
|
-
expect(
|
|
233
|
-
widget.versions.where_object_changes(an_integer: 77)
|
|
234
|
-
).to eq(widget.versions[1..2])
|
|
235
|
-
expect(
|
|
236
|
-
widget.versions.where_object_changes(an_integer: int)
|
|
237
|
-
).to eq([widget.versions.last])
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
it "handles queries for multiple attributes" do
|
|
241
|
-
expect(
|
|
242
|
-
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
|
|
243
|
-
).to eq(widget.versions[1..2])
|
|
244
|
-
end
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
context "JSON serializer" do
|
|
248
|
-
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
|
249
|
-
before do
|
|
250
|
-
unless override
|
|
251
|
-
expect(::ActiveSupport::Deprecation).to(
|
|
252
|
-
receive(:warn).at_least(:once).with(/^where_object_changes/)
|
|
253
|
-
)
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
it "locates versions according to their `object_changes` contents" do
|
|
258
|
-
expect(
|
|
259
|
-
widget.versions.where_object_changes(name: name)
|
|
260
|
-
).to eq(widget.versions[0..1])
|
|
261
|
-
expect(
|
|
262
|
-
widget.versions.where_object_changes(an_integer: 77)
|
|
263
|
-
).to eq(widget.versions[1..2])
|
|
264
|
-
expect(
|
|
265
|
-
widget.versions.where_object_changes(an_integer: int)
|
|
266
|
-
).to eq([widget.versions.last])
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
it "handles queries for multiple attributes" do
|
|
270
|
-
expect(
|
|
271
|
-
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
|
|
272
|
-
).to eq(widget.versions[1..2])
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
end
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
end
|