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
data/spec/models/car_spec.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Car, type: :model do
|
|
4
|
-
it { is_expected.to be_versioned }
|
|
5
|
-
|
|
6
|
-
describe "changeset", versioning: true do
|
|
7
|
-
it "has the expected keys (see issue 738)" do
|
|
8
|
-
car = Car.create!(name: "Alice")
|
|
9
|
-
car.update_attributes(name: "Bob")
|
|
10
|
-
assert_includes car.versions.last.changeset.keys, "name"
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe CustomPrimaryKeyRecord, type: :model do
|
|
4
|
-
it { is_expected.to be_versioned }
|
|
5
|
-
|
|
6
|
-
describe "#versions" do
|
|
7
|
-
it "returns instances of CustomPrimaryKeyRecordVersion", versioning: true do
|
|
8
|
-
custom_primary_key_record = described_class.create!
|
|
9
|
-
custom_primary_key_record.update_attributes!(name: "bob")
|
|
10
|
-
version = custom_primary_key_record.versions.last
|
|
11
|
-
expect(version).to be_a(CustomPrimaryKeyRecordVersion)
|
|
12
|
-
version_from_db = CustomPrimaryKeyRecordVersion.last
|
|
13
|
-
expect(version_from_db.reify).to be_a(CustomPrimaryKeyRecord)
|
|
14
|
-
custom_primary_key_record.destroy
|
|
15
|
-
expect(CustomPrimaryKeyRecordVersion.last.reify).to be_a(CustomPrimaryKeyRecord)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Document, type: :model, versioning: true do
|
|
4
|
-
describe "have_a_version_with matcher" do
|
|
5
|
-
it "works with custom versions association" do
|
|
6
|
-
document = Document.create!(name: "Foo")
|
|
7
|
-
document.update_attributes!(name: "Bar")
|
|
8
|
-
expect(document).to have_a_version_with(name: "Foo")
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe "have_a_version_with_changes matcher" do
|
|
13
|
-
it "works with custom versions association" do
|
|
14
|
-
document = Document.create!(name: "Foo")
|
|
15
|
-
document.update_attributes!(name: "Bar")
|
|
16
|
-
expect(document).to have_a_version_with_changes(name: "Bar")
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "#paper_trail.next_version" do
|
|
21
|
-
it "returns the expected document" do
|
|
22
|
-
doc = Document.create
|
|
23
|
-
doc.update_attributes(name: "Doc 1")
|
|
24
|
-
reified = doc.paper_trail_versions.last.reify
|
|
25
|
-
expect(doc.name).to(eq(reified.paper_trail.next_version.name))
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe "#paper_trail.previous_version" do
|
|
30
|
-
it "returns the expected document" do
|
|
31
|
-
doc = Document.create
|
|
32
|
-
doc.update_attributes(name: "Doc 1")
|
|
33
|
-
doc.update_attributes(name: "Doc 2")
|
|
34
|
-
expect(doc.paper_trail_versions.length).to(eq(3))
|
|
35
|
-
expect(doc.paper_trail.previous_version.name).to(eq("Doc 1"))
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe "#paper_trail_versions" do
|
|
40
|
-
it "returns the expected version records" do
|
|
41
|
-
doc = Document.create
|
|
42
|
-
doc.update_attributes(name: "Doc 1")
|
|
43
|
-
expect(doc.paper_trail_versions.length).to(eq(2))
|
|
44
|
-
expect(doc.paper_trail_versions.map(&:event)).to(
|
|
45
|
-
match_array(%w[create update])
|
|
46
|
-
)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
describe "#versions" do
|
|
51
|
-
it "does not respond to versions method" do
|
|
52
|
-
doc = Document.create
|
|
53
|
-
doc.update_attributes(name: "Doc 1")
|
|
54
|
-
expect(doc).not_to respond_to(:versions)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
data/spec/models/gadget_spec.rb
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Gadget, type: :model do
|
|
4
|
-
it { is_expected.to be_versioned }
|
|
5
|
-
|
|
6
|
-
let(:gadget) { Gadget.create!(name: "Wrench", brand: "Acme") }
|
|
7
|
-
|
|
8
|
-
describe "updates", versioning: true do
|
|
9
|
-
it "generates a version for updates to `name` attribute" do
|
|
10
|
-
expect { gadget.update_attribute(:name, "Hammer") }.to(change { gadget.versions.size }.by(1))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "ignores for updates to `brand` attribute" do
|
|
14
|
-
expect { gadget.update_attribute(:brand, "Stanley") }.not_to(change { gadget.versions.size })
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "still generates a version when only the `updated_at` attribute is updated" do
|
|
18
|
-
# Plus 1 second because MySQL lacks sub-second resolution
|
|
19
|
-
expect {
|
|
20
|
-
gadget.update_attribute(:updated_at, Time.now + 1)
|
|
21
|
-
}.to(change { gadget.versions.size }.by(1))
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "#changed_notably?", versioning: true do
|
|
26
|
-
context "new record" do
|
|
27
|
-
it "returns true" do
|
|
28
|
-
g = Gadget.new(created_at: Time.now)
|
|
29
|
-
expect(g.paper_trail.changed_notably?).to eq(true)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "persisted record without update timestamps" do
|
|
34
|
-
it "only acknowledges non-ignored attrs" do
|
|
35
|
-
subject = Gadget.create!(created_at: Time.now)
|
|
36
|
-
subject.name = "Wrench"
|
|
37
|
-
expect(subject.paper_trail.changed_notably?).to be true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "does not acknowledge ignored attr (brand)" do
|
|
41
|
-
subject = Gadget.create!(created_at: Time.now)
|
|
42
|
-
subject.brand = "Acme"
|
|
43
|
-
expect(subject.paper_trail.changed_notably?).to be false
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context "persisted record with update timestamps" do
|
|
48
|
-
it "only acknowledges non-ignored attrs" do
|
|
49
|
-
subject = Gadget.create!(created_at: Time.now)
|
|
50
|
-
subject.name = "Wrench"
|
|
51
|
-
subject.updated_at = Time.now
|
|
52
|
-
expect(subject.paper_trail.changed_notably?).to be true
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "does not acknowledge ignored attrs and timestamps only" do
|
|
56
|
-
subject = Gadget.create!(created_at: Time.now)
|
|
57
|
-
subject.brand = "Acme"
|
|
58
|
-
subject.updated_at = Time.now
|
|
59
|
-
expect(subject.paper_trail.changed_notably?).to be false
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe JoinedVersion, type: :model, versioning: true do
|
|
4
|
-
let(:widget) { Widget.create!(name: FFaker::Name.name) }
|
|
5
|
-
let(:version) { JoinedVersion.first }
|
|
6
|
-
|
|
7
|
-
describe "default_scope" do
|
|
8
|
-
it { expect(JoinedVersion.default_scopes).not_to be_empty }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "VersionConcern::ClassMethods" do
|
|
12
|
-
before { widget } # persist a widget
|
|
13
|
-
|
|
14
|
-
describe "#subsequent" do
|
|
15
|
-
it "does not raise error when there is a default_scope that joins" do
|
|
16
|
-
JoinedVersion.subsequent(version).first
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "#preceding" do
|
|
21
|
-
it "does not raise error when there is a default scope that joins" do
|
|
22
|
-
JoinedVersion.preceding(version).first
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "#between" do
|
|
27
|
-
it "does not raise error when there is a default scope that joins" do
|
|
28
|
-
JoinedVersion.between(Time.now, 1.minute.from_now).first
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "#index" do
|
|
34
|
-
it { is_expected.to respond_to(:index) }
|
|
35
|
-
|
|
36
|
-
it "does not raise error when there is a default scope that joins" do
|
|
37
|
-
widget # persist a widget
|
|
38
|
-
version.index
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
# The `json_versions` table tests postgres' `json` data type. So, that
|
|
4
|
-
# table is only created when testing against postgres and ActiveRecord >= 4.
|
|
5
|
-
if JsonVersion.table_exists?
|
|
6
|
-
RSpec.describe JsonVersion, type: :model do
|
|
7
|
-
it "includes the VersionConcern module" do
|
|
8
|
-
expect(described_class).to include(PaperTrail::VersionConcern)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "Methods" do
|
|
12
|
-
describe "Class" do
|
|
13
|
-
describe "#where_object" do
|
|
14
|
-
it { expect(described_class).to respond_to(:where_object) }
|
|
15
|
-
|
|
16
|
-
it "escapes values" do
|
|
17
|
-
f = Fruit.create(name: "Bobby")
|
|
18
|
-
expect(
|
|
19
|
-
f.
|
|
20
|
-
versions.
|
|
21
|
-
where_object(name: "Robert'; DROP TABLE Students;--").
|
|
22
|
-
count
|
|
23
|
-
).to eq(0)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "invalid arguments" do
|
|
27
|
-
it "raises an error" do
|
|
28
|
-
expect { described_class.where_object(:foo) }.to raise_error(ArgumentError)
|
|
29
|
-
expect { described_class.where_object([]) }.to raise_error(ArgumentError)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "valid arguments", versioning: true do
|
|
34
|
-
let(:fruit_names) { %w[apple orange lemon banana lime coconut strawberry blueberry] }
|
|
35
|
-
let(:fruit) { Fruit.new }
|
|
36
|
-
let(:name) { "pomegranate" }
|
|
37
|
-
let(:color) { FFaker::Color.name }
|
|
38
|
-
|
|
39
|
-
before do
|
|
40
|
-
fruit.update_attributes!(name: name)
|
|
41
|
-
fruit.update_attributes!(name: fruit_names.sample, color: color)
|
|
42
|
-
fruit.update_attributes!(name: fruit_names.sample, color: FFaker::Color.name)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "locates versions according to their `object` contents" do
|
|
46
|
-
expect(described_class.where_object(name: name)).to eq([fruit.versions[1]])
|
|
47
|
-
expect(described_class.where_object(color: color)).to eq([fruit.versions[2]])
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
describe "#where_object_changes" do
|
|
53
|
-
it { expect(described_class).to respond_to(:where_object_changes) }
|
|
54
|
-
|
|
55
|
-
it "escapes values" do
|
|
56
|
-
f = Fruit.create(name: "Bobby")
|
|
57
|
-
expect(
|
|
58
|
-
f.
|
|
59
|
-
versions.
|
|
60
|
-
where_object_changes(name: "Robert'; DROP TABLE Students;--").
|
|
61
|
-
count
|
|
62
|
-
).to eq(0)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context "invalid arguments" do
|
|
66
|
-
it "raises an error" do
|
|
67
|
-
expect { described_class.where_object_changes(:foo) }.to raise_error(ArgumentError)
|
|
68
|
-
expect { described_class.where_object_changes([]) }.to raise_error(ArgumentError)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
context "valid arguments", versioning: true do
|
|
73
|
-
let(:color) { %w[red green] }
|
|
74
|
-
let(:fruit) { Fruit.create!(name: name[0]) }
|
|
75
|
-
let(:name) { %w[banana kiwi mango] }
|
|
76
|
-
|
|
77
|
-
before do
|
|
78
|
-
fruit.update_attributes!(name: name[1], color: color[0])
|
|
79
|
-
fruit.update_attributes!(name: name[2], color: color[1])
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "finds versions according to their `object_changes` contents" do
|
|
83
|
-
expect(
|
|
84
|
-
fruit.versions.where_object_changes(name: name[0])
|
|
85
|
-
).to match_array(fruit.versions[0..1])
|
|
86
|
-
expect(
|
|
87
|
-
fruit.versions.where_object_changes(color: color[0])
|
|
88
|
-
).to match_array(fruit.versions[1..2])
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "finds versions with multiple attributes changed" do
|
|
92
|
-
expect(
|
|
93
|
-
fruit.versions.where_object_changes(color: color[0], name: name[0])
|
|
94
|
-
).to match_array([fruit.versions[1]])
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
module Kitchen
|
|
4
|
-
RSpec.describe Banana, type: :model do
|
|
5
|
-
it { is_expected.to be_versioned }
|
|
6
|
-
|
|
7
|
-
describe "#versions" do
|
|
8
|
-
it "returns instances of Kitchen::BananaVersion", versioning: true do
|
|
9
|
-
banana = described_class.create!
|
|
10
|
-
expect(banana.versions.first).to be_a(Kitchen::BananaVersion)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe LegacyWidget, type: :model, versioning: true do
|
|
4
|
-
describe "#custom_version" do
|
|
5
|
-
it "knows which version it came from" do
|
|
6
|
-
widget = described_class.create(name: "foo", version: 2)
|
|
7
|
-
%w[bar baz].each { |name| widget.update_attributes(name: name) }
|
|
8
|
-
version = widget.versions.last
|
|
9
|
-
reified = version.reify
|
|
10
|
-
expect(reified.custom_version).to(eq(version))
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#previous_version" do
|
|
15
|
-
it "return its previous self" do
|
|
16
|
-
widget = described_class.create(name: "foo", version: 2)
|
|
17
|
-
%w[bar baz].each { |name| widget.update_attributes(name: name) }
|
|
18
|
-
version = widget.versions.last
|
|
19
|
-
reified = version.reify
|
|
20
|
-
expect(reified.paper_trail.previous_version).to(eq(reified.versions[-2].reify))
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe "#update_attributes" do
|
|
25
|
-
it "does not create a PT version record because the updated column is ignored" do
|
|
26
|
-
described_class.create.update_attributes(version: 1)
|
|
27
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#version" do
|
|
32
|
-
it "is a normal attribute and has nothing to do with PT" do
|
|
33
|
-
widget = described_class.create(name: "foo", version: 2)
|
|
34
|
-
expect(widget.versions.size).to(eq(1))
|
|
35
|
-
expect(widget.version).to(eq(2))
|
|
36
|
-
widget.update_attributes(version: 3)
|
|
37
|
-
expect(widget.version).to(eq(3))
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe NotOnUpdate, type: :model do
|
|
4
|
-
describe "#touch_with_version", versioning: true do
|
|
5
|
-
let!(:record) { described_class.create! }
|
|
6
|
-
|
|
7
|
-
it "creates a version, regardless" do
|
|
8
|
-
expect { record.paper_trail.touch_with_version }.to change {
|
|
9
|
-
PaperTrail::Version.count
|
|
10
|
-
}.by(+1)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "increments the `:updated_at` timestamp" do
|
|
14
|
-
before = record.updated_at
|
|
15
|
-
# Travel 1 second because MySQL lacks sub-second resolution
|
|
16
|
-
Timecop.travel(1) do
|
|
17
|
-
record.paper_trail.touch_with_version
|
|
18
|
-
end
|
|
19
|
-
expect(record.updated_at).to be > before
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require_dependency "on/create"
|
|
3
|
-
|
|
4
|
-
module On
|
|
5
|
-
RSpec.describe Create, type: :model, versioning: true do
|
|
6
|
-
describe "#versions" do
|
|
7
|
-
it "only have a version for the create 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("create"))
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context "#paper_trail_event" do
|
|
17
|
-
it "rembembers the custom event name" do
|
|
18
|
-
record = described_class.new
|
|
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,27 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require_dependency "on/destroy"
|
|
3
|
-
|
|
4
|
-
module On
|
|
5
|
-
RSpec.describe Destroy, type: :model, versioning: true do
|
|
6
|
-
describe "#versions" do
|
|
7
|
-
it "only creates one version record, for the destroy 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("destroy"))
|
|
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,30 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require_dependency "on/empty_array"
|
|
3
|
-
|
|
4
|
-
module On
|
|
5
|
-
RSpec.describe EmptyArray, type: :model, versioning: true do
|
|
6
|
-
describe "#create" do
|
|
7
|
-
it "does not create any version records" do
|
|
8
|
-
record = described_class.create(name: "Alice")
|
|
9
|
-
expect(record.versions.length).to(eq(0))
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "#touch_with_version" do
|
|
14
|
-
it "creates a version record" do
|
|
15
|
-
record = described_class.create(name: "Alice")
|
|
16
|
-
record.paper_trail.touch_with_version
|
|
17
|
-
expect(record.versions.length).to(eq(1))
|
|
18
|
-
expect(record.versions.first.event).to(eq("update"))
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "#update_attributes" do
|
|
23
|
-
it "does not create any version records" do
|
|
24
|
-
record = described_class.create(name: "Alice")
|
|
25
|
-
record.update_attributes(name: "blah")
|
|
26
|
-
expect(record.versions.length).to(eq(0))
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|