acts_as_revisionable 1.1.1 → 1.1.2

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.
@@ -29,9 +29,15 @@ 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.
35
+ #
36
+ # acts_as_revisionable :label => lambda{|record| "Updated by #{record.updated_by} at #{record.updated_at}"}
37
+ #
32
38
  # A has_many :revision_records will also be added to the model for accessing the revisions.
33
39
  def acts_as_revisionable(options = {})
34
- class_attribute :acts_as_revisionable_options
40
+ class_attribute :acts_as_revisionable_options, :instance_writer => false, :instance_reader => false
35
41
  self.acts_as_revisionable_options = options.clone
36
42
  extend ClassMethods
37
43
  include InstanceMethods
@@ -220,6 +226,9 @@ module ActsAsRevisionable
220
226
  # Create a revision record based on this record and save it to the database.
221
227
  def create_revision!
222
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)
231
+ end
223
232
  revision.save!
224
233
  return revision
225
234
  end
@@ -94,7 +94,7 @@ describe ActsAsRevisionable do
94
94
  t.column :secret, :integer
95
95
  end unless table_exists?
96
96
 
97
- acts_as_revisionable :on_update => true
97
+ acts_as_revisionable :on_update => true, :label => lambda{|record| "name was '#{record.name}'"}
98
98
  end
99
99
 
100
100
  module ActsAsRevisionable
@@ -266,6 +266,14 @@ describe ActsAsRevisionable do
266
266
  ActsAsRevisionable::RevisionRecord.count.should == 1
267
267
  end
268
268
 
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
272
+ record_1.create_revision!
273
+ ActsAsRevisionable::RevisionRecord.count.should == 1
274
+ record_1.last_revision.label.should == "name was 'test'"
275
+ end
276
+
269
277
  it "should not create a revision entry if revisioning is disabled" do
270
278
  record = RevisionableTestModel.create(:name => "test")
271
279
  ActsAsRevisionable::RevisionRecord.count.should == 0
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: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
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-07-05 00:00:00 -05:00
18
+ date: 2011-07-12 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency