Skip to content

Commit

Permalink
Modified the :keep default to nil meaning "keep all old versions"
Browse files Browse the repository at this point in the history
Added a test for the default behaviour.

git-svn-id: http://rubymatt.rubyforge.org/svn/simply_versioned@8 9890f43a-5319-0410-996d-de745e0c2bc8
  • Loading branch information
mmower committed Jan 1, 2008
1 parent beb4d43 commit 582c7df
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.6 - 01-01-2008

The default is now to keep all versions, specify :keep if you want to set a limit.

0.5 - 30-12-2007

The revert_to_version call now takes an :except => [:name,:and,:so,:on] list of attributes whose value will not be reverted. The defautl is [:created_at,:updated_at].
Expand Down
11 changes: 9 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SimplyVersioned
===============

Release: 0.5
Date: 30-12-2007
Release: 0.6
Date: 01-01-2008
Author: Matt Mower <self@mattmower.com>

SimplyVersioned is a simple, non-invasive, approach to versioning ActiveRecord models.
Expand Down Expand Up @@ -35,6 +35,13 @@ Usage
class Thing < ActiveRecord::Base
simply_versioned :keep => 10
end

If you do not specify a limit then old versions are never automatically deleted. You can
manually delete them like this:

thing.versions.clean_old_version( 10 )

which would delete all the but the last ten versions.

5. Create versions

Expand Down
10 changes: 5 additions & 5 deletions lib/simply_versioned.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SimplyVersioned 0.5
# SimplyVersioned 0.6
#
# Simple ActiveRecord versioning
# Copyright (c) 2007 Matt Mower <self@mattmower.com>
# Copyright (c) 2007,2008 Matt Mower <self@mattmower.com>
# Released under the MIT license (see accompany MIT-LICENSE file)
#

Expand All @@ -18,15 +18,15 @@ module ClassMethods
# the +versions+ association.
#
# Options:
# +limit+ - specifies the number of old versions to keep (default = 99)
# +limit+ - specifies the number of old versions to keep (default = nil, never delete old versions)
#
# To save the record without creating a version either set +versioning_enabled+ to false
# on the model before calling save or, alternatively, use +without_versioning+ and save
# the model from its block.
#
def simply_versioned( options = {} )
options.reverse_merge!( {
:keep => 99
:keep => nil
})

has_many :versions, :order => 'number DESC', :as => :versionable, :dependent => :destroy, :extend => VersionsProxyMethods
Expand Down Expand Up @@ -105,7 +105,7 @@ def versioned?
def simply_versioned_create_version
if self.versioning_enabled?
if self.versions.create( :yaml => self.attributes.to_yaml )
self.versions.clean_old_versions( simply_versioned_keep_limit )
self.versions.clean_old_versions( simply_versioned_keep_limit.to_i ) if simply_versioned_keep_limit
end
end
true
Expand Down
4 changes: 2 additions & 2 deletions lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SimplyVersioned 0.5
# SimplyVersioned 0.6
#
# Simple ActiveRecord versioning
# Copyright (c) 2007 Matt Mower <self@mattmower.com>
# Copyright (c) 2007,2008 Matt Mower <self@mattmower.com>
# Released under the MIT license (see accompany MIT-LICENSE file)
#

Expand Down
12 changes: 10 additions & 2 deletions test/simply_versioned_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require File.join( File.dirname( __FILE__ ), 'test_helper' )

require 'mocha'

class Aardvark < ActiveRecord::Base
simply_versioned :keep => 3
end
Expand Down Expand Up @@ -178,7 +180,6 @@ def test_should_follow_back_and_forth
end

def test_should_be_trustworthy_collection

anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1
anthony.age += 1
anthony.save! #v2
Expand All @@ -187,7 +188,14 @@ def test_should_be_trustworthy_collection

alan = Aardvark.create!( :name => 'Alan', :age => 35 )
assert_equal 1, alan.versions.size

end

def test_should_not_delete_old_versions_by_default
ulrica = Undine.create!( :name => 'Ulrica' )
ulrica.versions.expects( :clean_old_versions ).never
100.times do
ulrica.update_attribute( :married, 1 - ulrica.married )
end
end

end

0 comments on commit 582c7df

Please sign in to comment.