acts_as_revisionable 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,6 +53,8 @@ Note that the table definition changed from version 1.0.x to 1.1.x. If you origi
53
53
 
54
54
  ActsAsRevisionable::RevisionRecord.update_version_1_table
55
55
 
56
+ As of version 1.2, you can customize the RevisionRecord model by adding your own columns or even create a subclass of RevisionRecord that uses its own table. See the documentation in ActsAsRevisionable for more details.
57
+
56
58
  == Destroying
57
59
 
58
60
  By default, the revision history of a record is destroyed along with the record. If you'd like to keep the history and be able to restore deleted records, then you can specify <tt>:dependent => :keep, :on_destroy => true</tt> in options of the +acts_as_revisionable+ call. This will keep the revision records and also automatically wrap all destroy calls in a +store_revision+ block. It is highly recommended that you turn on these options.
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'rdoc/task'
4
3
 
5
4
  desc 'Default: run unit tests.'
6
5
  task :default => :test
@@ -16,14 +15,6 @@ rescue LoadError
16
15
  end
17
16
  end
18
17
 
19
- desc 'Generate documentation for the gem.'
20
- Rake::RDocTask.new(:rdoc) do |rdoc|
21
- rdoc.rdoc_dir = 'rdoc'
22
- rdoc.options << '--title' << 'Acts As Revisionable' << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
23
- rdoc.rdoc_files.include('README.rdoc')
24
- rdoc.rdoc_files.include('lib/**/*.rb')
25
- end
26
-
27
18
  begin
28
19
  require 'jeweler'
29
20
  Jeweler::Tasks.new do |gem|
@@ -29,19 +29,37 @@ module ActsAsRevisionable
29
29
  # <tt>empty_trash</tt> method. You can set <tt>:on_destroy => true</tt> to automatically create the trash revision
30
30
  # whenever a record is destroyed. It is recommended that you turn both of these features on.
31
31
  #
32
- # Revision records have an optional +label+ field which can be used for display purposes to distinguish revisions
33
- # in a view. This value will only be set if you provide a Proc for the <tt>:label</tt> option to the +acts_as_revisionable+
34
- # call. The proc will be yielded to with the record before it is revisioned.
32
+ # Revision records can be extended to include other fields as needed and set with the <tt>:meta</tt> option.
33
+ # In order to extend a revision record, you must add columns to the database table. The values of the <tt>:meta</tt>
34
+ # option hash will be provided to the newly created revision record.
35
35
  #
36
- # acts_as_revisionable :label => lambda{|record| "Updated by #{record.updated_by} at #{record.updated_at}"}
36
+ # acts_as_revisionable :meta => {
37
+ # :updated_by => :last_updated_by,
38
+ # :label => lambda{|record| "Updated by #{record.updated_by} at #{record.updated_at}"},
39
+ # :version => 1
40
+ # }
41
+ #
42
+ # The values to the <tt>:meta</tt> hash can be either symbols or Procs. If it is a symbol, the method
43
+ # so named will be called on the record being revisioned. If it is a Proc, it will be called with the
44
+ # record as the argument. Any other class will be sent directly to the revision record.
45
+ #
46
+ # You can also use a subclass of RevisionRecord if desired so that you can add your own model logic as
47
+ # necessary. To specify a different class to use for revision records, simply subclass RevisionRecord and
48
+ # provide the class name to the <tt>:class_name</tt> option.
49
+ #
50
+ # acts_as_revisionable :class_name => "MyRevisionRecord"
37
51
  #
38
52
  # A has_many :revision_records will also be added to the model for accessing the revisions.
39
53
  def acts_as_revisionable(options = {})
40
54
  class_attribute :acts_as_revisionable_options, :instance_writer => false, :instance_reader => false
41
- self.acts_as_revisionable_options = options.clone
42
- extend ClassMethods
55
+ defaults = {:class_name => "ActsAsRevisionable::RevisionRecord"}
56
+ self.acts_as_revisionable_options = defaults.merge(options)
57
+ acts_as_revisionable_options[:class_name] = acts_as_revisionable_options[:class_name].name if acts_as_revisionable_options[:class_name].is_a?(Class)
58
+ extend ClassMethods
43
59
  include InstanceMethods
44
- has_many_options = {:as => :revisionable, :order => 'revision DESC', :class_name => "ActsAsRevisionable::RevisionRecord"}
60
+ class_name =
61
+ class_name = acts_as_revisionable_options[:class_name].to_s if acts_as_revisionable_options[:class_name]
62
+ has_many_options = {:as => :revisionable, :order => 'revision DESC', :class_name => class_name}
45
63
  has_many_options[:dependent] = :destroy unless options[:dependent] == :keep
46
64
  has_many :revision_records, has_many_options
47
65
  alias_method_chain :update, :revision if options[:on_update]
@@ -52,12 +70,12 @@ module ActsAsRevisionable
52
70
  module ClassMethods
53
71
  # Get a revision for a specified id.
54
72
  def revision(id, revision_number)
55
- RevisionRecord.find_revision(self, id, revision_number)
73
+ revision_record_class.find_revision(self, id, revision_number)
56
74
  end
57
75
 
58
76
  # Get the last revision for a specified id.
59
77
  def last_revision(id)
60
- RevisionRecord.last_revision(self, id)
78
+ revision_record_class.last_revision(self, id)
61
79
  end
62
80
 
63
81
  # Load a revision for a record with a particular id. Associations added since the revision
@@ -119,7 +137,11 @@ module ActsAsRevisionable
119
137
 
120
138
  # Delete all revision records for deleted items that are older than the specified maximum age in seconds.
121
139
  def empty_trash(max_age)
122
- RevisionRecord.empty_trash(self, max_age)
140
+ revision_record_class.empty_trash(self, max_age)
141
+ end
142
+
143
+ def revision_record_class
144
+ acts_as_revisionable_options[:class_name].constantize
123
145
  end
124
146
 
125
147
  private
@@ -187,7 +209,7 @@ module ActsAsRevisionable
187
209
  retval = nil
188
210
  revision = nil
189
211
  begin
190
- RevisionRecord.transaction do
212
+ revision_record_class.transaction do
191
213
  begin
192
214
  read_only = self.class.first(:conditions => {self.class.primary_key => self.id}, :readonly => true)
193
215
  if read_only
@@ -225,9 +247,17 @@ module ActsAsRevisionable
225
247
 
226
248
  # Create a revision record based on this record and save it to the database.
227
249
  def create_revision!
228
- revision = RevisionRecord.new(self, acts_as_revisionable_options[:encoding])
229
- if self.acts_as_revisionable_options[:label].is_a?(Proc)
230
- revision.label = self.acts_as_revisionable_options[:label].call(self)
250
+ revision = revision_record_class.new(self, acts_as_revisionable_options[:encoding])
251
+ if self.acts_as_revisionable_options[:meta].is_a?(Hash)
252
+ self.acts_as_revisionable_options[:meta].each do |attribute, value|
253
+ case value
254
+ when Symbol
255
+ value = self.send(value)
256
+ when Proc
257
+ value = value.call(self)
258
+ end
259
+ revision.send("#{attribute}=", value)
260
+ end
231
261
  end
232
262
  revision.save!
233
263
  return revision
@@ -236,7 +266,7 @@ module ActsAsRevisionable
236
266
  # Truncate the number of revisions kept for this record. Available options are :limit and :minimum_age.
237
267
  def truncate_revisions!(options = nil)
238
268
  options = {:limit => acts_as_revisionable_options[:limit], :minimum_age => acts_as_revisionable_options[:minimum_age]} unless options
239
- RevisionRecord.truncate_revisions(self.class, self.id, options)
269
+ revision_record_class.truncate_revisions(self.class, self.id, options)
240
270
  end
241
271
 
242
272
  # Disable the revisioning behavior inside of a block passed to the method.
@@ -259,6 +289,10 @@ module ActsAsRevisionable
259
289
  end
260
290
  end
261
291
 
292
+ def revision_record_class
293
+ self.class.revision_record_class
294
+ end
295
+
262
296
  private
263
297
 
264
298
  # Update the record while recording the revision.
@@ -46,18 +46,17 @@ module ActsAsRevisionable
46
46
 
47
47
  # Create the table to store revision records.
48
48
  def create_table
49
- connection.create_table :revision_records do |t|
49
+ connection.create_table table_name do |t|
50
50
  t.string :revisionable_type, :null => false, :limit => 100
51
51
  t.integer :revisionable_id, :null => false
52
52
  t.integer :revision, :null => false
53
53
  t.binary :data, :limit => (connection.adapter_name.match(/mysql/i) ? 5.megabytes : nil)
54
54
  t.timestamp :created_at, :null => false
55
55
  t.boolean :trash, :default => false
56
- t.string :label, :limit => 255, :null => true
57
56
  end
58
57
 
59
- connection.add_index :revision_records, :revisionable_id, :name => "revision_record_id"
60
- connection.add_index :revision_records, [:revisionable_type, :created_at, :trash], :name => "revisionable_type_and_created_at"
58
+ connection.add_index table_name, :revisionable_id, :name => "#{table_name}_id"
59
+ connection.add_index table_name, [:revisionable_type, :created_at, :trash], :name => "#{table_name}_type_and_created_at"
61
60
  end
62
61
 
63
62
  # Update a version 1.0.x table to the latest version. This method only needs to be called
@@ -65,9 +64,8 @@ module ActsAsRevisionable
65
64
  def update_version_1_table
66
65
  # Added in version 1.1.0
67
66
  connection.add_column(:revision_records, :trash, :boolean, :default => false)
68
- connection.add_column(:revision_records, :label, :string, :limit => 255, :null => true)
69
- connection.add_index :revision_records, :revisionable_id, :name => "revision_record_id"
70
- connection.add_index :revision_records, [:revisionable_type, :created_at, :trash], :name => "revisionable_type_and_created_at"
67
+ connection.add_index :revision_records, :revisionable_id, :name => "#{table_name}_id"
68
+ connection.add_index :revision_records, [:revisionable_type, :created_at, :trash], :name => "#{table_name}_type_and_created_at"
71
69
 
72
70
  # Removed in 1.1.0
73
71
  connection.remove_index(:revision_records, :name => "revisionable")
@@ -88,13 +88,22 @@ describe ActsAsRevisionable do
88
88
  end
89
89
  end
90
90
 
91
+ class RevisionRecord2 < ActsAsRevisionable::RevisionRecord
92
+ set_table_name "revision_records_2"
93
+ create_table
94
+ connection.add_column(table_name, :label, :string)
95
+ connection.add_column(table_name, :updated_by, :string)
96
+ connection.add_column(table_name, :version, :integer)
97
+ end
98
+
91
99
  class OtherRevisionableTestModel < ActiveRecord::Base
92
100
  connection.create_table(table_name) do |t|
93
- t.column :name, :string
94
- t.column :secret, :integer
101
+ t.string :name
102
+ t.integer :secret
103
+ t.string :updated_by
95
104
  end unless table_exists?
96
105
 
97
- acts_as_revisionable :on_update => true, :label => lambda{|record| "name was '#{record.name}'"}
106
+ acts_as_revisionable :on_update => true, :meta => {:label => lambda{|record| "name was '#{record.name}'"}, :updated_by => :updated_by, :version => 1}, :class_name => RevisionRecord2
98
107
  end
99
108
 
100
109
  module ActsAsRevisionable
@@ -129,6 +138,7 @@ describe ActsAsRevisionable do
129
138
  ActsAsRevisionable::RevisionRecord.delete_all
130
139
  ActsAsRevisionable::RevisionableNamespaceModel.delete_all
131
140
  OtherRevisionableTestModel.delete_all
141
+ RevisionRecord2.delete_all
132
142
  end
133
143
 
134
144
  context "injected methods" do
@@ -146,13 +156,13 @@ describe ActsAsRevisionable do
146
156
  end
147
157
 
148
158
  context "accessing revisions" do
149
- let(:record_1){ RevisionableTestModel.create(:name => "record 1") }
150
- let(:record_2){ OtherRevisionableTestModel.create(:name => "record 2") }
159
+ let(:record_1){ RevisionableTestModel.create!(:name => "record 1") }
160
+ let(:record_2){ OtherRevisionableTestModel.create!(:name => "record 2") }
151
161
 
152
162
  it "should be able to get a revision for a model" do
153
- revision_1 = ActsAsRevisionable::RevisionRecord.create(record_1)
154
- revision_2 = ActsAsRevisionable::RevisionRecord.create(record_1)
155
- revision_3 = ActsAsRevisionable::RevisionRecord.create(record_2)
163
+ revision_1 = ActsAsRevisionable::RevisionRecord.create!(record_1)
164
+ revision_2 = ActsAsRevisionable::RevisionRecord.create!(record_1)
165
+ revision_3 = RevisionRecord2.create!(record_2)
156
166
  record_1.revision(1).should == revision_1
157
167
  record_1.revision(2).should == revision_2
158
168
  record_1.revision(3).should == nil
@@ -160,9 +170,9 @@ describe ActsAsRevisionable do
160
170
  end
161
171
 
162
172
  it "should be able to get a revision for an id" do
163
- revision_1 = ActsAsRevisionable::RevisionRecord.create(record_1)
164
- revision_2 = ActsAsRevisionable::RevisionRecord.create(record_1)
165
- revision_3 = ActsAsRevisionable::RevisionRecord.create(record_2)
173
+ revision_1 = ActsAsRevisionable::RevisionRecord.create!(record_1)
174
+ revision_2 = ActsAsRevisionable::RevisionRecord.create!(record_1)
175
+ revision_3 = RevisionRecord2.create!(record_2)
166
176
  RevisionableTestModel.revision(record_1.id, 1).should == revision_1
167
177
  RevisionableTestModel.revision(record_1.id, 2).should == revision_2
168
178
  RevisionableTestModel.revision(record_1.id, 3).should == nil
@@ -170,17 +180,17 @@ describe ActsAsRevisionable do
170
180
  end
171
181
 
172
182
  it "should be able to get the last revision for a model" do
173
- revision_1 = ActsAsRevisionable::RevisionRecord.create(record_1)
174
- revision_2 = ActsAsRevisionable::RevisionRecord.create(record_1)
175
- revision_3 = ActsAsRevisionable::RevisionRecord.create(record_2)
183
+ revision_1 = ActsAsRevisionable::RevisionRecord.create!(record_1)
184
+ revision_2 = ActsAsRevisionable::RevisionRecord.create!(record_1)
185
+ revision_3 = RevisionRecord2.create!(record_2)
176
186
  record_1.last_revision.should == revision_2
177
187
  record_2.last_revision.should == revision_3
178
188
  end
179
189
 
180
190
  it "should be able to get the last revision for an id" do
181
- revision_1 = ActsAsRevisionable::RevisionRecord.create(record_1)
182
- revision_2 = ActsAsRevisionable::RevisionRecord.create(record_1)
183
- revision_3 = ActsAsRevisionable::RevisionRecord.create(record_2)
191
+ revision_1 = ActsAsRevisionable::RevisionRecord.create!(record_1)
192
+ revision_2 = ActsAsRevisionable::RevisionRecord.create!(record_1)
193
+ revision_3 = RevisionRecord2.create!(record_2)
184
194
  RevisionableTestModel.last_revision(record_1.id).should == revision_2
185
195
  OtherRevisionableTestModel.last_revision(record_2.id).should == revision_3
186
196
  end
@@ -196,7 +206,7 @@ describe ActsAsRevisionable do
196
206
  end
197
207
 
198
208
  it "should only store revisions when a record is updated in a store_revision block" do
199
- record = RevisionableTestModel.create(:name => "test")
209
+ record = RevisionableTestModel.create!(:name => "test")
200
210
  record.name = "new name"
201
211
  record.save!
202
212
  ActsAsRevisionable::RevisionRecord.count.should == 0
@@ -208,24 +218,24 @@ describe ActsAsRevisionable do
208
218
  end
209
219
 
210
220
  it "should always store revisions whenever a record is saved if :on_update is true" do
211
- record = OtherRevisionableTestModel.create(:name => "test")
221
+ record = OtherRevisionableTestModel.create!(:name => "test")
212
222
  record.name = "new name"
213
223
  record.save!
214
- ActsAsRevisionable::RevisionRecord.count.should == 1
224
+ RevisionRecord2.count.should == 1
215
225
  record.store_revision do
216
226
  record.name = "newer name"
217
227
  record.save!
218
228
  end
219
- ActsAsRevisionable::RevisionRecord.count.should == 2
229
+ RevisionRecord2.count.should == 2
220
230
  end
221
231
 
222
232
  it "should only store revisions when a record is destroyed in a store_revision block" do
223
- record_1 = RevisionableTestModel.create(:name => "test")
233
+ record_1 = RevisionableTestModel.create!(:name => "test")
224
234
  record_1.store_revision do
225
235
  record_1.name = "newer name"
226
236
  record_1.save!
227
237
  end
228
- record_2 = RevisionableTestModel.create(:name => "test")
238
+ record_2 = RevisionableTestModel.create!(:name => "test")
229
239
  record_2.store_revision do
230
240
  record_2.name = "newer name"
231
241
  record_2.save!
@@ -240,12 +250,12 @@ describe ActsAsRevisionable do
240
250
  end
241
251
 
242
252
  it "should always store revisions whenever a record is destroyed if :on_destroy is true" do
243
- record_1 = ActsAsRevisionable::RevisionableNamespaceModel.create(:name => "test")
253
+ record_1 = ActsAsRevisionable::RevisionableNamespaceModel.create!(:name => "test")
244
254
  record_1.store_revision do
245
255
  record_1.name = "newer name"
246
256
  record_1.save!
247
257
  end
248
- record_2 = ActsAsRevisionable::RevisionableNamespaceModel.create(:name => "test")
258
+ record_2 = ActsAsRevisionable::RevisionableNamespaceModel.create!(:name => "test")
249
259
  record_2.store_revision do
250
260
  record_2.name = "newer name"
251
261
  record_2.save!
@@ -260,22 +270,25 @@ describe ActsAsRevisionable do
260
270
  end
261
271
 
262
272
  it "should be able to create a revision record" do
263
- record_1 = RevisionableTestModel.create(:name => "test")
273
+ record_1 = RevisionableTestModel.create!(:name => "test")
264
274
  ActsAsRevisionable::RevisionRecord.count.should == 0
265
275
  record_1.create_revision!
266
276
  ActsAsRevisionable::RevisionRecord.count.should == 1
267
277
  end
268
278
 
269
- it "should yield to the label proc when creating a revision record" do
270
- record_1 = OtherRevisionableTestModel.create(:name => "test")
271
- ActsAsRevisionable::RevisionRecord.count.should == 0
279
+ it "should set metadata on the revison when creating a revision record" do
280
+ record_1 = OtherRevisionableTestModel.create!(:name => "test", :updated_by => "dude")
281
+ RevisionRecord2.count.should == 0
272
282
  record_1.create_revision!
273
- ActsAsRevisionable::RevisionRecord.count.should == 1
274
- record_1.last_revision.label.should == "name was 'test'"
283
+ RevisionRecord2.count.should == 1
284
+ revision = record_1.last_revision
285
+ revision.label.should == "name was 'test'"
286
+ revision.updated_by.should == "dude"
287
+ revision.version.should == 1
275
288
  end
276
289
 
277
290
  it "should not create a revision entry if revisioning is disabled" do
278
- record = RevisionableTestModel.create(:name => "test")
291
+ record = RevisionableTestModel.create!(:name => "test")
279
292
  ActsAsRevisionable::RevisionRecord.count.should == 0
280
293
  record.store_revision do
281
294
  record.name = "new name"
@@ -292,7 +305,7 @@ describe ActsAsRevisionable do
292
305
  end
293
306
 
294
307
  it "should truncate the revisions when new ones are created" do
295
- record = RevisionableTestModel.create(:name => "test")
308
+ record = RevisionableTestModel.create!(:name => "test")
296
309
  5.times do |i|
297
310
  record.store_revision do
298
311
  record.update_attribute(:name, "name #{i}")
@@ -512,8 +525,8 @@ describe ActsAsRevisionable do
512
525
  end
513
526
 
514
527
  it "should restore a record with has_and_belongs_to_many associations" do
515
- other_1 = NonRevisionableTestModel.create(:name => 'one')
516
- other_2 = NonRevisionableTestModel.create(:name => 'two')
528
+ other_1 = NonRevisionableTestModel.create!(:name => 'one')
529
+ other_2 = NonRevisionableTestModel.create!(:name => 'two')
517
530
  model = RevisionableTestModel.new(:name => 'test')
518
531
  model.non_revisionable_test_models = [other_1, other_2]
519
532
  model.store_revision do
@@ -525,7 +538,7 @@ describe ActsAsRevisionable do
525
538
 
526
539
  model.name = 'new_name'
527
540
  other_1.name = '111'
528
- other_3 = NonRevisionableTestModel.create(:name => '333')
541
+ other_3 = NonRevisionableTestModel.create!(:name => '333')
529
542
  model.store_revision do
530
543
  model.non_revisionable_test_models = [other_1, other_3]
531
544
  other_1.save!
@@ -667,7 +680,7 @@ describe ActsAsRevisionable do
667
680
 
668
681
  context "cleaning up revisions" do
669
682
  it "should destroy revisions if :dependent => :keep was not specified" do
670
- model = OtherRevisionableTestModel.create(:name => 'test')
683
+ model = OtherRevisionableTestModel.create!(:name => 'test')
671
684
  ActsAsRevisionable::RevisionRecord.count.should == 0
672
685
 
673
686
  model.name = 'new_name'
@@ -675,11 +688,11 @@ describe ActsAsRevisionable do
675
688
  model.save!
676
689
  end
677
690
  model.reload
678
- ActsAsRevisionable::RevisionRecord.count.should == 1
691
+ RevisionRecord2.count.should == 1
679
692
  model.name.should == 'new_name'
680
693
 
681
694
  model.destroy
682
- ActsAsRevisionable::RevisionRecord.count.should == 0
695
+ RevisionRecord2.count.should == 0
683
696
  end
684
697
 
685
698
  it "should not destroy revisions if :dependent => :keep was specified" do
@@ -704,7 +717,7 @@ describe ActsAsRevisionable do
704
717
  end
705
718
 
706
719
  it "should empty the trash by deleting all revisions for records that have been deleted for a specified period" do
707
- record_1 = ActsAsRevisionable::RevisionableNamespaceModel.create(:name => 'test')
720
+ record_1 = ActsAsRevisionable::RevisionableNamespaceModel.create!(:name => 'test')
708
721
  record_1.store_revision do
709
722
  record_1.update_attribute(:name, "new")
710
723
  end
@@ -714,7 +727,7 @@ describe ActsAsRevisionable do
714
727
  record_1.store_revision do
715
728
  record_1.destroy
716
729
  end
717
- record_2 = ActsAsRevisionable::RevisionableNamespaceModel.create(:name => 'test 2')
730
+ record_2 = ActsAsRevisionable::RevisionableNamespaceModel.create!(:name => 'test 2')
718
731
  record_2.store_revision do
719
732
  record_2.update_attribute(:name, "new 2")
720
733
  end
@@ -118,7 +118,7 @@ describe ActsAsRevisionable::RevisionRecord do
118
118
  end
119
119
 
120
120
  it "should set the revision number before it creates the record" do
121
- record = TestRevisionableRecord.create(:name => "test")
121
+ record = TestRevisionableRecord.create!(:name => "test")
122
122
  revision1 = ActsAsRevisionable::RevisionRecord.new(record)
123
123
  revision1.save!
124
124
  revision2 = ActsAsRevisionable::RevisionRecord.new(record)
@@ -178,9 +178,9 @@ describe ActsAsRevisionable::RevisionRecord do
178
178
 
179
179
  it "should serialize all revisionable has_many_and_belongs_to_many associations" do
180
180
  original = TestRevisionableRecord.new(:name => 'revision', :value => 1)
181
- other_1 = OtherRevisionableRecord.create(:name => "other 1")
182
- other_2 = OtherRevisionableRecord.create(:name => "other 2")
183
- other_3 = OtherRevisionableRecord.create(:name => "other 3")
181
+ other_1 = OtherRevisionableRecord.create!(:name => "other 1")
182
+ other_2 = OtherRevisionableRecord.create!(:name => "other 2")
183
+ other_3 = OtherRevisionableRecord.create!(:name => "other 3")
184
184
  original.other_revisionable_records << other_1
185
185
  original.other_revisionable_records << other_2
186
186
  original.other_revisionable_records << other_3
@@ -311,9 +311,9 @@ describe ActsAsRevisionable::RevisionRecord do
311
311
  end
312
312
 
313
313
  it "should be able to restore the has_and_belongs_to_many associations" do
314
- other_1 = OtherRevisionableRecord.create(:name => "other 1")
315
- other_2 = OtherRevisionableRecord.create(:name => "other 2")
316
- other_3 = OtherRevisionableRecord.create(:name => "other 3")
314
+ other_1 = OtherRevisionableRecord.create!(:name => "other 1")
315
+ other_2 = OtherRevisionableRecord.create!(:name => "other 2")
316
+ other_3 = OtherRevisionableRecord.create!(:name => "other 3")
317
317
  revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new)
318
318
  record = TestRevisionableRecord.new
319
319
  revision.send(:restore_association, record, :other_revisionable_records, [other_1.id, other_2.id, other_3.id])
@@ -418,7 +418,7 @@ describe ActsAsRevisionable::RevisionRecord do
418
418
  it "should really save the revision records to the database and restore without any mocking" do
419
419
  ActsAsRevisionable::RevisionRecord.count.should == 0
420
420
 
421
- original = TestRevisionableRecord.create(:name => 'revision 1', :value => 100)
421
+ original = TestRevisionableRecord.create!(:name => 'revision 1', :value => 100)
422
422
  ActsAsRevisionable::RevisionRecord.new(original).save!
423
423
  first_revision = ActsAsRevisionable::RevisionRecord.first
424
424
  original.name = 'revision 2'
@@ -443,19 +443,19 @@ describe ActsAsRevisionable::RevisionRecord do
443
443
  end
444
444
 
445
445
  it "should delete revisions for models in a class that no longer exist if they are older than a specified number of seconds" do
446
- record_1 = TestRevisionableRecord.create(:name => 'record_1')
446
+ record_1 = TestRevisionableRecord.create!(:name => 'record_1')
447
447
  record_2 = TestRevisionableAssociationLegacyRecord.create!(:name => 'record_2')
448
448
  record_2.id = record_1.id
449
449
  record_2.save!
450
- revision_0 = ActsAsRevisionable::RevisionRecord.create(record_1)
451
- revision_1 = ActsAsRevisionable::RevisionRecord.create(record_1)
450
+ revision_0 = ActsAsRevisionable::RevisionRecord.create!(record_1)
451
+ revision_1 = ActsAsRevisionable::RevisionRecord.create!(record_1)
452
452
  revision_1.trash!
453
- revision_2 = ActsAsRevisionable::RevisionRecord.create(record_2)
453
+ revision_2 = ActsAsRevisionable::RevisionRecord.create!(record_2)
454
454
  revision_2.trash!
455
- revision_3 = ActsAsRevisionable::RevisionRecord.create(TestRevisionableRecord.create(:name => 'record_3'))
455
+ revision_3 = ActsAsRevisionable::RevisionRecord.create!(TestRevisionableRecord.create!(:name => 'record_3'))
456
456
  now = Time.now
457
457
  Time.stub(:now => now + 60)
458
- revision_4 = ActsAsRevisionable::RevisionRecord.create(TestRevisionableRecord.create(:name => 'record_4'))
458
+ revision_4 = ActsAsRevisionable::RevisionRecord.create!(TestRevisionableRecord.create!(:name => 'record_4'))
459
459
  revision_4.trash!
460
460
  ActsAsRevisionable::RevisionRecord.count.should == 5
461
461
  ActsAsRevisionable::RevisionRecord.empty_trash(TestRevisionableRecord, 30)
@@ -3,6 +3,7 @@ require 'logger'
3
3
  require 'stringio'
4
4
 
5
5
  if ENV["ACTIVE_RECORD_VERSION"]
6
+ gem 'activesupport', ENV["ACTIVE_RECORD_VERSION"]
6
7
  gem 'activerecord', ENV["ACTIVE_RECORD_VERSION"]
7
8
  else
8
9
  gem 'activerecord'
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: 23
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
9
8
  - 2
10
- version: 1.1.2
9
+ - 0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Durand
@@ -15,16 +15,45 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-12 00:00:00 -05:00
18
+ date: 2011-08-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: activerecord
22
+ name: rake
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
23
32
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
33
+ type: :runtime
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
25
38
  none: false
26
39
  requirements:
27
40
  - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 2
45
+ - 6
46
+ - 0
47
+ version: 2.6.0
48
+ prerelease: false
49
+ type: :runtime
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: activerecord
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
28
57
  - !ruby/object:Gem::Version
29
58
  hash: 17
30
59
  segments:
@@ -32,12 +61,74 @@ dependencies:
32
61
  - 3
33
62
  - 9
34
63
  version: 2.3.9
64
+ prerelease: false
35
65
  type: :runtime
36
- version_requirements: *id001
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: activesupport
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 17
75
+ segments:
76
+ - 2
77
+ - 3
78
+ - 9
79
+ version: 2.3.9
80
+ prerelease: false
81
+ type: :runtime
82
+ requirement: *id004
37
83
  - !ruby/object:Gem::Dependency
38
84
  name: composite_primary_keys
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ prerelease: false
95
+ type: :runtime
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ hash: 19
105
+ segments:
106
+ - 1
107
+ - 3
108
+ - 4
109
+ version: 1.3.4
110
+ prerelease: false
111
+ type: :runtime
112
+ requirement: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ name: activerecord
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 17
121
+ segments:
122
+ - 2
123
+ - 3
124
+ - 9
125
+ version: 2.3.9
39
126
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
127
+ type: :runtime
128
+ requirement: *id007
129
+ - !ruby/object:Gem::Dependency
130
+ name: composite_primary_keys
131
+ version_requirements: &id008 !ruby/object:Gem::Requirement
41
132
  none: false
42
133
  requirements:
43
134
  - - ">="
@@ -46,12 +137,12 @@ dependencies:
46
137
  segments:
47
138
  - 0
48
139
  version: "0"
140
+ prerelease: false
49
141
  type: :development
50
- version_requirements: *id002
142
+ requirement: *id008
51
143
  - !ruby/object:Gem::Dependency
52
144
  name: sqlite3
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
145
+ version_requirements: &id009 !ruby/object:Gem::Requirement
55
146
  none: false
56
147
  requirements:
57
148
  - - ">="
@@ -60,12 +151,12 @@ dependencies:
60
151
  segments:
61
152
  - 0
62
153
  version: "0"
154
+ prerelease: false
63
155
  type: :development
64
- version_requirements: *id003
156
+ requirement: *id009
65
157
  - !ruby/object:Gem::Dependency
66
158
  name: rspec
67
- prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
159
+ version_requirements: &id010 !ruby/object:Gem::Requirement
69
160
  none: false
70
161
  requirements:
71
162
  - - ">="
@@ -76,12 +167,12 @@ dependencies:
76
167
  - 0
77
168
  - 0
78
169
  version: 2.0.0
170
+ prerelease: false
79
171
  type: :development
80
- version_requirements: *id004
172
+ requirement: *id010
81
173
  - !ruby/object:Gem::Dependency
82
174
  name: jeweler
83
- prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
175
+ version_requirements: &id011 !ruby/object:Gem::Requirement
85
176
  none: false
86
177
  requirements:
87
178
  - - ">="
@@ -90,8 +181,9 @@ dependencies:
90
181
  segments:
91
182
  - 0
92
183
  version: "0"
184
+ prerelease: false
93
185
  type: :development
94
- version_requirements: *id005
186
+ requirement: *id011
95
187
  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.
96
188
  email: brian@embellishedvisions.com
97
189
  executables: []