diff options
| author | technoweenie <technoweenie@567b1171-46fb-0310-a4c9-b4bef9110e78> | 2005-10-06 20:34:02 +0000 |
|---|---|---|
| committer | technoweenie <technoweenie@567b1171-46fb-0310-a4c9-b4bef9110e78> | 2005-10-06 20:34:02 +0000 |
| commit | 25d9f68ef8e39eeacff971933714cd3638b3d40f (patch) | |
| tree | 81ddabc6df90d74d47e06c33563806d54e8aa9f1 | |
| parent | 6092feacfcc3eb7072b2b7289e55cff30d6ebc79 (diff) | |
pushed out aav v0.2
git-svn-id: http://svn.techno-weenie.net/projects/acts_as_versioned@102 567b1171-46fb-0310-a4c9-b4bef9110e78
| -rw-r--r-- | CHANGELOG | 9 | ||||
| -rw-r--r-- | Rakefile | 2 | ||||
| -rw-r--r-- | lib/acts_as_versioned.rb | 68 | ||||
| -rw-r--r-- | test/migration_test.rb | 8 |
4 files changed, 53 insertions, 34 deletions
@@ -1,6 +1,11 @@ -*0.1.4* +*0.2* -* (30 Sep 2005) fixed bug where find_versions() would order by 'version' twice. +* (6 Oct 2005) added find_versions and find_version class methods. + +* (6 Oct 2005) removed transaction from create_versioned_table(). + this way you can specify your own transaction around a group of operations. + +* (30 Sep 2005) fixed bug where find_versions() would order by 'version' twice. (found by Joe Clark) * (26 Sep 2005) added :sequence_name option to acts_as_versioned to set the sequence name on the versioned model @@ -9,7 +9,7 @@ require 'rake/testtask' require 'rake/contrib/rubyforgepublisher' PKG_NAME = 'acts_as_versioned' -PKG_VERSION = '0.1.3' +PKG_VERSION = '0.2' PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PROD_HOST = "technoweenie@bidwell.textdrive.com" RUBY_FORGE_PROJECT = 'ar-versioned' diff --git a/lib/acts_as_versioned.rb b/lib/acts_as_versioned.rb index b6f44eacc..13cc3c281 100644 --- a/lib/acts_as_versioned.rb +++ b/lib/acts_as_versioned.rb @@ -318,6 +318,20 @@ module ActiveRecord #:nodoc: end module ClassMethods + # Finds a specific version of a specific row of this model + def find_version(id, version) + find_versions(id, + :conditions => ["#{versioned_foreign_key} = ? AND version = ?", id, version], + :limit => 1).first + end + + # Finds versions of a specific model. Takes an options hash like <tt>find</tt> + def find_versions(id, options = {}) + versioned_class.find :all, { + :conditions => ["#{versioned_foreign_key} = ?", id], + :order => 'version' }.merge(options) + end + # Returns an array of columns that are versioned. See non_versioned_fields def versioned_columns self.columns.select { |c| !non_versioned_fields.include?(c.name) } @@ -335,34 +349,32 @@ module ActiveRecord #:nodoc: # Rake migration task to create the versioned table using options passed to acts_as_versioned def create_versioned_table(create_table_options = {}) - self.transaction do - # create version column in main table if it does not exist - if !self.content_columns.find { |c| %w(version lock_version).include? c.name } - self.connection.add_column table_name, :version, :integer - end - - self.connection.create_table(versioned_table_name, create_table_options) do |t| - t.column versioned_foreign_key, :integer - t.column :version, :integer - end - - updated_col = nil - self.versioned_columns.each do |col| - updated_col = col if !updated_col and %(updated_at updated_on).include?(col.name) - self.connection.add_column versioned_table_name, col.name, col.type, - :limit => col.limit, - :default => col.default - end - - if type_col = self.columns_hash[inheritance_column] - self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type, - :limit => type_col.limit, - :default => type_col.default - end - - if updated_col.nil? - self.connection.add_column versioned_table_name, :updated_at, :timestamp - end + # create version column in main table if it does not exist + if !self.content_columns.find { |c| %w(version lock_version).include? c.name } + self.connection.add_column table_name, :version, :integer + end + + self.connection.create_table(versioned_table_name, create_table_options) do |t| + t.column versioned_foreign_key, :integer + t.column :version, :integer + end + + updated_col = nil + self.versioned_columns.each do |col| + updated_col = col if !updated_col and %(updated_at updated_on).include?(col.name) + self.connection.add_column versioned_table_name, col.name, col.type, + :limit => col.limit, + :default => col.default + end + + if type_col = self.columns_hash[inheritance_column] + self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type, + :limit => type_col.limit, + :default => type_col.default + end + + if updated_col.nil? + self.connection.add_column versioned_table_name, :updated_at, :timestamp end end diff --git a/test/migration_test.rb b/test/migration_test.rb index f2eacb29a..27bf2e81d 100644 --- a/test/migration_test.rb +++ b/test/migration_test.rb @@ -7,9 +7,6 @@ if ActiveRecord::Base.connection.supports_migrations? end class MigrationTest < Test::Unit::TestCase - def setup - end - def teardown ActiveRecord::Base.connection.initialize_schema_information ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0" @@ -21,9 +18,14 @@ if ActiveRecord::Base.connection.supports_migrations? def test_versioned_migration assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' } + # take 'er up ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/') t = Thing.create :title => 'blah blah' assert_equal 1, t.versions.size + + # now lets take 'er back down + ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/') + assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' } end end end |
