]> source.dussan.org Git - redmine.git/commitdiff
Get rid of acts_as_versioned.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 26 Jul 2017 16:41:06 +0000 (16:41 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 26 Jul 2017 16:41:06 +0000 (16:41 +0000)
WikiContent::Version becomes WikiContentVersion.

git-svn-id: http://svn.redmine.org/redmine/trunk@16889 e93f8b46-1217-0410-a6f0-8f06a7374b81

30 files changed:
app/models/wiki_content.rb
app/models/wiki_content_version.rb [new file with mode: 0644]
app/models/wiki_page.rb
lib/plugins/acts_as_versioned/CHANGELOG [deleted file]
lib/plugins/acts_as_versioned/MIT-LICENSE [deleted file]
lib/plugins/acts_as_versioned/README [deleted file]
lib/plugins/acts_as_versioned/RUNNING_UNIT_TESTS [deleted file]
lib/plugins/acts_as_versioned/Rakefile [deleted file]
lib/plugins/acts_as_versioned/init.rb [deleted file]
lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb [deleted file]
lib/plugins/acts_as_versioned/test/abstract_unit.rb [deleted file]
lib/plugins/acts_as_versioned/test/database.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/authors.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/landmark.rb [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/landmark_versions.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/landmarks.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/locked_pages.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/locked_pages_revisions.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/migrations/1_add_versioned_tables.rb [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/page.rb [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/page_versions.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/pages.yml [deleted file]
lib/plugins/acts_as_versioned/test/fixtures/widget.rb [deleted file]
lib/plugins/acts_as_versioned/test/migration_test.rb [deleted file]
lib/plugins/acts_as_versioned/test/schema.rb [deleted file]
lib/plugins/acts_as_versioned/test/versioned_test.rb [deleted file]
test/functional/wiki_controller_test.rb
test/unit/wiki_content_test.rb
test/unit/wiki_content_version_test.rb
test/unit/wiki_page_test.rb

index 0de717cd47788d97bf27c4db6917589494153e7d..3360b71cac7de5366cfc6d520274ced1513ac37e 100644 (file)
@@ -21,15 +21,22 @@ class WikiContent < ActiveRecord::Base
   self.locking_column = 'version'
   belongs_to :page, :class_name => 'WikiPage'
   belongs_to :author, :class_name => 'User'
+  has_many :versions, :class_name => 'WikiContentVersion', :dependent => :delete_all
   validates_presence_of :text
   validates_length_of :comments, :maximum => 1024, :allow_nil => true
 
-  acts_as_versioned
-
+  after_save :create_version
   after_save :send_notification
 
   scope :without_text, lambda {select(:id, :page_id, :version, :updated_on)}
 
+  def initialize(*args)
+    super
+    if new_record?
+      self.version = 1
+    end
+  end
+
   def visible?(user=User.current)
     page.visible?(user)
   end
@@ -56,107 +63,25 @@ class WikiContent < ActiveRecord::Base
     true
   end
 
-  class Version
-    belongs_to :page, :class_name => '::WikiPage'
-    belongs_to :author, :class_name => '::User'
-
-    acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"},
-                  :description => :comments,
-                  :datetime => :updated_on,
-                  :type => 'wiki-page',
-                  :group => :page,
-                  :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}}
-
-    acts_as_activity_provider :type => 'wiki_edits',
-                              :timestamp => "#{WikiContent.versioned_table_name}.updated_on",
-                              :author_key => "#{WikiContent.versioned_table_name}.author_id",
-                              :permission => :view_wiki_edits,
-                              :scope => select("#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
-                                               "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
-                                               "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
-                                               "#{WikiContent.versioned_table_name}.id").
-                                        joins("LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
-                                              "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
-                                              "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id")
-
-    after_destroy :page_update_after_destroy
-
-    def text=(plain)
-      case Setting.wiki_compression
-      when 'gzip'
-      begin
-        self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)
-        self.compression = 'gzip'
-      rescue
-        self.data = plain
-        self.compression = ''
-      end
-      else
-        self.data = plain
-        self.compression = ''
-      end
-      plain
-    end
-
-    def text
-      @text ||= begin
-        str = case compression
-              when 'gzip'
-                Zlib::Inflate.inflate(data)
-              else
-                # uncompressed data
-                data
-              end
-        str.force_encoding("UTF-8")
-        str
-      end
-    end
-
-    def project
-      page.project
-    end
-
-    def attachments
-      page.nil? ? [] : page.attachments
-    end
-
-    # Return true if the content is the current page content
-    def current_version?
-      page.content.version == self.version
-    end
-
-    # Returns the previous version or nil
-    def previous
-      @previous ||= WikiContent::Version.
-        reorder('version DESC').
-        includes(:author).
-        where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first
-    end
-
-    # Returns the next version or nil
-    def next
-      @next ||= WikiContent::Version.
-        reorder('version ASC').
-        includes(:author).
-        where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first
-    end
-
-    private
-
-    # Updates page's content if the latest version is removed
-    # or destroys the page if it was the only version
-    def page_update_after_destroy
-      latest = page.content.versions.reorder("#{self.class.table_name}.version DESC").first
-      if latest && page.content.version != latest.version
-        raise ActiveRecord::Rollback unless page.content.revert_to!(latest)
-      elsif latest.nil?
-        raise ActiveRecord::Rollback unless page.destroy
-      end
+  # Reverts the record to a previous version
+  def revert_to!(version)
+    if version.wiki_content_id == id
+      update_columns(
+          :author_id => version.author_id,
+          :text => version.text,
+          :comments => version.comments,
+          :version => version.version,
+          :updated_on => version.updated_on
+        ) && reload
     end
   end
 
   private
 
+  def create_version
+    versions << WikiContentVersion.new(attributes.except("id"))
+  end
+
   def send_notification
     # new_record? returns false in after_save callbacks
     if saved_change_to_id?
@@ -169,4 +94,8 @@ class WikiContent < ActiveRecord::Base
       end
     end
   end
+
+  # For backward compatibility
+  # TODO: remove it in Redmine 5
+  Version = WikiContentVersion
 end
diff --git a/app/models/wiki_content_version.rb b/app/models/wiki_content_version.rb
new file mode 100644 (file)
index 0000000..73d708c
--- /dev/null
@@ -0,0 +1,117 @@
+# Redmine - project management software\r
+# Copyright (C) 2006-2017  Jean-Philippe Lang\r
+#\r
+# This program is free software; you can redistribute it and/or\r
+# modify it under the terms of the GNU General Public License\r
+# as published by the Free Software Foundation; either version 2\r
+# of the License, or (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU General Public License\r
+# along with this program; if not, write to the Free Software\r
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+\r
+require 'zlib'\r
+\r
+class WikiContentVersion < ActiveRecord::Base\r
+  belongs_to :page, :class_name => 'WikiPage'\r
+  belongs_to :author, :class_name => 'User'\r
+\r
+  acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"},\r
+                :description => :comments,\r
+                :datetime => :updated_on,\r
+                :type => 'wiki-page',\r
+                :group => :page,\r
+                :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}}\r
+\r
+  acts_as_activity_provider :type => 'wiki_edits',\r
+                            :timestamp => "#{table_name}.updated_on",\r
+                            :author_key => "#{table_name}.author_id",\r
+                            :permission => :view_wiki_edits,\r
+                            :scope => select("#{table_name}.updated_on, #{table_name}.comments, " +\r
+                                             "#{table_name}.version, #{WikiPage.table_name}.title, " +\r
+                                             "#{table_name}.page_id, #{table_name}.author_id, " +\r
+                                             "#{table_name}.id").\r
+                                      joins("LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{table_name}.page_id " +\r
+                                            "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +\r
+                                            "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id")\r
+\r
+  after_destroy :page_update_after_destroy\r
+\r
+  def text=(plain)\r
+    case Setting.wiki_compression\r
+    when 'gzip'\r
+    begin\r
+      self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)\r
+      self.compression = 'gzip'\r
+    rescue\r
+      self.data = plain\r
+      self.compression = ''\r
+    end\r
+    else\r
+      self.data = plain\r
+      self.compression = ''\r
+    end\r
+    plain\r
+  end\r
+\r
+  def text\r
+    @text ||= begin\r
+      str = case compression\r
+            when 'gzip'\r
+              Zlib::Inflate.inflate(data)\r
+            else\r
+              # uncompressed data\r
+              data\r
+            end\r
+      str.force_encoding("UTF-8")\r
+      str\r
+    end\r
+  end\r
+\r
+  def project\r
+    page.project\r
+  end\r
+\r
+  def attachments\r
+    page.nil? ? [] : page.attachments\r
+  end\r
+\r
+  # Return true if the content is the current page content\r
+  def current_version?\r
+    page.content.version == self.version\r
+  end\r
+\r
+  # Returns the previous version or nil\r
+  def previous\r
+    @previous ||= WikiContentVersion.\r
+      reorder('version DESC').\r
+      includes(:author).\r
+      where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first\r
+  end\r
+\r
+  # Returns the next version or nil\r
+  def next\r
+    @next ||= WikiContentVersion.\r
+      reorder('version ASC').\r
+      includes(:author).\r
+      where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first\r
+  end\r
+\r
+  private\r
+\r
+  # Updates page's content if the latest version is removed\r
+  # or destroys the page if it was the only version\r
+  def page_update_after_destroy\r
+    latest = page.content.versions.reorder("#{self.class.table_name}.version DESC").first\r
+    if latest && page.content.version != latest.version\r
+      raise ActiveRecord::Rollback unless page.content.revert_to!(latest)\r
+    elsif latest.nil?\r
+      raise ActiveRecord::Rollback unless page.destroy\r
+    end\r
+  end\r
+end\r
index 6e4cf0c03ea47dde44cdd95a12cdc0d594271a70..9082859d32853b0b100b1738f6238cbcfdf3e026 100644 (file)
@@ -221,7 +221,6 @@ class WikiPage < ActiveRecord::Base
       if content.text_changed?
         begin
           self.content = content
-          ret = ret && content.changed?
         rescue ActiveRecord::RecordNotSaved
           ret = false
         end
diff --git a/lib/plugins/acts_as_versioned/CHANGELOG b/lib/plugins/acts_as_versioned/CHANGELOG
deleted file mode 100644 (file)
index a5d339c..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-*SVN* (version numbers are overrated)
-
-* (5 Oct 2006) Allow customization of #versions association options [Dan Peterson]
-
-*0.5.1*
-
-* (8 Aug 2006) Versioned models now belong to the unversioned model.  @article_version.article.class => Article [Aslak Hellesoy]
-
-*0.5* # do versions even matter for plugins?
-
-* (21 Apr 2006) Added without_locking and without_revision methods.
-
-  Foo.without_revision do
-    @foo.update_attributes ...
-  end
-
-*0.4*
-
-* (28 March 2006) Rename non_versioned_fields to non_versioned_columns (old one is kept for compatibility).
-* (28 March 2006) Made explicit documentation note that string column names are required for non_versioned_columns.
-
-*0.3.1*
-
-* (7 Jan 2006) explicitly set :foreign_key option for the versioned model's belongs_to assocation for STI [Caged]
-* (7 Jan 2006) added tests to prove has_many :through joins work
-
-*0.3*
-
-* (2 Jan 2006) added ability to share a mixin with versioned class
-* (2 Jan 2006) changed the dynamic version model to MyModel::Version
-
-*0.2.4*
-
-* (27 Nov 2005) added note about possible destructive behavior of if_changed? [Michael Schuerig]
-
-*0.2.3*
-
-* (12 Nov 2005) fixed bug with old behavior of #blank? [Michael Schuerig]
-* (12 Nov 2005) updated tests to use ActiveRecord Schema
-
-*0.2.2*
-
-* (3 Nov 2005) added documentation note to #acts_as_versioned [Martin Jul]
-
-*0.2.1*
-
-* (6 Oct 2005) renamed dirty? to changed? to keep it uniform.  it was aliased to keep it backwards compatible.
-
-*0.2* 
-
-* (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
-
-*0.1.3* (18 Sep 2005)
-
-* First RubyForge release
-
-*0.1.2*
-
-* check if module is already included when acts_as_versioned is called
-
-*0.1.1*
-
-* Adding tests and rdocs
-
-*0.1* 
-
-* Initial transfer from Rails ticket: http://dev.rubyonrails.com/ticket/1974
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/MIT-LICENSE b/lib/plugins/acts_as_versioned/MIT-LICENSE
deleted file mode 100644 (file)
index 5851fda..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (c) 2005 Rick Olson
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/README b/lib/plugins/acts_as_versioned/README
deleted file mode 100644 (file)
index 8961f05..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-= acts_as_versioned
-
-This library adds simple versioning to an ActiveRecord module.  ActiveRecord is required.
-
-== Resources
-
-Install
-
-* gem install acts_as_versioned
-
-Rubyforge project
-
-* http://rubyforge.org/projects/ar-versioned
-
-RDocs
-
-* http://ar-versioned.rubyforge.org
-
-Subversion
-
-* http://techno-weenie.net/svn/projects/acts_as_versioned
-
-Collaboa
-
-* http://collaboa.techno-weenie.net/repository/browse/acts_as_versioned
-
-Special thanks to Dreamer on ##rubyonrails for help in early testing.  His ServerSideWiki (http://serversidewiki.com) 
-was the first project to use acts_as_versioned <em>in the wild</em>.
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/RUNNING_UNIT_TESTS b/lib/plugins/acts_as_versioned/RUNNING_UNIT_TESTS
deleted file mode 100644 (file)
index a6e55b8..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-== Creating the test database
-
-The default name for the test databases is "activerecord_versioned". If you 
-want to use another database name then be sure to update the connection 
-adapter setups you want to test with in test/connections/<your database>/connection.rb. 
-When you have the database online, you can import the fixture tables with 
-the test/fixtures/db_definitions/*.sql files.
-
-Make sure that you create database objects with the same user that you specified in i
-connection.rb otherwise (on Postgres, at least) tests for default values will fail.
-
-== Running with Rake
-
-The easiest way to run the unit tests is through Rake. The default task runs
-the entire test suite for all the adapters. You can also run the suite on just
-one adapter by using the tasks test_mysql_ruby, test_ruby_mysql, test_sqlite, 
-or test_postresql. For more information, checkout the full array of rake tasks with "rake -T"
-
-Rake can be found at http://rake.rubyforge.org
-
-== Running by hand
-
-Unit tests are located in test directory. If you only want to run a single test suite, 
-or don't want to bother with Rake, you can do so with something like:
-
-   cd test; ruby -I "connections/native_mysql" base_test.rb
-   
-That'll run the base suite using the MySQL-Ruby adapter. Change the adapter
-and test suite name as needed.
-
-== Faster tests
-
-If you are using a database that supports transactions, you can set the
-"AR_TX_FIXTURES" environment variable to "yes" to use transactional fixtures.
-This gives a very large speed boost. With rake:
-
-  rake AR_TX_FIXTURES=yes
-
-Or, by hand:
-
-  AR_TX_FIXTURES=yes ruby -I connections/native_sqlite3 base_test.rb
diff --git a/lib/plugins/acts_as_versioned/Rakefile b/lib/plugins/acts_as_versioned/Rakefile
deleted file mode 100644 (file)
index 5bccb5d..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-require 'rubygems'\r
-\r
-Gem::manage_gems\r
-\r
-require 'rake/rdoctask'\r
-require 'rake/packagetask'\r
-require 'rake/gempackagetask'\r
-require 'rake/testtask'\r
-require 'rake/contrib/rubyforgepublisher'\r
-\r
-PKG_NAME           = 'acts_as_versioned'\r
-PKG_VERSION        = '0.3.1'\r
-PKG_FILE_NAME      = "#{PKG_NAME}-#{PKG_VERSION}"\r
-PROD_HOST          = "technoweenie@bidwell.textdrive.com"\r
-RUBY_FORGE_PROJECT = 'ar-versioned'\r
-RUBY_FORGE_USER    = 'technoweenie'\r
-\r
-desc 'Default: run unit tests.'\r
-task :default => :test\r
-\r
-desc 'Test the calculations plugin.'\r
-Rake::TestTask.new(:test) do |t|\r
-  t.libs << 'lib'\r
-  t.pattern = 'test/**/*_test.rb'\r
-  t.verbose = true\r
-end\r
-\r
-desc 'Generate documentation for the calculations plugin.'\r
-Rake::RDocTask.new(:rdoc) do |rdoc|\r
-  rdoc.rdoc_dir = 'rdoc'\r
-  rdoc.title    = "#{PKG_NAME} -- Simple versioning with active record models"\r
-  rdoc.options << '--line-numbers --inline-source'\r
-  rdoc.rdoc_files.include('README', 'CHANGELOG', 'RUNNING_UNIT_TESTS')\r
-  rdoc.rdoc_files.include('lib/**/*.rb')\r
-end\r
-\r
-spec = Gem::Specification.new do |s|\r
-  s.name            = PKG_NAME\r
-  s.version         = PKG_VERSION\r
-  s.platform        = Gem::Platform::RUBY\r
-  s.summary         = "Simple versioning with active record models"\r
-  s.files           = FileList["{lib,test}/**/*"].to_a + %w(README MIT-LICENSE CHANGELOG RUNNING_UNIT_TESTS)\r
-  s.files.delete      "acts_as_versioned_plugin.sqlite.db"\r
-  s.files.delete      "acts_as_versioned_plugin.sqlite3.db"\r
-  s.files.delete      "test/debug.log"\r
-  s.require_path    = 'lib'\r
-  s.autorequire     = 'acts_as_versioned'\r
-  s.has_rdoc        = true\r
-  s.test_files      = Dir['test/**/*_test.rb']\r
-  s.add_dependency    'activerecord', '>= 1.10.1'\r
-  s.add_dependency    'activesupport', '>= 1.1.1'\r
-  s.author          = "Rick Olson"\r
-  s.email           = "technoweenie@gmail.com"\r
-  s.homepage        = "http://techno-weenie.net"\r
-end\r
-\r
-Rake::GemPackageTask.new(spec) do |pkg|\r
-  pkg.need_tar = true\r
-end\r
-\r
-desc "Publish the API documentation"\r
-task :pdoc => [:rdoc] do\r
-  Rake::RubyForgePublisher.new(RUBY_FORGE_PROJECT, RUBY_FORGE_USER).upload\r
-end\r
-\r
-desc 'Publish the gem and API docs'\r
-task :publish => [:pdoc, :rubyforge_upload]\r
-\r
-desc "Publish the release files to RubyForge."\r
-task :rubyforge_upload => :package do\r
-  files = %w(gem tgz).map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }\r
-\r
-  if RUBY_FORGE_PROJECT then\r
-    require 'net/http'\r
-    require 'open-uri'\r
-\r
-    project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"\r
-    project_data = open(project_uri) { |data| data.read }\r
-    group_id = project_data[/[?&]group_id=(\d+)/, 1]\r
-    raise "Couldn't get group id" unless group_id\r
-\r
-    # This echos password to shell which is a bit sucky\r
-    if ENV["RUBY_FORGE_PASSWORD"]\r
-      password = ENV["RUBY_FORGE_PASSWORD"]\r
-    else\r
-      print "#{RUBY_FORGE_USER}@rubyforge.org's password: "\r
-      password = STDIN.gets.chomp\r
-    end\r
-\r
-    login_response = Net::HTTP.start("rubyforge.org", 80) do |http|\r
-      data = [\r
-        "login=1",\r
-        "form_loginname=#{RUBY_FORGE_USER}",\r
-        "form_pw=#{password}"\r
-      ].join("&")\r
-      http.post("/account/login.php", data)\r
-    end\r
-\r
-    cookie = login_response["set-cookie"]\r
-    raise "Login failed" unless cookie\r
-    headers = { "Cookie" => cookie }\r
-\r
-    release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"\r
-    release_data = open(release_uri, headers) { |data| data.read }\r
-    package_id = release_data[/[?&]package_id=(\d+)/, 1]\r
-    raise "Couldn't get package id" unless package_id\r
-\r
-    first_file = true\r
-    release_id = ""\r
-\r
-    files.each do |filename|\r
-      basename  = File.basename(filename)\r
-      file_ext  = File.extname(filename)\r
-      file_data = File.open(filename, "rb") { |file| file.read }\r
-\r
-      puts "Releasing #{basename}..."\r
-\r
-      release_response = Net::HTTP.start("rubyforge.org", 80) do |http|\r
-        release_date = Time.now.strftime("%Y-%m-%d %H:%M")\r
-        type_map = {\r
-          ".zip"    => "3000",\r
-          ".tgz"    => "3110",\r
-          ".gz"     => "3110",\r
-          ".gem"    => "1400"\r
-        }; type_map.default = "9999"\r
-        type = type_map[file_ext]\r
-        boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"\r
-\r
-        query_hash = if first_file then\r
-          {\r
-            "group_id" => group_id,\r
-            "package_id" => package_id,\r
-            "release_name" => PKG_FILE_NAME,\r
-            "release_date" => release_date,\r
-            "type_id" => type,\r
-            "processor_id" => "8000", # Any\r
-            "release_notes" => "",\r
-            "release_changes" => "",\r
-            "preformatted" => "1",\r
-            "submit" => "1"\r
-          }\r
-        else\r
-          {\r
-            "group_id" => group_id,\r
-            "release_id" => release_id,\r
-            "package_id" => package_id,\r
-            "step2" => "1",\r
-            "type_id" => type,\r
-            "processor_id" => "8000", # Any\r
-            "submit" => "Add This File"\r
-          }\r
-        end\r
-\r
-        query = "?" + query_hash.map do |(name, value)|\r
-          [name, URI.encode(value)].join("=")\r
-        end.join("&")\r
-\r
-        data = [\r
-          "--" + boundary,\r
-          "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",\r
-          "Content-Type: application/octet-stream",\r
-          "Content-Transfer-Encoding: binary",\r
-          "", file_data, ""\r
-          ].join("\x0D\x0A")\r
-\r
-        release_headers = headers.merge(\r
-          "Content-Type" => "multipart/form-data; boundary=#{boundary}"\r
-        )\r
-\r
-        target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"\r
-        http.post(target + query, data, release_headers)\r
-      end\r
-\r
-      if first_file then\r
-        release_id = release_response.body[/release_id=(\d+)/, 1]\r
-        raise("Couldn't get release id") unless release_id\r
-      end\r
-\r
-      first_file = false\r
-    end\r
-  end\r
-end
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/init.rb b/lib/plugins/acts_as_versioned/init.rb
deleted file mode 100644 (file)
index 5937bbc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-require 'acts_as_versioned'
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb b/lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb
deleted file mode 100644 (file)
index bccb406..0000000
+++ /dev/null
@@ -1,569 +0,0 @@
-# Copyright (c) 2005 Rick Olson
-# 
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-# 
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-module ActiveRecord #:nodoc:
-  module Acts #:nodoc:
-    # Specify this act if you want to save a copy of the row in a versioned table.  This assumes there is a 
-    # versioned table ready and that your model has a version field.  This works with optimistic locking if the lock_version
-    # column is present as well.
-    #
-    # The class for the versioned model is derived the first time it is seen. Therefore, if you change your database schema you have to restart
-    # your container for the changes to be reflected. In development mode this usually means restarting WEBrick.
-    #
-    #   class Page < ActiveRecord::Base
-    #     # assumes pages_versions table
-    #     acts_as_versioned
-    #   end
-    #
-    # Example:
-    #
-    #   page = Page.create(:title => 'hello world!')
-    #   page.version       # => 1
-    #
-    #   page.title = 'hello world'
-    #   page.save
-    #   page.version       # => 2
-    #   page.versions.size # => 2
-    #
-    #   page.revert_to(1)  # using version number
-    #   page.title         # => 'hello world!'
-    #
-    #   page.revert_to(page.versions.last) # using versioned instance
-    #   page.title         # => 'hello world'
-    #
-    #   page.versions.earliest # efficient query to find the first version
-    #   page.versions.latest   # efficient query to find the most recently created version
-    #
-    #
-    # Simple Queries to page between versions
-    #
-    #   page.versions.before(version) 
-    #   page.versions.after(version)
-    #
-    # Access the previous/next versions from the versioned model itself
-    #
-    #   version = page.versions.latest
-    #   version.previous # go back one version
-    #   version.next     # go forward one version
-    #
-    # See ActiveRecord::Acts::Versioned::ClassMethods#acts_as_versioned for configuration options
-    module Versioned
-      CALLBACKS = [:set_new_version, :save_version_on_create, :save_version?, :clear_altered_attributes]
-      def self.included(base) # :nodoc:
-        base.extend ClassMethods
-      end
-
-      module ClassMethods
-        # == Configuration options
-        #
-        # * <tt>class_name</tt> - versioned model class name (default: PageVersion in the above example)
-        # * <tt>table_name</tt> - versioned model table name (default: page_versions in the above example)
-        # * <tt>foreign_key</tt> - foreign key used to relate the versioned model to the original model (default: page_id in the above example)
-        # * <tt>inheritance_column</tt> - name of the column to save the model's inheritance_column value for STI.  (default: versioned_type)
-        # * <tt>version_column</tt> - name of the column in the model that keeps the version number (default: version)
-        # * <tt>sequence_name</tt> - name of the custom sequence to be used by the versioned model.
-        # * <tt>limit</tt> - number of revisions to keep, defaults to unlimited
-        # * <tt>if</tt> - symbol of method to check before saving a new version.  If this method returns false, a new version is not saved.
-        #   For finer control, pass either a Proc or modify Model#version_condition_met?
-        #
-        #     acts_as_versioned :if => Proc.new { |auction| !auction.expired? }
-        #
-        #   or...
-        #
-        #     class Auction
-        #       def version_condition_met? # totally bypasses the <tt>:if</tt> option
-        #         !expired?
-        #       end
-        #     end
-        #
-        # * <tt>if_changed</tt> - Simple way of specifying attributes that are required to be changed before saving a model.  This takes
-        #   either a symbol or array of symbols.  WARNING - This will attempt to overwrite any attribute setters you may have.
-        #   Use this instead if you want to write your own attribute setters (and ignore if_changed):
-        # 
-        #     def name=(new_name)
-        #       write_changed_attribute :name, new_name
-        #     end
-        #
-        # * <tt>extend</tt> - Lets you specify a module to be mixed in both the original and versioned models.  You can also just pass a block
-        #   to create an anonymous mixin:
-        #
-        #     class Auction
-        #       acts_as_versioned do
-        #         def started?
-        #           !started_at.nil?
-        #         end
-        #       end
-        #     end
-        #
-        #   or...
-        #
-        #     module AuctionExtension
-        #       def started?
-        #         !started_at.nil?
-        #       end
-        #     end
-        #     class Auction
-        #       acts_as_versioned :extend => AuctionExtension
-        #     end
-        #
-        #  Example code:
-        #
-        #    @auction = Auction.find(1)
-        #    @auction.started?
-        #    @auction.versions.first.started?
-        #
-        # == Database Schema
-        #
-        # The model that you're versioning needs to have a 'version' attribute. The model is versioned 
-        # into a table called #{model}_versions where the model name is singlular. The _versions table should 
-        # contain all the fields you want versioned, the same version column, and a #{model}_id foreign key field.
-        #
-        # A lock_version field is also accepted if your model uses Optimistic Locking.  If your table uses Single Table inheritance,
-        # then that field is reflected in the versioned model as 'versioned_type' by default.
-        #
-        # Acts_as_versioned comes prepared with the ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table 
-        # method, perfect for a migration.  It will also create the version column if the main model does not already have it.
-        #
-        #   class AddVersions < ActiveRecord::Migration
-        #     def self.up
-        #       # create_versioned_table takes the same options hash
-        #       # that create_table does
-        #       Post.create_versioned_table
-        #     end
-        # 
-        #     def self.down
-        #       Post.drop_versioned_table
-        #     end
-        #   end
-        # 
-        # == Changing What Fields Are Versioned
-        #
-        # By default, acts_as_versioned will version all but these fields: 
-        # 
-        #   [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column]
-        #
-        # You can add or change those by modifying #non_versioned_columns.  Note that this takes strings and not symbols.
-        #
-        #   class Post < ActiveRecord::Base
-        #     acts_as_versioned
-        #     self.non_versioned_columns << 'comments_count'
-        #   end
-        # 
-        def acts_as_versioned(options = {}, &extension)
-          # don't allow multiple calls
-          return if self.included_modules.include?(ActiveRecord::Acts::Versioned::ActMethods)
-
-          send :include, ActiveRecord::Acts::Versioned::ActMethods
-
-          cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name, :versioned_inheritance_column, 
-            :version_column, :max_version_limit, :track_altered_attributes, :version_condition, :version_sequence_name, :non_versioned_columns,
-            :version_association_options
-
-          # legacy
-          alias_method :non_versioned_fields,  :non_versioned_columns
-          alias_method :non_versioned_fields=, :non_versioned_columns=
-
-          class << self
-            alias_method :non_versioned_fields,  :non_versioned_columns
-            alias_method :non_versioned_fields=, :non_versioned_columns=
-          end
-
-          send :attr_accessor, :altered_attributes
-
-          self.versioned_class_name         = options[:class_name]  || "Version"
-          self.versioned_foreign_key        = options[:foreign_key] || self.to_s.foreign_key
-          self.versioned_table_name         = options[:table_name]  || "#{table_name_prefix}#{base_class.name.demodulize.underscore}_versions#{table_name_suffix}"
-          self.versioned_inheritance_column = options[:inheritance_column] || "versioned_#{inheritance_column}"
-          self.version_column               = options[:version_column]     || 'version'
-          self.version_sequence_name        = options[:sequence_name]
-          self.max_version_limit            = options[:limit].to_i
-          self.version_condition            = options[:if] || true
-          self.non_versioned_columns        = [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column]
-          self.version_association_options  = {
-                                                :class_name  => "#{self.to_s}::#{versioned_class_name}",
-                                                :foreign_key => versioned_foreign_key,
-                                                :dependent   => :delete_all
-                                              }.merge(options[:association_options] || {})
-
-          if block_given?
-            extension_module_name = "#{versioned_class_name}Extension"
-            silence_warnings do
-              self.const_set(extension_module_name, Module.new(&extension))
-            end
-
-            options[:extend] = self.const_get(extension_module_name)
-          end
-
-          class_eval do
-            has_many :versions, version_association_options do
-              # finds earliest version of this record
-              def earliest
-                @earliest ||= order('version').first
-              end
-
-              # find latest version of this record
-              def latest
-                @latest ||= order('version desc').first
-              end
-            end
-            before_save  :set_new_version
-            after_create :save_version_on_create
-            after_update :save_version
-            after_save   :clear_old_versions
-            after_save   :clear_altered_attributes
-
-            unless options[:if_changed].nil?
-              self.track_altered_attributes = true
-              options[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array)
-              options[:if_changed].each do |attr_name|
-                define_method("#{attr_name}=") do |value|
-                  write_changed_attribute attr_name, value
-                end
-              end
-            end
-
-            include options[:extend] if options[:extend].is_a?(Module)
-          end
-
-          # create the dynamic versioned model
-          const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do
-            def self.reloadable? ; false ; end
-            # find first version before the given version
-            def self.before(version)
-              order('version desc').
-                where("#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version).
-                first
-            end
-
-            # find first version after the given version.
-            def self.after(version)
-              order('version').
-                where("#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version).
-                first
-            end
-
-            def previous
-              self.class.before(self)
-            end
-
-            def next
-              self.class.after(self)
-            end
-
-            def versions_count
-              page.version
-            end
-          end
-
-          versioned_class.cattr_accessor :original_class
-          versioned_class.original_class = self
-          versioned_class.table_name = versioned_table_name
-          versioned_class.belongs_to self.to_s.demodulize.underscore.to_sym, 
-            :class_name  => "::#{self.to_s}", 
-            :foreign_key => versioned_foreign_key
-          versioned_class.send :include, options[:extend]         if options[:extend].is_a?(Module)
-          versioned_class.set_sequence_name version_sequence_name if version_sequence_name
-        end
-      end
-
-      module ActMethods
-        def self.included(base) # :nodoc:
-          base.extend ClassMethods
-        end
-
-        # Finds a specific version of this record
-        def find_version(version = nil)
-          self.class.find_version(id, version)
-        end
-
-        # Saves a version of the model if applicable
-        def save_version
-          save_version_on_create if save_version?
-        end
-
-        # Saves a version of the model in the versioned table.  This is called in the after_save callback by default
-        def save_version_on_create
-          rev = self.class.versioned_class.new
-          self.clone_versioned_model(self, rev)
-          rev.version = send(self.class.version_column)
-          rev.send("#{self.class.versioned_foreign_key}=", self.id)
-          rev.save
-        end
-
-        # Clears old revisions if a limit is set with the :limit option in <tt>acts_as_versioned</tt>.
-        # Override this method to set your own criteria for clearing old versions.
-        def clear_old_versions
-          return if self.class.max_version_limit == 0
-          excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit
-          if excess_baggage > 0
-            sql = "DELETE FROM #{self.class.versioned_table_name} WHERE version <= #{excess_baggage} AND #{self.class.versioned_foreign_key} = #{self.id}"
-            self.class.versioned_class.connection.execute sql
-          end
-        end
-
-        def versions_count
-          version
-        end
-
-        # Reverts a model to a given version.  Takes either a version number or an instance of the versioned model
-        def revert_to(version)
-          if version.is_a?(self.class.versioned_class)
-            return false unless version.send(self.class.versioned_foreign_key) == self.id and !version.new_record?
-          else
-            return false unless version = versions.find_by_version(version)
-          end
-          self.clone_versioned_model(version, self)
-          self.send("#{self.class.version_column}=", version.version)
-          true
-        end
-
-        # Reverts a model to a given version and saves the model.
-        # Takes either a version number or an instance of the versioned model
-        def revert_to!(version)
-          revert_to(version) ? save_without_revision : false
-        end
-
-        # Temporarily turns off Optimistic Locking while saving.  Used when reverting so that a new version is not created.
-        def save_without_revision
-          save_without_revision!
-          true
-        rescue
-          false
-        end
-
-        def save_without_revision!
-          without_locking do
-            without_revision do
-              save!
-            end
-          end
-        end
-
-        # Returns an array of attribute keys that are versioned.  See non_versioned_columns
-        def versioned_attributes
-          self.attributes.keys.select { |k| !self.class.non_versioned_columns.include?(k) }
-        end
-
-        # If called with no parameters, gets whether the current model has changed and needs to be versioned.
-        # If called with a single parameter, gets whether the parameter has changed.
-        def changed?(attr_name = nil)
-          attr_name.nil? ?
-            (!self.class.track_altered_attributes || (altered_attributes && altered_attributes.length > 0)) :
-            (altered_attributes && altered_attributes.include?(attr_name.to_s))
-        end
-
-        # keep old dirty? method
-        alias_method :dirty?, :changed?
-
-        # Clones a model.  Used when saving a new version or reverting a model's version.
-        def clone_versioned_model(orig_model, new_model)
-          self.versioned_attributes.each do |key|
-            new_model.send("#{key}=", orig_model.send(key)) if orig_model.respond_to?(key)
-          end
-
-          if self.class.columns_hash.include?(self.class.inheritance_column)
-            if orig_model.is_a?(self.class.versioned_class)
-              new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
-            elsif new_model.is_a?(self.class.versioned_class)
-              new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
-            end
-          end
-        end
-
-        # Checks whether a new version shall be saved or not.  Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
-        def save_version?
-          version_condition_met? && changed?
-        end
-
-        # Checks condition set in the :if option to check whether a revision should be created or not.  Override this for
-        # custom version condition checking.
-        def version_condition_met?
-          case
-          when version_condition.is_a?(Symbol)
-            send(version_condition)
-          when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1)
-            version_condition.call(self)
-          else
-            version_condition
-          end
-        end
-
-        # Executes the block with the versioning callbacks disabled.
-        #
-        #   @foo.without_revision do
-        #     @foo.save
-        #   end
-        #
-        def without_revision(&block)
-          self.class.without_revision(&block)
-        end
-
-        # Turns off optimistic locking for the duration of the block
-        #
-        #   @foo.without_locking do
-        #     @foo.save
-        #   end
-        #
-        def without_locking(&block)
-          self.class.without_locking(&block)
-        end
-
-        def empty_callback() end #:nodoc:
-
-        protected
-          # sets the new version before saving, unless you're using optimistic locking.  In that case, let it take care of the version.
-          def set_new_version
-            self.send("#{self.class.version_column}=", self.next_version) if new_record? || (!locking_enabled? && save_version?)
-          end
-
-          # Gets the next available version for the current record, or 1 for a new record
-          def next_version
-            return 1 if new_record?
-            (versions.maximum('version') || 0) + 1
-          end
-
-          # clears current changed attributes.  Called after save.
-          def clear_altered_attributes
-            self.altered_attributes = []
-          end
-
-          def write_changed_attribute(attr_name, attr_value)
-            # Convert to db type for comparison. Avoids failing Float<=>String comparisons.
-            attr_value_for_db = self.class.columns_hash[attr_name.to_s].type_cast_from_database(attr_value)
-            (self.altered_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) || self.send(attr_name) == attr_value_for_db
-            write_attribute(attr_name, attr_value_for_db)
-          end
-
-        module ClassMethods
-          # Finds a specific version of a specific row of this model
-          def find_version(id, version = nil)
-            return find(id) unless version
-
-            conditions = ["#{versioned_foreign_key} = ? AND version = ?", id, version]
-            options = { :conditions => conditions, :limit => 1 }
-
-            if result = find_versions(id, options).first
-              result
-            else
-              raise RecordNotFound, "Couldn't find #{name} with ID=#{id} and VERSION=#{version}"
-            end
-          end
-
-          # Finds versions of a specific model.  Takes an options hash like <tt>find</tt>
-          def find_versions(id, options = {})
-            versioned_class.
-                where(options[:conditions] || {versioned_foreign_key => id}).
-                limit(options[:limit]).
-                order('version')
-          end
-
-          # Returns an array of columns that are versioned.  See non_versioned_columns
-          def versioned_columns
-            self.columns.select { |c| !non_versioned_columns.include?(c.name) }
-          end
-
-          # Returns an instance of the dynamic versioned model
-          def versioned_class
-            const_get versioned_class_name
-          end
-
-          # Rake migration task to create the versioned table using options passed to acts_as_versioned
-          def create_versioned_table(create_table_options = {})
-            # 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 && %(updated_at updated_on).include?(col.name)
-              self.connection.add_column versioned_table_name, col.name, col.type, 
-                :limit => col.limit, 
-                :default => col.default,
-                :scale => col.scale,
-                :precision => col.precision
-            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,
-                :scale => type_col.scale,
-                :precision => type_col.precision
-            end
-
-            if updated_col.nil?
-              self.connection.add_column versioned_table_name, :updated_at, :timestamp
-            end
-          end
-
-          # Rake migration task to drop the versioned table
-          def drop_versioned_table
-            self.connection.drop_table versioned_table_name
-          end
-
-          # Executes the block with the versioning callbacks disabled.
-          #
-          #   Foo.without_revision do
-          #     @foo.save
-          #   end
-          #
-          def without_revision(&block)
-            class_eval do 
-              CALLBACKS.each do |attr_name|
-                alias_method "orig_#{attr_name}".to_sym, attr_name
-                alias_method attr_name, :empty_callback
-              end
-            end
-            block.call
-          ensure
-            class_eval do 
-              CALLBACKS.each do |attr_name|
-                alias_method attr_name, "orig_#{attr_name}".to_sym
-              end
-            end
-          end
-
-          # Turns off optimistic locking for the duration of the block
-          #
-          #   Foo.without_locking do
-          #     @foo.save
-          #   end
-          #
-          def without_locking(&block)
-            current = ActiveRecord::Base.lock_optimistically
-            ActiveRecord::Base.lock_optimistically = false if current
-            result = block.call
-            ActiveRecord::Base.lock_optimistically = true if current
-            result
-          end
-        end
-      end
-    end
-  end
-end
-
-ActiveRecord::Base.send :include, ActiveRecord::Acts::Versioned
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/abstract_unit.rb b/lib/plugins/acts_as_versioned/test/abstract_unit.rb
deleted file mode 100644 (file)
index 86f5062..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + '/../../../rails/activesupport/lib')
-$:.unshift(File.dirname(__FILE__) + '/../../../rails/activerecord/lib')
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-require 'test/unit'
-begin
-  require 'active_support'
-  require 'active_record'
-  require 'active_record/fixtures'
-rescue LoadError
-  require 'rubygems'
-  retry
-end
-require 'acts_as_versioned'
-
-config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
-ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
-ActiveRecord::Base.configurations = {'test' => config[ENV['DB'] || 'sqlite3']}
-ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
-
-load(File.dirname(__FILE__) + "/schema.rb")
-
-# set up custom sequence on widget_versions for DBs that support sequences
-if ENV['DB'] == 'postgresql'
-  ActiveRecord::Base.connection.execute "DROP SEQUENCE widgets_seq;" rescue nil
-  ActiveRecord::Base.connection.remove_column :widget_versions, :id
-  ActiveRecord::Base.connection.execute "CREATE SEQUENCE widgets_seq START 101;"
-  ActiveRecord::Base.connection.execute "ALTER TABLE widget_versions ADD COLUMN id INTEGER PRIMARY KEY DEFAULT nextval('widgets_seq');"
-end
-
-Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
-$:.unshift(Test::Unit::TestCase.fixture_path)
-
-class Test::Unit::TestCase #:nodoc:
-  # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
-  self.use_transactional_fixtures = true
-  
-  # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
-  self.use_instantiated_fixtures  = false
-
-  # Add more helper methods to be used by all tests here...
-end
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/database.yml b/lib/plugins/acts_as_versioned/test/database.yml
deleted file mode 100644 (file)
index 506e6bd..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-sqlite:
-  :adapter: sqlite
-  :dbfile: acts_as_versioned_plugin.sqlite.db
-sqlite3:
-  :adapter: sqlite3
-  :dbfile: acts_as_versioned_plugin.sqlite3.db
-postgresql:
-  :adapter: postgresql
-  :username: postgres
-  :password: postgres
-  :database: acts_as_versioned_plugin_test
-  :min_messages: ERROR
-mysql:
-  :adapter: mysql
-  :host: localhost
-  :username: rails
-  :password:
-  :database: acts_as_versioned_plugin_test
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/authors.yml b/lib/plugins/acts_as_versioned/test/fixtures/authors.yml
deleted file mode 100644 (file)
index bd7a5ae..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-caged:
-  id: 1
-  name: caged
-mly:
-  id: 2
-  name: mly
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/landmark.rb b/lib/plugins/acts_as_versioned/test/fixtures/landmark.rb
deleted file mode 100644 (file)
index cb9b930..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-class Landmark < ActiveRecord::Base
-  acts_as_versioned :if_changed => [ :name, :longitude, :latitude ]
-end
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/landmark_versions.yml b/lib/plugins/acts_as_versioned/test/fixtures/landmark_versions.yml
deleted file mode 100644 (file)
index 2dbd54e..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-washington:
-    id: 1
-    landmark_id: 1
-    version: 1
-    name: Washington, D.C.
-    latitude: 38.895
-    longitude: -77.036667
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/landmarks.yml b/lib/plugins/acts_as_versioned/test/fixtures/landmarks.yml
deleted file mode 100644 (file)
index 46d9617..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-washington:
-    id: 1
-    name: Washington, D.C.
-    latitude: 38.895
-    longitude: -77.036667
-    version: 1
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/locked_pages.yml b/lib/plugins/acts_as_versioned/test/fixtures/locked_pages.yml
deleted file mode 100644 (file)
index 318e776..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-welcome:
-  id: 1
-  title: Welcome to the weblog
-  lock_version: 24
-  type: LockedPage
-thinking:
-  id: 2
-  title: So I was thinking
-  lock_version: 24
-  type: SpecialLockedPage
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/locked_pages_revisions.yml b/lib/plugins/acts_as_versioned/test/fixtures/locked_pages_revisions.yml
deleted file mode 100644 (file)
index 5c978e6..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-welcome_1:
-  id: 1
-  page_id: 1
-  title: Welcome to the weblg
-  version: 23
-  version_type: LockedPage
-
-welcome_2:
-  id: 2
-  page_id: 1
-  title: Welcome to the weblog
-  version: 24
-  version_type: LockedPage
-
-thinking_1:
-  id: 3
-  page_id: 2
-  title: So I was thinking!!!
-  version: 23
-  version_type: SpecialLockedPage
-
-thinking_2:
-  id: 4
-  page_id: 2
-  title: So I was thinking
-  version: 24
-  version_type: SpecialLockedPage
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/migrations/1_add_versioned_tables.rb b/lib/plugins/acts_as_versioned/test/fixtures/migrations/1_add_versioned_tables.rb
deleted file mode 100644 (file)
index 9512b5e..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-class AddVersionedTables < ActiveRecord::Migration
-  def self.up
-    create_table("things") do |t|
-      t.column :title, :text
-    end
-    Thing.create_versioned_table
-  end
-  
-  def self.down
-    Thing.drop_versioned_table
-    drop_table "things" rescue nil
-  end
-end
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/page.rb b/lib/plugins/acts_as_versioned/test/fixtures/page.rb
deleted file mode 100644 (file)
index f133e35..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-class Page < ActiveRecord::Base
-  belongs_to :author
-  has_many   :authors,  :through => :versions, :order => 'name'
-  belongs_to :revisor,  :class_name => 'Author'
-  has_many   :revisors, :class_name => 'Author', :through => :versions, :order => 'name'
-  acts_as_versioned :if => :feeling_good? do
-    def self.included(base)
-      base.cattr_accessor :feeling_good
-      base.feeling_good = true
-      base.belongs_to :author
-      base.belongs_to :revisor, :class_name => 'Author'
-    end
-    
-    def feeling_good?
-      @@feeling_good == true
-    end
-  end
-end
-
-module LockedPageExtension
-  def hello_world
-    'hello_world'
-  end
-end
-
-class LockedPage < ActiveRecord::Base
-  acts_as_versioned \
-    :inheritance_column => :version_type, 
-    :foreign_key        => :page_id, 
-    :table_name         => :locked_pages_revisions, 
-    :class_name         => 'LockedPageRevision',
-    :version_column     => :lock_version,
-    :limit              => 2,
-    :if_changed         => :title,
-    :extend             => LockedPageExtension
-end
-
-class SpecialLockedPage < LockedPage
-end
-
-class Author < ActiveRecord::Base
-  has_many :pages
-end
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/page_versions.yml b/lib/plugins/acts_as_versioned/test/fixtures/page_versions.yml
deleted file mode 100644 (file)
index ef565fa..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-welcome_2:
-  id: 1
-  page_id: 1
-  title: Welcome to the weblog
-  body: Such a lovely day
-  version: 24
-  author_id: 1
-  revisor_id: 1
-welcome_1:
-  id: 2
-  page_id: 1
-  title: Welcome to the weblg
-  body: Such a lovely day
-  version: 23
-  author_id: 2
-  revisor_id: 2
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/pages.yml b/lib/plugins/acts_as_versioned/test/fixtures/pages.yml
deleted file mode 100644 (file)
index 07ac51f..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-welcome:
-  id: 1
-  title: Welcome to the weblog
-  body: Such a lovely day
-  version: 24
-  author_id: 1
-  revisor_id: 1
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/fixtures/widget.rb b/lib/plugins/acts_as_versioned/test/fixtures/widget.rb
deleted file mode 100644 (file)
index 086ac2b..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-class Widget < ActiveRecord::Base
-  acts_as_versioned :sequence_name => 'widgets_seq', :association_options => {
-    :dependent => :nullify, :order => 'version desc'
-  }
-  non_versioned_columns << 'foo'
-end
\ No newline at end of file
diff --git a/lib/plugins/acts_as_versioned/test/migration_test.rb b/lib/plugins/acts_as_versioned/test/migration_test.rb
deleted file mode 100644 (file)
index 4ead4a8..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-require File.join(File.dirname(__FILE__), 'abstract_unit')
-
-if ActiveRecord::Base.connection.supports_migrations? 
-  class Thing < ActiveRecord::Base
-    attr_accessor :version
-    acts_as_versioned
-  end
-
-  class MigrationTest < Test::Unit::TestCase
-    self.use_transactional_fixtures = false
-    def teardown
-      if ActiveRecord::Base.connection.respond_to?(:initialize_schema_information)
-        ActiveRecord::Base.connection.initialize_schema_information
-        ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
-      else
-        ActiveRecord::Base.connection.initialize_schema_migrations_table
-        ActiveRecord::Base.connection.assume_migrated_upto_version(0)
-      end
-      
-      Thing.connection.drop_table "things" rescue nil
-      Thing.connection.drop_table "thing_versions" rescue nil
-      Thing.reset_column_information
-    end
-        
-    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', :price => 123.45, :type => 'Thing'
-      assert_equal 1, t.versions.size
-      
-      # check that the price column has remembered its value correctly
-      assert_equal t.price,  t.versions.first.price
-      assert_equal t.title,  t.versions.first.title
-      assert_equal t[:type], t.versions.first[:type]
-      
-      # make sure that the precision of the price column has been preserved
-      assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision
-      assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale
-
-      # 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
diff --git a/lib/plugins/acts_as_versioned/test/schema.rb b/lib/plugins/acts_as_versioned/test/schema.rb
deleted file mode 100644 (file)
index 7d5153d..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-ActiveRecord::Schema.define(:version => 0) do
-  create_table :pages, :force => true do |t|
-    t.column :version, :integer
-    t.column :title, :string, :limit => 255
-    t.column :body, :text
-    t.column :updated_on, :datetime
-    t.column :author_id, :integer
-    t.column :revisor_id, :integer
-  end
-
-  create_table :page_versions, :force => true do |t|
-    t.column :page_id, :integer
-    t.column :version, :integer
-    t.column :title, :string, :limit => 255
-    t.column :body, :text
-    t.column :updated_on, :datetime
-    t.column :author_id, :integer
-    t.column :revisor_id, :integer
-  end
-  
-  create_table :authors, :force => true do |t|
-    t.column :page_id, :integer
-    t.column :name, :string
-  end
-  
-  create_table :locked_pages, :force => true do |t|
-    t.column :lock_version, :integer
-    t.column :title, :string, :limit => 255
-    t.column :type, :string, :limit => 255
-  end
-
-  create_table :locked_pages_revisions, :force => true do |t|
-    t.column :page_id, :integer
-    t.column :version, :integer
-    t.column :title, :string, :limit => 255
-    t.column :version_type, :string, :limit => 255
-    t.column :updated_at, :datetime
-  end
-
-  create_table :widgets, :force => true do |t|
-    t.column :name, :string, :limit => 50
-    t.column :foo, :string
-    t.column :version, :integer
-    t.column :updated_at, :datetime
-  end
-
-  create_table :widget_versions, :force => true do |t|
-    t.column :widget_id, :integer
-    t.column :name, :string, :limit => 50
-    t.column :version, :integer
-    t.column :updated_at, :datetime
-  end
-  
-  create_table :landmarks, :force => true do |t|
-    t.column :name, :string
-    t.column :latitude, :float
-    t.column :longitude, :float
-    t.column :version, :integer
-  end
-
-  create_table :landmark_versions, :force => true do |t|
-    t.column :landmark_id, :integer
-    t.column :name, :string
-    t.column :latitude, :float
-    t.column :longitude, :float
-    t.column :version, :integer
-  end
-end
diff --git a/lib/plugins/acts_as_versioned/test/versioned_test.rb b/lib/plugins/acts_as_versioned/test/versioned_test.rb
deleted file mode 100644 (file)
index a7bc208..0000000
+++ /dev/null
@@ -1,347 +0,0 @@
-require File.join(File.dirname(__FILE__), 'abstract_unit')
-require File.join(File.dirname(__FILE__), 'fixtures/page')
-require File.join(File.dirname(__FILE__), 'fixtures/widget')
-
-class VersionedTest < Test::Unit::TestCase
-  fixtures :pages, :page_versions, :locked_pages, :locked_pages_revisions, :authors, :landmarks, :landmark_versions
-  set_fixture_class :page_versions => Page::Version
-
-  def test_saves_versioned_copy
-    p = Page.create! :title => 'first title', :body => 'first body'
-    assert !p.new_record?
-    assert_equal 1, p.versions.size
-    assert_equal 1, p.version
-    assert_instance_of Page.versioned_class, p.versions.first
-  end
-
-  def test_saves_without_revision
-    p = pages(:welcome)
-    old_versions = p.versions.count
-
-    p.save_without_revision
-
-    p.without_revision do
-      p.update_attributes :title => 'changed'
-    end
-
-    assert_equal old_versions, p.versions.count
-  end
-
-  def test_rollback_with_version_number
-    p = pages(:welcome)
-    assert_equal 24, p.version
-    assert_equal 'Welcome to the weblog', p.title
-
-    assert p.revert_to!(p.versions.first.version), "Couldn't revert to 23"
-    assert_equal 23, p.version
-    assert_equal 'Welcome to the weblg', p.title
-  end
-
-  def test_versioned_class_name
-    assert_equal 'Version', Page.versioned_class_name
-    assert_equal 'LockedPageRevision', LockedPage.versioned_class_name
-  end
-
-  def test_versioned_class
-    assert_equal Page::Version,                  Page.versioned_class
-    assert_equal LockedPage::LockedPageRevision, LockedPage.versioned_class
-  end
-
-  def test_special_methods
-    assert_nothing_raised { pages(:welcome).feeling_good? }
-    assert_nothing_raised { pages(:welcome).versions.first.feeling_good? }
-    assert_nothing_raised { locked_pages(:welcome).hello_world }
-    assert_nothing_raised { locked_pages(:welcome).versions.first.hello_world }
-  end
-
-  def test_rollback_with_version_class
-    p = pages(:welcome)
-    assert_equal 24, p.version
-    assert_equal 'Welcome to the weblog', p.title
-
-    assert p.revert_to!(p.versions.first), "Couldn't revert to 23"
-    assert_equal 23, p.version
-    assert_equal 'Welcome to the weblg', p.title
-  end
-
-  def test_rollback_fails_with_invalid_revision
-    p = locked_pages(:welcome)
-    assert !p.revert_to!(locked_pages(:thinking))
-  end
-
-  def test_saves_versioned_copy_with_options
-    p = LockedPage.create! :title => 'first title'
-    assert !p.new_record?
-    assert_equal 1, p.versions.size
-    assert_instance_of LockedPage.versioned_class, p.versions.first
-  end
-
-  def test_rollback_with_version_number_with_options
-    p = locked_pages(:welcome)
-    assert_equal 'Welcome to the weblog', p.title
-    assert_equal 'LockedPage', p.versions.first.version_type
-
-    assert p.revert_to!(p.versions.first.version), "Couldn't revert to 23"
-    assert_equal 'Welcome to the weblg', p.title
-    assert_equal 'LockedPage', p.versions.first.version_type
-  end
-
-  def test_rollback_with_version_class_with_options
-    p = locked_pages(:welcome)
-    assert_equal 'Welcome to the weblog', p.title
-    assert_equal 'LockedPage', p.versions.first.version_type
-
-    assert p.revert_to!(p.versions.first), "Couldn't revert to 1"
-    assert_equal 'Welcome to the weblg', p.title
-    assert_equal 'LockedPage', p.versions.first.version_type
-  end
-
-  def test_saves_versioned_copy_with_sti
-    p = SpecialLockedPage.create! :title => 'first title'
-    assert !p.new_record?
-    assert_equal 1, p.versions.size
-    assert_instance_of LockedPage.versioned_class, p.versions.first
-    assert_equal 'SpecialLockedPage', p.versions.first.version_type
-  end
-
-  def test_rollback_with_version_number_with_sti
-    p = locked_pages(:thinking)
-    assert_equal 'So I was thinking', p.title
-
-    assert p.revert_to!(p.versions.first.version), "Couldn't revert to 1"
-    assert_equal 'So I was thinking!!!', p.title
-    assert_equal 'SpecialLockedPage', p.versions.first.version_type
-  end
-
-  def test_lock_version_works_with_versioning
-    p = locked_pages(:thinking)
-    p2 = LockedPage.find(p.id)
-
-    p.title = 'fresh title'
-    p.save
-    assert_equal 2, p.versions.size # limit!
-
-    assert_raises(ActiveRecord::StaleObjectError) do
-      p2.title = 'stale title'
-      p2.save
-    end
-  end
-
-  def test_version_if_condition
-    p = Page.create! :title => "title"
-    assert_equal 1, p.version
-
-    Page.feeling_good = false
-    p.save
-    assert_equal 1, p.version
-    Page.feeling_good = true
-  end
-
-  def test_version_if_condition2
-    # set new if condition
-    Page.class_eval do
-      def new_feeling_good() title[0..0] == 'a'; end
-      alias_method :old_feeling_good, :feeling_good?
-      alias_method :feeling_good?, :new_feeling_good
-    end
-
-    p = Page.create! :title => "title"
-    assert_equal 1, p.version # version does not increment
-    assert_equal 1, p.versions(true).size
-
-    p.update_attributes(:title => 'new title')
-    assert_equal 1, p.version # version does not increment
-    assert_equal 1, p.versions(true).size
-
-    p.update_attributes(:title => 'a title')
-    assert_equal 2, p.version
-    assert_equal 2, p.versions(true).size
-
-    # reset original if condition
-    Page.class_eval { alias_method :feeling_good?, :old_feeling_good }
-  end
-
-  def test_version_if_condition_with_block
-    # set new if condition
-    old_condition = Page.version_condition
-    Page.version_condition = Proc.new { |page| page.title[0..0] == 'b' }
-
-    p = Page.create! :title => "title"
-    assert_equal 1, p.version # version does not increment
-    assert_equal 1, p.versions(true).size
-
-    p.update_attributes(:title => 'a title')
-    assert_equal 1, p.version # version does not increment
-    assert_equal 1, p.versions(true).size
-
-    p.update_attributes(:title => 'b title')
-    assert_equal 2, p.version
-    assert_equal 2, p.versions(true).size
-
-    # reset original if condition
-    Page.version_condition = old_condition
-  end
-
-  def test_version_no_limit
-    p = Page.create! :title => "title", :body => 'first body'
-    p.save
-    p.save
-    5.times do |i|
-      assert_page_title p, i
-    end
-  end
-
-  def test_version_max_limit
-    p = LockedPage.create! :title => "title"
-    p.update_attributes(:title => "title1")
-    p.update_attributes(:title => "title2")
-    5.times do |i|
-      assert_page_title p, i, :lock_version
-      assert p.versions(true).size <= 2, "locked version can only store 2 versions"
-    end
-  end
-
-  def test_track_altered_attributes_default_value
-    assert !Page.track_altered_attributes
-    assert LockedPage.track_altered_attributes
-    assert SpecialLockedPage.track_altered_attributes
-  end
-
-  def test_version_order
-    assert_equal 23, pages(:welcome).versions.first.version
-    assert_equal 24, pages(:welcome).versions.last.version
-  end
-
-  def test_track_altered_attributes
-    p = LockedPage.create! :title => "title"
-    assert_equal 1, p.lock_version
-    assert_equal 1, p.versions(true).size
-
-    p.title = 'title'
-    assert !p.save_version?
-    p.save
-    assert_equal 2, p.lock_version # still increments version because of optimistic locking
-    assert_equal 1, p.versions(true).size
-
-    p.title = 'updated title'
-    assert p.save_version?
-    p.save
-    assert_equal 3, p.lock_version
-    assert_equal 1, p.versions(true).size # version 1 deleted
-
-    p.title = 'updated title!'
-    assert p.save_version?
-    p.save
-    assert_equal 4, p.lock_version
-    assert_equal 2, p.versions(true).size # version 1 deleted
-  end
-
-  def assert_page_title(p, i, version_field = :version)
-    p.title = "title#{i}"
-    p.save
-    assert_equal "title#{i}", p.title
-    assert_equal (i+4), p.send(version_field)
-  end
-
-  def test_find_versions
-    assert_equal 2, locked_pages(:welcome).versions.size
-    assert_equal 1, locked_pages(:welcome).versions.find(:all, :conditions => ['title LIKE ?', '%weblog%']).length
-    assert_equal 2, locked_pages(:welcome).versions.find(:all, :conditions => ['title LIKE ?', '%web%']).length
-    assert_equal 0, locked_pages(:thinking).versions.find(:all, :conditions => ['title LIKE ?', '%web%']).length
-    assert_equal 2, locked_pages(:welcome).versions.length
-  end
-
-  def test_find_version
-    assert_equal page_versions(:welcome_1), Page.find_version(pages(:welcome).id, 23)
-    assert_equal page_versions(:welcome_2), Page.find_version(pages(:welcome).id, 24)
-    assert_equal pages(:welcome), Page.find_version(pages(:welcome).id)
-
-    assert_equal page_versions(:welcome_1), pages(:welcome).find_version(23)
-    assert_equal page_versions(:welcome_2), pages(:welcome).find_version(24)
-    assert_equal pages(:welcome), pages(:welcome).find_version
-
-    assert_raise(ActiveRecord::RecordNotFound) { Page.find_version(pages(:welcome).id, 1) }
-    assert_raise(ActiveRecord::RecordNotFound) { Page.find_version(0, 23) }
-  end
-
-  def test_with_sequence
-    assert_equal 'widgets_seq', Widget.versioned_class.sequence_name
-    3.times { Widget.create! :name => 'new widget' }
-    assert_equal 3, Widget.count
-    assert_equal 3, Widget.versioned_class.count
-  end
-
-  def test_has_many_through
-    assert_equal [authors(:caged), authors(:mly)], pages(:welcome).authors
-  end
-
-  def test_has_many_through_with_custom_association
-    assert_equal [authors(:caged), authors(:mly)], pages(:welcome).revisors
-  end
-
-  def test_referential_integrity
-    pages(:welcome).destroy
-    assert_equal 0, Page.count
-    assert_equal 0, Page::Version.count
-  end
-
-  def test_association_options
-    association = Page.reflect_on_association(:versions)
-    options = association.options
-    assert_equal :delete_all, options[:dependent]
-    assert_equal 'version', options[:order]
-
-    association = Widget.reflect_on_association(:versions)
-    options = association.options
-    assert_equal :nullify, options[:dependent]
-    assert_equal 'version desc', options[:order]
-    assert_equal 'widget_id', options[:foreign_key]
-
-    widget = Widget.create! :name => 'new widget'
-    assert_equal 1, Widget.count
-    assert_equal 1, Widget.versioned_class.count
-    widget.destroy
-    assert_equal 0, Widget.count
-    assert_equal 1, Widget.versioned_class.count
-  end
-
-  def test_versioned_records_should_belong_to_parent
-    page = pages(:welcome)
-    page_version = page.versions.last
-    assert_equal page, page_version.page
-  end
-
-  def test_unaltered_attributes
-    landmarks(:washington).attributes = landmarks(:washington).attributes.except("id")
-    assert !landmarks(:washington).changed?
-  end
-
-  def test_unchanged_string_attributes
-    landmarks(:washington).attributes = landmarks(:washington).attributes.except("id").inject({}) { |params, (key, value)| params.update(key => value.to_s) }
-    assert !landmarks(:washington).changed?
-  end
-
-  def test_should_find_earliest_version
-    assert_equal page_versions(:welcome_1), pages(:welcome).versions.earliest
-  end
-
-  def test_should_find_latest_version
-    assert_equal page_versions(:welcome_2), pages(:welcome).versions.latest
-  end
-
-  def test_should_find_previous_version
-    assert_equal page_versions(:welcome_1), page_versions(:welcome_2).previous
-    assert_equal page_versions(:welcome_1), pages(:welcome).versions.before(page_versions(:welcome_2))
-  end
-
-  def test_should_find_next_version
-    assert_equal page_versions(:welcome_2), page_versions(:welcome_1).next
-    assert_equal page_versions(:welcome_2), pages(:welcome).versions.after(page_versions(:welcome_1))
-  end
-
-  def test_should_find_version_count
-    assert_equal 24, pages(:welcome).versions_count
-    assert_equal 24, page_versions(:welcome_1).versions_count
-    assert_equal 24, page_versions(:welcome_2).versions_count
-  end
-end
\ No newline at end of file
index 98d076cbdf2fac0496bbcf442a2f31c9e2b751c0..7260d9094ea60505beab05fe54d7b3ff0538f422 100644 (file)
@@ -336,7 +336,7 @@ class WikiControllerTest < Redmine::ControllerTest
     @request.session[:user_id] = 2
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_difference 'WikiContent::Version.count' do
+        assert_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Another_page',
@@ -361,7 +361,7 @@ class WikiControllerTest < Redmine::ControllerTest
     @request.session[:user_id] = 2
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_difference 'WikiContent::Version.count' do
+        assert_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Another_page',
@@ -388,7 +388,7 @@ class WikiControllerTest < Redmine::ControllerTest
     @request.session[:user_id] = 2
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_no_difference 'WikiContent::Version.count' do
+        assert_no_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Another_page',
@@ -414,7 +414,7 @@ class WikiControllerTest < Redmine::ControllerTest
     @request.session[:user_id] = 2
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_no_difference 'WikiContent::Version.count' do
+        assert_no_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Another_page',
@@ -437,7 +437,7 @@ class WikiControllerTest < Redmine::ControllerTest
     @request.session[:user_id] = 2
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_no_difference 'WikiContent::Version.count' do
+        assert_no_difference 'WikiContentVersion.count' do
           assert_difference 'Attachment.count' do
             put :update, :params => {
               :project_id => 1,
@@ -466,7 +466,7 @@ class WikiControllerTest < Redmine::ControllerTest
 
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_no_difference 'WikiContent::Version.count' do
+        assert_no_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Another_page',
@@ -514,7 +514,7 @@ class WikiControllerTest < Redmine::ControllerTest
 
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_difference 'WikiContent::Version.count' do
+        assert_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Page_with_sections',
@@ -540,7 +540,7 @@ class WikiControllerTest < Redmine::ControllerTest
 
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_difference 'WikiContent::Version.count' do
+        assert_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Page_with_sections',
@@ -565,7 +565,7 @@ class WikiControllerTest < Redmine::ControllerTest
 
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_no_difference 'WikiContent::Version.count' do
+        assert_no_difference 'WikiContentVersion.count' do
           put :update, :params => {
             :project_id => 1,
             :id => 'Page_with_sections',
@@ -652,7 +652,7 @@ class WikiControllerTest < Redmine::ControllerTest
 
   def test_diff
     content = WikiPage.find(1).content
-    assert_difference 'WikiContent::Version.count', 2 do
+    assert_difference 'WikiContentVersion.count', 2 do
       content.text = "Line removed\nThis is a sample text for testing diffs"
       content.save!
       content.text = "This is a sample text for testing diffs\nLine added"
@@ -893,7 +893,7 @@ class WikiControllerTest < Redmine::ControllerTest
 
   def test_destroy_version
     @request.session[:user_id] = 2
-    assert_difference 'WikiContent::Version.count', -1 do
+    assert_difference 'WikiContentVersion.count', -1 do
       assert_no_difference 'WikiContent.count' do
         assert_no_difference 'WikiPage.count' do
           delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2}
@@ -905,7 +905,7 @@ class WikiControllerTest < Redmine::ControllerTest
 
   def test_destroy_invalid_version_should_respond_with_404
     @request.session[:user_id] = 2
-    assert_no_difference 'WikiContent::Version.count' do
+    assert_no_difference 'WikiContentVersion.count' do
       assert_no_difference 'WikiContent.count' do
         assert_no_difference 'WikiPage.count' do
           delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 99}
index 8f9678b9121446b3d37b937523f7340369a2300f..d3cb7442726308a7b28a13b761415d0a9a54be1e 100644 (file)
@@ -61,14 +61,14 @@ class WikiContentTest < ActiveSupport::TestCase
     content = @page.content
     version_count = content.version
     content.text = "My new content"
-    assert_difference 'WikiContent::Version.count' do
+    assert_difference 'WikiContentVersion.count' do
       assert content.save
     end
     content.reload
     assert_equal version_count+1, content.version
     assert_equal version_count+1, content.versions.length
 
-    version = WikiContent::Version.order('id DESC').first
+    version = WikiContentVersion.order('id DESC').first
     assert_equal @page.id, version.page_id
     assert_equal '', version.compression
     assert_equal "My new content", version.data
@@ -79,12 +79,12 @@ class WikiContentTest < ActiveSupport::TestCase
     with_settings :wiki_compression => 'gzip' do
       content = @page.content
       content.text = "My new content"
-      assert_difference 'WikiContent::Version.count' do
+      assert_difference 'WikiContentVersion.count' do
         assert content.save
       end
     end
 
-    version = WikiContent::Version.order('id DESC').first
+    version = WikiContentVersion.order('id DESC').first
     assert_equal @page.id, version.page_id
     assert_equal 'gzip', version.compression
     assert_not_equal "My new content", version.data
@@ -127,39 +127,39 @@ class WikiContentTest < ActiveSupport::TestCase
   end
 
   def test_previous_for_first_version_should_return_nil
-    content = WikiContent::Version.find_by_page_id_and_version(1, 1)
+    content = WikiContentVersion.find_by_page_id_and_version(1, 1)
     assert_nil content.previous
   end
 
   def test_previous_for_version_should_return_previous_version
-    content = WikiContent::Version.find_by_page_id_and_version(1, 3)
+    content = WikiContentVersion.find_by_page_id_and_version(1, 3)
     assert_not_nil content.previous
     assert_equal 2, content.previous.version
   end
 
   def test_previous_for_version_with_gap_should_return_previous_available_version
-    WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
+    WikiContentVersion.find_by_page_id_and_version(1, 2).destroy
 
-    content = WikiContent::Version.find_by_page_id_and_version(1, 3)
+    content = WikiContentVersion.find_by_page_id_and_version(1, 3)
     assert_not_nil content.previous
     assert_equal 1, content.previous.version
   end
 
   def test_next_for_last_version_should_return_nil
-    content = WikiContent::Version.find_by_page_id_and_version(1, 3)
+    content = WikiContentVersion.find_by_page_id_and_version(1, 3)
     assert_nil content.next
   end
 
   def test_next_for_version_should_return_next_version
-    content = WikiContent::Version.find_by_page_id_and_version(1, 1)
+    content = WikiContentVersion.find_by_page_id_and_version(1, 1)
     assert_not_nil content.next
     assert_equal 2, content.next.version
   end
 
   def test_next_for_version_with_gap_should_return_next_available_version
-    WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
+    WikiContentVersion.find_by_page_id_and_version(1, 2).destroy
 
-    content = WikiContent::Version.find_by_page_id_and_version(1, 1)
+    content = WikiContentVersion.find_by_page_id_and_version(1, 1)
     assert_not_nil content.next
     assert_equal 3, content.next.version
   end
index d6fe0a556df8115889b47d109a82f44a81ed9f42..9252e3a9c3a3b679923cd67b3f8c1d3b0b2522f7 100644 (file)
@@ -24,24 +24,24 @@ class WikiContentVersionTest < ActiveSupport::TestCase
   end
 
   def test_should_respond_to_attachments
-    v = WikiContent::Version.find(2)
+    v = WikiContentVersion.find(2)
     assert v.respond_to?(:attachments)
   end
 
   def test_destroy
-    v = WikiContent::Version.find(2)
+    v = WikiContentVersion.find(2)
 
-    assert_difference 'WikiContent::Version.count', -1 do
+    assert_difference 'WikiContentVersion.count', -1 do
       v.destroy
     end
   end
 
   def test_destroy_last_version_should_revert_content
-    v = WikiContent::Version.find(3)
+    v = WikiContentVersion.find(3)
 
     assert_no_difference 'WikiPage.count' do
       assert_no_difference 'WikiContent.count' do
-        assert_difference 'WikiContent::Version.count', -1 do
+        assert_difference 'WikiContentVersion.count', -1 do
           assert v.destroy
         end
       end
@@ -57,13 +57,13 @@ class WikiContentVersionTest < ActiveSupport::TestCase
   end
 
   def test_destroy_all_versions_should_delete_page
-    WikiContent::Version.find(1).destroy
-    WikiContent::Version.find(2).destroy
-    v = WikiContent::Version.find(3)
+    WikiContentVersion.find(1).destroy
+    WikiContentVersion.find(2).destroy
+    v = WikiContentVersion.find(3)
 
     assert_difference 'WikiPage.count', -1 do
       assert_difference 'WikiContent.count', -1 do
-        assert_difference 'WikiContent::Version.count', -1 do
+        assert_difference 'WikiContentVersion.count', -1 do
           assert v.destroy
         end
       end
index cbd292285dc0697dd9c741bb86ed5f03d2020931..21744572cab7a03fb22f46e345b77a9cf90ead29 100644 (file)
@@ -145,7 +145,7 @@ class WikiPageTest < ActiveSupport::TestCase
     assert_nil WikiPage.find_by_id(1)
     # make sure that page content and its history are deleted
     assert_equal 0, WikiContent.where(:page_id => 1).count
-    assert_equal 0, WikiContent.versioned_class.where(:page_id => 1).count
+    assert_equal 0, WikiContentVersion.where(:page_id => 1).count
   end
 
   def test_destroy_should_not_nullify_children