paper_trail 6.0.2 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +20 -0
- data/.rubocop.yml +30 -2
- data/.rubocop_todo.yml +20 -0
- data/.travis.yml +3 -5
- data/Appraisals +5 -6
- data/CHANGELOG.md +33 -0
- data/README.md +43 -81
- data/Rakefile +1 -1
- data/doc/bug_report_template.rb +4 -2
- data/gemfiles/ar_4.0.gemfile +7 -0
- data/gemfiles/ar_4.2.gemfile +0 -1
- data/lib/generators/paper_trail/templates/create_version_associations.rb +1 -1
- data/lib/generators/paper_trail/templates/create_versions.rb +1 -1
- data/lib/paper_trail.rb +7 -9
- data/lib/paper_trail/config.rb +0 -15
- data/lib/paper_trail/frameworks/rspec.rb +8 -2
- data/lib/paper_trail/model_config.rb +6 -2
- data/lib/paper_trail/record_trail.rb +3 -1
- data/lib/paper_trail/reifier.rb +43 -354
- data/lib/paper_trail/reifiers/belongs_to.rb +48 -0
- data/lib/paper_trail/reifiers/has_and_belongs_to_many.rb +50 -0
- data/lib/paper_trail/reifiers/has_many.rb +110 -0
- data/lib/paper_trail/reifiers/has_many_through.rb +90 -0
- data/lib/paper_trail/reifiers/has_one.rb +76 -0
- data/lib/paper_trail/serializers/yaml.rb +2 -25
- data/lib/paper_trail/version_concern.rb +5 -5
- data/lib/paper_trail/version_number.rb +7 -3
- data/paper_trail.gemspec +7 -34
- data/spec/controllers/articles_controller_spec.rb +1 -1
- data/spec/generators/install_generator_spec.rb +40 -34
- data/spec/models/animal_spec.rb +50 -25
- data/spec/models/boolit_spec.rb +8 -7
- data/spec/models/callback_modifier_spec.rb +13 -13
- data/spec/models/document_spec.rb +21 -0
- data/spec/models/gadget_spec.rb +35 -39
- data/spec/models/joined_version_spec.rb +4 -4
- data/spec/models/json_version_spec.rb +14 -15
- data/spec/models/not_on_update_spec.rb +1 -1
- data/spec/models/post_with_status_spec.rb +2 -2
- data/spec/models/skipper_spec.rb +4 -4
- data/spec/models/thing_spec.rb +1 -1
- data/spec/models/truck_spec.rb +1 -1
- data/spec/models/vehicle_spec.rb +1 -1
- data/spec/models/version_spec.rb +152 -168
- data/spec/models/widget_spec.rb +170 -196
- data/spec/modules/paper_trail_spec.rb +3 -3
- data/spec/modules/version_concern_spec.rb +5 -8
- data/spec/modules/version_number_spec.rb +11 -36
- data/spec/paper_trail/cleaner_spec.rb +152 -0
- data/spec/paper_trail/config_spec.rb +1 -1
- data/spec/paper_trail/serializers/custom_yaml_serializer_spec.rb +45 -0
- data/spec/paper_trail/serializers/json_spec.rb +57 -0
- data/spec/paper_trail/version_limit_spec.rb +55 -0
- data/spec/paper_trail_spec.rb +45 -32
- data/spec/requests/articles_spec.rb +4 -4
- data/test/dummy/app/models/custom_primary_key_record.rb +4 -2
- data/test/dummy/app/models/document.rb +1 -1
- data/test/dummy/app/models/not_on_update.rb +1 -1
- data/test/dummy/app/models/on/create.rb +6 -0
- data/test/dummy/app/models/on/destroy.rb +6 -0
- data/test/dummy/app/models/on/empty_array.rb +6 -0
- data/test/dummy/app/models/on/update.rb +6 -0
- data/test/dummy/app/models/person.rb +1 -0
- data/test/dummy/app/models/song.rb +19 -28
- data/test/dummy/config/application.rb +10 -43
- data/test/dummy/config/routes.rb +1 -1
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +25 -51
- data/test/dummy/db/schema.rb +29 -19
- data/test/test_helper.rb +0 -16
- data/test/unit/associations_test.rb +81 -81
- data/test/unit/model_test.rb +48 -131
- data/test/unit/serializer_test.rb +34 -45
- data/test/unit/serializers/mixin_json_test.rb +3 -1
- data/test/unit/serializers/yaml_test.rb +1 -5
- metadata +44 -19
- data/lib/paper_trail/frameworks/sinatra.rb +0 -40
- data/test/functional/modular_sinatra_test.rb +0 -46
- data/test/functional/sinatra_test.rb +0 -51
- data/test/unit/cleaner_test.rb +0 -151
- data/test/unit/inheritance_column_test.rb +0 -41
- data/test/unit/serializers/json_test.rb +0 -95
- data/test/unit/serializers/mixin_yaml_test.rb +0 -53
@@ -15,19 +15,19 @@ describe JoinedVersion, type: :model, versioning: true do
|
|
15
15
|
before { widget } # persist a widget
|
16
16
|
|
17
17
|
describe "#subsequent" do
|
18
|
-
it "
|
18
|
+
it "does not raise error when there is a default_scope that joins" do
|
19
19
|
JoinedVersion.subsequent(version).first
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#preceding" do
|
24
|
-
it "
|
24
|
+
it "does not raise error when there is a default scope that joins" do
|
25
25
|
JoinedVersion.preceding(version).first
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#between" do
|
30
|
-
it "
|
30
|
+
it "does not raise error when there is a default scope that joins" do
|
31
31
|
JoinedVersion.between(Time.now, 1.minute.from_now).first
|
32
32
|
end
|
33
33
|
end
|
@@ -38,7 +38,7 @@ describe JoinedVersion, type: :model, versioning: true do
|
|
38
38
|
describe "#index" do
|
39
39
|
it { is_expected.to respond_to(:index) }
|
40
40
|
|
41
|
-
it "
|
41
|
+
it "does not raise error when there is a default scope that joins" do
|
42
42
|
widget # persist a widget
|
43
43
|
version.index
|
44
44
|
end
|
@@ -3,16 +3,15 @@ require "rails_helper"
|
|
3
3
|
# The `json_versions` table tests postgres' `json` data type. So, that
|
4
4
|
# table is only created when testing against postgres and ActiveRecord >= 4.
|
5
5
|
if JsonVersion.table_exists?
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
expect(JsonVersion).to include(PaperTrail::VersionConcern)
|
6
|
+
RSpec.describe JsonVersion, type: :model do
|
7
|
+
it "includes the VersionConcern module" do
|
8
|
+
expect(described_class).to include(PaperTrail::VersionConcern)
|
10
9
|
end
|
11
10
|
|
12
11
|
describe "Methods" do
|
13
12
|
describe "Class" do
|
14
13
|
describe "#where_object" do
|
15
|
-
it { expect(
|
14
|
+
it { expect(described_class).to respond_to(:where_object) }
|
16
15
|
|
17
16
|
it "escapes values" do
|
18
17
|
f = Fruit.create(name: "Bobby")
|
@@ -25,9 +24,9 @@ if JsonVersion.table_exists?
|
|
25
24
|
end
|
26
25
|
|
27
26
|
context "invalid arguments" do
|
28
|
-
it "
|
29
|
-
expect {
|
30
|
-
expect {
|
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)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
@@ -43,15 +42,15 @@ if JsonVersion.table_exists?
|
|
43
42
|
fruit.update_attributes!(name: fruit_names.sample, color: FFaker::Color.name)
|
44
43
|
end
|
45
44
|
|
46
|
-
it "
|
47
|
-
expect(
|
48
|
-
expect(
|
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]])
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
52
|
describe "#where_object_changes" do
|
54
|
-
it { expect(
|
53
|
+
it { expect(described_class).to respond_to(:where_object_changes) }
|
55
54
|
|
56
55
|
it "escapes values" do
|
57
56
|
f = Fruit.create(name: "Bobby")
|
@@ -64,9 +63,9 @@ if JsonVersion.table_exists?
|
|
64
63
|
end
|
65
64
|
|
66
65
|
context "invalid arguments" do
|
67
|
-
it "
|
68
|
-
expect {
|
69
|
-
expect {
|
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)
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
@@ -4,7 +4,7 @@ describe NotOnUpdate, type: :model do
|
|
4
4
|
describe "#touch_with_version", versioning: true do
|
5
5
|
let!(:record) { described_class.create! }
|
6
6
|
|
7
|
-
it "
|
7
|
+
it "creates a version, regardless" do
|
8
8
|
expect { record.paper_trail.touch_with_version }.to change {
|
9
9
|
PaperTrail::Version.count
|
10
10
|
}.by(+1)
|
@@ -4,7 +4,7 @@ describe PostWithStatus, type: :model do
|
|
4
4
|
with_versioning do
|
5
5
|
let(:post) { described_class.create!(status: "draft") }
|
6
6
|
|
7
|
-
it "
|
7
|
+
it "saves the enum value in versions" do
|
8
8
|
post.published!
|
9
9
|
post.archived!
|
10
10
|
expect(post.paper_trail.previous_version.published?).to be true
|
@@ -23,7 +23,7 @@ describe PostWithStatus, type: :model do
|
|
23
23
|
context "storing enum object_changes" do
|
24
24
|
subject { post.versions.last }
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "saves the enum value properly in versions object_changes" do
|
27
27
|
post.published!
|
28
28
|
post.archived!
|
29
29
|
expect(subject.changeset["status"]).to eql %w(published archived)
|
data/spec/models/skipper_spec.rb
CHANGED
@@ -9,11 +9,11 @@ describe Skipper, type: :model do
|
|
9
9
|
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
|
10
10
|
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "does not create a version" do
|
13
13
|
skipper = Skipper.create!(another_timestamp: t1)
|
14
14
|
expect {
|
15
15
|
skipper.update_attributes!(another_timestamp: t2)
|
16
|
-
}.
|
16
|
+
}.not_to(change { skipper.versions.length })
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -24,7 +24,7 @@ describe Skipper, type: :model do
|
|
24
24
|
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
|
25
25
|
|
26
26
|
context "without preserve (default)" do
|
27
|
-
it "
|
27
|
+
it "has no timestamp" do
|
28
28
|
skipper = Skipper.create!(another_timestamp: t1)
|
29
29
|
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
|
30
30
|
skipper = skipper.versions.last.reify
|
@@ -33,7 +33,7 @@ describe Skipper, type: :model do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
context "with preserve" do
|
36
|
-
it "
|
36
|
+
it "preserves its timestamp" do
|
37
37
|
skipper = Skipper.create!(another_timestamp: t1)
|
38
38
|
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
|
39
39
|
skipper = skipper.versions.last.reify(unversioned_attributes: :preserve)
|
data/spec/models/thing_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "rails_helper"
|
|
3
3
|
describe Thing, type: :model do
|
4
4
|
it { is_expected.to be_versioned }
|
5
5
|
|
6
|
-
describe "
|
6
|
+
describe "does not store object_changes", versioning: true do
|
7
7
|
let(:thing) { Thing.create(name: "pencil") }
|
8
8
|
|
9
9
|
it { expect(thing.versions.last.object_changes).to be_nil }
|
data/spec/models/truck_spec.rb
CHANGED
data/spec/models/vehicle_spec.rb
CHANGED
data/spec/models/version_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rails_helper"
|
2
2
|
|
3
3
|
describe PaperTrail::Version, type: :model do
|
4
|
-
it "
|
4
|
+
it "includes the VersionConcern module" do
|
5
5
|
expect(PaperTrail::Version).to include(PaperTrail::VersionConcern)
|
6
6
|
end
|
7
7
|
|
@@ -13,7 +13,7 @@ describe PaperTrail::Version, type: :model do
|
|
13
13
|
context "serializer is YAML" do
|
14
14
|
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "store out as a plain hash" do
|
17
17
|
expect(value =~ /HashWithIndifferentAccess/).to be_nil
|
18
18
|
end
|
19
19
|
end
|
@@ -21,7 +21,7 @@ describe PaperTrail::Version, type: :model do
|
|
21
21
|
context "serializer is JSON" do
|
22
22
|
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "store out as a plain hash" do
|
25
25
|
expect(value =~ /HashWithIndifferentAccess/).to be_nil
|
26
26
|
end
|
27
27
|
|
@@ -35,43 +35,41 @@ describe PaperTrail::Version, type: :model do
|
|
35
35
|
subject { PaperTrail::Version.new }
|
36
36
|
|
37
37
|
describe "#paper_trail_originator" do
|
38
|
-
it { is_expected.to respond_to(:paper_trail_originator) }
|
39
|
-
|
40
38
|
context "No previous versions" do
|
41
39
|
specify { expect(subject.previous).to be_nil }
|
42
40
|
|
43
|
-
it "
|
41
|
+
it "return nil" do
|
44
42
|
expect(subject.paper_trail_originator).to be_nil
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
46
|
context "Has previous version", versioning: true do
|
47
|
+
subject { widget.versions.last }
|
48
|
+
|
49
49
|
let(:name) { FFaker::Name.name }
|
50
50
|
let(:widget) { Widget.create!(name: FFaker::Name.name) }
|
51
|
+
|
51
52
|
before do
|
52
53
|
widget.versions.first.update_attributes!(whodunnit: name)
|
53
54
|
widget.update_attributes!(name: FFaker::Name.first_name)
|
54
55
|
end
|
55
|
-
subject { widget.versions.last }
|
56
56
|
|
57
57
|
specify { expect(subject.previous).to be_instance_of(PaperTrail::Version) }
|
58
58
|
|
59
|
-
it "
|
59
|
+
it "return nil" do
|
60
60
|
expect(subject.paper_trail_originator).to eq(name)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
describe "#originator" do
|
66
|
-
it
|
67
|
-
|
68
|
-
it "should set the invoke `paper_trail_originator`" do
|
66
|
+
it "sets the invoke `paper_trail_originator`" do
|
69
67
|
allow(ActiveSupport::Deprecation).to receive(:warn)
|
70
68
|
is_expected.to receive(:paper_trail_originator)
|
71
69
|
subject.originator
|
72
70
|
end
|
73
71
|
|
74
|
-
it "
|
72
|
+
it "displays a deprecation warning" do
|
75
73
|
expect(ActiveSupport::Deprecation).to receive(:warn).
|
76
74
|
with(/Use paper_trail_originator instead of originator/)
|
77
75
|
subject.originator
|
@@ -79,10 +77,9 @@ describe PaperTrail::Version, type: :model do
|
|
79
77
|
end
|
80
78
|
|
81
79
|
describe "#terminator" do
|
82
|
-
let(:attributes) { { whodunnit: FFaker::Name.first_name } }
|
83
80
|
subject { PaperTrail::Version.new attributes }
|
84
81
|
|
85
|
-
|
82
|
+
let(:attributes) { { whodunnit: FFaker::Name.first_name } }
|
86
83
|
|
87
84
|
it "is an alias for the `whodunnit` attribute" do
|
88
85
|
expect(subject.terminator).to eq(attributes[:whodunnit])
|
@@ -90,180 +87,167 @@ describe PaperTrail::Version, type: :model do
|
|
90
87
|
end
|
91
88
|
|
92
89
|
describe "#version_author" do
|
93
|
-
it
|
94
|
-
|
95
|
-
it "should be an alias for the `terminator` method" do
|
90
|
+
it "is an alias for the `terminator` method" do
|
96
91
|
expect(subject.method(:version_author)).to eq(subject.method(:terminator))
|
97
92
|
end
|
98
93
|
end
|
99
94
|
end
|
100
95
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
96
|
+
column_overrides = [false]
|
97
|
+
if ENV["DB"] == "postgres" && ::ActiveRecord::VERSION::MAJOR >= 4
|
98
|
+
column_overrides << "json"
|
99
|
+
# 'jsonb' column types are only supported for ActiveRecord 4.2+
|
100
|
+
column_overrides << "jsonb" if ::ActiveRecord::VERSION::STRING >= "4.2"
|
101
|
+
end
|
102
|
+
|
103
|
+
column_overrides.shuffle.each do |override|
|
104
|
+
context "with a #{override || 'text'} column" do
|
105
|
+
before do
|
106
|
+
if override
|
107
|
+
ActiveRecord::Base.connection.execute("SAVEPOINT pgtest;")
|
108
|
+
%w(object object_changes).each do |column|
|
109
|
+
ActiveRecord::Base.connection.execute(
|
110
|
+
"ALTER TABLE versions DROP COLUMN #{column};"
|
111
|
+
)
|
112
|
+
ActiveRecord::Base.connection.execute(
|
113
|
+
"ALTER TABLE versions ADD COLUMN #{column} #{override};"
|
114
|
+
)
|
115
|
+
end
|
116
|
+
PaperTrail::Version.reset_column_information
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
after do
|
121
|
+
if override
|
122
|
+
ActiveRecord::Base.connection.execute("ROLLBACK TO SAVEPOINT pgtest;")
|
123
|
+
PaperTrail::Version.reset_column_information
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#where_object", versioning: true do
|
128
|
+
let(:widget) { Widget.new }
|
129
|
+
let(:name) { FFaker::Name.first_name }
|
130
|
+
let(:int) { rand(10) + 1 }
|
108
131
|
|
109
|
-
column_overrides.shuffle.each do |override|
|
110
|
-
context "with a #{override || 'text'} column" do
|
111
132
|
before do
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
PaperTrail::Version.
|
133
|
+
widget.update_attributes!(name: name, an_integer: int)
|
134
|
+
widget.update_attributes!(name: "foobar", an_integer: 100)
|
135
|
+
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "requires its argument to be a Hash" do
|
139
|
+
expect {
|
140
|
+
PaperTrail::Version.where_object(:foo)
|
141
|
+
}.to raise_error(ArgumentError)
|
142
|
+
expect {
|
143
|
+
PaperTrail::Version.where_object([])
|
144
|
+
}.to raise_error(ArgumentError)
|
145
|
+
end
|
146
|
+
|
147
|
+
context "`serializer == YAML`" do
|
148
|
+
specify do
|
149
|
+
expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML
|
150
|
+
end
|
151
|
+
|
152
|
+
it "locates versions according to their `object` contents" do
|
153
|
+
expect(
|
154
|
+
PaperTrail::Version.where_object(name: name)
|
155
|
+
).to eq([widget.versions[1]])
|
156
|
+
expect(
|
157
|
+
PaperTrail::Version.where_object(an_integer: 100)
|
158
|
+
).to eq([widget.versions[2]])
|
123
159
|
end
|
124
160
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
PaperTrail::
|
161
|
+
|
162
|
+
context "JSON serializer" do
|
163
|
+
before(:all) do
|
164
|
+
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
165
|
+
end
|
166
|
+
|
167
|
+
specify do
|
168
|
+
expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON
|
169
|
+
end
|
170
|
+
|
171
|
+
it "locates versions according to their `object` contents" do
|
172
|
+
expect(
|
173
|
+
PaperTrail::Version.where_object(name: name)
|
174
|
+
).to eq([widget.versions[1]])
|
175
|
+
expect(
|
176
|
+
PaperTrail::Version.where_object(an_integer: 100)
|
177
|
+
).to eq([widget.versions[2]])
|
129
178
|
end
|
179
|
+
|
180
|
+
after(:all) do
|
181
|
+
PaperTrail.serializer = PaperTrail::Serializers::YAML
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "#where_object_changes", versioning: true do
|
187
|
+
let(:widget) { Widget.new }
|
188
|
+
let(:name) { FFaker::Name.first_name }
|
189
|
+
let(:int) { rand(5) + 2 }
|
190
|
+
|
191
|
+
before do
|
192
|
+
widget.update_attributes!(name: name, an_integer: 0)
|
193
|
+
widget.update_attributes!(name: "foobar", an_integer: 77)
|
194
|
+
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: int)
|
130
195
|
end
|
131
196
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
197
|
+
it "requires its argument to be a Hash" do
|
198
|
+
expect {
|
199
|
+
PaperTrail::Version.where_object_changes(:foo)
|
200
|
+
}.to raise_error(ArgumentError)
|
201
|
+
expect {
|
202
|
+
PaperTrail::Version.where_object_changes([])
|
203
|
+
}.to raise_error(ArgumentError)
|
204
|
+
end
|
205
|
+
|
206
|
+
context "YAML serializer" do
|
207
|
+
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
208
|
+
|
209
|
+
it "locates versions according to their `object_changes` contents" do
|
210
|
+
expect(
|
211
|
+
widget.versions.where_object_changes(name: name)
|
212
|
+
).to eq(widget.versions[0..1])
|
213
|
+
expect(
|
214
|
+
widget.versions.where_object_changes(an_integer: 77)
|
215
|
+
).to eq(widget.versions[1..2])
|
216
|
+
expect(
|
217
|
+
widget.versions.where_object_changes(an_integer: int)
|
218
|
+
).to eq([widget.versions.last])
|
144
219
|
end
|
145
220
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
before do
|
152
|
-
widget.update_attributes!(name: name, an_integer: int)
|
153
|
-
widget.update_attributes!(name: "foobar", an_integer: 100)
|
154
|
-
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15)
|
155
|
-
end
|
156
|
-
|
157
|
-
context "`serializer == YAML`" do
|
158
|
-
specify do
|
159
|
-
expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should be able to locate versions according to their `object` contents" do
|
163
|
-
expect(
|
164
|
-
PaperTrail::Version.where_object(name: name)
|
165
|
-
).to eq([widget.versions[1]])
|
166
|
-
expect(
|
167
|
-
PaperTrail::Version.where_object(an_integer: 100)
|
168
|
-
).to eq([widget.versions[2]])
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context "JSON serializer" do
|
173
|
-
before(:all) do
|
174
|
-
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
175
|
-
end
|
176
|
-
|
177
|
-
specify do
|
178
|
-
expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should be able to locate versions according to their `object` contents" do
|
182
|
-
expect(
|
183
|
-
PaperTrail::Version.where_object(name: name)
|
184
|
-
).to eq([widget.versions[1]])
|
185
|
-
expect(
|
186
|
-
PaperTrail::Version.where_object(an_integer: 100)
|
187
|
-
).to eq([widget.versions[2]])
|
188
|
-
end
|
189
|
-
|
190
|
-
after(:all) do
|
191
|
-
PaperTrail.serializer = PaperTrail::Serializers::YAML
|
192
|
-
end
|
193
|
-
end
|
221
|
+
it "handles queries for multiple attributes" do
|
222
|
+
expect(
|
223
|
+
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
|
224
|
+
).to eq(widget.versions[1..2])
|
194
225
|
end
|
195
226
|
end
|
196
227
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
228
|
+
context "JSON serializer" do
|
229
|
+
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
230
|
+
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON }
|
231
|
+
|
232
|
+
it "locates versions according to their `object_changes` contents" do
|
233
|
+
expect(
|
234
|
+
widget.versions.where_object_changes(name: name)
|
235
|
+
).to eq(widget.versions[0..1])
|
236
|
+
expect(
|
237
|
+
widget.versions.where_object_changes(an_integer: 77)
|
238
|
+
).to eq(widget.versions[1..2])
|
239
|
+
expect(
|
240
|
+
widget.versions.where_object_changes(an_integer: int)
|
241
|
+
).to eq([widget.versions.last])
|
207
242
|
end
|
208
243
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
before do
|
215
|
-
widget.update_attributes!(name: name, an_integer: 0)
|
216
|
-
widget.update_attributes!(name: "foobar", an_integer: 77)
|
217
|
-
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: int)
|
218
|
-
end
|
219
|
-
|
220
|
-
context "YAML serializer" do
|
221
|
-
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
222
|
-
|
223
|
-
it "locates versions according to their `object_changes` contents" do
|
224
|
-
expect(
|
225
|
-
widget.versions.where_object_changes(name: name)
|
226
|
-
).to eq(widget.versions[0..1])
|
227
|
-
expect(
|
228
|
-
widget.versions.where_object_changes(an_integer: 77)
|
229
|
-
).to eq(widget.versions[1..2])
|
230
|
-
expect(
|
231
|
-
widget.versions.where_object_changes(an_integer: int)
|
232
|
-
).to eq([widget.versions.last])
|
233
|
-
end
|
234
|
-
|
235
|
-
it "handles queries for multiple attributes" do
|
236
|
-
expect(
|
237
|
-
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
|
238
|
-
).to eq(widget.versions[1..2])
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
context "JSON serializer" do
|
243
|
-
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
244
|
-
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON }
|
245
|
-
|
246
|
-
it "locates versions according to their `object_changes` contents" do
|
247
|
-
expect(
|
248
|
-
widget.versions.where_object_changes(name: name)
|
249
|
-
).to eq(widget.versions[0..1])
|
250
|
-
expect(
|
251
|
-
widget.versions.where_object_changes(an_integer: 77)
|
252
|
-
).to eq(widget.versions[1..2])
|
253
|
-
expect(
|
254
|
-
widget.versions.where_object_changes(an_integer: int)
|
255
|
-
).to eq([widget.versions.last])
|
256
|
-
end
|
257
|
-
|
258
|
-
it "handles queries for multiple attributes" do
|
259
|
-
expect(
|
260
|
-
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
|
261
|
-
).to eq(widget.versions[1..2])
|
262
|
-
end
|
263
|
-
|
264
|
-
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
265
|
-
end
|
244
|
+
it "handles queries for multiple attributes" do
|
245
|
+
expect(
|
246
|
+
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
|
247
|
+
).to eq(widget.versions[1..2])
|
266
248
|
end
|
249
|
+
|
250
|
+
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
267
251
|
end
|
268
252
|
end
|
269
253
|
end
|