paper_trail 7.0.3 → 7.1.0
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/.github/CONTRIBUTING.md +21 -27
- data/.gitignore +4 -4
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +17 -0
- data/README.md +31 -2
- data/Rakefile +4 -1
- data/lib/paper_trail.rb +2 -0
- data/lib/paper_trail/serializers/json.rb +9 -0
- data/lib/paper_trail/version_concern.rb +1 -1
- data/lib/paper_trail/version_number.rb +2 -2
- data/paper_trail.gemspec +2 -3
- data/spec/controllers/widgets_controller_spec.rb +85 -0
- data/{test/dummy → spec/dummy_app}/Rakefile +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/application_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/articles_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/test_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/widgets_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/animal.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/article.rb +1 -0
- data/{test/dummy → spec/dummy_app}/app/models/authorship.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/bar_habtm.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/book.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/boolit.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/callback_modifier.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/car.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/cat.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/chapter.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/citation.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/custom_primary_key_record.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/customer.rb +0 -0
- data/spec/dummy_app/app/models/document.rb +8 -0
- data/{test/dummy → spec/dummy_app}/app/models/dog.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/editor.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/editorship.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/elephant.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/fluxor.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/foo_habtm.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/foo_widget.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/fruit.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/gadget.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/kitchen/banana.rb +0 -0
- data/spec/dummy_app/app/models/legacy_widget.rb +6 -0
- data/{test/dummy → spec/dummy_app}/app/models/line_item.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/not_on_update.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/create.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/destroy.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/empty_array.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/update.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/order.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/paragraph.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/person.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/post.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/post_with_status.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/quotation.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/section.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/skipper.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/song.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/thing.rb +0 -0
- data/spec/dummy_app/app/models/translation.rb +11 -0
- data/{test/dummy → spec/dummy_app}/app/models/truck.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/vehicle.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/whatchamajigger.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/widget.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/wotsit.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/custom_primary_key_record_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/joined_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/json_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/kitchen/banana_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/post_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config.ru +0 -0
- data/{test/dummy → spec/dummy_app}/config/application.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/boot.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/database.mysql.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/database.postgres.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/database.sqlite.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/environment.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/environments/development.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/environments/production.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/environments/test.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/backtrace_silencers.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/inflections.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/mime_types.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/paper_trail.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/secret_token.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/session_store.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/locales/en.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/routes.rb +0 -0
- data/{test/dummy → spec/dummy_app}/db/migrate/20110208155312_set_up_test_tables.rb +0 -0
- data/{test/dummy → spec/dummy_app}/db/schema.rb +0 -0
- data/spec/models/article_spec.rb +186 -0
- data/spec/models/document_spec.rb +41 -5
- data/spec/models/legacy_widget_spec.rb +40 -0
- data/spec/models/on/create_spec.rb +27 -0
- data/spec/models/on/destroy_spec.rb +27 -0
- data/spec/models/on/empty_array_spec.rb +30 -0
- data/spec/models/on/update_spec.rb +27 -0
- data/spec/models/translation_spec.rb +70 -0
- data/spec/models/version_spec.rb +7 -3
- data/spec/paper_trail/config_spec.rb +12 -0
- data/spec/paper_trail/model_spec.rb +0 -429
- data/spec/paper_trail/serializers/custom_json_serializer_spec.rb +18 -0
- data/spec/paper_trail/thread_safety_spec.rb +44 -0
- data/spec/paper_trail_spec.rb +9 -0
- data/spec/spec_helper.rb +6 -10
- metadata +178 -179
- data/test/dummy/app/models/document.rb +0 -6
- data/test/dummy/app/models/legacy_widget.rb +0 -3
- data/test/dummy/app/models/translation.rb +0 -6
- data/test/functional/controller_test.rb +0 -90
- data/test/functional/thread_safety_test.rb +0 -46
- data/test/test_helper.rb +0 -68
- data/test/unit/serializers/mixin_json_test.rb +0 -39
|
@@ -0,0 +1,40 @@
|
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1,70 @@
|
|
|
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/version_spec.rb
CHANGED
|
@@ -225,8 +225,6 @@ module PaperTrail
|
|
|
225
225
|
end
|
|
226
226
|
|
|
227
227
|
context "YAML serializer" do
|
|
228
|
-
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
|
229
|
-
|
|
230
228
|
it "locates versions according to their `object_changes` contents" do
|
|
231
229
|
expect(
|
|
232
230
|
widget.versions.where_object_changes(name: name)
|
|
@@ -248,7 +246,13 @@ module PaperTrail
|
|
|
248
246
|
|
|
249
247
|
context "JSON serializer" do
|
|
250
248
|
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
|
251
|
-
|
|
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
|
|
252
256
|
|
|
253
257
|
it "locates versions according to their `object_changes` contents" do
|
|
254
258
|
expect(
|
|
@@ -29,5 +29,17 @@ module PaperTrail
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
describe ".version_limit", versioning: true do
|
|
34
|
+
after { PaperTrail.config.version_limit = nil }
|
|
35
|
+
|
|
36
|
+
it "limits the number of versions to 3 (2 plus the created at event)" do
|
|
37
|
+
PaperTrail.config.version_limit = 2
|
|
38
|
+
widget = Widget.create!(name: "Henry")
|
|
39
|
+
6.times { widget.update_attribute(:name, FFaker::Lorem.word) }
|
|
40
|
+
expect(widget.versions.first.event).to(eq("create"))
|
|
41
|
+
expect(widget.versions.size).to(eq(3))
|
|
42
|
+
end
|
|
43
|
+
end
|
|
32
44
|
end
|
|
33
45
|
end
|
|
@@ -1,262 +1,6 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
RSpec.describe(::PaperTrail, versioning: true) do
|
|
4
|
-
context "A record with defined 'only' and 'ignore' attributes" do
|
|
5
|
-
before { @article = Article.create }
|
|
6
|
-
|
|
7
|
-
it "creation should change the number of versions" do
|
|
8
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context "which updates an ignored column" do
|
|
12
|
-
it "not change the number of versions" do
|
|
13
|
-
@article.update_attributes(title: "My first title")
|
|
14
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "which updates an ignored column with truly Proc" do
|
|
19
|
-
it "not change the number of versions" do
|
|
20
|
-
@article.update_attributes(abstract: "ignore abstract")
|
|
21
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "which updates an ignored column with falsy Proc" do
|
|
26
|
-
it "change the number of versions" do
|
|
27
|
-
@article.update_attributes(abstract: "do not ignore abstract!")
|
|
28
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
context "which updates an ignored column, ignored with truly Proc and a selected column" do
|
|
33
|
-
before do
|
|
34
|
-
@article.update_attributes(
|
|
35
|
-
title: "My first title",
|
|
36
|
-
content: "Some text here.",
|
|
37
|
-
abstract: "ignore abstract"
|
|
38
|
-
)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "change the number of versions" do
|
|
42
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "show the new version in the model's `versions` association" do
|
|
46
|
-
expect(@article.versions.size).to(eq(2))
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "have stored only non-ignored attributes" do
|
|
50
|
-
expected = { "content" => [nil, "Some text here."] }
|
|
51
|
-
expect(@article.versions.last.changeset).to(eq(expected))
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context "which updates an ignored column, ignored with falsy Proc and a selected column" do
|
|
56
|
-
before do
|
|
57
|
-
@article.update_attributes(
|
|
58
|
-
title: "My first title",
|
|
59
|
-
content: "Some text here.",
|
|
60
|
-
abstract: "do not ignore abstract"
|
|
61
|
-
)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "change the number of versions" do
|
|
65
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "show the new version in the model's `versions` association" do
|
|
69
|
-
expect(@article.versions.size).to(eq(2))
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "have stored only non-ignored attributes" do
|
|
73
|
-
expected = {
|
|
74
|
-
"content" => [nil, "Some text here."],
|
|
75
|
-
"abstract" => [nil, "do not ignore abstract"]
|
|
76
|
-
}
|
|
77
|
-
expect(@article.versions.last.changeset).to(eq(expected))
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
context "which updates a selected column" do
|
|
82
|
-
before { @article.update_attributes(content: "Some text here.") }
|
|
83
|
-
|
|
84
|
-
it "change the number of versions" do
|
|
85
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "show the new version in the model's `versions` association" do
|
|
89
|
-
expect(@article.versions.size).to(eq(2))
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
context "which updates a non-ignored and non-selected column" do
|
|
94
|
-
it "not change the number of versions" do
|
|
95
|
-
@article.update_attributes(abstract: "Other abstract")
|
|
96
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
context "which updates a skipped column" do
|
|
101
|
-
it "not change the number of versions" do
|
|
102
|
-
@article.update_attributes(file_upload: "Your data goes here")
|
|
103
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context "which updates a skipped column and a selected column" do
|
|
108
|
-
before do
|
|
109
|
-
@article.update_attributes(
|
|
110
|
-
file_upload: "Your data goes here",
|
|
111
|
-
content: "Some text here."
|
|
112
|
-
)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "change the number of versions" do
|
|
116
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "show the new version in the model's `versions` association" do
|
|
120
|
-
expect(@article.versions.size).to(eq(2))
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "have stored only non-skipped attributes" do
|
|
124
|
-
expect(
|
|
125
|
-
@article.versions.last.changeset
|
|
126
|
-
).to(eq("content" => [nil, "Some text here."]))
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
context "and when updated again" do
|
|
130
|
-
before do
|
|
131
|
-
@article.update_attributes(
|
|
132
|
-
file_upload: "More data goes here",
|
|
133
|
-
content: "More text here."
|
|
134
|
-
)
|
|
135
|
-
@old_article = @article.versions.last
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it "have removed the skipped attributes when saving the previous version" do
|
|
139
|
-
expect(
|
|
140
|
-
PaperTrail.serializer.load(@old_article.object)["file_upload"]
|
|
141
|
-
).to(be_nil)
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
it "have kept the non-skipped attributes in the previous version" do
|
|
145
|
-
expect(
|
|
146
|
-
PaperTrail.serializer.load(@old_article.object)["content"]
|
|
147
|
-
).to(eq("Some text here."))
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
context "which gets destroyed" do
|
|
153
|
-
before { @article.destroy }
|
|
154
|
-
|
|
155
|
-
it "change the number of versions" do
|
|
156
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "show the new version in the model's `versions` association" do
|
|
160
|
-
expect(@article.versions.size).to(eq(2))
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
context "A record with defined 'ignore' attribute" do
|
|
166
|
-
before { @legacy_widget = LegacyWidget.create }
|
|
167
|
-
|
|
168
|
-
context "which updates an ignored column" do
|
|
169
|
-
before { @legacy_widget.update_attributes(version: 1) }
|
|
170
|
-
|
|
171
|
-
it "not change the number of versions" do
|
|
172
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
context "A record with defined \"if\" and \"unless\" attributes" do
|
|
178
|
-
before { @translation = Translation.new(headline: "Headline") }
|
|
179
|
-
|
|
180
|
-
context "for non-US translations" do
|
|
181
|
-
before { @translation.save }
|
|
182
|
-
|
|
183
|
-
it "not change the number of versions" do
|
|
184
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
context "after update" do
|
|
188
|
-
before { @translation.update_attributes(content: "Content") }
|
|
189
|
-
|
|
190
|
-
it "not change the number of versions" do
|
|
191
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
context "after destroy" do
|
|
196
|
-
before { @translation.destroy }
|
|
197
|
-
|
|
198
|
-
it "not change the number of versions" do
|
|
199
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
context "for US translations" do
|
|
205
|
-
before { @translation.language_code = "US" }
|
|
206
|
-
|
|
207
|
-
context "that are drafts" do
|
|
208
|
-
before do
|
|
209
|
-
@translation.type = "DRAFT"
|
|
210
|
-
@translation.save
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
it "not change the number of versions" do
|
|
214
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
context "after update" do
|
|
218
|
-
before { @translation.update_attributes(content: "Content") }
|
|
219
|
-
|
|
220
|
-
it "not change the number of versions" do
|
|
221
|
-
expect(PaperTrail::Version.count).to(eq(0))
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
context "that are not drafts" do
|
|
227
|
-
before { @translation.save }
|
|
228
|
-
|
|
229
|
-
it "change the number of versions" do
|
|
230
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
context "after update" do
|
|
234
|
-
before { @translation.update_attributes(content: "Content") }
|
|
235
|
-
|
|
236
|
-
it "change the number of versions" do
|
|
237
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
it "show the new version in the model's `versions` association" do
|
|
241
|
-
expect(@translation.versions.size).to(eq(2))
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
context "after destroy" do
|
|
246
|
-
before { @translation.destroy }
|
|
247
|
-
|
|
248
|
-
it "change the number of versions" do
|
|
249
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
it "show the new version in the model's `versions` association" do
|
|
253
|
-
expect(@translation.versions.size).to(eq(2))
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
|
|
260
4
|
context "A new record" do
|
|
261
5
|
before { @widget = Widget.new }
|
|
262
6
|
|
|
@@ -1245,177 +989,4 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|
|
1245
989
|
expect(@widget.versions.empty?).to(eq(true))
|
|
1246
990
|
end
|
|
1247
991
|
end
|
|
1248
|
-
|
|
1249
|
-
context "A model with a custom association" do
|
|
1250
|
-
before do
|
|
1251
|
-
@doc = Document.create
|
|
1252
|
-
@doc.update_attributes(name: "Doc 1")
|
|
1253
|
-
end
|
|
1254
|
-
|
|
1255
|
-
it "not respond to versions method" do
|
|
1256
|
-
expect(!@doc.respond_to?(:versions)).to(be_truthy)
|
|
1257
|
-
end
|
|
1258
|
-
|
|
1259
|
-
it "create a new version record" do
|
|
1260
|
-
expect(@doc.paper_trail_versions.length).to(eq(2))
|
|
1261
|
-
end
|
|
1262
|
-
|
|
1263
|
-
it "respond to `next_version` as normal" do
|
|
1264
|
-
reified = @doc.paper_trail_versions.last.reify
|
|
1265
|
-
expect(@doc.name).to(eq(reified.paper_trail.next_version.name))
|
|
1266
|
-
end
|
|
1267
|
-
|
|
1268
|
-
it "respond to `previous_version` as normal" do
|
|
1269
|
-
@doc.update_attributes(name: "Doc 2")
|
|
1270
|
-
expect(@doc.paper_trail_versions.length).to(eq(3))
|
|
1271
|
-
expect(@doc.paper_trail.previous_version.name).to(eq("Doc 1"))
|
|
1272
|
-
end
|
|
1273
|
-
end
|
|
1274
|
-
|
|
1275
|
-
context "The `on` option" do
|
|
1276
|
-
context "on create" do
|
|
1277
|
-
it "only have a version for the create event" do
|
|
1278
|
-
record = ::On::Create.create(name: "Alice")
|
|
1279
|
-
record.update_attributes(name: "blah")
|
|
1280
|
-
record.destroy
|
|
1281
|
-
expect(record.versions.length).to(eq(1))
|
|
1282
|
-
expect(record.versions.last.event).to(eq("create"))
|
|
1283
|
-
end
|
|
1284
|
-
end
|
|
1285
|
-
|
|
1286
|
-
context "on update" do
|
|
1287
|
-
it "only have a version for the update event" do
|
|
1288
|
-
record = ::On::Update.create(name: "Alice")
|
|
1289
|
-
record.update_attributes(name: "blah")
|
|
1290
|
-
record.destroy
|
|
1291
|
-
expect(record.versions.length).to(eq(1))
|
|
1292
|
-
expect(record.versions.last.event).to(eq("update"))
|
|
1293
|
-
end
|
|
1294
|
-
end
|
|
1295
|
-
|
|
1296
|
-
context "on destroy" do
|
|
1297
|
-
it "only have a version for the destroy event" do
|
|
1298
|
-
record = ::On::Destroy.create(name: "Alice")
|
|
1299
|
-
record.update_attributes(name: "blah")
|
|
1300
|
-
record.destroy
|
|
1301
|
-
expect(record.versions.length).to(eq(1))
|
|
1302
|
-
expect(record.versions.last.event).to(eq("destroy"))
|
|
1303
|
-
end
|
|
1304
|
-
end
|
|
1305
|
-
|
|
1306
|
-
context "on []" do
|
|
1307
|
-
before do
|
|
1308
|
-
@record = ::On::EmptyArray.create(name: "Alice")
|
|
1309
|
-
@record.update_attributes(name: "blah")
|
|
1310
|
-
end
|
|
1311
|
-
|
|
1312
|
-
after { @record.destroy }
|
|
1313
|
-
|
|
1314
|
-
it "not have any versions" do
|
|
1315
|
-
expect(@record.versions.length).to(eq(0))
|
|
1316
|
-
end
|
|
1317
|
-
|
|
1318
|
-
it "still respond to touch_with_version" do
|
|
1319
|
-
@record.paper_trail.touch_with_version
|
|
1320
|
-
expect(@record.versions.length).to(eq(1))
|
|
1321
|
-
end
|
|
1322
|
-
end
|
|
1323
|
-
|
|
1324
|
-
context "allows a symbol to be passed" do
|
|
1325
|
-
it "only have a version for hte create event" do
|
|
1326
|
-
record = ::On::Create.create(name: "Alice")
|
|
1327
|
-
record.update_attributes(name: "blah")
|
|
1328
|
-
record.destroy
|
|
1329
|
-
expect(record.versions.length).to(eq(1))
|
|
1330
|
-
expect(record.versions.last.event).to(eq("create"))
|
|
1331
|
-
end
|
|
1332
|
-
end
|
|
1333
|
-
end
|
|
1334
|
-
|
|
1335
|
-
context "A model with column version and custom version_method" do
|
|
1336
|
-
before do
|
|
1337
|
-
@legacy_widget = LegacyWidget.create(name: "foo", version: 2)
|
|
1338
|
-
end
|
|
1339
|
-
|
|
1340
|
-
it "set version on create" do
|
|
1341
|
-
expect(@legacy_widget.version).to(eq(2))
|
|
1342
|
-
end
|
|
1343
|
-
|
|
1344
|
-
it "allow version updates" do
|
|
1345
|
-
@legacy_widget.update_attributes(version: 3)
|
|
1346
|
-
expect(@legacy_widget.version).to(eq(3))
|
|
1347
|
-
end
|
|
1348
|
-
|
|
1349
|
-
it "create a new version record" do
|
|
1350
|
-
expect(@legacy_widget.versions.size).to(eq(1))
|
|
1351
|
-
end
|
|
1352
|
-
end
|
|
1353
|
-
|
|
1354
|
-
context "A reified item with a column -version- and custom version_method" do
|
|
1355
|
-
before do
|
|
1356
|
-
widget = LegacyWidget.create(name: "foo", version: 2)
|
|
1357
|
-
%w[bar baz].each { |name| widget.update_attributes(name: name) }
|
|
1358
|
-
@version = widget.versions.last
|
|
1359
|
-
@widget = @version.reify
|
|
1360
|
-
end
|
|
1361
|
-
|
|
1362
|
-
it "know which version it came from" do
|
|
1363
|
-
expect(@widget.custom_version).to(eq(@version))
|
|
1364
|
-
end
|
|
1365
|
-
|
|
1366
|
-
it "return its previous self" do
|
|
1367
|
-
expect(@widget.paper_trail.previous_version).to(eq(@widget.versions[-2].reify))
|
|
1368
|
-
end
|
|
1369
|
-
end
|
|
1370
|
-
|
|
1371
|
-
context "custom events" do
|
|
1372
|
-
context "on create" do
|
|
1373
|
-
it "only have a version for the created event" do
|
|
1374
|
-
record = ::On::Create.new.tap { |model| model.paper_trail_event = "created" }
|
|
1375
|
-
record.update_attributes(name: "blah")
|
|
1376
|
-
record.destroy
|
|
1377
|
-
expect(record.versions.length).to(eq(1))
|
|
1378
|
-
expect(record.versions.last.event).to(eq("created"))
|
|
1379
|
-
end
|
|
1380
|
-
end
|
|
1381
|
-
|
|
1382
|
-
context "on update" do
|
|
1383
|
-
it "only have a version for the name_updated event" do
|
|
1384
|
-
record = ::On::Update.create(name: "Alice").tap do |model|
|
|
1385
|
-
model.paper_trail_event = "name_updated"
|
|
1386
|
-
end
|
|
1387
|
-
record.update_attributes(name: "blah")
|
|
1388
|
-
record.destroy
|
|
1389
|
-
expect(record.versions.length).to(eq(1))
|
|
1390
|
-
expect(record.versions.last.event).to(eq("name_updated"))
|
|
1391
|
-
end
|
|
1392
|
-
end
|
|
1393
|
-
|
|
1394
|
-
context "on destroy" do
|
|
1395
|
-
it "only have a version for the destroy event" do
|
|
1396
|
-
record = ::On::Destroy.create(name: "Alice").tap do |model|
|
|
1397
|
-
model.paper_trail_event = "destroyed"
|
|
1398
|
-
end
|
|
1399
|
-
record.update_attributes(name: "blah")
|
|
1400
|
-
record.destroy
|
|
1401
|
-
expect(record.versions.length).to(eq(1))
|
|
1402
|
-
expect(record.versions.last.event).to(eq("destroyed"))
|
|
1403
|
-
end
|
|
1404
|
-
end
|
|
1405
|
-
end
|
|
1406
|
-
|
|
1407
|
-
context "`PaperTrail::Config.version_limit` set" do
|
|
1408
|
-
before do
|
|
1409
|
-
PaperTrail.config.version_limit = 2
|
|
1410
|
-
@widget = Widget.create!(name: "Henry")
|
|
1411
|
-
6.times { @widget.update_attribute(:name, FFaker::Lorem.word) }
|
|
1412
|
-
end
|
|
1413
|
-
|
|
1414
|
-
after { PaperTrail.config.version_limit = nil }
|
|
1415
|
-
|
|
1416
|
-
it "limit the number of versions to 3 (2 plus the created at event)" do
|
|
1417
|
-
expect(@widget.versions.first.event).to(eq("create"))
|
|
1418
|
-
expect(@widget.versions.size).to(eq(3))
|
|
1419
|
-
end
|
|
1420
|
-
end
|
|
1421
992
|
end
|