rtiss_acts_as_versioned 0.10.2 → 0.11.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/README.md +367 -11
- data/lib/rtiss_acts_as_versioned/act_methods.rb +108 -38
- data/lib/rtiss_acts_as_versioned/version.rb +1 -1
- data/lib/rtiss_acts_as_versioned.rb +51 -15
- data/mise.toml.example +2 -0
- data/rtiss_acts_as_versioned.gemspec +17 -10
- data/test/abstract_unit.rb +6 -7
- data/test/callbacks_test.rb +87 -0
- data/test/failed_version_save_test.rb +54 -0
- data/test/fixtures/audited_thing.rb +43 -0
- data/test/fixtures/good_thing.rb +8 -0
- data/test/fixtures/migrations/2_add_versioned_tables.rb +3 -3
- data/test/fixtures/page.rb +4 -4
- data/test/fixtures/widget.rb +2 -4
- data/test/migration_test.rb +23 -21
- data/test/revert_test.rb +61 -0
- data/test/schema.rb +33 -56
- data/test/sql_injection_test.rb +69 -0
- data/test/tiss_test.rb +261 -172
- data/test/versioned_test.rb +23 -23
- data/test/without_revision_and_locking_test.rb +86 -0
- metadata +22 -16
- data/test/fixtures/locked_rolle.rb +0 -8
- data/test/fixtures/rolle.rb +0 -7
data/test/versioned_test.rb
CHANGED
|
@@ -22,7 +22,7 @@ class VersionedTest < ActiveSupport::TestCase
|
|
|
22
22
|
p.save_without_revision
|
|
23
23
|
|
|
24
24
|
p.without_revision do
|
|
25
|
-
p.
|
|
25
|
+
p.update :title => 'changed'
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
assert_equal old_versions, p.versions.count
|
|
@@ -156,11 +156,11 @@ class VersionedTest < ActiveSupport::TestCase
|
|
|
156
156
|
assert_equal 1, p.version # version does not increment
|
|
157
157
|
assert_equal 1, p.versions.count
|
|
158
158
|
|
|
159
|
-
p.
|
|
159
|
+
p.update(:title => 'new title')
|
|
160
160
|
assert_equal 1, p.version # version does not increment
|
|
161
161
|
assert_equal 1, p.versions.count
|
|
162
162
|
|
|
163
|
-
p.
|
|
163
|
+
p.update(:title => 'a title')
|
|
164
164
|
assert_equal 2, p.version
|
|
165
165
|
assert_equal 2, p.versions.count
|
|
166
166
|
|
|
@@ -177,11 +177,11 @@ class VersionedTest < ActiveSupport::TestCase
|
|
|
177
177
|
assert_equal 1, p.version # version does not increment
|
|
178
178
|
assert_equal 1, p.versions.count
|
|
179
179
|
|
|
180
|
-
p.
|
|
180
|
+
p.update(:title => 'a title')
|
|
181
181
|
assert_equal 1, p.version # version does not increment
|
|
182
182
|
assert_equal 1, p.versions.count
|
|
183
183
|
|
|
184
|
-
p.
|
|
184
|
+
p.update(:title => 'b title')
|
|
185
185
|
assert_equal 2, p.version
|
|
186
186
|
assert_equal 2, p.versions.count
|
|
187
187
|
|
|
@@ -203,14 +203,14 @@ class VersionedTest < ActiveSupport::TestCase
|
|
|
203
203
|
|
|
204
204
|
def test_version_max_limit
|
|
205
205
|
p = LockedPage.create! :title => "title"
|
|
206
|
-
p.
|
|
207
|
-
p.
|
|
206
|
+
p.update(:title => "title1")
|
|
207
|
+
p.update(:title => "title2")
|
|
208
208
|
5.times do |i|
|
|
209
209
|
p.title = "title#{i}"
|
|
210
210
|
p.save
|
|
211
211
|
assert_equal "title#{i}", p.title
|
|
212
212
|
assert_equal (i+4), p.version
|
|
213
|
-
assert p.versions
|
|
213
|
+
assert p.versions.reload.size <= 2, "locked version can only store 2 versions"
|
|
214
214
|
end
|
|
215
215
|
end
|
|
216
216
|
|
|
@@ -223,29 +223,29 @@ class VersionedTest < ActiveSupport::TestCase
|
|
|
223
223
|
def test_track_altered_attributes
|
|
224
224
|
p = LockedPage.create! :title => "title"
|
|
225
225
|
assert_equal 1, p.version
|
|
226
|
-
assert_equal 1, p.versions
|
|
226
|
+
assert_equal 1, p.versions.reload.size
|
|
227
227
|
|
|
228
228
|
p.body = 'whoa'
|
|
229
229
|
assert !p.save_version?
|
|
230
230
|
p.save
|
|
231
231
|
assert_equal 1, p.version # no increment, because we're not using lock_version column
|
|
232
|
-
assert_equal 1, p.versions
|
|
232
|
+
assert_equal 1, p.versions.reload.size
|
|
233
233
|
|
|
234
234
|
p.title = 'updated title'
|
|
235
235
|
assert p.save_version?
|
|
236
236
|
p.save
|
|
237
237
|
assert_equal 2, p.version
|
|
238
|
-
assert_equal 2, p.versions
|
|
238
|
+
assert_equal 2, p.versions.reload.size
|
|
239
239
|
|
|
240
240
|
p.title = 'updated title!'
|
|
241
241
|
assert p.save_version?
|
|
242
242
|
p.save
|
|
243
243
|
assert_equal 3, p.version
|
|
244
|
-
assert_equal 2, p.versions
|
|
244
|
+
assert_equal 2, p.versions.reload.size # version 1 deleted
|
|
245
245
|
end
|
|
246
246
|
|
|
247
247
|
def test_find_versions
|
|
248
|
-
assert_equal 1, locked_pages(:welcome).versions.
|
|
248
|
+
assert_equal 1, locked_pages(:welcome).versions.where('title LIKE ?', '%weblog%').size
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
def test_find_version
|
|
@@ -276,7 +276,7 @@ class VersionedTest < ActiveSupport::TestCase
|
|
|
276
276
|
def test_association_options
|
|
277
277
|
association = Page.reflect_on_association(:versions)
|
|
278
278
|
options = association.options
|
|
279
|
-
|
|
279
|
+
assert_nil options[:dependent]
|
|
280
280
|
|
|
281
281
|
association = Widget.reflect_on_association(:versions)
|
|
282
282
|
options = association.options
|
|
@@ -350,28 +350,28 @@ class VersionedTest < ActiveSupport::TestCase
|
|
|
350
350
|
end
|
|
351
351
|
|
|
352
352
|
def test_without_locking_temporarily_disables_optimistic_locking
|
|
353
|
-
enabled1 =
|
|
353
|
+
enabled1 = nil
|
|
354
354
|
block_called = false
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
|
|
356
|
+
assert LockedPage.locking_enabled?
|
|
357
357
|
LockedPage.without_locking do
|
|
358
|
-
enabled1 =
|
|
358
|
+
enabled1 = LockedPage.locking_enabled?
|
|
359
359
|
block_called = true
|
|
360
360
|
end
|
|
361
|
-
|
|
362
|
-
|
|
361
|
+
|
|
363
362
|
assert block_called
|
|
364
363
|
assert !enabled1
|
|
365
|
-
assert
|
|
364
|
+
assert LockedPage.locking_enabled?
|
|
365
|
+
assert ActiveRecord::Base.lock_optimistically
|
|
366
366
|
end
|
|
367
|
-
|
|
367
|
+
|
|
368
368
|
def test_without_locking_reverts_optimistic_locking_settings_if_block_raises_exception
|
|
369
369
|
assert_raises(RuntimeError) do
|
|
370
370
|
LockedPage.without_locking do
|
|
371
371
|
raise RuntimeError, "oh noes"
|
|
372
372
|
end
|
|
373
373
|
end
|
|
374
|
-
assert
|
|
374
|
+
assert LockedPage.locking_enabled?
|
|
375
375
|
end
|
|
376
376
|
|
|
377
377
|
def test_deleted_in_original_table
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
|
2
|
+
require File.join(File.dirname(__FILE__), 'fixtures/good_thing')
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'fixtures/page')
|
|
4
|
+
|
|
5
|
+
# without_revision and without_locking must only affect the current thread and must be nestable.
|
|
6
|
+
class WithoutRevisionAndLockingTest < ActiveSupport::TestCase
|
|
7
|
+
fixtures :locked_pages, :locked_pages_revisions
|
|
8
|
+
|
|
9
|
+
def test_without_revision_suppresses_versions
|
|
10
|
+
thing = GoodThing.create!(name: 'Sun')
|
|
11
|
+
GoodThing.without_revision { thing.update!(name: 'Moon') }
|
|
12
|
+
assert_equal 1, thing.versions.count
|
|
13
|
+
assert_equal 'Moon', thing.reload.name
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_nested_without_revision_restores_versioning
|
|
17
|
+
thing = GoodThing.create!(name: 'Sun')
|
|
18
|
+
GoodThing.without_revision do
|
|
19
|
+
GoodThing.without_revision { thing.update!(name: 'Moon') }
|
|
20
|
+
assert GoodThing.without_revision?
|
|
21
|
+
thing.save_without_revision
|
|
22
|
+
end
|
|
23
|
+
assert !GoodThing.without_revision?
|
|
24
|
+
|
|
25
|
+
thing.update!(name: 'Stars')
|
|
26
|
+
assert_equal 2, thing.versions.count
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_without_revision_is_reset_after_exception
|
|
30
|
+
thing = GoodThing.create!(name: 'Sun')
|
|
31
|
+
assert_raises(RuntimeError) do
|
|
32
|
+
GoodThing.without_revision { raise 'oh noes' }
|
|
33
|
+
end
|
|
34
|
+
assert !GoodThing.without_revision?
|
|
35
|
+
|
|
36
|
+
thing.update!(name: 'Moon')
|
|
37
|
+
assert_equal 2, thing.versions.count
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_without_revision_only_affects_the_given_class_and_subclasses
|
|
41
|
+
Page.without_revision do
|
|
42
|
+
assert Page.without_revision?
|
|
43
|
+
assert !GoodThing.without_revision?
|
|
44
|
+
end
|
|
45
|
+
LockedPage.without_revision do
|
|
46
|
+
assert SpecialLockedPage.without_revision?
|
|
47
|
+
end
|
|
48
|
+
SpecialLockedPage.without_revision do
|
|
49
|
+
assert !LockedPage.without_revision?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_without_revision_does_not_affect_other_threads
|
|
54
|
+
assert_equal [true, false], in_block_and_other_thread(GoodThing.method(:without_revision)) { GoodThing.without_revision? }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_without_locking_does_not_affect_other_threads
|
|
58
|
+
assert_equal [false, true], in_block_and_other_thread(LockedPage.method(:without_locking)) { !!LockedPage.locking_enabled? }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_without_locking_allows_saving_stale_records
|
|
62
|
+
page = LockedPage.find(locked_pages(:welcome).id)
|
|
63
|
+
stale = LockedPage.find(page.id)
|
|
64
|
+
page.update!(title: 'fresh')
|
|
65
|
+
|
|
66
|
+
stale.title = 'stale'
|
|
67
|
+
assert_raises(ActiveRecord::StaleObjectError) { stale.save! }
|
|
68
|
+
|
|
69
|
+
LockedPage.without_locking { stale.save! }
|
|
70
|
+
assert_equal 'stale', page.reload.title
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
# Calls the check inside the block (in this thread) and in a second thread while the block is still running.
|
|
76
|
+
# The second thread does not touch the database.
|
|
77
|
+
def in_block_and_other_thread(wrapper, &check)
|
|
78
|
+
inside = nil
|
|
79
|
+
other = nil
|
|
80
|
+
wrapper.call do
|
|
81
|
+
inside = check.call
|
|
82
|
+
other = Thread.new { check.call }.value
|
|
83
|
+
end
|
|
84
|
+
[inside, other]
|
|
85
|
+
end
|
|
86
|
+
end
|
metadata
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rtiss_acts_as_versioned
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rick Olson
|
|
8
8
|
- Johannes Thoma
|
|
9
9
|
- Igor Jancev
|
|
10
|
-
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date: 2026-
|
|
12
|
+
date: 2026-12-02 00:00:00.000000000 Z
|
|
14
13
|
dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
|
16
15
|
name: activerecord
|
|
@@ -68,18 +67,21 @@ dependencies:
|
|
|
68
67
|
- - ">="
|
|
69
68
|
- !ruby/object:Gem::Version
|
|
70
69
|
version: '0'
|
|
71
|
-
description:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
description: |-
|
|
71
|
+
Add simple versioning to ActiveRecord models (TISS version).
|
|
72
|
+
|
|
73
|
+
Every change to a record saves a full copy of the record in a separate history
|
|
74
|
+
table (Model::Version). Destroys are versioned too (deletes are not), so destroyed
|
|
75
|
+
records can be restored with the same id.
|
|
76
|
+
|
|
77
|
+
This fork is used by the TISS-Team at TU Wien and substantially differs from the
|
|
78
|
+
original. If you need a general-purpose versioning gem, consider technoweenie's
|
|
79
|
+
acts_as_versioned (on GitHub) or one of the actively maintained alternatives.
|
|
78
80
|
executables: []
|
|
79
81
|
extensions: []
|
|
80
82
|
extra_rdoc_files:
|
|
81
|
-
- README.md
|
|
82
83
|
- MIT-LICENSE
|
|
84
|
+
- README.md
|
|
83
85
|
files:
|
|
84
86
|
- Gemfile
|
|
85
87
|
- MIT-LICENSE
|
|
@@ -90,30 +92,35 @@ files:
|
|
|
90
92
|
- lib/rtiss_acts_as_versioned.rb
|
|
91
93
|
- lib/rtiss_acts_as_versioned/act_methods.rb
|
|
92
94
|
- lib/rtiss_acts_as_versioned/version.rb
|
|
95
|
+
- mise.toml.example
|
|
93
96
|
- rtiss_acts_as_versioned.gemspec
|
|
94
97
|
- test/abstract_unit.rb
|
|
98
|
+
- test/callbacks_test.rb
|
|
95
99
|
- test/database.yml
|
|
100
|
+
- test/failed_version_save_test.rb
|
|
101
|
+
- test/fixtures/audited_thing.rb
|
|
96
102
|
- test/fixtures/authors.yml
|
|
103
|
+
- test/fixtures/good_thing.rb
|
|
97
104
|
- test/fixtures/landmark.rb
|
|
98
105
|
- test/fixtures/landmark_h.yml
|
|
99
106
|
- test/fixtures/landmarks.yml
|
|
100
107
|
- test/fixtures/locked_pages.yml
|
|
101
108
|
- test/fixtures/locked_pages_revisions.yml
|
|
102
|
-
- test/fixtures/locked_rolle.rb
|
|
103
109
|
- test/fixtures/migrations/2_add_versioned_tables.rb
|
|
104
110
|
- test/fixtures/page.rb
|
|
105
111
|
- test/fixtures/pages.yml
|
|
106
112
|
- test/fixtures/pages_h.yml
|
|
107
|
-
- test/fixtures/rolle.rb
|
|
108
113
|
- test/fixtures/widget.rb
|
|
109
114
|
- test/migration_test.rb
|
|
115
|
+
- test/revert_test.rb
|
|
110
116
|
- test/schema.rb
|
|
117
|
+
- test/sql_injection_test.rb
|
|
111
118
|
- test/tiss_test.rb
|
|
112
119
|
- test/versioned_test.rb
|
|
120
|
+
- test/without_revision_and_locking_test.rb
|
|
113
121
|
homepage: http://github.com/rtiss/rtiss_acts_as_versioned
|
|
114
122
|
licenses: []
|
|
115
123
|
metadata: {}
|
|
116
|
-
post_install_message:
|
|
117
124
|
rdoc_options:
|
|
118
125
|
- "--charset=UTF-8"
|
|
119
126
|
require_paths:
|
|
@@ -129,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
129
136
|
- !ruby/object:Gem::Version
|
|
130
137
|
version: '0'
|
|
131
138
|
requirements: []
|
|
132
|
-
rubygems_version: 3.
|
|
133
|
-
signing_key:
|
|
139
|
+
rubygems_version: 3.6.9
|
|
134
140
|
specification_version: 4
|
|
135
141
|
summary: Add simple versioning to ActiveRecord models (TISS version).
|
|
136
142
|
test_files: []
|