rtiss_acts_as_versioned 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a52b967ef4cb3fd70eda63abb22684b5ee4d5b1
4
- data.tar.gz: b057e9ebe4156925141231be0e28203b0a56e03c
3
+ metadata.gz: a47925d46be533c4270653aa1c6ecd3bdec9a8d5
4
+ data.tar.gz: 2d1c25a86d66ab51f3c747f26abc34818e8a4b53
5
5
  SHA512:
6
- metadata.gz: cec76f055810b23b62087ccd0bb02228f485f1b61df23d8582fe09eeb6004bb928108d33872a9f6c49882c37dbf819bf00795639944774e27238551d30902e15
7
- data.tar.gz: de50c719b3f639119dbe6fca26f0ef58940957f3dd80958db40682f51680ccc1f2639d3533c30ec63dad31130be93a8c8b474e1900e3fe431158dfdc8bafaa6c
6
+ metadata.gz: a117151d322b33a6a87eec2931bb4f6d3290c84d9ffcc18b3e248188e745fcd7a81557893c585e2d061b861a4893b57af23979120a9e6637b3b5512a1528e400
7
+ data.tar.gz: 7bdca076be71230b7e08e4daf4527177829efce40f884265e4fbfeed4f17f2111f30fe1ed326d61e9457f3891ba798f4d22f6f7973b35d44963b403cdd197ee4
data/README CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  This library adds simple versioning to an ActiveRecord module. ActiveRecord is required.
4
4
 
5
- This is the patched version for rtiss.
6
-
7
- Versions 0.6.x (rails2 branch) are for rails 2.x
8
- Versions 0.7.x (rails3 branch) are for rails 3.x
9
- Versions 0.8.x (master branch) are for rails 4.x
10
-
11
5
  == Resources
12
6
 
13
7
  Install
@@ -27,10 +21,4 @@ Subversion
27
21
  * http://svn.github.com/technoweenie/acts_as_versioned.git
28
22
 
29
23
  Special thanks to Dreamer on ##rubyonrails for help in early testing. His ServerSideWiki (http://serversidewiki.com)
30
- was the first project to use acts_as_versioned <em>in the wild</em>.
31
-
32
- == Publishing a new release
33
-
34
- * increase the VERSION in rtiss_acts_as_versioned.rb
35
- * run: bundle exec rake test
36
- * run: bundle exec rake release
24
+ was the first project to use acts_as_versioned <em>in the wild</em>.
data/Rakefile CHANGED
@@ -73,6 +73,14 @@ task :console do
73
73
  sh "irb -rubygems -r ./lib//#{name}.rb"
74
74
  end
75
75
 
76
+ #############################################################################
77
+ #
78
+ # Custom tasks (add your own tasks here)
79
+ #
80
+ #############################################################################
81
+
82
+
83
+
76
84
  #############################################################################
77
85
  #
78
86
  # Packaging tasks
@@ -80,11 +88,14 @@ end
80
88
  #############################################################################
81
89
 
82
90
  task :release => :build do
91
+ unless `git branch` =~ /^\* master$/
92
+ puts "You must be on the master branch to release!"
93
+ exit!
94
+ end
83
95
  sh "git commit --allow-empty -a -m 'Release #{version}'"
84
- sh "git tag #{version}" # create new release tag
85
- sh "git push origin rails3" # push current branch
86
- sh "git push origin #{version}" # push the new release tag
87
- sh "gem push pkg/#{name}-#{version}.gem" # push the gem to RubyGems.org
96
+ sh "git tag #{version}"
97
+ sh "git push origin master --tags"
98
+ sh "gem push pkg/#{name}-#{version}.gem"
88
99
  end
89
100
 
90
101
  task :build => :gemspec do
@@ -20,7 +20,7 @@
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
- VERSION = '0.7.9'
23
+ VERSION = '0.8.0'
24
24
 
25
25
  module ActiveRecord #:nodoc:
26
26
  module Acts #:nodoc:
@@ -173,7 +173,7 @@ module ActiveRecord #:nodoc:
173
173
 
174
174
  cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name, :versioned_inheritance_column,
175
175
  :version_column, :max_version_limit, :track_altered_attributes, :version_condition, :version_sequence_name, :non_versioned_columns,
176
- :version_association_options, :version_if_changed, :deleted_in_original_table_flag, :record_restored_column
176
+ :version_association_options, :version_if_changed, :deleted_in_original_table_flag, :record_restored_flag
177
177
 
178
178
  self.versioned_class_name = options[:class_name] || "Version"
179
179
  self.versioned_foreign_key = options[:foreign_key] || self.to_s.foreign_key
@@ -182,14 +182,11 @@ module ActiveRecord #:nodoc:
182
182
  self.versioned_inheritance_column = options[:inheritance_column] || "versioned_#{inheritance_column}"
183
183
  self.version_column = options[:version_column] || 'version'
184
184
  self.deleted_in_original_table_flag = options[:deleted_in_original_table_flag] || 'deleted_in_original_table'
185
- self.record_restored_column = options[:record_restored_column] || 'record_restored'
185
+ self.record_restored_flag = options[:record_restored_flag] || 'record_restored'
186
186
  self.version_sequence_name = options[:sequence_name]
187
187
  self.max_version_limit = options[:limit].to_i
188
188
  self.version_condition = options[:if] || true
189
189
  self.non_versioned_columns = [self.primary_key, inheritance_column, self.version_column, 'lock_version', versioned_inheritance_column] + options[:non_versioned_columns].to_a.map(&:to_s)
190
- if options[:association_options].is_a?(Hash) && options[:association_options][:dependent] == :nullify
191
- raise "Illegal option :dependent => :nullify - this would produce orphans in version model"
192
- end
193
190
  self.version_association_options = {
194
191
  :class_name => "#{self.to_s}::#{versioned_class_name}",
195
192
  :foreign_key => versioned_foreign_key
@@ -204,7 +201,7 @@ module ActiveRecord #:nodoc:
204
201
  options[:extend] = self.const_get(extension_module_name)
205
202
  end
206
203
 
207
- class_eval <<-CLASS_METHODS
204
+ class_eval <<-CLASS_METHODS, __FILE__, __LINE__ + 1
208
205
  has_many :versions, version_association_options do
209
206
  # finds earliest version of this record
210
207
  def earliest
@@ -234,7 +231,6 @@ module ActiveRecord #:nodoc:
234
231
  const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do
235
232
  def self.reloadable? ; false ; end
236
233
  # find first version before the given version
237
- # TODO: replace "version" in selects with version_column, use select-method instead of find
238
234
  def self.before(version)
239
235
  find :first, :order => 'version desc',
240
236
  :conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version]
@@ -267,7 +263,7 @@ module ActiveRecord #:nodoc:
267
263
  version_hash = self.attributes
268
264
  version_hash.delete "id"
269
265
  version_hash.delete self.original_class.deleted_in_original_table_flag.to_s
270
- version_hash.delete self.original_class.record_restored_column.to_s
266
+ version_hash.delete self.original_class.record_restored_flag.to_s
271
267
  version_hash.delete self.original_class.versioned_foreign_key.to_s
272
268
 
273
269
  restored_record = self.original_class.new(version_hash)
@@ -275,26 +271,18 @@ module ActiveRecord #:nodoc:
275
271
  if restored_record.respond_to? :updated_at=
276
272
  restored_record.updated_at = Time.now
277
273
  end
278
- # DON'T EVEN THINK ABOUT CALCULATING THE VERSION NUMBER USING THE VERSIONS ASSOCIATION HERE:
279
- # There is a problem in ActiveRecord. An association Relation will be converted to an Array internally, when the SQL-select is
280
- # executed.
281
- # Some ActiveRecord-Methods (for example #ActiveRecord::Base::AutosaveAssociation#save_collection_association) try to use ActiveRecord methods
282
- # with these Relations, and if these Relations have been converted to Arrays, these calls fail with an Exception
283
- new_version_number = self.class.where(self.original_class.versioned_foreign_key => id).order('id desc').first.send(restored_record.version_column).to_i + 1
284
- restored_record.send("#{restored_record.version_column}=", new_version_number)
285
274
  unless restored_record.save_without_revision(perform_validation)
286
275
  raise RuntimeError.new("Couldn't restore the record, id = #{id} class = #{self.class.name}")
287
276
  end
288
- restored_record.save_version(true, false, self.send(self.original_class.version_column))
289
- end
290
-
291
- def record_restored?
292
- self.read_attribute(self.original_class.record_restored_column) != nil
293
- end
294
- alias :record_restored :record_restored?
295
277
 
296
- def record_restored_from_version
297
- self.read_attribute(self.original_class.record_restored_column)
278
+ new_version = clone
279
+ new_version.version += 1
280
+ new_version.send("#{self.original_class.deleted_in_original_table_flag}=", false)
281
+ new_version.send("#{self.original_class.record_restored_flag}=", true)
282
+ if new_version.respond_to? :updated_at=
283
+ new_version.updated_at = Time.now
284
+ end
285
+ new_version.save!
298
286
  end
299
287
 
300
288
  def original_record_exists?
@@ -319,15 +307,15 @@ module ActiveRecord #:nodoc:
319
307
  end
320
308
 
321
309
  # Saves a version of the model in the versioned table. This is called in the after_save callback by default
322
- def save_version(save_this=false, deleted_flag=false, restored_from_version=nil)
323
- if @saving_version || save_this
310
+ def save_version
311
+ if @saving_version
324
312
  @saving_version = nil
325
313
  rev = self.class.versioned_class.new
326
314
  clone_versioned_model(self, rev)
327
315
  rev.send("#{self.class.version_column}=", send(self.class.version_column))
328
316
  rev.send("#{self.class.versioned_foreign_key}=", id)
329
- rev.send("#{self.class.deleted_in_original_table_flag}=", deleted_flag)
330
- rev.send("#{self.class.record_restored_column}=", restored_from_version)
317
+ rev.send("#{self.class.deleted_in_original_table_flag}=", false)
318
+ rev.send("#{self.class.record_restored_flag}=", false)
331
319
  if rev.respond_to? :updated_at=
332
320
  rev.updated_at = Time.now
333
321
  end
@@ -343,7 +331,7 @@ module ActiveRecord #:nodoc:
343
331
  rev.send("#{self.class.version_column}=", highest_version+1)
344
332
  rev.send("#{self.class.versioned_foreign_key}=", id)
345
333
  rev.send("#{self.class.deleted_in_original_table_flag}=", true)
346
- rev.send("#{self.class.record_restored_column}=", nil)
334
+ rev.send("#{self.class.record_restored_flag}=", false)
347
335
  if rev.respond_to? :updated_at=
348
336
  rev.updated_at = Time.now
349
337
  end
@@ -363,11 +351,9 @@ module ActiveRecord #:nodoc:
363
351
  # Reverts a model to a given version. Takes either a version number or an instance of the versioned model
364
352
  def revert_to(version)
365
353
  if version.is_a?(self.class.versioned_class)
366
- @reverted_from = version.send(self.class.version_column)
367
354
  return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record?
368
355
  else
369
- @reverted_from = version
370
- return false unless version = versions.where(self.class.version_column => version).first
356
+ return false unless version = versions.send("find_by_#{self.class.version_column}", version)
371
357
  end
372
358
  self.clone_versioned_model(version, self)
373
359
  send("#{self.class.version_column}=", version.send(self.class.version_column))
@@ -377,13 +363,7 @@ module ActiveRecord #:nodoc:
377
363
  # Reverts a model to a given version and saves the model.
378
364
  # Takes either a version number or an instance of the versioned model
379
365
  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
366
+ revert_to(version) ? save_without_revision : false
387
367
  end
388
368
 
389
369
  # Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created.
@@ -486,7 +466,7 @@ module ActiveRecord #:nodoc:
486
466
  def find_newest_version
487
467
  return nil if self.id.nil?
488
468
 
489
- self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id}").order("version DESC").first
469
+ self.class.versioned_class.find(:first, :conditions => "#{self.class.versioned_foreign_key} = #{self.id}", :order => "version DESC")
490
470
  end
491
471
 
492
472
  def highest_version
@@ -501,22 +481,22 @@ module ActiveRecord #:nodoc:
501
481
  def find_version(version)
502
482
  return nil if self.id.nil?
503
483
 
504
- ret = self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id} and #{self.class.version_column}=#{version}").first
484
+ ret = self.class.versioned_class.find(:first, :conditions => "#{self.class.versioned_foreign_key} = #{self.id} and version=#{version}") # TODO: version column
505
485
  raise "find_version: version #{version} not found in database" unless ret
506
486
  ret
507
487
  end
508
488
 
509
489
  protected
510
- # sets the new version before saving
511
- def set_new_version
512
- @saving_version = new_record? || save_version?
513
- self.send("#{self.class.version_column}=", next_version) if new_record? || save_version?
514
- end
490
+ # sets the new version before saving, unless you're using optimistic locking. In that case, let it take care of the version.
491
+ def set_new_version
492
+ @saving_version = new_record? || save_version?
493
+ self.send("#{self.class.version_column}=", next_version) if new_record? || (!locking_enabled? && save_version?)
494
+ end
515
495
 
516
- # Gets the next available version for the current record, or 1 for a new record
517
- def next_version
518
- (new_record? ? 0 : versions.calculate(:maximum, version_column).to_i) + 1
519
- end
496
+ # Gets the next available version for the current record, or 1 for a new record
497
+ def next_version
498
+ (new_record? ? 0 : versions.calculate(:maximum, version_column).to_i) + 1
499
+ end
520
500
 
521
501
  module ClassMethods
522
502
  # Returns an array of columns that are versioned. See non_versioned_columns
@@ -543,7 +523,7 @@ module ActiveRecord #:nodoc:
543
523
  t.column versioned_foreign_key, :integer
544
524
  t.column version_column, :integer
545
525
  t.column deleted_in_original_table_flag, :boolean, :default => false
546
- t.column record_restored_column, :integer, :default => nil
526
+ t.column record_restored_flag, :boolean, :default => false
547
527
  end
548
528
 
549
529
  self.versioned_columns.each do |col|
@@ -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.7.9'
16
- s.date = '2014-11-18'
15
+ s.version = '0.8.0'
16
+ s.date = '2014-10-30'
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).
@@ -1,12 +1,10 @@
1
1
  welcome:
2
2
  id: 1
3
3
  title: Welcome to the weblog
4
- version: 24
5
- lock_version: 1
4
+ lock_version: 24
6
5
  type: LockedPage
7
6
  thinking:
8
7
  id: 2
9
8
  title: So I was thinking
10
- version: 24
11
- lock_version: 1
9
+ lock_version: 24
12
10
  type: SpecialLockedPage
@@ -2,26 +2,26 @@ welcome_1:
2
2
  id: 1
3
3
  page_id: 1
4
4
  title: Welcome to the weblg
5
- version: 23
5
+ lock_version: 23
6
6
  version_type: LockedPage
7
7
 
8
8
  welcome_2:
9
9
  id: 2
10
10
  page_id: 1
11
11
  title: Welcome to the weblog
12
- version: 24
12
+ lock_version: 24
13
13
  version_type: LockedPage
14
14
 
15
15
  thinking_1:
16
16
  id: 3
17
17
  page_id: 2
18
18
  title: So I was thinking!!!
19
- version: 23
19
+ lock_version: 23
20
20
  version_type: SpecialLockedPage
21
21
 
22
22
  thinking_2:
23
23
  id: 4
24
24
  page_id: 2
25
25
  title: So I was thinking
26
- version: 24
26
+ lock_version: 24
27
27
  version_type: SpecialLockedPage
@@ -29,6 +29,7 @@ class LockedPage < ActiveRecord::Base
29
29
  :foreign_key => :page_id,
30
30
  :table_name => :locked_pages_revisions,
31
31
  :class_name => 'LockedPageRevision',
32
+ :version_column => :lock_version,
32
33
  :limit => 2,
33
34
  :if_changed => :title,
34
35
  :extend => LockedPageExtension
@@ -1,6 +1,6 @@
1
1
  class Widget < ActiveRecord::Base
2
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
3
+ :dependent => :nullify, :order => 'version desc'
4
4
  }
5
5
  non_versioned_columns << 'foo'
6
6
  end
data/test/schema.rb CHANGED
@@ -19,7 +19,7 @@ ActiveRecord::Schema.define(:version => 0) do
19
19
  t.column :author_id, :integer
20
20
  t.column :revisor_id, :integer
21
21
  t.column :deleted_in_original_table, :boolean
22
- t.column :record_restored, :integer, :precision => 38, :scale => 0, :default => nil
22
+ t.column :record_restored, :boolean
23
23
  end
24
24
 
25
25
  add_index :pages_h, [:page_id, :version], :unique => true
@@ -31,7 +31,6 @@ ActiveRecord::Schema.define(:version => 0) do
31
31
 
32
32
  create_table :locked_pages, :force => true do |t|
33
33
  t.column :lock_version, :integer
34
- t.column :version, :integer
35
34
  t.column :title, :string, :limit => 255
36
35
  t.column :body, :text
37
36
  t.column :type, :string, :limit => 255
@@ -39,17 +38,16 @@ ActiveRecord::Schema.define(:version => 0) do
39
38
 
40
39
  create_table :locked_pages_revisions, :force => true do |t|
41
40
  t.column :page_id, :integer
42
- t.column :version, :integer
43
- #t.column :lock_version, :integer
41
+ t.column :lock_version, :integer
44
42
  t.column :title, :string, :limit => 255
45
43
  t.column :body, :text
46
44
  t.column :version_type, :string, :limit => 255
47
45
  t.column :updated_at, :datetime
48
46
  t.column :deleted_in_original_table, :boolean
49
- t.column :record_restored, :integer, :precision => 38, :scale => 0, :default => nil
47
+ t.column :record_restored, :boolean
50
48
  end
51
49
 
52
- add_index :locked_pages_revisions, [:page_id, :version], :unique => true
50
+ add_index :locked_pages_revisions, [:page_id, :lock_version], :unique => true
53
51
 
54
52
  create_table :widgets, :force => true do |t|
55
53
  t.column :name, :string, :limit => 50
@@ -64,7 +62,7 @@ ActiveRecord::Schema.define(:version => 0) do
64
62
  t.column :version, :integer
65
63
  t.column :updated_at, :datetime
66
64
  t.column :deleted_in_original_table, :boolean
67
- t.column :record_restored, :integer, :precision => 38, :scale => 0, :default => nil
65
+ t.column :record_restored, :boolean
68
66
  end
69
67
 
70
68
  add_index :widgets_h, [:widget_id, :version], :unique => true
@@ -85,7 +83,7 @@ ActiveRecord::Schema.define(:version => 0) do
85
83
  t.column :doesnt_trigger_version,:string
86
84
  t.column :version, :integer
87
85
  t.column :deleted_in_original_table, :boolean
88
- t.column :record_restored, :integer, :precision => 38, :scale => 0, :default => nil
86
+ t.column :record_restored, :boolean
89
87
  end
90
88
 
91
89
  add_index :landmark_h, [:landmark_id, :version], :unique => true
@@ -113,7 +111,7 @@ ActiveRecord::Schema.define(:version => 0) do
113
111
  t.string "name", :limit => 50
114
112
  t.string "beschreibung", :limit => 250
115
113
  t.boolean "deleted_in_original_table", :precision => 1, :scale => 0
116
- t.integer "record_restored", :precision => 38, :scale => 0, :default => nil
114
+ t.boolean "record_restored", :precision => 1, :scale => 0
117
115
  t.integer "parent_id", :precision => 38, :scale => 0
118
116
  t.string "beschreibung_intern", :limit => 4000
119
117
  t.string "geltungsbereich", :limit => 1000
@@ -146,7 +144,7 @@ ActiveRecord::Schema.define(:version => 0) do
146
144
  t.string "name", :limit => 50
147
145
  t.string "beschreibung", :limit => 250
148
146
  t.boolean "deleted_in_original_table", :precision => 1, :scale => 0
149
- t.integer "record_restored", :precision => 38, :scale => 0, :default => nil
147
+ t.boolean "record_restored", :precision => 1, :scale => 0
150
148
  t.integer "parent_id", :precision => 38, :scale => 0
151
149
  t.string "beschreibung_intern", :limit => 4000
152
150
  t.string "geltungsbereich", :limit => 1000
data/test/tiss_test.rb CHANGED
@@ -106,63 +106,23 @@ class TissTest < ActiveSupport::TestCase
106
106
  oid = o.id
107
107
  v = o.find_version(1)
108
108
  assert v!=nil
109
-
109
+
110
110
  assert_raises(RuntimeError) { v.restore }
111
111
  assert !v.deleted_in_original_table
112
112
  assert !v.record_restored, "Record_restored shows that the record was undeleted (should be false) for a newly created record"
113
113
 
114
- old_version = o.version
115
114
  o.destroy
116
115
  v = o.find_newest_version
117
- first_delete_version = v.version
118
- assert v.deleted_in_original_table, "Deleted-Flag in versioned record is not set"
119
- assert_equal old_version + 1, v.version, "Destroy did not increment version number in history record"
116
+ assert v.deleted_in_original_table
120
117
 
121
118
  v.restore
122
- restored_version = v.version
123
119
  assert !v.record_restored, "Record_restored shows that the record was undeleted (should be false) for the restored version record (but should be in the newly created record)"
124
120
  o = Rolle.find oid
121
+ assert v.version == o.version, "Version field not restored correctly"
122
+
125
123
  v = o.find_newest_version
126
- v_old = v
127
- assert_equal v.version, o.version
128
- assert_equal old_version + 2, v.version, "Version field not restored correctly"
129
124
  assert !v.deleted_in_original_table, "Deleted_in_original_table doesn't show that the record was undeleted (should be false)"
130
125
  assert v.record_restored, "Record_restored doesn't show that the record was undeleted (should be true) for the version record created upon restore"
131
- assert_equal restored_version, v.record_restored_from_version
132
-
133
- o.name = 'kaputt'
134
- assert o.save
135
- o.destroy
136
- v = o.find_newest_version
137
- v.restore
138
- o = Rolle.find oid
139
- assert_equal v.version + 1, o.version
140
- assert_equal 'kaputt', o.name
141
- assert_equal v.version, o.find_newest_version.record_restored_from_version
142
- o.destroy
143
- v_old.restore
144
- o = Rolle.find oid
145
- assert_equal 'lebt', o.name
146
- assert_equal v_old.version, o.find_newest_version.record_restored_from_version
147
- end
148
-
149
- def test_restore_and_destroy_with_revision_on_every_change
150
- r = Rolle.new(:name => 'karin')
151
- assert r.save
152
- r.name = 'zak'
153
- assert r.save
154
- assert_equal 2, Rolle::Version.count
155
- r.destroy
156
- assert_equal 0, Rolle.count
157
- assert_equal 3, Rolle::Version.count
158
- assert version = r.find_version(3)
159
- assert version.deleted_in_original_table?
160
- assert version = r.find_version(2)
161
- version.restore
162
- assert r = Rolle.first
163
- assert r.find_newest_version.record_restored?
164
- assert_equal 4, Rolle::Version.count
165
- assert_equal 4, r.version
166
126
  end
167
127
 
168
128
  def test_original_record_exists
@@ -233,8 +193,7 @@ class TissTest < ActiveSupport::TestCase
233
193
  assert r.save
234
194
  r.name = 'zak'
235
195
  assert r.save
236
- r.reload
237
- assert_equal 2, r.versions.size
196
+ assert_equal 2, r.versions.size
238
197
  assert_equal 2, r.versions.count
239
198
  end
240
199
 
@@ -246,9 +205,9 @@ class TissTest < ActiveSupport::TestCase
246
205
 
247
206
  r = Rolle.new(:name => 'karin')
248
207
  assert r.save
208
+
249
209
  assert_raises RuntimeError do version.restore end
250
- #assert_nothing_raised do
251
- version.restore(perform_validations = false) #end
210
+ assert_nothing_raised do version.restore(perform_validations = false) end
252
211
  end
253
212
 
254
213
  def test_save_without_revision
@@ -29,14 +29,11 @@ class VersionedTest < ActiveSupport::TestCase
29
29
 
30
30
  def test_rollback_with_version_number
31
31
  p = pages(:welcome)
32
- versioncount = p.versions.count
33
32
  assert_equal 24, p.version
34
33
  assert_equal 'Welcome to the weblog', p.title
35
34
 
36
35
  assert p.revert_to!(23), "Couldn't revert to 23"
37
- assert p.reload
38
- assert_equal versioncount + 1, p.versions.count
39
- assert_equal 25, p.version
36
+ assert_equal 23, p.version
40
37
  assert_equal 'Welcome to the weblg', p.title
41
38
  end
42
39
 
@@ -59,14 +56,11 @@ class VersionedTest < ActiveSupport::TestCase
59
56
 
60
57
  def test_rollback_with_version_class
61
58
  p = pages(:welcome)
62
- versioncount = p.versions.count
63
59
  assert_equal 24, p.version
64
60
  assert_equal 'Welcome to the weblog', p.title
65
61
 
66
62
  assert p.revert_to!(p.versions.find_by_version(23)), "Couldn't revert to 23"
67
- assert p.reload
68
- assert_equal versioncount + 1, p.versions.count
69
- assert_equal 25, p.version
63
+ assert_equal 23, p.version
70
64
  assert_equal 'Welcome to the weblg', p.title
71
65
  end
72
66
 
@@ -87,7 +81,7 @@ class VersionedTest < ActiveSupport::TestCase
87
81
  assert_equal 'Welcome to the weblog', p.title
88
82
  assert_equal 'LockedPage', p.versions.first.version_type
89
83
 
90
- assert p.revert_to!(p.versions.first.version), "Couldn't revert to 23"
84
+ assert p.revert_to!(p.versions.first.lock_version), "Couldn't revert to 23"
91
85
  assert_equal 'Welcome to the weblg', p.title
92
86
  assert_equal 'LockedPage', p.versions.first.version_type
93
87
  end
@@ -114,7 +108,7 @@ class VersionedTest < ActiveSupport::TestCase
114
108
  p = locked_pages(:thinking)
115
109
  assert_equal 'So I was thinking', p.title
116
110
 
117
- assert p.revert_to!(p.versions.first.version), "Couldn't revert to 1"
111
+ assert p.revert_to!(p.versions.first.lock_version), "Couldn't revert to 1"
118
112
  assert_equal 'So I was thinking!!!', p.title
119
113
  assert_equal 'SpecialLockedPage', p.versions.first.version_type
120
114
  end
@@ -208,7 +202,7 @@ class VersionedTest < ActiveSupport::TestCase
208
202
  p.title = "title#{i}"
209
203
  p.save
210
204
  assert_equal "title#{i}", p.title
211
- assert_equal (i+4), p.version
205
+ assert_equal (i+4), p.lock_version
212
206
  assert p.versions(true).size <= 2, "locked version can only store 2 versions"
213
207
  end
214
208
  end
@@ -221,25 +215,25 @@ class VersionedTest < ActiveSupport::TestCase
221
215
 
222
216
  def test_track_altered_attributes
223
217
  p = LockedPage.create! :title => "title"
224
- assert_equal 1, p.version
218
+ assert_equal 1, p.lock_version
225
219
  assert_equal 1, p.versions(true).size
226
220
 
227
221
  p.body = 'whoa'
228
222
  assert !p.save_version?
229
223
  p.save
230
- assert_equal 1, p.version # no increment, because we're not using lock_version column
224
+ assert_equal 2, p.lock_version # still increments version because of optimistic locking
231
225
  assert_equal 1, p.versions(true).size
232
226
 
233
227
  p.title = 'updated title'
234
228
  assert p.save_version?
235
229
  p.save
236
- assert_equal 2, p.version
237
- assert_equal 2, p.versions(true).size
230
+ assert_equal 3, p.lock_version
231
+ assert_equal 1, p.versions(true).size # version 1 deleted
238
232
 
239
233
  p.title = 'updated title!'
240
234
  assert p.save_version?
241
235
  p.save
242
- assert_equal 3, p.version
236
+ assert_equal 4, p.lock_version
243
237
  assert_equal 2, p.versions(true).size # version 1 deleted
244
238
  end
245
239
 
@@ -279,7 +273,7 @@ class VersionedTest < ActiveSupport::TestCase
279
273
 
280
274
  association = Widget.reflect_on_association(:versions)
281
275
  options = association.options
282
- #assert_equal :nullify, options[:dependent] #Removed! we do not nullify the foreign key, because on restore we want to set the correct original ID
276
+ assert_equal :nullify, options[:dependent]
283
277
  assert_equal 'version desc', options[:order]
284
278
  assert_equal 'widget_id', options[:foreign_key]
285
279
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtiss_acts_as_versioned
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Olson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-11-18 00:00:00.000000000 Z
13
+ date: 2014-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord