acts_as_revisionable 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,28 @@
1
1
  require 'rubygems'
2
+ require 'logger'
3
+ require 'stringio'
2
4
 
3
5
  if ENV["ACTIVE_RECORD_VERSION"]
4
6
  gem 'activerecord', ENV["ACTIVE_RECORD_VERSION"]
5
7
  else
6
8
  gem 'activerecord'
7
9
  end
10
+ require 'active_record'
11
+ require 'active_record/version'
12
+ ActiveRecord::ActiveRecordError
13
+
14
+ ActiveRecord::Base.logger = Logger.new(StringIO.new)
15
+ puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
16
+
17
+ composite_primary_key_version = nil
18
+ if ActiveRecord::VERSION::MAJOR >= 3
19
+ composite_primary_key_version = ">=3.0.0"
20
+ else
21
+ composite_primary_key_version = "~>2.3.5"
22
+ end
23
+
24
+ gem 'composite_primary_keys', composite_primary_key_version
25
+ require 'composite_primary_keys'
8
26
 
9
27
  require File.expand_path('../../lib/acts_as_revisionable', __FILE__)
10
28
  require 'sqlite3'
@@ -13,7 +31,6 @@ module ActsAsRevisionable
13
31
  module Test
14
32
  def self.create_database
15
33
  ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
16
- ActsAsRevisionable::RevisionRecord.create_table
17
34
  end
18
35
 
19
36
  def self.delete_database
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe "upgrade to version 1.1" do
4
+
5
+ before :each do
6
+ ActsAsRevisionable::Test.create_database
7
+ end
8
+
9
+ after :each do
10
+ ActsAsRevisionable::Test.delete_database
11
+ end
12
+
13
+ it "should update an older table definition with the latest definition on create_table" do
14
+ connection = ActsAsRevisionable::RevisionRecord.connection
15
+
16
+ connection.create_table(:revision_records) do |t|
17
+ t.string :revisionable_type, :null => false, :limit => 100
18
+ t.integer :revisionable_id, :null => false
19
+ t.integer :revision, :null => false
20
+ t.binary :data, :limit => (connection.adapter_name.match(/mysql/i) ? 5.megabytes : nil)
21
+ t.timestamp :created_at, :null => false
22
+ end
23
+ connection.add_index :revision_records, [:revisionable_type, :revisionable_id, :revision], :name => "revisionable", :unique => true
24
+
25
+ ActsAsRevisionable::RevisionRecord.update_version_1_table
26
+
27
+ columns = connection.columns(:revision_records)
28
+ trash_column = columns.detect{|c| c.name == 'trash'}
29
+ trash_column.type.should == :boolean
30
+ trash_column.default.should == false
31
+
32
+ if connection.respond_to?(:index_exists?)
33
+ connection.index_exists?(:revision_records, [:revisionable_type, :revisionable_id, :revision], :name => "revisionable", :unique => true).should_not
34
+ connection.index_exists?(:revision_records, :revisionable_id, :name => "revision_record_id").should
35
+ connection.index_exists?(:revision_records, [:revisionable_type, :created_at, :trash], :name => "revisionable_type_and_created_at").should
36
+ else
37
+ STDERR.puts("Could not check if indexes were updated with this version of ActiveRecord")
38
+ end
39
+ end
40
+
41
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_revisionable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 6
10
- version: 1.0.6
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Durand
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-08 00:00:00 -06:00
18
+ date: 2011-06-23 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,15 +26,16 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 7
29
+ hash: 9
30
30
  segments:
31
31
  - 2
32
- - 2
33
- version: "2.2"
32
+ - 3
33
+ - 5
34
+ version: 2.3.5
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  - !ruby/object:Gem::Dependency
37
- name: sqlite3
38
+ name: composite_primary_keys
38
39
  prerelease: false
39
40
  requirement: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
@@ -48,9 +49,23 @@ dependencies:
48
49
  type: :development
49
50
  version_requirements: *id002
50
51
  - !ruby/object:Gem::Dependency
51
- name: rspec
52
+ name: sqlite3
52
53
  prerelease: false
53
54
  requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
54
69
  none: false
55
70
  requirements:
56
71
  - - ">="
@@ -62,11 +77,11 @@ dependencies:
62
77
  - 0
63
78
  version: 2.0.0
64
79
  type: :development
65
- version_requirements: *id003
80
+ version_requirements: *id004
66
81
  - !ruby/object:Gem::Dependency
67
82
  name: jeweler
68
83
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
84
+ requirement: &id005 !ruby/object:Gem::Requirement
70
85
  none: false
71
86
  requirements:
72
87
  - - ">="
@@ -76,7 +91,7 @@ dependencies:
76
91
  - 0
77
92
  version: "0"
78
93
  type: :development
79
- version_requirements: *id004
94
+ version_requirements: *id005
80
95
  description: ActiveRecord extension that provides revision support so that history can be tracked and changes can be reverted. Emphasis for this plugin versus similar ones is including associations, saving on storage, and extensibility of the model.
81
96
  email: brian@embellishedvisions.com
82
97
  executables: []
@@ -88,15 +103,16 @@ extra_rdoc_files:
88
103
  files:
89
104
  - MIT-LICENSE
90
105
  - README.rdoc
106
+ - RELEASES.txt
91
107
  - Rakefile
92
108
  - VERSION
93
109
  - acts_as_revisionable.gemspec
94
110
  - lib/acts_as_revisionable.rb
95
111
  - lib/acts_as_revisionable/revision_record.rb
96
112
  - spec/acts_as_revisionable_spec.rb
97
- - spec/full_spec.rb
98
113
  - spec/revision_record_spec.rb
99
114
  - spec/spec_helper.rb
115
+ - spec/version_1_1_upgrade_spec.rb
100
116
  has_rdoc: true
101
117
  homepage: http://github.com/bdurand/acts_as_revisionable
102
118
  licenses: []
@@ -106,6 +122,7 @@ rdoc_options:
106
122
  - --charset=UTF-8
107
123
  - --main
108
124
  - README.rdoc
125
+ - MIT-LICENSE
109
126
  require_paths:
110
127
  - lib
111
128
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -129,12 +146,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
146
  requirements: []
130
147
 
131
148
  rubyforge_project:
132
- rubygems_version: 1.4.1
149
+ rubygems_version: 1.5.2
133
150
  signing_key:
134
151
  specification_version: 3
135
152
  summary: ActiveRecord extension that provides revision support so that history can be tracked and changes can be reverted.
136
- test_files:
137
- - spec/acts_as_revisionable_spec.rb
138
- - spec/full_spec.rb
139
- - spec/revision_record_spec.rb
140
- - spec/spec_helper.rb
153
+ test_files: []
154
+
@@ -1,449 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "ActsAsRevisionable Full Test" do
4
-
5
- before(:all) do
6
- ActsAsRevisionable::Test.create_database
7
-
8
- ActiveRecord::Base.store_full_sti_class = true
9
-
10
- class RevisionableTestSubThing < ActiveRecord::Base
11
- connection.create_table(:revisionable_test_sub_things) do |t|
12
- t.column :name, :string
13
- t.column :revisionable_test_many_thing_id, :integer
14
- end unless table_exists?
15
- end
16
-
17
- class RevisionableTestManyThing < ActiveRecord::Base
18
- connection.create_table(:revisionable_test_many_things) do |t|
19
- t.column :name, :string
20
- t.column :revisionable_test_model_id, :integer
21
- end unless table_exists?
22
-
23
- has_many :sub_things, :class_name => 'RevisionableTestSubThing'
24
- end
25
-
26
- class RevisionableTestManyOtherThing < ActiveRecord::Base
27
- connection.create_table(:revisionable_test_many_other_things) do |t|
28
- t.column :name, :string
29
- t.column :revisionable_test_model_id, :integer
30
- end unless table_exists?
31
- end
32
-
33
- class RevisionableTestOneThing < ActiveRecord::Base
34
- connection.create_table(:revisionable_test_one_things) do |t|
35
- t.column :name, :string
36
- t.column :revisionable_test_model_id, :integer
37
- end unless table_exists?
38
- end
39
-
40
- class NonRevisionableTestModel < ActiveRecord::Base
41
- connection.create_table(:non_revisionable_test_models) do |t|
42
- t.column :name, :string
43
- end unless table_exists?
44
- end
45
-
46
- class NonRevisionableTestModelsRevisionableTestModel < ActiveRecord::Base
47
- connection.create_table(:non_revisionable_test_models_revisionable_test_models, :id => false) do |t|
48
- t.column :non_revisionable_test_model_id, :integer
49
- t.column :revisionable_test_model_id, :integer
50
- end unless table_exists?
51
- end
52
-
53
- class RevisionableTestModel < ActiveRecord::Base
54
- connection.create_table(:revisionable_test_models) do |t|
55
- t.column :name, :string
56
- t.column :secret, :integer
57
- end unless table_exists?
58
-
59
- has_many :many_things, :class_name => 'RevisionableTestManyThing', :dependent => :destroy
60
- has_many :many_other_things, :class_name => 'RevisionableTestManyOtherThing', :dependent => :destroy
61
- has_one :one_thing, :class_name => 'RevisionableTestOneThing'
62
- has_and_belongs_to_many :non_revisionable_test_models
63
-
64
- attr_protected :secret
65
-
66
- acts_as_revisionable :limit => 3, :associations => [:one_thing, :non_revisionable_test_models, {:many_things => :sub_things}]
67
-
68
- def set_secret (val)
69
- self.secret = val
70
- end
71
-
72
- private
73
-
74
- def secret= (val)
75
- self[:secret] = val
76
- end
77
- end
78
-
79
- module ActsAsRevisionable
80
- class RevisionableNamespaceModel < ActiveRecord::Base
81
- connection.create_table(:revisionable_namespace_models) do |t|
82
- t.column :name, :string
83
- t.column :type_name, :string
84
- end unless table_exists?
85
-
86
- set_inheritance_column :type_name
87
- acts_as_revisionable :dependent => :keep, :encoding => :xml
88
- self.store_full_sti_class = false
89
- end
90
-
91
- class RevisionableSubclassModel < RevisionableNamespaceModel
92
- end
93
- end
94
- end
95
-
96
- after :all do
97
- ActsAsRevisionable::Test.delete_database
98
- end
99
-
100
- before :each do
101
- RevisionableTestModel.delete_all
102
- RevisionableTestManyThing.delete_all
103
- RevisionableTestManyOtherThing.delete_all
104
- RevisionableTestSubThing.delete_all
105
- RevisionableTestOneThing.delete_all
106
- NonRevisionableTestModelsRevisionableTestModel.delete_all
107
- NonRevisionableTestModel.delete_all
108
- ActsAsRevisionable::RevisionRecord.delete_all
109
- ActsAsRevisionable::RevisionableNamespaceModel.delete_all
110
- end
111
-
112
- it "should only store revisions in a store revision block if :on_update is not true" do
113
- model = RevisionableTestModel.new(:name => 'test')
114
- model.set_secret(1234)
115
- model.save!
116
- ActsAsRevisionable::RevisionRecord.count.should == 0
117
- model.name = 'new_name'
118
- model.save!
119
- ActsAsRevisionable::RevisionRecord.count.should == 0
120
- end
121
-
122
- it "should not save a revision if an update raises an exception" do
123
- model = RevisionableTestModel.new(:name => 'test')
124
- model.store_revision do
125
- model.save!
126
- end
127
- model.reload
128
- ActsAsRevisionable::RevisionRecord.count.should == 0
129
-
130
- model.should_receive(:update).and_raise("update failed")
131
- model.name = 'new_name'
132
- begin
133
- model.store_revision do
134
- ActsAsRevisionable::RevisionRecord.count.should == 1
135
- model.save
136
- end
137
- rescue
138
- end
139
- ActsAsRevisionable::RevisionRecord.count.should == 0
140
- end
141
-
142
- it "should not save a revision if an update fails with errors" do
143
- model = RevisionableTestModel.new(:name => 'test')
144
- model.store_revision do
145
- model.save!
146
- end
147
- model.reload
148
- ActsAsRevisionable::RevisionRecord.count.should == 0
149
-
150
- model.name = 'new_name'
151
- model.store_revision do
152
- ActsAsRevisionable::RevisionRecord.count.should == 1
153
- model.save!
154
- model.errors.add(:name, "isn't right")
155
- end
156
- ActsAsRevisionable::RevisionRecord.count.should == 0
157
- end
158
-
159
- it "should restore a record without associations" do
160
- model = RevisionableTestModel.new(:name => 'test')
161
- model.set_secret(1234)
162
- model.store_revision do
163
- model.save!
164
- end
165
- model.reload
166
- ActsAsRevisionable::RevisionRecord.count.should == 0
167
-
168
- model.name = 'new_name'
169
- model.set_secret(5678)
170
- model.store_revision do
171
- model.save!
172
- end
173
- model.reload
174
- ActsAsRevisionable::RevisionRecord.count.should == 1
175
- model.name.should == 'new_name'
176
- model.secret.should == 5678
177
-
178
- restored = model.restore_revision(1)
179
- restored.name.should == 'test'
180
- restored.secret.should == 1234
181
- restored.id.should == model.id
182
-
183
- restored.store_revision do
184
- restored.save!
185
- end
186
- RevisionableTestModel.count.should == 1
187
- ActsAsRevisionable::RevisionRecord.count.should == 2
188
- restored_model = RevisionableTestModel.find(model.id)
189
- restored_model.name.should == restored.name
190
- restored_model.secret.should == restored.secret
191
- end
192
-
193
- it "should restore a record with has_many associations" do
194
- many_thing_1 = RevisionableTestManyThing.new(:name => 'many_thing_1')
195
- many_thing_1.sub_things.build(:name => 'sub_thing_1')
196
- many_thing_1.sub_things.build(:name => 'sub_thing_2')
197
-
198
- model = RevisionableTestModel.new(:name => 'test')
199
- model.many_things << many_thing_1
200
- model.many_things.build(:name => 'many_thing_2')
201
- model.many_other_things.build(:name => 'many_other_thing_1')
202
- model.many_other_things.build(:name => 'many_other_thing_2')
203
- model.save!
204
- model.reload
205
- RevisionableTestManyThing.count.should == 2
206
- RevisionableTestSubThing.count.should == 2
207
- RevisionableTestManyOtherThing.count.should == 2
208
- ActsAsRevisionable::RevisionRecord.count.should == 0
209
-
210
- model.store_revision do
211
- model.name = 'new_name'
212
- many_thing_1 = model.many_things.detect{|t| t.name == 'many_thing_1'}
213
- many_thing_1.name = 'new_many_thing_1'
214
- sub_thing_1 = many_thing_1.sub_things.detect{|t| t.name == 'sub_thing_1'}
215
- sub_thing_1.name = 'new_sub_thing_1'
216
- sub_thing_2 = many_thing_1.sub_things.detect{|t| t.name == 'sub_thing_2'}
217
- many_thing_1.sub_things.build(:name => 'sub_thing_3')
218
- many_thing_1.sub_things.delete(sub_thing_2)
219
- many_thing_2 = model.many_things.detect{|t| t.name == 'many_thing_2'}
220
- model.many_things.delete(many_thing_2)
221
- model.many_things.build(:name => 'many_thing_3')
222
- many_other_thing_1 = model.many_other_things.detect{|t| t.name == 'many_other_thing_1'}
223
- many_other_thing_1.name = 'new_many_other_thing_1'
224
- many_other_thing_2 = model.many_other_things.detect{|t| t.name == 'many_other_thing_2'}
225
- model.many_other_things.delete(many_other_thing_2)
226
- model.many_other_things.build(:name => 'many_other_thing_3')
227
- model.save!
228
- many_thing_1.save!
229
- sub_thing_1.save!
230
- many_other_thing_1.save!
231
- end
232
-
233
- model.reload
234
- ActsAsRevisionable::RevisionRecord.count.should == 1
235
- RevisionableTestManyThing.count.should == 2
236
- RevisionableTestSubThing.count.should == 3
237
- RevisionableTestManyOtherThing.count.should == 2
238
- model.name.should == 'new_name'
239
- model.many_things.collect{|t| t.name}.sort.should == ['many_thing_3', 'new_many_thing_1']
240
- model.many_things.detect{|t| t.name == 'new_many_thing_1'}.sub_things.collect{|t| t.name}.sort.should == ['new_sub_thing_1', 'sub_thing_3']
241
- model.many_other_things.collect{|t| t.name}.sort.should == ['many_other_thing_3', 'new_many_other_thing_1']
242
-
243
- # restore to memory
244
- restored = model.restore_revision(1)
245
- restored.name.should == 'test'
246
- restored.id.should == model.id
247
- restored.many_things.collect{|t| t.name}.sort.should == ['many_thing_1', 'many_thing_2']
248
- restored.many_things.detect{|t| t.name == 'many_thing_1'}.sub_things.collect{|t| t.name}.sort.should == ['sub_thing_1', 'sub_thing_2']
249
- restored.many_other_things.collect{|t| t.name}.sort.should == ['many_other_thing_3', 'new_many_other_thing_1']
250
- restored.valid?.should == true
251
-
252
- # make the restore to memory didn't affect the database
253
- model.reload
254
- model.name.should == 'new_name'
255
- model.many_things.collect{|t| t.name}.sort.should == ['many_thing_3', 'new_many_thing_1']
256
- model.many_things.detect{|t| t.name == 'new_many_thing_1'}.sub_things.collect{|t| t.name}.sort.should == ['new_sub_thing_1', 'sub_thing_3']
257
- model.many_other_things.collect{|t| t.name}.sort.should == ['many_other_thing_3', 'new_many_other_thing_1']
258
-
259
- model.restore_revision!(1)
260
- RevisionableTestModel.count.should == 1
261
- RevisionableTestManyThing.count.should == 2
262
- RevisionableTestSubThing.count.should == 3
263
- RevisionableTestManyOtherThing.count.should == 2
264
- ActsAsRevisionable::RevisionRecord.count.should == 2
265
- restored_model = RevisionableTestModel.find(model.id)
266
- restored_model.name.should == 'test'
267
- restored.many_things.collect{|t| t.name}.sort.should == ['many_thing_1', 'many_thing_2']
268
- restored.many_things.detect{|t| t.name == 'many_thing_1'}.sub_things.collect{|t| t.name}.sort.should == ['sub_thing_1', 'sub_thing_2']
269
- restored.many_things.detect{|t| t.name == 'many_thing_2'}.sub_things.collect{|t| t.name}.sort.should == []
270
- restored.many_other_things.collect{|t| t.name}.sort.should == ['many_other_thing_3', 'new_many_other_thing_1']
271
- end
272
-
273
- it "should restore a record with has_one associations" do
274
- model = RevisionableTestModel.new(:name => 'test')
275
- model.build_one_thing(:name => 'other')
276
- model.store_revision do
277
- model.save!
278
- end
279
- model.reload
280
- ActsAsRevisionable::RevisionRecord.count.should == 0
281
- RevisionableTestOneThing.count.should == 1
282
-
283
- model.name = 'new_name'
284
- model.one_thing.name = 'new_other'
285
- model.store_revision do
286
- model.one_thing.save!
287
- model.save!
288
- end
289
-
290
- model.reload
291
- ActsAsRevisionable::RevisionRecord.count.should == 1
292
- model.name.should == 'new_name'
293
- model.one_thing.name.should == 'new_other'
294
-
295
- # restore to memory
296
- restored = model.restore_revision(1)
297
- restored.name.should == 'test'
298
- restored.one_thing.name.should == 'other'
299
- restored.one_thing.id.should == model.one_thing.id
300
-
301
- # make sure restore to memory didn't affect the database
302
- model.reload
303
- ActsAsRevisionable::RevisionRecord.count.should == 1
304
- model.name.should == 'new_name'
305
- model.one_thing.name.should == 'new_other'
306
-
307
- model.restore_revision!(1)
308
- RevisionableTestModel.count.should == 1
309
- RevisionableTestOneThing.count.should == 1
310
- ActsAsRevisionable::RevisionRecord.count.should == 2
311
- restored_model = RevisionableTestModel.find(model.id)
312
- restored_model.name.should == 'test'
313
- restored_model.one_thing.name.should == 'other'
314
- restored_model.one_thing.id.should == model.one_thing.id
315
- end
316
-
317
- it "should restore a record with has_and_belongs_to_many associations" do
318
- other_1 = NonRevisionableTestModel.create(:name => 'one')
319
- other_2 = NonRevisionableTestModel.create(:name => 'two')
320
- model = RevisionableTestModel.new(:name => 'test')
321
- model.non_revisionable_test_models = [other_1, other_2]
322
- model.store_revision do
323
- model.save!
324
- end
325
- model.reload
326
- ActsAsRevisionable::RevisionRecord.count.should == 0
327
- NonRevisionableTestModel.count.should == 2
328
-
329
- model.name = 'new_name'
330
- other_1.name = '111'
331
- other_3 = NonRevisionableTestModel.create(:name => '333')
332
- model.store_revision do
333
- model.non_revisionable_test_models = [other_1, other_3]
334
- other_1.save!
335
- model.save!
336
- end
337
-
338
- model.reload
339
- ActsAsRevisionable::RevisionRecord.count.should == 1
340
- NonRevisionableTestModel.count.should == 3
341
- model.name.should == 'new_name'
342
- model.non_revisionable_test_models.collect{|r| r.name}.sort.should == ['111', '333']
343
-
344
- # restore to memory
345
- restored = model.restore_revision(1)
346
- restored.name.should == 'test'
347
- restored.non_revisionable_test_models.collect{|r| r.name}.sort.should == ['111', 'two']
348
-
349
- # make sure the restore to memory didn't affect the database
350
- model.reload
351
- model.name.should == 'new_name'
352
- model.non_revisionable_test_models.collect{|r| r.name}.sort.should == ['111', '333']
353
-
354
- model.restore_revision!(1)
355
- NonRevisionableTestModelsRevisionableTestModel.count.should == 2
356
- RevisionableTestModel.count.should == 1
357
- NonRevisionableTestModel.count.should == 3
358
- ActsAsRevisionable::RevisionRecord.count.should == 2
359
- restored_model = RevisionableTestModel.find(model.id)
360
- restored_model.name.should == 'test'
361
- restored_model.non_revisionable_test_models.collect{|r| r.name}.sort.should == ['111', 'two']
362
- end
363
-
364
- it "should handle namespaces and single table inheritance" do
365
- model = ActsAsRevisionable::RevisionableNamespaceModel.new(:name => 'test')
366
- model.store_revision do
367
- model.save!
368
- end
369
- model.reload
370
- ActsAsRevisionable::RevisionRecord.count.should == 0
371
-
372
- model.name = 'new_name'
373
- model.store_revision do
374
- model.save!
375
- end
376
- model.reload
377
- ActsAsRevisionable::RevisionRecord.count.should == 1
378
- model.name.should == 'new_name'
379
-
380
- restored = model.restore_revision(1)
381
- restored.class.should == ActsAsRevisionable::RevisionableNamespaceModel
382
- restored.name.should == 'test'
383
- restored.id.should == model.id
384
- end
385
-
386
- it "should handle single table inheritance" do
387
- model = ActsAsRevisionable::RevisionableSubclassModel.new(:name => 'test')
388
- model.store_revision do
389
- model.save!
390
- end
391
- model.reload
392
- ActsAsRevisionable::RevisionRecord.count.should == 0
393
-
394
- model.name = 'new_name'
395
- model.store_revision do
396
- model.save!
397
- end
398
- model.reload
399
- ActsAsRevisionable::RevisionRecord.count.should == 1
400
- model.name.should == 'new_name'
401
-
402
- restored = model.restore_revision(1)
403
- restored.class.should == ActsAsRevisionable::RevisionableSubclassModel
404
- restored.name.should == 'test'
405
- restored.id.should == model.id
406
- restored.type_name.should == 'RevisionableSubclassModel'
407
- end
408
-
409
- it "should destroy revisions if :dependent => :keep was not specified" do
410
- model = RevisionableTestModel.new(:name => 'test')
411
- model.store_revision do
412
- model.save!
413
- end
414
- model.reload
415
- ActsAsRevisionable::RevisionRecord.count.should == 0
416
-
417
- model.name = 'new_name'
418
- model.store_revision do
419
- model.save!
420
- end
421
- model.reload
422
- ActsAsRevisionable::RevisionRecord.count.should == 1
423
- model.name.should == 'new_name'
424
-
425
- model.destroy
426
- ActsAsRevisionable::RevisionRecord.count.should == 0
427
- end
428
-
429
- it "should not destroy revisions if :dependent => :keep was specified" do
430
- model = ActsAsRevisionable::RevisionableSubclassModel.new(:name => 'test')
431
- model.store_revision do
432
- model.save!
433
- end
434
- model.reload
435
- ActsAsRevisionable::RevisionRecord.count.should == 0
436
-
437
- model.name = 'new_name'
438
- model.store_revision do
439
- model.save!
440
- end
441
- model.reload
442
- ActsAsRevisionable::RevisionRecord.count.should == 1
443
- model.name.should == 'new_name'
444
-
445
- model.destroy
446
- ActsAsRevisionable::RevisionRecord.count.should == 1
447
- end
448
-
449
- end