diff --git a/config/initializers/version_polymorphic_overrides.rb b/config/initializers/version_polymorphic_overrides.rb new file mode 100644 index 00000000000..6a2c2984fb9 --- /dev/null +++ b/config/initializers/version_polymorphic_overrides.rb @@ -0,0 +1,8 @@ +Version.class_eval do + include PolymorphicTypeOverride + + override_polymorphic_types versionable_type: { + 'Quiz' => 'Quizzes::Quiz', + 'QuizSubmission' => 'Quizzes::QuizSubmission' + } +end diff --git a/vendor/plugins/simply_versioned/CHANGES b/gems/plugins/simply_versioned/CHANGES similarity index 100% rename from vendor/plugins/simply_versioned/CHANGES rename to gems/plugins/simply_versioned/CHANGES diff --git a/vendor/plugins/simply_versioned/MIT-LICENSE b/gems/plugins/simply_versioned/MIT-LICENSE similarity index 91% rename from vendor/plugins/simply_versioned/MIT-LICENSE rename to gems/plugins/simply_versioned/MIT-LICENSE index c2e1056fc1e..3f5ff7a41e6 100644 --- a/vendor/plugins/simply_versioned/MIT-LICENSE +++ b/gems/plugins/simply_versioned/MIT-LICENSE @@ -1,4 +1,5 @@ -Copyright (c) 2007 Matt Mower +Portions Copyright (c) 2007 Matt Mower +Portions Copyright (c) 2011-2014 Instructure, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/vendor/plugins/simply_versioned/README b/gems/plugins/simply_versioned/README similarity index 100% rename from vendor/plugins/simply_versioned/README rename to gems/plugins/simply_versioned/README diff --git a/gems/plugins/simply_versioned/lib/simply_versioned.rb b/gems/plugins/simply_versioned/lib/simply_versioned.rb new file mode 100644 index 00000000000..b8d075de451 --- /dev/null +++ b/gems/plugins/simply_versioned/lib/simply_versioned.rb @@ -0,0 +1,304 @@ +# SimplyVersioned 0.9.3 +# +# Simple ActiveRecord versioning +# Copyright (c) 2007,2008 Matt Mower +# Released under the MIT license (see accompany MIT-LICENSE file) +# + +require 'simply_versioned/gem_version' +require 'simply_versioned/version' + +module SimplyVersioned + + class BadOptions < StandardError + def initialize( keys ) + super( "Keys: #{keys.join( "," )} are not known by SimplyVersioned" ) + end + end + + DEFAULTS = { + :keep => nil, + :automatic => true, + :exclude => [], + :explicit => false, + # callbacks + :when => nil, + :on_create => nil, + :on_update => nil, + :on_load => nil + } + + module ClassMethods + + # Marks this ActiveRecord model as being versioned. Calls to +create+ or +save+ will, + # in future, create a series of associated Version instances that can be accessed via + # the +versions+ association. + # + # Options: + # +keep+ - specifies the number of old versions to keep (default = nil, never delete old versions) + # +automatic+ - controls whether versions are created automatically (default = true, save versions) + # +exclude+ - specify columns that will not be saved (default = [], save all columns) + # + # Additional INSTRUCTURE options: + # +explicit+ - explicit versioning keeps the last version up to date, + # but doesn't automatically create new versions (default = false) + # +when+ - callback to indicate whether an instance needs a version + # saved or not. if present, the model is passed to the + # callback which should return true or false, true indicating + # a version should be saved. if absent, versions are saved if + # any attribute other than updated_at is changed. + # +on_create+ - callback to allow additional changes to a new version + # that's about to be saved. + # +on_update+ - callback to allow additional changes to an updated (see + # +explicit+ parameter) version that's about to be saved. + # +on_load+ - callback to allow processing or changes after loading + # (finding) the version from the database. + # + # To save the record without creating a version either set +versioning_enabled+ to false + # on the model before calling save or, alternatively, use +without_versioning+ and save + # the model from its block. + # + + def simply_versioned( options = {} ) + bad_keys = options.keys - SimplyVersioned::DEFAULTS.keys + raise SimplyVersioned::BadOptions.new( bad_keys ) unless bad_keys.empty? + + options.reverse_merge!(DEFAULTS) + options[:exclude] = Array( options[ :exclude ] ).map( &:to_s ) + + has_many :versions, :order => 'number DESC', :as => :versionable, + :dependent => :destroy, + :inverse_of => :versionable, :extend => VersionsProxyMethods + # INSTRUCTURE: Added to allow quick access to the most recent version + # See 'current_version' below for the common use of current_version_unidirectional + has_one :current_version_unidirectional, :class_name => 'Version', :order => 'number DESC', :as => :versionable, :dependent => :destroy + # INSTRUCTURE: Lets us ignore certain things when deciding whether to store a new version + before_save :check_if_changes_are_worth_versioning + after_save :simply_versioned_create_version + + cattr_accessor :simply_versioned_options + self.simply_versioned_options = options + + class_eval do + def versioning_enabled=( enabled ) + self.instance_variable_set( :@simply_versioned_enabled, enabled ) + end + + def versioning_enabled? + enabled = self.instance_variable_get( :@simply_versioned_enabled ) + if enabled.nil? + enabled = self.instance_variable_set( :@simply_versioned_enabled, self.simply_versioned_options[:automatic] ) + end + enabled + end + end + end + + end + + # Methods that will be defined on the ActiveRecord model being versioned + module InstanceMethods + + # Revert the attributes of this model to their values as of an earlier version. + # + # Pass either a Version instance or a version number. + # + # options: + # +except+ specify a list of attributes that are not restored (default: created_at, updated_at) + # + def revert_to_version( version, options = {} ) + options.reverse_merge!({ + :except => [:created_at,:updated_at] + }) + + version = if version.kind_of?( Version ) + version + elsif version.kind_of?( Fixnum ) + self.versions.find_by_number( version ) + end + + raise "Invalid version (#{version.inspect}) specified!" unless version + + options[:except] = options[:except].map( &:to_s ) + + self.update_attributes( YAML::load( version.yaml ).except( *options[:except] ) ) + end + + # Invoke the supplied block passing the receiver as the sole block argument with + # versioning enabled or disabled depending upon the value of the +enabled+ parameter + # for the duration of the block. + def with_versioning( enabled = true) + versioning_was_enabled = self.versioning_enabled? + explicit_versioning_was_enabled = @simply_versioned_explicit_enabled + explicit_enabled = false + if enabled.is_a?(Hash) + opts = enabled + enabled = true + explicit_enabled = true if opts[:explicit] + end + self.versioning_enabled = enabled + @simply_versioned_explicit_enabled = explicit_enabled + # INSTRUCTURE: always create a version if explicitly told to do so + @versioning_explicitly_enabled = enabled == true + begin + yield self + ensure + @versioning_explicitly_enabled = nil + self.versioning_enabled = versioning_was_enabled + @simply_versioned_explicit_enabled = explicit_enabled + end + end + + def without_versioning(&block) + with_versioning(false, &block) + end + + def unversioned? + self.versions.nil? || !self.versions.exists? + end + + def versioned? + !unversioned? + end + + # INSTRUCTURE: Added to allow model instances pulled out + # of versions to still know their version number + def force_version_number(number) + @simply_versioned_version_number = number + end + attr_accessor :simply_versioned_version_model + + def version_number + if @simply_versioned_version_number + @simply_versioned_version_number + else + self.versions.maximum(:number) || 0 + end + end + + def current_version? + !@simply_versioned_version_number + end + + # Create a bi-directional current_version association so we don't need + # to reload the 'versionable' object each time we access the model + def current_version + current_version_unidirectional.tap do |version| + version.versionable = self + end + end + + protected + + # INSTRUCTURE: If defined on a method, allow a check + # on the before_save to see if the changes are worth + # creating a new version for + def check_if_changes_are_worth_versioning + @changes_are_worth_versioning = simply_versioned_options[:when] ? + simply_versioned_options[:when].call(self) : + (self.changes.keys.map(&:to_s) - simply_versioned_options[:exclude] - ["updated_at"]).present? + true + end + + def simply_versioned_create_version + if self.versioning_enabled? + # INSTRUCTURE + if @versioning_explicitly_enabled || @changes_are_worth_versioning + @changes_are_worth_versioning = nil + if simply_versioned_options[:explicit] && !@simply_versioned_explicit_enabled && versioned? + version = self.versions.current + version.yaml = self.attributes.except( *simply_versioned_options[:exclude] ).to_yaml + simply_versioned_options[:on_update].try(:call, self, version) + version.save + else + version = self.versions.create( :yaml => self.attributes.except( *simply_versioned_options[:exclude] ).to_yaml ) + if version + simply_versioned_options[:on_create].try(:call, self, version) + self.versions.clean_old_versions( simply_versioned_options[:keep].to_i ) if simply_versioned_options[:keep] + end + end + end + end + true + end + + end + + module VersionsProxyMethods + # Anything that returns a Version should have its versionable pre- + # populated. This is basically a way of getting around the fact that + # ActiveRecord doesn't have a polymorphic :inverse_of option. + def method_missing(method, *a, &b) + case method + when :minimum, :maximum, :exists?, :all, :find_all, :each then + populate_versionables(super) + when :find then + case a.first + when :all then populate_versionables(super) + when :first, :last then populate_versionable(super) + else super + end + else + super + end + end + + def populate_versionables(versions) + versions.each{ |v| populate_versionable(v) } if versions.is_a?(Array) + versions + end + + def populate_versionable(version) + if version && !version.frozen? + version.versionable = proxy_association.owner + end + version + end + + # Get the Version instance corresponding to this models for the specified version number. + def get_version( number ) + populate_versionable find_by_number( number ) + end + alias_method :get, :get_version + + # Get the first Version corresponding to this model. + def first_version + populate_versionable reorder( 'number ASC' ).limit(1).to_a.first + end + alias_method :first, :first_version + + # Get the current Version corresponding to this model. + def current_version + populate_versionable reorder( 'number DESC' ).limit(1).to_a.first + end + alias_method :current, :current_version + + # If the model instance has more versions than the limit specified, delete all excess older versions. + def clean_old_versions( versions_to_keep ) + where( 'number <= ?', self.maximum( :number ) - versions_to_keep ).each do |version| + version.destroy + end + end + alias_method :purge, :clean_old_versions + + # Return the Version for this model with the next higher version + def next_version( number ) + populate_versionable reorder( 'number ASC' ).where( "number > ?", number ).limit(1).to_a.first + end + alias_method :next, :next_version + + # Return the Version for this model with the next lower version + def previous_version( number ) + populate_versionable reorder( 'number DESC' ).where( "number < ?", number ).limit(1).to_a.first + end + alias_method :previous, :previous_version + end + + def self.included( receiver ) + receiver.extend ClassMethods + receiver.send :include, InstanceMethods + end + +end + +ActiveRecord::Base.send( :include, SimplyVersioned ) diff --git a/gems/plugins/simply_versioned/lib/simply_versioned/gem_version.rb b/gems/plugins/simply_versioned/lib/simply_versioned/gem_version.rb new file mode 100644 index 00000000000..fe3d9b0e279 --- /dev/null +++ b/gems/plugins/simply_versioned/lib/simply_versioned/gem_version.rb @@ -0,0 +1,3 @@ +module SimplyVersioned + VERSION = "1.0.0" +end diff --git a/vendor/plugins/simply_versioned/lib/version.rb b/gems/plugins/simply_versioned/lib/simply_versioned/version.rb similarity index 92% rename from vendor/plugins/simply_versioned/lib/version.rb rename to gems/plugins/simply_versioned/lib/simply_versioned/version.rb index 0f868e2a583..e69b49774ae 100644 --- a/vendor/plugins/simply_versioned/lib/version.rb +++ b/gems/plugins/simply_versioned/lib/simply_versioned/version.rb @@ -13,10 +13,6 @@ # class with those attributes. # class Version < ActiveRecord::Base #:nodoc: - # INSTRUCTURE: shims for quizzes namespacing - include PolymorphicTypeOverride - override_polymorphic_types versionable_type: {'Quiz' => 'Quizzes::Quiz', 'QuizSubmission' => 'Quizzes::QuizSubmission'} - belongs_to :versionable, :polymorphic => true before_create :initialize_number diff --git a/gems/plugins/simply_versioned/simply_versioned.gemspec b/gems/plugins/simply_versioned/simply_versioned.gemspec new file mode 100644 index 00000000000..f11d040a785 --- /dev/null +++ b/gems/plugins/simply_versioned/simply_versioned.gemspec @@ -0,0 +1,19 @@ +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "simply_versioned/gem_version" + +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = "simply_versioned" + s.version = SimplyVersioned::VERSION + s.authors = ["Matt Mower", "Brian Palmer"] + s.email = ["brianp@instructure.com"] + s.homepage = "http://www.instructure.com" + s.summary = "Instructure-maintained fork of simply_versioned" + + s.files = Dir["{app,config,db,lib}/**/*"] + s.test_files = Dir["spec_canvas/**/*"] + + s.add_dependency "rails", ">= 3.2", "< 4.2" +end diff --git a/vendor/plugins/simply_versioned/spec_canvas/simply_versioned_spec.rb b/gems/plugins/simply_versioned/spec_canvas/simply_versioned_spec.rb similarity index 100% rename from vendor/plugins/simply_versioned/spec_canvas/simply_versioned_spec.rb rename to gems/plugins/simply_versioned/spec_canvas/simply_versioned_spec.rb diff --git a/vendor/plugins/simply_versioned/Rakefile b/vendor/plugins/simply_versioned/Rakefile deleted file mode 100644 index f4a8854bbf9..00000000000 --- a/vendor/plugins/simply_versioned/Rakefile +++ /dev/null @@ -1,31 +0,0 @@ -require 'rake' -require 'rake/testtask' -require 'rdoc/task' - -desc 'Default: run unit tests.' -task :default => :test - -desc 'Test the simply_versioned plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end - -desc 'Generate documentation for the simply_versioned plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'SimplyVersioned' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end - -desc 'Measures test coverage using rcov' -task :rcov do - rm_f "coverage" - rm_f "coverage.data" - rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" - system("#{rcov} --html #{Dir.glob('test/**/*_test.rb').join(' ')}") - system("open coverage/index.html") if PLATFORM['darwin'] -end diff --git a/vendor/plugins/simply_versioned/generators/simply_versioned_migration/simply_versioned_migration_generator.rb b/vendor/plugins/simply_versioned/generators/simply_versioned_migration/simply_versioned_migration_generator.rb deleted file mode 100644 index 5b00ed8ab59..00000000000 --- a/vendor/plugins/simply_versioned/generators/simply_versioned_migration/simply_versioned_migration_generator.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'rails/generators/active_record' - -class SimplyVersionedMigrationGenerator < ActiveRecord::Generators::Base - source_root File.expand_path('../templates', __FILE__) - def create_migration_file - migration_template "migration.rb", "db/migrate/#{file_name}.rb" - end - - def file_name - "simply_versioned_migration" - end -end diff --git a/vendor/plugins/simply_versioned/generators/simply_versioned_migration/templates/migration.rb b/vendor/plugins/simply_versioned/generators/simply_versioned_migration/templates/migration.rb deleted file mode 100644 index b078cc47ace..00000000000 --- a/vendor/plugins/simply_versioned/generators/simply_versioned_migration/templates/migration.rb +++ /dev/null @@ -1,18 +0,0 @@ -class SimplyVersionedMigration < ActiveRecord::Migration - - def self.up - create_table :versions do |t| - t.integer :versionable_id - t.string :versionable_type - t.integer :number - t.text :yaml - t.datetime :created_at - end - - add_index :versions, [:versionable_id, :versionable_type] - end - - def self.down - drop_table :versions - end -end diff --git a/vendor/plugins/simply_versioned/init.rb b/vendor/plugins/simply_versioned/init.rb deleted file mode 100644 index 0b51518d4e3..00000000000 --- a/vendor/plugins/simply_versioned/init.rb +++ /dev/null @@ -1 +0,0 @@ -require 'simply_versioned' diff --git a/vendor/plugins/simply_versioned/install.rb b/vendor/plugins/simply_versioned/install.rb deleted file mode 100644 index f7732d3796c..00000000000 --- a/vendor/plugins/simply_versioned/install.rb +++ /dev/null @@ -1 +0,0 @@ -# Install hook code here diff --git a/vendor/plugins/simply_versioned/lib/simply_versioned.rb b/vendor/plugins/simply_versioned/lib/simply_versioned.rb deleted file mode 100644 index b9bb9612cfe..00000000000 --- a/vendor/plugins/simply_versioned/lib/simply_versioned.rb +++ /dev/null @@ -1,309 +0,0 @@ -# SimplyVersioned 0.9.3 -# -# Simple ActiveRecord versioning -# Copyright (c) 2007,2008 Matt Mower -# Released under the MIT license (see accompany MIT-LICENSE file) -# - -module SoftwareHeretics - - module ActiveRecord - - module SimplyVersioned - - class BadOptions < StandardError - def initialize( keys ) - super( "Keys: #{keys.join( "," )} are not known by SimplyVersioned" ) - end - end - - DEFAULTS = { - :keep => nil, - :automatic => true, - :exclude => [], - :explicit => false, - # callbacks - :when => nil, - :on_create => nil, - :on_update => nil, - :on_load => nil - } - - module ClassMethods - - # Marks this ActiveRecord model as being versioned. Calls to +create+ or +save+ will, - # in future, create a series of associated Version instances that can be accessed via - # the +versions+ association. - # - # Options: - # +keep+ - specifies the number of old versions to keep (default = nil, never delete old versions) - # +automatic+ - controls whether versions are created automatically (default = true, save versions) - # +exclude+ - specify columns that will not be saved (default = [], save all columns) - # - # Additional INSTRUCTURE options: - # +explicit+ - explicit versioning keeps the last version up to date, - # but doesn't automatically create new versions (default = false) - # +when+ - callback to indicate whether an instance needs a version - # saved or not. if present, the model is passed to the - # callback which should return true or false, true indicating - # a version should be saved. if absent, versions are saved if - # any attribute other than updated_at is changed. - # +on_create+ - callback to allow additional changes to a new version - # that's about to be saved. - # +on_update+ - callback to allow additional changes to an updated (see - # +explicit+ parameter) version that's about to be saved. - # +on_load+ - callback to allow processing or changes after loading - # (finding) the version from the database. - # - # To save the record without creating a version either set +versioning_enabled+ to false - # on the model before calling save or, alternatively, use +without_versioning+ and save - # the model from its block. - # - - def simply_versioned( options = {} ) - bad_keys = options.keys - SimplyVersioned::DEFAULTS.keys - raise SimplyVersioned::BadOptions.new( bad_keys ) unless bad_keys.empty? - - options.reverse_merge!(DEFAULTS) - options[:exclude] = Array( options[ :exclude ] ).map( &:to_s ) - - has_many :versions, :order => 'number DESC', :as => :versionable, - :dependent => :destroy, - :inverse_of => :versionable, :extend => VersionsProxyMethods - # INSTRUCTURE: Added to allow quick access to the most recent version - # See 'current_version' below for the common use of current_version_unidirectional - has_one :current_version_unidirectional, :class_name => 'Version', :order => 'number DESC', :as => :versionable, :dependent => :destroy - # INSTRUCTURE: Lets us ignore certain things when deciding whether to store a new version - before_save :check_if_changes_are_worth_versioning - after_save :simply_versioned_create_version - - cattr_accessor :simply_versioned_options - self.simply_versioned_options = options - - class_eval do - def versioning_enabled=( enabled ) - self.instance_variable_set( :@simply_versioned_enabled, enabled ) - end - - def versioning_enabled? - enabled = self.instance_variable_get( :@simply_versioned_enabled ) - if enabled.nil? - enabled = self.instance_variable_set( :@simply_versioned_enabled, self.simply_versioned_options[:automatic] ) - end - enabled - end - end - end - - end - - # Methods that will be defined on the ActiveRecord model being versioned - module InstanceMethods - - # Revert the attributes of this model to their values as of an earlier version. - # - # Pass either a Version instance or a version number. - # - # options: - # +except+ specify a list of attributes that are not restored (default: created_at, updated_at) - # - def revert_to_version( version, options = {} ) - options.reverse_merge!({ - :except => [:created_at,:updated_at] - }) - - version = if version.kind_of?( Version ) - version - elsif version.kind_of?( Fixnum ) - self.versions.find_by_number( version ) - end - - raise "Invalid version (#{version.inspect}) specified!" unless version - - options[:except] = options[:except].map( &:to_s ) - - self.update_attributes( YAML::load( version.yaml ).except( *options[:except] ) ) - end - - # Invoke the supplied block passing the receiver as the sole block argument with - # versioning enabled or disabled depending upon the value of the +enabled+ parameter - # for the duration of the block. - def with_versioning( enabled = true) - versioning_was_enabled = self.versioning_enabled? - explicit_versioning_was_enabled = @simply_versioned_explicit_enabled - explicit_enabled = false - if enabled.is_a?(Hash) - opts = enabled - enabled = true - explicit_enabled = true if opts[:explicit] - end - self.versioning_enabled = enabled - @simply_versioned_explicit_enabled = explicit_enabled - # INSTRUCTURE: always create a version if explicitly told to do so - @versioning_explicitly_enabled = enabled == true - begin - yield self - ensure - @versioning_explicitly_enabled = nil - self.versioning_enabled = versioning_was_enabled - @simply_versioned_explicit_enabled = explicit_enabled - end - end - - def without_versioning(&block) - with_versioning(false, &block) - end - - def unversioned? - self.versions.nil? || !self.versions.exists? - end - - def versioned? - !unversioned? - end - - # INSTRUCTURE: Added to allow model instances pulled out - # of versions to still know their version number - def force_version_number(number) - @simply_versioned_version_number = number - end - attr_accessor :simply_versioned_version_model - - def version_number - if @simply_versioned_version_number - @simply_versioned_version_number - else - self.versions.maximum(:number) || 0 - end - end - - def current_version? - !@simply_versioned_version_number - end - - # Create a bi-directional current_version association so we don't need - # to reload the 'versionable' object each time we access the model - def current_version - current_version_unidirectional.tap do |version| - version.versionable = self - end - end - - protected - - # INSTRUCTURE: If defined on a method, allow a check - # on the before_save to see if the changes are worth - # creating a new version for - def check_if_changes_are_worth_versioning - @changes_are_worth_versioning = simply_versioned_options[:when] ? - simply_versioned_options[:when].call(self) : - (self.changes.keys.map(&:to_s) - simply_versioned_options[:exclude] - ["updated_at"]).present? - true - end - - def simply_versioned_create_version - if self.versioning_enabled? - # INSTRUCTURE - if @versioning_explicitly_enabled || @changes_are_worth_versioning - @changes_are_worth_versioning = nil - if simply_versioned_options[:explicit] && !@simply_versioned_explicit_enabled && versioned? - version = self.versions.current - version.yaml = self.attributes.except( *simply_versioned_options[:exclude] ).to_yaml - simply_versioned_options[:on_update].try(:call, self, version) - version.save - else - version = self.versions.create( :yaml => self.attributes.except( *simply_versioned_options[:exclude] ).to_yaml ) - if version - simply_versioned_options[:on_create].try(:call, self, version) - self.versions.clean_old_versions( simply_versioned_options[:keep].to_i ) if simply_versioned_options[:keep] - end - end - end - end - true - end - - end - - module VersionsProxyMethods - # Anything that returns a Version should have its versionable pre- - # populated. This is basically a way of getting around the fact that - # ActiveRecord doesn't have a polymorphic :inverse_of option. - def method_missing(method, *a, &b) - case method - when :minimum, :maximum, :exists?, :all, :find_all, :each then - populate_versionables(super) - when :find then - case a.first - when :all then populate_versionables(super) - when :first, :last then populate_versionable(super) - else super - end - else - super - end - end - - def populate_versionables(versions) - versions.each{ |v| populate_versionable(v) } if versions.is_a?(Array) - versions - end - - def populate_versionable(version) - if version && !version.frozen? - version.versionable = proxy_association.owner - end - version - end - - # Get the Version instance corresponding to this models for the specified version number. - def get_version( number ) - populate_versionable find_by_number( number ) - end - alias_method :get, :get_version - - # Get the first Version corresponding to this model. - def first_version - populate_versionable reorder( 'number ASC' ).limit(1).to_a.first - end - alias_method :first, :first_version - - # Get the current Version corresponding to this model. - def current_version - populate_versionable reorder( 'number DESC' ).limit(1).to_a.first - end - alias_method :current, :current_version - - # If the model instance has more versions than the limit specified, delete all excess older versions. - def clean_old_versions( versions_to_keep ) - where( 'number <= ?', self.maximum( :number ) - versions_to_keep ).each do |version| - version.destroy - end - end - alias_method :purge, :clean_old_versions - - # Return the Version for this model with the next higher version - def next_version( number ) - populate_versionable reorder( 'number ASC' ).where( "number > ?", number ).limit(1).to_a.first - end - alias_method :next, :next_version - - # Return the Version for this model with the next lower version - def previous_version( number ) - populate_versionable reorder( 'number DESC' ).where( "number < ?", number ).limit(1).to_a.first - end - alias_method :previous, :previous_version - end - - def self.included( receiver ) - receiver.extend ClassMethods - receiver.send :include, InstanceMethods - end - - end - - end - -end - -ActiveRecord::Base.send( :include, SoftwareHeretics::ActiveRecord::SimplyVersioned ) diff --git a/vendor/plugins/simply_versioned/lib/tasks/simply_versioned_tasks.rake b/vendor/plugins/simply_versioned/lib/tasks/simply_versioned_tasks.rake deleted file mode 100644 index 290426d9e86..00000000000 --- a/vendor/plugins/simply_versioned/lib/tasks/simply_versioned_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :simply_versioned do -# # Task goes here -# end diff --git a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics.html b/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics.html deleted file mode 100644 index f6fe50eba66..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics.html +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - Module: SoftwareHeretics - - - - - - - - - - -
- - - - - - - - - - -
ModuleSoftwareHeretics
In: - - lib/simply_versioned.rb - -
-
-
- - -
- - - -
- -
-

-SimplyVersioned 0.1 -

-

-Simple ActiveRecord -versioning Copyright (c) 2007 Matt Mower <self@mattmower.com> -Released under the MIT license (see accompany MIT-LICENSE file) -

- -
- - -
- - -
- - - - -
- -
-

Classes and Modules

- - Module SoftwareHeretics::ActiveRecord
- -
- - - - - - - - - - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord.html b/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord.html deleted file mode 100644 index 4e41e6ac34f..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord.html +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - Module: SoftwareHeretics::ActiveRecord - - - - - - - - - - -
- - - - - - - - - - -
ModuleSoftwareHeretics::ActiveRecord
In: - - lib/simply_versioned.rb - -
-
-
- - -
- - - -
- - - -
- - -
- - - - -
- -
-

Classes and Modules

- - Module SoftwareHeretics::ActiveRecord::SimplyVersioned
- -
- - - - - - - - - - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned.html b/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned.html deleted file mode 100644 index d14f4e022aa..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - Module: SoftwareHeretics::ActiveRecord::SimplyVersioned - - - - - - - - - - -
- - - - - - - - - - -
ModuleSoftwareHeretics::ActiveRecord::SimplyVersioned
In: - - lib/simply_versioned.rb - -
-
-
- - -
- - - -
- - - -
- -
-

Methods

- -
- included   -
-
- -
- - - - -
- - - - - - - - - - -
-

Public Class methods

- -
- - - - -
-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 96
-96:       def self.included( receiver )
-97:         receiver.extend         ClassMethods
-98:         receiver.send :include, InstanceMethods
-99:       end
-
-
-
-
- - -
- - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/ClassMethods.html b/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/ClassMethods.html deleted file mode 100644 index f317b3a8c9f..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/ClassMethods.html +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - Module: SoftwareHeretics::ActiveRecord::SimplyVersioned::ClassMethods - - - - - - - - - - -
- - - - - - - - - - -
ModuleSoftwareHeretics::ActiveRecord::SimplyVersioned::ClassMethods
In: - - lib/simply_versioned.rb - -
-
-
- - -
- - - -
- - - -
- -
-

Methods

- - -
- -
- - - - -
- - - - - - - - - -
-

Public Instance methods

- -
- - - - -
-

-Marks this ActiveRecord model as -being versioned. Calls to create or save will, in future, -create a series of associated Version instances that can be accessed via -the versions association. -

-

-Options: limit - specifies the number of old versions to keep -(default = 99) -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 23
-23:         def simply_versioned( options = {} )
-24:           options.reverse_merge!( {
-25:             :keep => 99
-26:           })
-27:           
-28:           has_many :versions, :order => 'number DESC', :as => :versionable, :dependent => :destroy, :extend => VersionsProxyMethods
-29: 
-30:           after_save :simply_versioned_create_version
-31:           
-32:           cattr_accessor :simply_versioned_keep_limit
-33:           self.simply_versioned_keep_limit = options[:keep]
-34:         end
-
-
-
-
- - -
- - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/InstanceMethods.html b/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/InstanceMethods.html deleted file mode 100644 index ef9ed47321d..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/InstanceMethods.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - Module: SoftwareHeretics::ActiveRecord::SimplyVersioned::InstanceMethods - - - - - - - - - - -
- - - - - - - - - - -
ModuleSoftwareHeretics::ActiveRecord::SimplyVersioned::InstanceMethods
In: - - lib/simply_versioned.rb - -
-
-
- - -
- - - -
- - - -
- -
-

Methods

- - -
- -
- - - - -
- - - - - - - - - -
-

Public Instance methods

- -
- - - - -
-

-Revert this model instance to the attributes it had at the specified -version number. -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 41
-41:         def revert_to_version( version )
-42:           version = if version.kind_of?( Version )
-43:             version
-44:           else
-45:             version = self.versions.find( :first, :conditions => { :number => Integer( version ) } )
-46:           end
-47:           self.update_attributes( YAML::load( version.yaml ) )
-48:         end
-
-
-
-
- -

Protected Instance methods

- -
- - - - -
-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 52
-52:         def simply_versioned_create_version
-53:           if self.versions.create( :yaml => self.attributes.to_yaml )
-54:             self.versions.clean( simply_versioned_keep_limit )
-55:           end
-56:           true
-57:         end
-
-
-
-
- - -
- - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/VersionsProxyMethods.html b/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/VersionsProxyMethods.html deleted file mode 100644 index 639698b1df6..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/VersionsProxyMethods.html +++ /dev/null @@ -1,286 +0,0 @@ - - - - - - Module: SoftwareHeretics::ActiveRecord::SimplyVersioned::VersionsProxyMethods - - - - - - - - - - -
- - - - - - - - - - -
ModuleSoftwareHeretics::ActiveRecord::SimplyVersioned::VersionsProxyMethods
In: - - lib/simply_versioned.rb - -
-
-
- - -
- - - -
- - - -
- -
-

Methods

- -
- clean   - current   - first   - get   - next   - prev   -
-
- -
- - - - -
- - - - - - - - - -
-

Public Instance methods

- -
- - - - -
-

-If the model instance has more versions than the limit specified, delete -all excess older versions. -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 79
-79:         def clean( versions_to_keep )
-80:           find( :all, :conditions => [ 'number <= ?', self.maximum( :number ) - versions_to_keep ] ).each do |version|
-81:             version.destroy
-82:           end
-83:         end
-
-
-
-
- -
- - - - -
-

-Get the current Version -corresponding to this model. -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 74
-74:         def current
-75:           find( :first, :order => 'number DESC' )
-76:         end
-
-
-
-
- -
- - - - -
-

-Get the first Version -corresponding to this model. -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 69
-69:         def first
-70:           find( :first, :order => 'number ASC' )
-71:         end
-
-
-
-
- -
- - - - -
-

-Get the Version instance corresponding to this models for the specified -version number. -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 64
-64:         def get( number )
-65:           find_by_number( number )
-66:         end
-
-
-
-
- -
- - - - -
-

-Return the Version for this model with the next higher version -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 86
-86:         def next( number )
-87:           find( :first, :order => 'number ASC', :conditions => [ "number > ?", number ] )
-88:         end
-
-
-
-
- -
- - - - -
-

-Return the Version for this model with the next lower version -

-

[Source]

-
-
-    # File lib/simply_versioned.rb, line 91
-91:         def prev( number )
-92:           find( :first, :order => 'number DESC', :conditions => [ "number < ?", number ] )
-93:         end
-
-
-
-
- - -
- - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/created.rid b/vendor/plugins/simply_versioned/rdoc/created.rid deleted file mode 100644 index 1b23321289b..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/created.rid +++ /dev/null @@ -1 +0,0 @@ -Sun, 30 Dec 2007 11:52:57 +0000 diff --git a/vendor/plugins/simply_versioned/rdoc/files/README.html b/vendor/plugins/simply_versioned/rdoc/files/README.html deleted file mode 100644 index ec8ac632d13..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/files/README.html +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - File: README - - - - - - - - - - -
-

README

- - - - - - - - - -
Path:README -
Last Update:Sun Dec 30 11:51:41 +0000 2007
-
- - -
- - - -
- -
-

-SimplyVersioned -

-
=========
-

-Release: 0.2 Date: 30-12-2007 Author: Matt Mower <self@mattmower.com> -

-

-SimplyVersioned is a simple, non-invasive, approach to versioning -ActiveRecord models. -

-

-SimplyVersioned does not require any structural change to the models to be -versioned and requires only one versions table to be created (a migration -generator is supplied with the plugin) regardless of the number of models -being versioned. -

-

-The plugin introduces a ‘Version’ ActiveRecord model (that -reflects changes to model attributes) to which versioned models are -polymorphically associated. Version records store the model information as -a YAML hash. -

-

-SimplyVersioned meets a simple need for model versioning. If your needs are -more complex maybe try Rick Olsen‘s acts_as_versioned (svn.techno-weenie.net/projects/plugins/acts_as_versioned/). -

-

-SimplyVersioned has (so far) been tested and found to work with Rails 2.0.1 -and Ruby 1.8.6p111. -

-

-Usage -

-
-
    -
  1. Install the plugin - -
  2. -
-
-  ./script/plugin install http://rubymatt.rubyforge.org/svn/simply_versioned
-
-
    -
  1. Generate the migration - -
  2. -
-
-  ./script/generate simply_versioned_migration
-
-
    -
  1. Create the versions table - -
  2. -
-
-  rake db:migrate
-
-
    -
  1. Annotate the models you want to version specifying how many versions to -keep - -
    -     class Thing < ActiveRecord::Base
    -       simply_versioned :keep => 10
    -     end
    -
    -
  2. -
  3. Create versions - -
    -     thing = Thing.create!( :foo => bar ) # creates v1
    -     thing.foo = baz
    -     thing.save! # creates v2
    -
    -
  4. -
  5. Find versions - -
    -     thing.versions.each do |version| ... end
    -     render :partial => 'thing_version', :collection => thing.versions
    -     thing.versions.current
    -     thing.versions.first
    -     thing.versions.get( 3 )
    -
    -
  6. -
  7. Revert to a previous version - -
    -     thing.revert_to_version( 5 )
    -
    -
  8. -
  9. Traverse versions - -
    -     thing.versions.current.previous
    -     thing.versions.first.next
    -
    -
  10. -
  11. Obtain a copy of a previous versioned model - -
    -     thing.versions.first.model # => Instantiated Thing with versioned values
    -
    -
  12. -
-

-Copyright (c) 2007 Matt Mower <self@mattmower.com> and released under -the MIT license -

- -
- - -
- - -
- - - - -
- - - - - - - - - - - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/files/lib/simply_versioned_rb.html b/vendor/plugins/simply_versioned/rdoc/files/lib/simply_versioned_rb.html deleted file mode 100644 index b63cb0cd09f..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/files/lib/simply_versioned_rb.html +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - File: simply_versioned.rb - - - - - - - - - - -
-

simply_versioned.rb

- - - - - - - - - -
Path:lib/simply_versioned.rb -
Last Update:Sun Dec 30 11:46:53 +0000 2007
-
- - -
- - - -
- -
-

-SimplyVersioned 0.1 -

-

-Simple ActiveRecord versioning Copyright (c) 2007 Matt Mower -<self@mattmower.com> Released under the MIT license (see accompany -MIT-LICENSE file) -

- -
- - -
- - -
- - - - -
- - - - - - - - - - - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/files/lib/version_rb.html b/vendor/plugins/simply_versioned/rdoc/files/lib/version_rb.html deleted file mode 100644 index 56c6a364328..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/files/lib/version_rb.html +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - File: version.rb - - - - - - - - - - -
-

version.rb

- - - - - - - - - -
Path:lib/version.rb -
Last Update:Sun Dec 30 11:31:55 +0000 2007
-
- - -
- - - -
- -
-

-SimplyVersioned 0.1 -

-

-Simple ActiveRecord versioning Copyright (c) 2007 Matt Mower -<self@mattmower.com> Released under the MIT license (see accompany -MIT-LICENSE file) -

- -
- - -
- - -
- - - - -
- - - - - - - - - - - -
- - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/fr_class_index.html b/vendor/plugins/simply_versioned/rdoc/fr_class_index.html deleted file mode 100644 index ba4d40b0889..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/fr_class_index.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - Classes - - - - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/fr_file_index.html b/vendor/plugins/simply_versioned/rdoc/fr_file_index.html deleted file mode 100644 index c34d13145ac..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/fr_file_index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - Files - - - - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/fr_method_index.html b/vendor/plugins/simply_versioned/rdoc/fr_method_index.html deleted file mode 100644 index dae813659c8..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/fr_method_index.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - Methods - - - - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/index.html b/vendor/plugins/simply_versioned/rdoc/index.html deleted file mode 100644 index 2e9b267dfb5..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - SimplyVersioned - - - - - - - - - - - \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/rdoc/rdoc-style.css b/vendor/plugins/simply_versioned/rdoc/rdoc-style.css deleted file mode 100644 index 44c7b3d13ad..00000000000 --- a/vendor/plugins/simply_versioned/rdoc/rdoc-style.css +++ /dev/null @@ -1,208 +0,0 @@ - -body { - font-family: Verdana,Arial,Helvetica,sans-serif; - font-size: 90%; - margin: 0; - margin-left: 40px; - padding: 0; - background: white; -} - -h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; } -h1 { font-size: 150%; } -h2,h3,h4 { margin-top: 1em; } - -a { background: #eef; color: #039; text-decoration: none; } -a:hover { background: #039; color: #eef; } - -/* Override the base stylesheet's Anchor inside a table cell */ -td > a { - background: transparent; - color: #039; - text-decoration: none; -} - -/* and inside a section title */ -.section-title > a { - background: transparent; - color: #eee; - text-decoration: none; -} - -/* === Structural elements =================================== */ - -div#index { - margin: 0; - margin-left: -40px; - padding: 0; - font-size: 90%; -} - - -div#index a { - margin-left: 0.7em; -} - -div#index .section-bar { - margin-left: 0px; - padding-left: 0.7em; - background: #ccc; - font-size: small; -} - - -div#classHeader, div#fileHeader { - width: auto; - color: white; - padding: 0.5em 1.5em 0.5em 1.5em; - margin: 0; - margin-left: -40px; - border-bottom: 3px solid #006; -} - -div#classHeader a, div#fileHeader a { - background: inherit; - color: white; -} - -div#classHeader td, div#fileHeader td { - background: inherit; - color: white; -} - - -div#fileHeader { - background: #057; -} - -div#classHeader { - background: #048; -} - - -.class-name-in-header { - font-size: 180%; - font-weight: bold; -} - - -div#bodyContent { - padding: 0 1.5em 0 1.5em; -} - -div#description { - padding: 0.5em 1.5em; - background: #efefef; - border: 1px dotted #999; -} - -div#description h1,h2,h3,h4,h5,h6 { - color: #125;; - background: transparent; -} - -div#validator-badges { - text-align: center; -} -div#validator-badges img { border: 0; } - -div#copyright { - color: #333; - background: #efefef; - font: 0.75em sans-serif; - margin-top: 5em; - margin-bottom: 0; - padding: 0.5em 2em; -} - - -/* === Classes =================================== */ - -table.header-table { - color: white; - font-size: small; -} - -.type-note { - font-size: small; - color: #DEDEDE; -} - -.xxsection-bar { - background: #eee; - color: #333; - padding: 3px; -} - -.section-bar { - color: #333; - border-bottom: 1px solid #999; - margin-left: -20px; -} - - -.section-title { - background: #79a; - color: #eee; - padding: 3px; - margin-top: 2em; - margin-left: -30px; - border: 1px solid #999; -} - -.top-aligned-row { vertical-align: top } -.bottom-aligned-row { vertical-align: bottom } - -/* --- Context section classes ----------------------- */ - -.context-row { } -.context-item-name { font-family: monospace; font-weight: bold; color: black; } -.context-item-value { font-size: small; color: #448; } -.context-item-desc { color: #333; padding-left: 2em; } - -/* --- Method classes -------------------------- */ -.method-detail { - background: #efefef; - padding: 0; - margin-top: 0.5em; - margin-bottom: 1em; - border: 1px dotted #ccc; -} -.method-heading { - color: black; - background: #ccc; - border-bottom: 1px solid #666; - padding: 0.2em 0.5em 0 0.5em; -} -.method-signature { color: black; background: inherit; } -.method-name { font-weight: bold; } -.method-args { font-style: italic; } -.method-description { padding: 0 0.5em 0 0.5em; } - -/* --- Source code sections -------------------- */ - -a.source-toggle { font-size: 90%; } -div.method-source-code { - background: #262626; - color: #ffdead; - margin: 1em; - padding: 0.5em; - border: 1px dashed #999; - overflow: hidden; -} - -div.method-source-code pre { color: #ffdead; overflow: hidden; } - -/* --- Ruby keyword styles --------------------- */ - -.standalone-code { background: #221111; color: #ffdead; overflow: hidden; } - -.ruby-constant { color: #7fffd4; background: transparent; } -.ruby-keyword { color: #00ffff; background: transparent; } -.ruby-ivar { color: #eedd82; background: transparent; } -.ruby-operator { color: #00ffee; background: transparent; } -.ruby-identifier { color: #ffdead; background: transparent; } -.ruby-node { color: #ffa07a; background: transparent; } -.ruby-comment { color: #b22222; font-weight: bold; background: transparent; } -.ruby-regexp { color: #ffa07a; background: transparent; } -.ruby-value { color: #7fffd4; background: transparent; } \ No newline at end of file diff --git a/vendor/plugins/simply_versioned/test/simply_versioned_test.rb b/vendor/plugins/simply_versioned/test/simply_versioned_test.rb deleted file mode 100644 index d1f0cb6152e..00000000000 --- a/vendor/plugins/simply_versioned/test/simply_versioned_test.rb +++ /dev/null @@ -1,313 +0,0 @@ -require File.join( File.dirname( __FILE__ ), 'test_helper' ) - -require 'mocha/api' - -class Aardvark < ActiveRecord::Base - simply_versioned :keep => 3 -end - -class Gnu < ActiveRecord::Base - simply_versioned :keep => 4 -end - -class Undine < ActiveRecord::Base -end - -class Heffalump < ActiveRecord::Base - simply_versioned :automatic => false -end - -class Saproling < ActiveRecord::Base - simply_versioned :exclude => [:trouble] -end - -class SimplyVersionedTest < FixturedTestCase - - def self.suite_setup - ActiveRecord::Schema.define do - create_table :aardvarks, :force => true do |t| - t.string :name - t.integer :age - end - - create_table :gnus, :force => true do |t| - t.string :name - t.text :description - end - - create_table :undines, :force => true do |t| - t.string :name - t.integer :married, :default => 0 - end - - create_table :heffalumps, :force => true do |t| - t.string :name - end - - create_table :saprolings, :force => true do |t| - t.string :name - t.string :trouble - end - - create_table :versions, :force => true do |t| - t.integer :versionable_id - t.string :versionable_type - t.integer :number - t.text :yaml - t.datetime :created_at - end - end - end - - def self.suite_teardown - ActiveRecord::Schema.define do - drop_table :versions - drop_table :saprolings - drop_table :heffalumps - drop_table :undines - drop_table :gnus - drop_table :aardvarks - end - end - - def test_should_reject_unknown_options - assert_raises SoftwareHeretics::ActiveRecord::SimplyVersioned::BadOptions do - cls = Class.new( ActiveRecord::Base ) do - simply_versioned :bogus => true - end - end - end - - def test_should_start_with_empty_versions - anthony = Aardvark.new( :name => 'Anthony', :age => 35 ) - assert anthony.versions.empty? - assert anthony.unversioned? - end - - def test_should_be_versioned - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) - assert anthony.versioned? - end - - def test_should_get_versions - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) - anthony.age += 1 - anthony.save! - - assert_equal 35, anthony.versions.get_version(1).model.age - assert_equal 35, anthony.versions.get(1).model.age - - assert_equal 36, anthony.versions.get_version(2).model.age - assert_equal 36, anthony.versions.get(2).model.age - end - - def test_should_version_on_create - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) - assert_equal 1, anthony.versions.count - assert_equal 1, anthony.versions.current_version.number - assert_equal 1, anthony.versions.current.number - end - - def test_should_version_on_save - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) - anthony.age += 1 - anthony.save! - assert_equal 2, anthony.versions.count - end - - def test_should_trim_versions - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - anthony.age += 1 - anthony.save! #v2 - - anthony.age += 1 - anthony.save! #v3 - - anthony.age += 1 - anthony.save! #v4 !! - - assert_equal 3, anthony.versions.count - assert_equal 36, anthony.versions.first_version.model.age - assert_equal 36, anthony.versions.first.model.age - assert_equal 38, anthony.versions.current_version.model.age - assert_equal 38, anthony.versions.current.model.age - end - - def test_should_revert - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - anthony.age += 1 - anthony.save! #v2 - - anthony.revert_to_version( 1 ) - assert_equal 35, anthony.age - end - - def test_should_revert_except - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - - anthony.name = "Tony" - anthony.age = 45 - anthony.save! # v2 - - anthony.revert_to_version( 1, :except => [:name,:created_at,:updated_at] ) - assert_equal "Tony", anthony.name - assert_equal 35, anthony.age - end - - def test_should_raise_on_reversion_to_bad_version - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - anthony.name = "Tony" - anthony.age = 45 - anthony.save! # v2 - - assert_raise RuntimeError do - anthony.revert_to_version( -1 ) - end - - assert_raise RuntimeError do - anthony.revert_to_version( "a" ) - end - - assert_raise RuntimeError do - anthony.revert_to_version( nil ) - end - end - - def test_should_delete_dependent_versions - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - anthony.age += 1 - anthony.save! #v2 - - assert_difference( 'Version.count', -2 ) do - anthony.destroy - end - end - - def test_should_isolate_versioned_models - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) - gary = Gnu.create!( :name => 'Gary', :description => 'Gary the GNU' ) - - assert_equal 2, Version.count - assert_equal 1, anthony.versions.first.number - assert_equal 1, gary.versions.first.number - end - - def test_should_be_able_to_control_versioning - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - - assert_no_difference( 'anthony.versions.count' ) do - anthony.age += 1 - anthony.with_versioning( false, &:save! ) - end - - assert_difference( 'anthony.versions.count' ) do - anthony.age += 1 - anthony.with_versioning( true, &:save! ) - end - end - - def test_should_not_version_in_block - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - - assert_no_difference( 'anthony.versions.count' ) do - anthony.age += 1 - anthony.with_versioning( false ) do - anthony.save! - end - end - end - - def test_should_begin_versioning_existing_record - ulrica = Undine.create!( :name => 'Ulrica' ) - - # Now we begin versioning this kind of record - Undine.class_eval do - simply_versioned - end - - ulrica = Undine.find_by_name( 'Ulrica' ) - assert ulrica.unversioned? - - ulrica.update_attributes( :married => 1 ) - assert !ulrica.unversioned? - assert_equal 1, ulrica.versions.size - assert_equal 1, ulrica.versions.first.model.married - end - - def test_should_follow_back_and_forth - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - anthony.age += 1 - anthony.save! #v2 - anthony.age += 1 - anthony.save! - - assert_equal anthony.versions.current_version, anthony.versions.first_version.next.next - assert_equal anthony.versions.first_version, anthony.versions.current_version.previous.previous - end - - def test_should_be_trustworthy_collection - anthony = Aardvark.create!( :name => 'Anthony', :age => 35 ) # v1 - anthony.age += 1 - anthony.save! #v2 - - # Now create another record - - alan = Aardvark.create!( :name => 'Alan', :age => 35 ) - assert_equal 1, alan.versions.size - end - - def test_should_not_delete_old_versions_by_default - ulrica = Undine.create!( :name => 'Ulrica' ) - ulrica.versions.expects( :clean_old_versions ).never - 100.times do - ulrica.update_attribute( :married, 1 - ulrica.married ) - end - end - - def test_should_not_automatically_create_versions - henry = Heffalump.create!( :name => 'Henry' ) - assert_equal 0, henry.versions.count - - assert_no_difference( 'henry.versions.count' ) do - henry.name = 'Harry' - henry.save! - end - end - - def test_should_create_versions_on_demand - henry = Heffalump.create!( :name => 'Henry' ) - - assert_difference( "henry.versions.count", 1 ) do - henry.with_versioning( true, &:save ) - end - end - - def test_should_exclude_columns - assert_equal ["trouble"], Saproling.simply_versioned_options[:exclude] - - sylvia = Saproling.create!( :name => 'Sylvia', :trouble => "big" ) - - yaml = YAML::load( sylvia.versions.first.yaml ) - assert_equal Set.new( [ "id", "name" ] ), Set.new( yaml.keys ) - end - - def test_should_exclude_column_equivalent_syntax - klass = Class.new( ActiveRecord::Base ) - klass.module_eval <<-DEFN - simply_versioned :exclude => :some_column - DEFN - assert_equal ['some_column'], klass.simply_versioned_options[:exclude] - end - - def test_should_report_version_number - anthony = Aardvark.new( :name => 'Anthony', :age => 35 ) - assert_equal 0, anthony.version_number - - anthony.save! - assert_equal 1, anthony.version_number - - anthony.save! - assert_equal 2, anthony.version_number # and so on - end - -end diff --git a/vendor/plugins/simply_versioned/test/test_helper.rb b/vendor/plugins/simply_versioned/test/test_helper.rb deleted file mode 100644 index 0f3776f45b7..00000000000 --- a/vendor/plugins/simply_versioned/test/test_helper.rb +++ /dev/null @@ -1,56 +0,0 @@ -ENV["RAILS_ENV"] = "test" -TEST_FOLDER = File.dirname( __FILE__ ) - -$:.unshift( File.join( TEST_FOLDER, '..', 'lib' ) ) - -HOST_APP_FOLDER = File.expand_path( ENV['HOST_APP'] || File.join( TEST_FOLDER, '..', '..', '..', '..' ) ) -puts "Host application: #{HOST_APP_FOLDER}" - -require 'test/unit' -require File.expand_path( File.join( HOST_APP_FOLDER, 'config', 'environment.rb' ) ) -require 'test_help' -require 'turn' unless ENV['NO_TURN'] - -ActiveRecord::Base.logger = Logger.new( File.join( TEST_FOLDER, 'test.log' ) ) -ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :dbfile => File.join( TEST_FOLDER, 'test.db' ) ) - -class FixturedTestSuite < Test::Unit::TestSuite - def run( result, &progress_block ) - @tests.first.class.__send__( :suite_setup ) - yield(STARTED, name) - @tests.each do |test| - test.run(result, &progress_block) - end - yield(FINISHED, name) - @tests.first.class.__send__( :suite_teardown ) - end -end - -class FixturedTestCase < Test::Unit::TestCase - self.use_transactional_fixtures = true - self.use_instantiated_fixtures = false - - def suite_setup - end - - def suite_teardown - end - - # Rolls up all of the test* methods in the fixture into - # one suite, creating a new instance of the fixture for - # each method. - def self.suite - method_names = public_instance_methods(true) - tests = method_names.delete_if {|method_name| method_name !~ /^test./} - suite = FixturedTestSuite.new(name) - tests.sort.each do - |test| - catch(:invalid_test) do - suite << new(test) - end - end - return suite - end -end - - diff --git a/vendor/plugins/simply_versioned/uninstall.rb b/vendor/plugins/simply_versioned/uninstall.rb deleted file mode 100644 index 97383334634..00000000000 --- a/vendor/plugins/simply_versioned/uninstall.rb +++ /dev/null @@ -1 +0,0 @@ -# Uninstall hook code here