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,88 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "generator_spec/test_case"
|
|
3
|
-
require File.expand_path("../../../lib/generators/paper_trail/install_generator", __FILE__)
|
|
4
|
-
|
|
5
|
-
RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
|
6
|
-
include GeneratorSpec::TestCase
|
|
7
|
-
destination File.expand_path("../tmp", __FILE__)
|
|
8
|
-
|
|
9
|
-
after(:all) { prepare_destination } # cleanup the tmp directory
|
|
10
|
-
|
|
11
|
-
describe "no options" do
|
|
12
|
-
before(:all) do
|
|
13
|
-
prepare_destination
|
|
14
|
-
run_generator
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "generates a migration for creating the 'versions' table" do
|
|
18
|
-
expected_parent_class = lambda {
|
|
19
|
-
old_school = "ActiveRecord::Migration"
|
|
20
|
-
ar_version = ActiveRecord::VERSION
|
|
21
|
-
if ar_version::MAJOR >= 5
|
|
22
|
-
format("%s[%d.%d]", old_school, ar_version::MAJOR, ar_version::MINOR)
|
|
23
|
-
else
|
|
24
|
-
old_school
|
|
25
|
-
end
|
|
26
|
-
}.call
|
|
27
|
-
expected_create_table_options = lambda {
|
|
28
|
-
if described_class::MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
|
|
29
|
-
', { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }'
|
|
30
|
-
else
|
|
31
|
-
""
|
|
32
|
-
end
|
|
33
|
-
}.call
|
|
34
|
-
expect(destination_root).to(
|
|
35
|
-
have_structure {
|
|
36
|
-
directory("db") {
|
|
37
|
-
directory("migrate") {
|
|
38
|
-
migration("create_versions") {
|
|
39
|
-
contains("class CreateVersions < " + expected_parent_class)
|
|
40
|
-
contains "def change"
|
|
41
|
-
contains "create_table :versions#{expected_create_table_options}"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
describe "`--with-changes` option set to `true`" do
|
|
51
|
-
before(:all) do
|
|
52
|
-
prepare_destination
|
|
53
|
-
run_generator %w[--with-changes]
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "generates a migration for creating the 'versions' table" do
|
|
57
|
-
expect(destination_root).to(
|
|
58
|
-
have_structure {
|
|
59
|
-
directory("db") {
|
|
60
|
-
directory("migrate") {
|
|
61
|
-
migration("create_versions") {
|
|
62
|
-
contains "class CreateVersions"
|
|
63
|
-
contains "def change"
|
|
64
|
-
contains "create_table :versions"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
|
|
73
|
-
expect(destination_root).to(
|
|
74
|
-
have_structure {
|
|
75
|
-
directory("db") {
|
|
76
|
-
directory("migrate") {
|
|
77
|
-
migration("add_object_changes_to_versions") {
|
|
78
|
-
contains "class AddObjectChangesToVersions"
|
|
79
|
-
contains "def change"
|
|
80
|
-
contains "add_column :versions, :object_changes, :text"
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
data/spec/models/animal_spec.rb
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Animal, type: :model, versioning: true do
|
|
4
|
-
it "baseline test setup" do
|
|
5
|
-
expect(Animal.new).to be_versioned
|
|
6
|
-
expect(Animal.inheritance_column).to eq("species")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "works with custom STI inheritance column" do
|
|
10
|
-
animal = Animal.create(name: "Animal")
|
|
11
|
-
animal.update_attributes(name: "Animal from the Muppets")
|
|
12
|
-
animal.update_attributes(name: "Animal Muppet")
|
|
13
|
-
animal.destroy
|
|
14
|
-
dog = Dog.create(name: "Snoopy")
|
|
15
|
-
dog.update_attributes(name: "Scooby")
|
|
16
|
-
dog.update_attributes(name: "Scooby Doo")
|
|
17
|
-
dog.destroy
|
|
18
|
-
cat = Cat.create(name: "Garfield")
|
|
19
|
-
cat.update_attributes(name: "Garfield (I hate Mondays)")
|
|
20
|
-
cat.update_attributes(name: "Garfield The Cat")
|
|
21
|
-
cat.destroy
|
|
22
|
-
expect(PaperTrail::Version.count).to(eq(12))
|
|
23
|
-
expect(animal.versions.count).to(eq(4))
|
|
24
|
-
expect(animal.versions.first.reify).to(be_nil)
|
|
25
|
-
animal.versions[(1..-1)].each do |v|
|
|
26
|
-
expect(v.reify.class.name).to(eq("Animal"))
|
|
27
|
-
end
|
|
28
|
-
dog_versions = PaperTrail::Version.where(item_id: dog.id).order(:created_at)
|
|
29
|
-
expect(dog_versions.count).to(eq(4))
|
|
30
|
-
expect(dog_versions.first.reify).to(be_nil)
|
|
31
|
-
expect(dog_versions.map { |v| v.reify.class.name }).to eq(%w[NilClass Dog Dog Dog])
|
|
32
|
-
cat_versions = PaperTrail::Version.where(item_id: cat.id).order(:created_at)
|
|
33
|
-
expect(cat_versions.count).to(eq(4))
|
|
34
|
-
expect(cat_versions.first.reify).to(be_nil)
|
|
35
|
-
expect(cat_versions.map { |v| v.reify.class.name }).to eq(%w[NilClass Cat Cat Cat])
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "allows the inheritance_column (species) to be updated" do
|
|
39
|
-
cat = Cat.create!(name: "Leo")
|
|
40
|
-
cat.update_attributes(name: "Spike", species: "Dog")
|
|
41
|
-
dog = Animal.find(cat.id)
|
|
42
|
-
expect(dog).to be_instance_of(Dog)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context "with callback-methods" do
|
|
46
|
-
context "when only has_paper_trail set in super class" do
|
|
47
|
-
let(:callback_cat) { Cat.create(name: "Markus") }
|
|
48
|
-
|
|
49
|
-
it "trails all events" do
|
|
50
|
-
callback_cat.update_attributes(name: "Billie")
|
|
51
|
-
callback_cat.destroy
|
|
52
|
-
expect(callback_cat.versions.collect(&:event)).to eq %w[create update destroy]
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "does not break reify" do
|
|
56
|
-
callback_cat.destroy
|
|
57
|
-
expect { callback_cat.versions.last.reify }.not_to raise_error
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
data/spec/models/article_spec.rb
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Article, type: :model, versioning: true do
|
|
4
|
-
describe ".create" do
|
|
5
|
-
it "also creates a version record" do
|
|
6
|
-
expect { described_class.create }.to(
|
|
7
|
-
change { PaperTrail::Version.count }.by(+1)
|
|
8
|
-
)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context "which updates an ignored column" do
|
|
13
|
-
it "not change the number of versions" do
|
|
14
|
-
article = described_class.create
|
|
15
|
-
article.update_attributes(title: "My first title")
|
|
16
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context "which updates an ignored column with truly Proc" do
|
|
21
|
-
it "not change the number of versions" do
|
|
22
|
-
article = described_class.create
|
|
23
|
-
article.update_attributes(abstract: "ignore abstract")
|
|
24
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "which updates an ignored column with falsy Proc" do
|
|
29
|
-
it "change the number of versions" do
|
|
30
|
-
article = described_class.create
|
|
31
|
-
article.update_attributes(abstract: "do not ignore abstract!")
|
|
32
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "which updates an ignored column, ignored with truly Proc and a selected column" do
|
|
37
|
-
it "change the number of versions" do
|
|
38
|
-
article = described_class.create
|
|
39
|
-
article.update_attributes(
|
|
40
|
-
title: "My first title",
|
|
41
|
-
content: "Some text here.",
|
|
42
|
-
abstract: "ignore abstract"
|
|
43
|
-
)
|
|
44
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
45
|
-
expect(article.versions.size).to(eq(2))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "have stored only non-ignored attributes" do
|
|
49
|
-
article = described_class.create
|
|
50
|
-
article.update_attributes(
|
|
51
|
-
title: "My first title",
|
|
52
|
-
content: "Some text here.",
|
|
53
|
-
abstract: "ignore abstract"
|
|
54
|
-
)
|
|
55
|
-
expected = { "content" => [nil, "Some text here."] }
|
|
56
|
-
expect(article.versions.last.changeset).to(eq(expected))
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "which updates an ignored column, ignored with falsy Proc and a selected column" do
|
|
61
|
-
it "change the number of versions" do
|
|
62
|
-
article = described_class.create
|
|
63
|
-
article.update_attributes(
|
|
64
|
-
title: "My first title",
|
|
65
|
-
content: "Some text here.",
|
|
66
|
-
abstract: "do not ignore abstract"
|
|
67
|
-
)
|
|
68
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
69
|
-
expect(article.versions.size).to(eq(2))
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "stores only non-ignored attributes" do
|
|
73
|
-
article = described_class.create
|
|
74
|
-
article.update_attributes(
|
|
75
|
-
title: "My first title",
|
|
76
|
-
content: "Some text here.",
|
|
77
|
-
abstract: "do not ignore abstract"
|
|
78
|
-
)
|
|
79
|
-
expected = {
|
|
80
|
-
"content" => [nil, "Some text here."],
|
|
81
|
-
"abstract" => [nil, "do not ignore abstract"]
|
|
82
|
-
}
|
|
83
|
-
expect(article.versions.last.changeset).to(eq(expected))
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
context "which updates a selected column" do
|
|
88
|
-
it "change the number of versions" do
|
|
89
|
-
article = described_class.create
|
|
90
|
-
article.update_attributes(content: "Some text here.")
|
|
91
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
92
|
-
expect(article.versions.size).to(eq(2))
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context "which updates a non-ignored and non-selected column" do
|
|
97
|
-
it "not change the number of versions" do
|
|
98
|
-
article = described_class.create
|
|
99
|
-
article.update_attributes(abstract: "Other abstract")
|
|
100
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
context "which updates a skipped column" do
|
|
105
|
-
it "not change the number of versions" do
|
|
106
|
-
article = described_class.create
|
|
107
|
-
article.update_attributes(file_upload: "Your data goes here")
|
|
108
|
-
expect(PaperTrail::Version.count).to(eq(1))
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
context "which updates a skipped column and a selected column" do
|
|
113
|
-
it "change the number of versions" do
|
|
114
|
-
article = described_class.create
|
|
115
|
-
article.update_attributes(
|
|
116
|
-
file_upload: "Your data goes here",
|
|
117
|
-
content: "Some text here."
|
|
118
|
-
)
|
|
119
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "show the new version in the model's `versions` association" do
|
|
123
|
-
article = described_class.create
|
|
124
|
-
article.update_attributes(
|
|
125
|
-
file_upload: "Your data goes here",
|
|
126
|
-
content: "Some text here."
|
|
127
|
-
)
|
|
128
|
-
expect(article.versions.size).to(eq(2))
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "have stored only non-skipped attributes" do
|
|
132
|
-
article = described_class.create
|
|
133
|
-
article.update_attributes(
|
|
134
|
-
file_upload: "Your data goes here",
|
|
135
|
-
content: "Some text here."
|
|
136
|
-
)
|
|
137
|
-
expect(
|
|
138
|
-
article.versions.last.changeset
|
|
139
|
-
).to(eq("content" => [nil, "Some text here."]))
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
context "and when updated again" do
|
|
143
|
-
it "have removed the skipped attributes when saving the previous version" do
|
|
144
|
-
article = described_class.create
|
|
145
|
-
article.update_attributes(
|
|
146
|
-
file_upload: "Your data goes here",
|
|
147
|
-
content: "Some text here."
|
|
148
|
-
)
|
|
149
|
-
article.update_attributes(
|
|
150
|
-
file_upload: "More data goes here",
|
|
151
|
-
content: "More text here."
|
|
152
|
-
)
|
|
153
|
-
old_article = article.versions.last
|
|
154
|
-
expect(
|
|
155
|
-
PaperTrail.serializer.load(old_article.object)["file_upload"]
|
|
156
|
-
).to(be_nil)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "have kept the non-skipped attributes in the previous version" do
|
|
160
|
-
article = described_class.create
|
|
161
|
-
article.update_attributes(
|
|
162
|
-
file_upload: "Your data goes here",
|
|
163
|
-
content: "Some text here."
|
|
164
|
-
)
|
|
165
|
-
article.update_attributes(
|
|
166
|
-
file_upload: "More data goes here",
|
|
167
|
-
content: "More text here."
|
|
168
|
-
)
|
|
169
|
-
old_article = article.versions.last
|
|
170
|
-
expect(
|
|
171
|
-
PaperTrail.serializer.load(old_article.object)["content"]
|
|
172
|
-
).to(eq("Some text here."))
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
context "#destroy" do
|
|
178
|
-
it "creates a version record" do
|
|
179
|
-
article = described_class.create
|
|
180
|
-
article.destroy
|
|
181
|
-
expect(PaperTrail::Version.count).to(eq(2))
|
|
182
|
-
expect(article.versions.size).to(eq(2))
|
|
183
|
-
expect(article.versions.map(&:event)).to(match_array(%w[create destroy]))
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
end
|
data/spec/models/boolit_spec.rb
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "support/custom_json_serializer"
|
|
3
|
-
|
|
4
|
-
RSpec.describe Boolit, type: :model, versioning: true do
|
|
5
|
-
subject { Boolit.create! }
|
|
6
|
-
|
|
7
|
-
before { subject.update_attributes!(name: FFaker::Name.name) }
|
|
8
|
-
|
|
9
|
-
it "has two versions" do
|
|
10
|
-
expect(subject.versions.size).to eq(2)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "can be reified and persisted" do
|
|
14
|
-
expect { subject.versions.last.reify.save! }.not_to raise_error
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "Instance falls out of default scope" do
|
|
18
|
-
before { subject.update_attributes!(scoped: false) }
|
|
19
|
-
|
|
20
|
-
it "is NOT scoped" do
|
|
21
|
-
expect(Boolit.first).to be_nil
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "still can be reified and persisted" do
|
|
25
|
-
expect { subject.paper_trail.previous_version.save! }.not_to raise_error
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "with `nil` attributes on the live instance" do
|
|
29
|
-
before do
|
|
30
|
-
PaperTrail.serializer = CustomJsonSerializer
|
|
31
|
-
subject.update_attributes!(name: nil)
|
|
32
|
-
subject.update_attributes!(name: FFaker::Name.name)
|
|
33
|
-
end
|
|
34
|
-
after { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
|
35
|
-
|
|
36
|
-
it "does not overwrite that attribute during the reification process" do
|
|
37
|
-
expect(subject.paper_trail.previous_version.name).to be_nil
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe CallbackModifier, type: :model, versioning: true do
|
|
4
|
-
describe "paper_trail_on_destroy" do
|
|
5
|
-
it "adds :destroy to paper_trail_options[:on]" do
|
|
6
|
-
modifier = NoArgDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
7
|
-
expect(modifier.paper_trail_options[:on]).to eq([:destroy])
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "when :before" do
|
|
11
|
-
it "creates the version before destroy" do
|
|
12
|
-
modifier = BeforeDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
13
|
-
modifier.test_destroy
|
|
14
|
-
expect(modifier.versions.last.reify).not_to be_flagged_deleted
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "when :after" do
|
|
19
|
-
it "creates the version after destroy" do
|
|
20
|
-
modifier = AfterDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
21
|
-
modifier.test_destroy
|
|
22
|
-
expect(modifier.versions.last.reify).to be_flagged_deleted
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "when no argument" do
|
|
27
|
-
it "defaults to before destroy" do
|
|
28
|
-
modifier = NoArgDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
29
|
-
modifier.test_destroy
|
|
30
|
-
expect(modifier.versions.last.reify).not_to be_flagged_deleted
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "paper_trail_on_update" do
|
|
36
|
-
it "adds :update to paper_trail_options[:on]" do
|
|
37
|
-
modifier = UpdateModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
38
|
-
expect(modifier.paper_trail_options[:on]).to eq [:update]
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "creates a version" do
|
|
42
|
-
modifier = UpdateModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
43
|
-
modifier.update_attributes! some_content: "modified"
|
|
44
|
-
expect(modifier.versions.last.event).to eq "update"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe "paper_trail_on_create" do
|
|
49
|
-
it "adds :create to paper_trail_options[:on]" do
|
|
50
|
-
modifier = CreateModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
51
|
-
expect(modifier.paper_trail_options[:on]).to eq [:create]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "creates a version" do
|
|
55
|
-
modifier = CreateModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
56
|
-
expect(modifier.versions.last.event).to eq "create"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "when no callback-method used" do
|
|
61
|
-
it "sets paper_trail_options[:on] to [:create, :update, :destroy]" do
|
|
62
|
-
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
63
|
-
expect(modifier.paper_trail_options[:on]).to eq %i[create update destroy]
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "tracks destroy" do
|
|
67
|
-
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
68
|
-
modifier.destroy
|
|
69
|
-
expect(modifier.versions.last.event).to eq "destroy"
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "tracks update" do
|
|
73
|
-
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
74
|
-
modifier.update_attributes! some_content: "modified"
|
|
75
|
-
expect(modifier.versions.last.event).to eq "update"
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "tracks create" do
|
|
79
|
-
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
80
|
-
expect(modifier.versions.last.event).to eq "create"
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
context "when only one callback-method" do
|
|
85
|
-
it "does only track the corresponding event" do
|
|
86
|
-
modifier = CreateModifier.create!(some_content: FFaker::Lorem.sentence)
|
|
87
|
-
modifier.update_attributes!(some_content: "modified")
|
|
88
|
-
modifier.test_destroy
|
|
89
|
-
expect(modifier.versions.collect(&:event)).to eq ["create"]
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|