rtiss_acts_as_versioned 0.9.3 → 0.10.3
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 +5 -5
- data/README.md +304 -0
- data/Rakefile +7 -7
- data/init.rb +3 -2
- data/lib/rtiss_acts_as_versioned/act_methods.rb +289 -0
- data/lib/rtiss_acts_as_versioned/version.rb +7 -0
- data/lib/rtiss_acts_as_versioned.rb +18 -355
- data/mise.toml.example +2 -0
- data/rtiss_acts_as_versioned.gemspec +11 -11
- data/test/abstract_unit.rb +6 -7
- 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/schema.rb +15 -59
- data/test/tiss_test.rb +143 -177
- data/test/versioned_test.rb +14 -14
- metadata +16 -34
- data/CHANGELOG +0 -84
- data/README +0 -37
- data/test/fixtures/locked_rolle.rb +0 -8
- data/test/fixtures/rolle.rb +0 -7
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
require_relative './rtiss_acts_as_versioned/act_methods'
|
|
24
|
+
require_relative './rtiss_acts_as_versioned/version'
|
|
24
25
|
|
|
25
26
|
module ActiveRecord #:nodoc:
|
|
26
27
|
module Acts #:nodoc:
|
|
@@ -130,14 +131,14 @@ module ActiveRecord #:nodoc:
|
|
|
130
131
|
#
|
|
131
132
|
# == Database Schema
|
|
132
133
|
#
|
|
133
|
-
# The model that you're versioning needs to have a 'version' attribute. The model is versioned
|
|
134
|
-
# into a table called #{model}_versions where the model name is singlular. The _versions table should
|
|
134
|
+
# The model that you're versioning needs to have a 'version' attribute. The model is versioned
|
|
135
|
+
# into a table called #{model}_versions where the model name is singlular. The _versions table should
|
|
135
136
|
# contain all the fields you want versioned, the same version column, and a #{model}_id foreign key field.
|
|
136
137
|
#
|
|
137
138
|
# A lock_version field is also accepted if your model uses Optimistic Locking. If your table uses Single Table inheritance,
|
|
138
139
|
# then that field is reflected in the versioned model as 'versioned_type' by default.
|
|
139
140
|
#
|
|
140
|
-
# Acts_as_versioned comes prepared with the ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table
|
|
141
|
+
# Acts_as_versioned comes prepared with the ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table
|
|
141
142
|
# method, perfect for a migration. It will also create the version column if the main model does not already have it.
|
|
142
143
|
#
|
|
143
144
|
# class AddVersions < ActiveRecord::Migration
|
|
@@ -146,16 +147,16 @@ module ActiveRecord #:nodoc:
|
|
|
146
147
|
# # that create_table does
|
|
147
148
|
# Post.create_versioned_table
|
|
148
149
|
# end
|
|
149
|
-
#
|
|
150
|
+
#
|
|
150
151
|
# def self.down
|
|
151
152
|
# Post.drop_versioned_table
|
|
152
153
|
# end
|
|
153
154
|
# end
|
|
154
|
-
#
|
|
155
|
+
#
|
|
155
156
|
# == Changing What Fields Are Versioned
|
|
156
157
|
#
|
|
157
|
-
# By default, acts_as_versioned will version all but these fields:
|
|
158
|
-
#
|
|
158
|
+
# By default, acts_as_versioned will version all but these fields:
|
|
159
|
+
#
|
|
159
160
|
# [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column]
|
|
160
161
|
#
|
|
161
162
|
# You can add or change those by modifying #non_versioned_columns. Note that this takes strings and not symbols.
|
|
@@ -164,7 +165,7 @@ module ActiveRecord #:nodoc:
|
|
|
164
165
|
# acts_as_versioned
|
|
165
166
|
# self.non_versioned_columns << 'comments_count'
|
|
166
167
|
# end
|
|
167
|
-
#
|
|
168
|
+
#
|
|
168
169
|
def acts_as_versioned(options = {}, &extension)
|
|
169
170
|
# don't allow multiple calls
|
|
170
171
|
return if self.included_modules.include?(ActiveRecord::Acts::Versioned::ActMethods)
|
|
@@ -197,10 +198,7 @@ module ActiveRecord #:nodoc:
|
|
|
197
198
|
|
|
198
199
|
if block_given?
|
|
199
200
|
extension_module_name = "#{versioned_class_name}Extension"
|
|
200
|
-
|
|
201
|
-
self.const_set(extension_module_name, Module.new(&extension))
|
|
202
|
-
end
|
|
203
|
-
|
|
201
|
+
const_set(extension_module_name, Module.new(&extension)) unless const_defined?(extension_module_name, false)
|
|
204
202
|
options[:extend] = self.const_get(extension_module_name)
|
|
205
203
|
end
|
|
206
204
|
|
|
@@ -234,14 +232,17 @@ module ActiveRecord #:nodoc:
|
|
|
234
232
|
const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do
|
|
235
233
|
def self.reloadable? ; false ; end
|
|
236
234
|
# find first version before the given version
|
|
237
|
-
# TODO: replace "version" in selects with version_column, use select-method instead of find
|
|
238
235
|
def self.before(version)
|
|
239
|
-
where("#{original_class.versioned_foreign_key} = ? and
|
|
236
|
+
where("#{original_class.versioned_foreign_key} = ? and #{original_class.version_column} < ?",
|
|
237
|
+
version.send(original_class.versioned_foreign_key), version.version)
|
|
238
|
+
.order("#{original_class.version_column} desc").first
|
|
240
239
|
end
|
|
241
240
|
|
|
242
241
|
# find first version after the given version.
|
|
243
242
|
def self.after(version)
|
|
244
|
-
where("#{original_class.versioned_foreign_key} = ? and
|
|
243
|
+
where("#{original_class.versioned_foreign_key} = ? and #{original_class.version_column} > ?",
|
|
244
|
+
version.send(original_class.versioned_foreign_key), version.version)
|
|
245
|
+
.order(original_class.version_column).first
|
|
245
246
|
end
|
|
246
247
|
|
|
247
248
|
def previous
|
|
@@ -252,10 +253,6 @@ module ActiveRecord #:nodoc:
|
|
|
252
253
|
self.class.after(self)
|
|
253
254
|
end
|
|
254
255
|
|
|
255
|
-
def versions_count
|
|
256
|
-
page.version # TODO: ?!
|
|
257
|
-
end
|
|
258
|
-
|
|
259
256
|
def restore(perform_validation = true)
|
|
260
257
|
id = self.send(self.original_class.versioned_foreign_key)
|
|
261
258
|
if self.original_class.exists?(id)
|
|
@@ -311,342 +308,8 @@ module ActiveRecord #:nodoc:
|
|
|
311
308
|
versioned_class.sequence_name = version_sequence_name if version_sequence_name
|
|
312
309
|
end
|
|
313
310
|
end
|
|
314
|
-
|
|
315
|
-
module ActMethods
|
|
316
|
-
def self.included(base) # :nodoc:
|
|
317
|
-
base.extend ClassMethods
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
# Saves a version of the model in the versioned table. This is called in the after_save callback by default
|
|
321
|
-
def save_version(save_this=false, deleted_flag=false, restored_from_version=nil)
|
|
322
|
-
if @saving_version || save_this
|
|
323
|
-
@saving_version = nil
|
|
324
|
-
rev = self.class.versioned_class.new
|
|
325
|
-
clone_versioned_model(self, rev)
|
|
326
|
-
rev.send("#{self.class.version_column}=", send(self.class.version_column))
|
|
327
|
-
rev.send("#{self.class.versioned_foreign_key}=", id)
|
|
328
|
-
rev.send("#{self.class.deleted_in_original_table_flag}=", deleted_flag)
|
|
329
|
-
rev.send("#{self.class.record_restored_column}=", restored_from_version)
|
|
330
|
-
if rev.respond_to? :updated_at=
|
|
331
|
-
rev.updated_at = Time.now
|
|
332
|
-
end
|
|
333
|
-
rev.save
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
def set_deleted_flag
|
|
338
|
-
return if self.id.nil?
|
|
339
|
-
|
|
340
|
-
rev = self.class.versioned_class.new
|
|
341
|
-
clone_versioned_model(self, rev)
|
|
342
|
-
rev.send("#{self.class.version_column}=", highest_version+1)
|
|
343
|
-
rev.send("#{self.class.versioned_foreign_key}=", id)
|
|
344
|
-
rev.send("#{self.class.deleted_in_original_table_flag}=", true)
|
|
345
|
-
rev.send("#{self.class.record_restored_column}=", nil)
|
|
346
|
-
if rev.respond_to? :updated_at=
|
|
347
|
-
rev.updated_at = Time.now
|
|
348
|
-
end
|
|
349
|
-
rev.save
|
|
350
|
-
end
|
|
351
|
-
|
|
352
|
-
# Clears old revisions if a limit is set with the :limit option in <tt>acts_as_versioned</tt>.
|
|
353
|
-
# Override this method to set your own criteria for clearing old versions.
|
|
354
|
-
def clear_old_versions
|
|
355
|
-
return if self.class.max_version_limit == 0
|
|
356
|
-
excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit
|
|
357
|
-
if excess_baggage > 0
|
|
358
|
-
self.class.versioned_class.delete_all ["#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?", excess_baggage, id]
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
# Reverts a model to a given version. Takes either a version number or an instance of the versioned model
|
|
363
|
-
def revert_to(version)
|
|
364
|
-
if version.is_a?(self.class.versioned_class)
|
|
365
|
-
@reverted_from = version.send(self.class.version_column)
|
|
366
|
-
return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record?
|
|
367
|
-
else
|
|
368
|
-
@reverted_from = version
|
|
369
|
-
version = versions.where(self.class.version_column => version).first
|
|
370
|
-
return false unless version
|
|
371
|
-
end
|
|
372
|
-
self.clone_versioned_model(version, self)
|
|
373
|
-
send("#{self.class.version_column}=", version.send(self.class.version_column))
|
|
374
|
-
true
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
# Reverts a model to a given version and saves the model.
|
|
378
|
-
# Takes either a version number or an instance of the versioned model
|
|
379
|
-
def revert_to!(version)
|
|
380
|
-
if revert_to(version)
|
|
381
|
-
set_new_version
|
|
382
|
-
save_without_revision
|
|
383
|
-
save_version(true, false, @reverted_from)
|
|
384
|
-
else
|
|
385
|
-
false
|
|
386
|
-
end
|
|
387
|
-
end
|
|
388
|
-
|
|
389
|
-
# Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created.
|
|
390
|
-
def save_without_revision(perform_validation = true)
|
|
391
|
-
ret = false
|
|
392
|
-
without_locking do
|
|
393
|
-
without_revision do
|
|
394
|
-
ret = save(:validate => perform_validation)
|
|
395
|
-
end
|
|
396
|
-
end
|
|
397
|
-
return ret
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
def save_without_revision!
|
|
401
|
-
without_locking do
|
|
402
|
-
without_revision do
|
|
403
|
-
save!
|
|
404
|
-
end
|
|
405
|
-
end
|
|
406
|
-
end
|
|
407
|
-
|
|
408
|
-
def altered?
|
|
409
|
-
track_altered_attributes ? (version_if_changed - changed).length < version_if_changed.length : changed?
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
# Clones a model. Used when saving a new version or reverting a model's version.
|
|
413
|
-
def clone_versioned_model(orig_model, new_model)
|
|
414
|
-
self.class.versioned_columns.each do |col|
|
|
415
|
-
new_model.send("#{col.name}=", orig_model.send(col.name)) if orig_model.has_attribute?(col.name)
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
clone_inheritance_column(orig_model, new_model)
|
|
419
|
-
end
|
|
420
|
-
|
|
421
|
-
def clone_inheritance_column(orig_model, new_model)
|
|
422
|
-
if orig_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(new_model.class.inheritance_column.to_s)
|
|
423
|
-
new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
|
|
424
|
-
elsif new_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(self.class.versioned_inheritance_column.to_s)
|
|
425
|
-
new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
|
|
426
|
-
end
|
|
427
|
-
end
|
|
428
|
-
|
|
429
|
-
# Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
|
|
430
|
-
def save_version?
|
|
431
|
-
version_condition_met? && altered?
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
# Checks condition set in the :if option to check whether a revision should be created or not. Override this for
|
|
435
|
-
# custom version condition checking.
|
|
436
|
-
def version_condition_met?
|
|
437
|
-
case
|
|
438
|
-
when version_condition.is_a?(Symbol)
|
|
439
|
-
send(version_condition)
|
|
440
|
-
when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1)
|
|
441
|
-
version_condition.call(self)
|
|
442
|
-
else
|
|
443
|
-
version_condition
|
|
444
|
-
end
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
# Executes the block with the versioning callbacks disabled.
|
|
448
|
-
#
|
|
449
|
-
# @foo.without_revision do
|
|
450
|
-
# @foo.save
|
|
451
|
-
# end
|
|
452
|
-
#
|
|
453
|
-
def without_revision(&block)
|
|
454
|
-
self.class.without_revision(&block)
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
# Turns off optimistic locking for the duration of the block
|
|
458
|
-
#
|
|
459
|
-
# @foo.without_locking do
|
|
460
|
-
# @foo.save
|
|
461
|
-
# end
|
|
462
|
-
#
|
|
463
|
-
def without_locking(&block)
|
|
464
|
-
self.class.without_locking(&block)
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
def empty_callback() end #:nodoc:
|
|
468
|
-
|
|
469
|
-
=begin
|
|
470
|
-
# Alte finder-Syntax ab Rails 5 nicht mehr verwendbar.
|
|
471
|
-
# Assoziation versions stattdessen verwenden
|
|
472
|
-
def find_versions(*args)
|
|
473
|
-
return [] if self.id.nil?
|
|
474
|
-
|
|
475
|
-
options = args.extract_options!
|
|
476
|
-
version_condition = "#{self.class.versioned_foreign_key} = #{self.id}"
|
|
477
|
-
if options[:conditions]
|
|
478
|
-
options[:conditions] += " and #{version_condition}"
|
|
479
|
-
else
|
|
480
|
-
options[:conditions] = version_condition
|
|
481
|
-
end
|
|
482
|
-
if args.first.is_a?(Symbol)
|
|
483
|
-
versions.find(args.first, options)
|
|
484
|
-
else # TODO: is_a?(Fixnum)
|
|
485
|
-
versions.find(options)
|
|
486
|
-
end
|
|
487
|
-
end
|
|
488
|
-
=end
|
|
489
|
-
|
|
490
|
-
def find_newest_version
|
|
491
|
-
return nil if self.id.nil?
|
|
492
|
-
|
|
493
|
-
self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id}").order("version DESC").first
|
|
494
|
-
end
|
|
495
|
-
|
|
496
|
-
def highest_version
|
|
497
|
-
v = find_newest_version
|
|
498
|
-
if v then
|
|
499
|
-
v.version
|
|
500
|
-
else
|
|
501
|
-
-1
|
|
502
|
-
end
|
|
503
|
-
end
|
|
504
|
-
|
|
505
|
-
def find_version(version)
|
|
506
|
-
return nil if self.id.nil?
|
|
507
|
-
|
|
508
|
-
ret = self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id} and #{self.class.version_column}=#{version}").first
|
|
509
|
-
raise "find_version: version #{version} not found in database" unless ret
|
|
510
|
-
ret
|
|
511
|
-
end
|
|
512
|
-
|
|
513
|
-
protected
|
|
514
|
-
# sets the new version before saving
|
|
515
|
-
def set_new_version
|
|
516
|
-
@saving_version = new_record? || save_version?
|
|
517
|
-
self.send("#{self.class.version_column}=", next_version) if new_record? || save_version?
|
|
518
|
-
end
|
|
519
|
-
|
|
520
|
-
# Gets the next available version for the current record, or 1 for a new record
|
|
521
|
-
def next_version
|
|
522
|
-
(new_record? ? 0 : versions.calculate(:maximum, version_column).to_i) + 1
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
module ClassMethods
|
|
526
|
-
# Returns an array of columns that are versioned. See non_versioned_columns
|
|
527
|
-
def versioned_columns
|
|
528
|
-
@versioned_columns ||= columns.select { |c| !non_versioned_columns.include?(c.name) }
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
# Returns an instance of the dynamic versioned model
|
|
532
|
-
def versioned_class
|
|
533
|
-
const_get versioned_class_name
|
|
534
|
-
end
|
|
535
|
-
|
|
536
|
-
# Rake migration task to create the versioned table using options passed to acts_as_versioned
|
|
537
|
-
def create_versioned_table(create_table_options = {})
|
|
538
|
-
# create version column in main table if it does not exist
|
|
539
|
-
if !self.content_columns.find { |c| [version_column.to_s, 'lock_version'].include? c.name }
|
|
540
|
-
self.connection.add_column table_name, version_column, :integer
|
|
541
|
-
self.reset_column_information
|
|
542
|
-
end
|
|
543
|
-
|
|
544
|
-
return if connection.table_exists?(versioned_table_name)
|
|
545
|
-
|
|
546
|
-
self.connection.create_table(versioned_table_name, create_table_options) do |t|
|
|
547
|
-
t.column versioned_foreign_key, :integer
|
|
548
|
-
t.column version_column, :integer
|
|
549
|
-
t.column deleted_in_original_table_flag, :boolean, :default => false
|
|
550
|
-
t.column record_restored_column, :integer, :default => nil
|
|
551
|
-
end
|
|
552
|
-
|
|
553
|
-
self.versioned_columns.each do |col|
|
|
554
|
-
self.connection.add_column versioned_table_name, col.name, col.type,
|
|
555
|
-
:limit => col.limit,
|
|
556
|
-
:default => col.default,
|
|
557
|
-
:scale => col.scale,
|
|
558
|
-
:precision => col.precision
|
|
559
|
-
end
|
|
560
|
-
|
|
561
|
-
if type_col = self.columns_hash[inheritance_column]
|
|
562
|
-
self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type,
|
|
563
|
-
:limit => type_col.limit,
|
|
564
|
-
:default => type_col.default,
|
|
565
|
-
:scale => type_col.scale,
|
|
566
|
-
:precision => type_col.precision
|
|
567
|
-
end
|
|
568
|
-
|
|
569
|
-
#self.connection.add_index versioned_table_name, versioned_foreign_key
|
|
570
|
-
end
|
|
571
|
-
|
|
572
|
-
# Rake migration task to drop the versioned table
|
|
573
|
-
def drop_versioned_table
|
|
574
|
-
self.connection.drop_table versioned_table_name
|
|
575
|
-
end
|
|
576
|
-
|
|
577
|
-
def restore_deleted(id)
|
|
578
|
-
version_record = versioned_class.where("#{versioned_foreign_key} = #{id}").order("version DESC").first
|
|
579
|
-
version_record.restore
|
|
580
|
-
end
|
|
581
|
-
|
|
582
|
-
def restore_deleted_version(id, version)
|
|
583
|
-
version_record = versioned_class.where("#{versioned_foreign_key} = #{id} and version = #{version}").first
|
|
584
|
-
version_record.restore
|
|
585
|
-
end
|
|
586
|
-
|
|
587
|
-
# Executes the block with the versioning callbacks disabled.
|
|
588
|
-
#
|
|
589
|
-
# Foo.without_revision do
|
|
590
|
-
# @foo.save
|
|
591
|
-
# end
|
|
592
|
-
#
|
|
593
|
-
def without_revision(&block)
|
|
594
|
-
class_eval do
|
|
595
|
-
CALLBACKS.each do |attr_name|
|
|
596
|
-
alias_method "orig_#{attr_name}".to_sym, attr_name
|
|
597
|
-
alias_method attr_name, :empty_callback
|
|
598
|
-
end
|
|
599
|
-
end
|
|
600
|
-
block.call
|
|
601
|
-
ensure
|
|
602
|
-
class_eval do
|
|
603
|
-
CALLBACKS.each do |attr_name|
|
|
604
|
-
alias_method attr_name, "orig_#{attr_name}".to_sym
|
|
605
|
-
end
|
|
606
|
-
end
|
|
607
|
-
end
|
|
608
|
-
|
|
609
|
-
# Turns off optimistic locking for the duration of the block
|
|
610
|
-
#
|
|
611
|
-
# Foo.without_locking do
|
|
612
|
-
# @foo.save
|
|
613
|
-
# end
|
|
614
|
-
#
|
|
615
|
-
def without_locking(&block)
|
|
616
|
-
current = ActiveRecord::Base.lock_optimistically
|
|
617
|
-
ActiveRecord::Base.lock_optimistically = false if current
|
|
618
|
-
begin
|
|
619
|
-
block.call
|
|
620
|
-
ensure
|
|
621
|
-
ActiveRecord::Base.lock_optimistically = true if current
|
|
622
|
-
end
|
|
623
|
-
end
|
|
624
|
-
end
|
|
625
|
-
end
|
|
626
311
|
end
|
|
627
312
|
end
|
|
628
313
|
end
|
|
629
314
|
|
|
630
|
-
|
|
631
|
-
module ActiveRecord #:nodoc:
|
|
632
|
-
module ConnectionAdapters #:nodoc:
|
|
633
|
-
class TableDefinition
|
|
634
|
-
## Erzeugt 4 Spalten created_at, updated_at, version, mutator_id die in
|
|
635
|
-
## jeder Daten-Tabelle notwendig sind. Verwendung:
|
|
636
|
-
## create_table :adresse do |t|
|
|
637
|
-
## t.standard_spalten
|
|
638
|
-
## t.string strasse, :size=>120
|
|
639
|
-
## t.string plz, :size=>4
|
|
640
|
-
## end
|
|
641
|
-
def standard_spalten
|
|
642
|
-
column(:created_at, :datetime)
|
|
643
|
-
column(:updated_at, :datetime)
|
|
644
|
-
column(:version, :integer, :default=>1)
|
|
645
|
-
column(:mutator_id, :integer, :default=>0)
|
|
646
|
-
end
|
|
647
|
-
end
|
|
648
|
-
end
|
|
649
|
-
end
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
ActiveRecord::Base.send :include, ActiveRecord::Acts::Versioned
|
|
315
|
+
ActiveRecord::Base.send :include, ActiveRecord::Acts::Versioned
|
data/mise.toml.example
ADDED
|
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
## If your rubyforge_project name is different, then edit it and comment out
|
|
13
13
|
## the sub! line in the Rakefile
|
|
14
14
|
s.name = 'rtiss_acts_as_versioned'
|
|
15
|
-
s.version = '0.
|
|
16
|
-
s.date = '
|
|
15
|
+
s.version = '0.10.3'
|
|
16
|
+
s.date = '2026-11-26'
|
|
17
17
|
s.rubyforge_project = 'rtiss_acts_as_versioned'
|
|
18
18
|
s.summary = "Add simple versioning to ActiveRecord models (TISS version)."
|
|
19
19
|
s.description = "Add simple versioning to ActiveRecord models (TISS version).
|
|
@@ -29,42 +29,42 @@ to use technoweenie's version (can be found also on github)"
|
|
|
29
29
|
s.homepage = 'http://github.com/rtiss/rtiss_acts_as_versioned'
|
|
30
30
|
s.require_paths = ["lib"]
|
|
31
31
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
32
|
-
s.extra_rdoc_files = %w[README MIT-LICENSE
|
|
32
|
+
s.extra_rdoc_files = %w[README.md MIT-LICENSE]
|
|
33
33
|
|
|
34
|
-
s.add_dependency 'activerecord', ">=
|
|
35
|
-
s.add_development_dependency 'sqlite3
|
|
36
|
-
s.add_development_dependency 'rails', "~>
|
|
34
|
+
s.add_dependency 'activerecord', ">= 7.1.6"
|
|
35
|
+
s.add_development_dependency 'sqlite3', '~> 2.7'
|
|
36
|
+
s.add_development_dependency 'rails', "~> 7.1.6"
|
|
37
37
|
s.add_development_dependency 'activerecord-testcase'
|
|
38
|
-
s.add_development_dependency 'activerecord-deprecated_finders' # todo alte, hash-basierte finders auf die neue AR Query-API migrieren
|
|
39
38
|
|
|
40
39
|
## Leave this section as-is. It will be automatically generated from the
|
|
41
40
|
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
|
42
41
|
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
|
43
42
|
# = MANIFEST =
|
|
44
43
|
s.files = %w[
|
|
45
|
-
CHANGELOG
|
|
46
44
|
Gemfile
|
|
47
45
|
MIT-LICENSE
|
|
48
|
-
README
|
|
46
|
+
README.md
|
|
49
47
|
RUNNING_UNIT_TESTS
|
|
50
48
|
Rakefile
|
|
51
49
|
init.rb
|
|
52
50
|
lib/rtiss_acts_as_versioned.rb
|
|
51
|
+
lib/rtiss_acts_as_versioned/act_methods.rb
|
|
52
|
+
lib/rtiss_acts_as_versioned/version.rb
|
|
53
|
+
mise.toml.example
|
|
53
54
|
rtiss_acts_as_versioned.gemspec
|
|
54
55
|
test/abstract_unit.rb
|
|
55
56
|
test/database.yml
|
|
56
57
|
test/fixtures/authors.yml
|
|
58
|
+
test/fixtures/good_thing.rb
|
|
57
59
|
test/fixtures/landmark.rb
|
|
58
60
|
test/fixtures/landmark_h.yml
|
|
59
61
|
test/fixtures/landmarks.yml
|
|
60
62
|
test/fixtures/locked_pages.yml
|
|
61
63
|
test/fixtures/locked_pages_revisions.yml
|
|
62
|
-
test/fixtures/locked_rolle.rb
|
|
63
64
|
test/fixtures/migrations/2_add_versioned_tables.rb
|
|
64
65
|
test/fixtures/page.rb
|
|
65
66
|
test/fixtures/pages.yml
|
|
66
67
|
test/fixtures/pages_h.yml
|
|
67
|
-
test/fixtures/rolle.rb
|
|
68
68
|
test/fixtures/widget.rb
|
|
69
69
|
test/migration_test.rb
|
|
70
70
|
test/schema.rb
|
data/test/abstract_unit.rb
CHANGED
|
@@ -7,15 +7,14 @@ require 'active_support'
|
|
|
7
7
|
require 'active_record'
|
|
8
8
|
require 'active_record/fixtures'
|
|
9
9
|
require 'active_record/test_case'
|
|
10
|
-
require 'active_record/deprecated_finders'
|
|
11
10
|
require 'rtiss_acts_as_versioned'
|
|
12
11
|
|
|
13
12
|
ActiveSupport::TestCase.test_order = :sorted
|
|
14
13
|
|
|
15
|
-
config = YAML
|
|
14
|
+
config = YAML.safe_load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
|
16
15
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
|
17
|
-
|
|
18
|
-
ActiveRecord::Base.establish_connection(
|
|
16
|
+
db_config = config[ENV['DB'] || 'sqlite3']
|
|
17
|
+
ActiveRecord::Base.establish_connection(db_config)
|
|
19
18
|
|
|
20
19
|
load(File.dirname(__FILE__) + "/schema.rb")
|
|
21
20
|
|
|
@@ -30,10 +29,10 @@ end
|
|
|
30
29
|
class ActiveSupport::TestCase #:nodoc:
|
|
31
30
|
include ActiveRecord::TestFixtures
|
|
32
31
|
|
|
33
|
-
self.
|
|
32
|
+
self.fixture_paths = [File.dirname(__FILE__) + "/fixtures/"]
|
|
34
33
|
|
|
35
34
|
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
|
|
36
|
-
self.
|
|
35
|
+
self.use_transactional_tests = true
|
|
37
36
|
|
|
38
37
|
# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
|
|
39
38
|
self.use_instantiated_fixtures = false
|
|
@@ -41,4 +40,4 @@ class ActiveSupport::TestCase #:nodoc:
|
|
|
41
40
|
# Add more helper methods to be used by all tests here...
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
$:.unshift(ActiveSupport::TestCase.
|
|
43
|
+
$:.unshift(ActiveSupport::TestCase.fixture_paths.first)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
class AddVersionedTables < ActiveRecord::Migration
|
|
2
|
-
def
|
|
1
|
+
class AddVersionedTables < ActiveRecord::Migration[7.1]
|
|
2
|
+
def up
|
|
3
3
|
create_table "things" do |t|
|
|
4
4
|
t.column :title, :text
|
|
5
5
|
t.column :price, :decimal, :precision => 7, :scale => 2
|
|
@@ -8,7 +8,7 @@ class AddVersionedTables < ActiveRecord::Migration
|
|
|
8
8
|
Thing.create_versioned_table
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def
|
|
11
|
+
def down
|
|
12
12
|
Thing.drop_versioned_table
|
|
13
13
|
drop_table "things" rescue nil
|
|
14
14
|
end
|
data/test/fixtures/page.rb
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
class Page < ActiveRecord::Base
|
|
2
|
-
belongs_to :author
|
|
3
|
-
has_many :authors, -> { order(:name)}, :through => :versions
|
|
4
|
-
belongs_to :revisor, :class_name => 'Author'
|
|
5
|
-
has_many :revisors, -> { order(:name)}, :class_name => 'Author', :through => :versions
|
|
6
2
|
|
|
7
3
|
acts_as_versioned :if => :feeling_good? do
|
|
8
4
|
def self.included(base)
|
|
@@ -16,6 +12,10 @@ class Page < ActiveRecord::Base
|
|
|
16
12
|
@@feeling_good == true
|
|
17
13
|
end
|
|
18
14
|
end
|
|
15
|
+
belongs_to :author
|
|
16
|
+
has_many :authors, -> { order(:name)}, :through => :versions
|
|
17
|
+
belongs_to :revisor, :class_name => 'Author'
|
|
18
|
+
has_many :revisors, -> { order(:name)}, :class_name => 'Author', :through => :versions
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
module LockedPageExtension
|
data/test/fixtures/widget.rb
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
class Widget < ActiveRecord::Base
|
|
2
|
-
acts_as_versioned :sequence_name => 'widgets_seq', :association_options => {
|
|
3
|
-
:order => 'version desc' # Don't nullify the foreign key column when deleting the original record! :dependent => :nullify option removed
|
|
4
|
-
}
|
|
2
|
+
acts_as_versioned :sequence_name => 'widgets_seq', :association_options => { :validate => true }
|
|
5
3
|
non_versioned_columns << 'foo'
|
|
6
|
-
end
|
|
4
|
+
end
|
data/test/migration_test.rb
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
|
2
|
+
require File.join(File.dirname(__FILE__), 'fixtures/migrations/2_add_versioned_tables')
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
class Thing < ActiveRecord::Base
|
|
5
|
+
attr_accessor :version
|
|
6
|
+
acts_as_versioned
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class MigrationTest < ActiveSupport::TestCase
|
|
10
|
+
self.use_transactional_tests = false
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
# make the test repeatable (the sqlite db file survives between runs)
|
|
14
|
+
ActiveRecord::Base.connection.drop_table :things_h, if_exists: true
|
|
15
|
+
ActiveRecord::Base.connection.drop_table :things, if_exists: true
|
|
7
16
|
end
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
def test_versioned_migration
|
|
19
|
+
AddVersionedTables.new.migrate(:up)
|
|
20
|
+
t = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing'
|
|
21
|
+
assert_equal 1, t.versions.size
|
|
11
22
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
require migrations_path + '/2_add_versioned_tables'
|
|
16
|
-
ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations(migrations_path), 2).run
|
|
17
|
-
t = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing'
|
|
18
|
-
assert_equal 1, t.versions.size
|
|
19
|
-
|
|
20
|
-
# check that the price column has remembered its value correctly
|
|
21
|
-
assert_equal t.price, t.versions.first.price
|
|
22
|
-
assert_equal t.title, t.versions.first.title
|
|
23
|
+
# check that the price column has remembered its value correctly
|
|
24
|
+
assert_equal t.price, t.versions.first.price
|
|
25
|
+
assert_equal t.title, t.versions.first.title
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
27
|
+
# make sure that the precision of the price column has been preserved
|
|
28
|
+
assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision
|
|
29
|
+
assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale
|
|
28
30
|
end
|
|
29
31
|
end
|