vestal_versions 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -20
 - data/.travis.yml +22 -0
 - data/CHANGELOG.md +7 -0
 - data/Gemfile +10 -0
 - data/README.rdoc +63 -36
 - data/Rakefile +4 -43
 - data/gemfiles/activerecord_3_0.gemfile +10 -0
 - data/gemfiles/activerecord_3_1.gemfile +10 -0
 - data/gemfiles/activerecord_3_2.gemfile +10 -0
 - data/gemfiles/activerecord_4_0.gemfile +10 -0
 - data/lib/generators/vestal_versions.rb +11 -0
 - data/lib/generators/vestal_versions/migration/migration_generator.rb +17 -0
 - data/{generators/vestal_versions → lib/generators/vestal_versions/migration}/templates/initializer.rb +0 -0
 - data/{generators/vestal_versions → lib/generators/vestal_versions/migration}/templates/migration.rb +4 -3
 - data/lib/vestal_versions.rb +39 -12
 - data/lib/vestal_versions/changes.rb +43 -47
 - data/lib/vestal_versions/conditions.rb +31 -43
 - data/lib/vestal_versions/control.rb +162 -138
 - data/lib/vestal_versions/creation.rb +67 -59
 - data/lib/vestal_versions/deletion.rb +37 -0
 - data/lib/vestal_versions/options.rb +6 -10
 - data/lib/vestal_versions/reload.rb +7 -14
 - data/lib/vestal_versions/reset.rb +15 -19
 - data/lib/vestal_versions/reversion.rb +64 -52
 - data/lib/vestal_versions/users.rb +36 -39
 - data/lib/vestal_versions/version.rb +57 -2
 - data/lib/vestal_versions/version_tagging.rb +51 -0
 - data/lib/vestal_versions/versioned.rb +14 -17
 - data/lib/vestal_versions/versions.rb +22 -7
 - data/spec/spec_helper.rb +28 -0
 - data/spec/support/models.rb +19 -0
 - data/spec/support/schema.rb +25 -0
 - data/spec/vestal_versions/changes_spec.rb +134 -0
 - data/spec/vestal_versions/conditions_spec.rb +103 -0
 - data/spec/vestal_versions/control_spec.rb +120 -0
 - data/spec/vestal_versions/creation_spec.rb +90 -0
 - data/spec/vestal_versions/deletion_spec.rb +86 -0
 - data/spec/vestal_versions/options_spec.rb +45 -0
 - data/spec/vestal_versions/reload_spec.rb +18 -0
 - data/spec/vestal_versions/reset_spec.rb +111 -0
 - data/spec/vestal_versions/reversion_spec.rb +103 -0
 - data/spec/vestal_versions/users_spec.rb +21 -0
 - data/spec/vestal_versions/version_spec.rb +61 -0
 - data/spec/vestal_versions/version_tagging_spec.rb +39 -0
 - data/spec/vestal_versions/versioned_spec.rb +16 -0
 - data/spec/vestal_versions/versions_spec.rb +176 -0
 - data/vestal_versions.gemspec +18 -100
 - metadata +153 -102
 - data/VERSION +0 -1
 - data/generators/vestal_versions/vestal_versions_generator.rb +0 -10
 - data/init.rb +0 -1
 - data/lib/vestal_versions/configuration.rb +0 -40
 - data/lib/vestal_versions/tagging.rb +0 -50
 - data/test/changes_test.rb +0 -169
 - data/test/conditions_test.rb +0 -137
 - data/test/configuration_test.rb +0 -39
 - data/test/control_test.rb +0 -152
 - data/test/creation_test.rb +0 -110
 - data/test/options_test.rb +0 -52
 - data/test/reload_test.rb +0 -19
 - data/test/reset_test.rb +0 -112
 - data/test/reversion_test.rb +0 -68
 - data/test/schema.rb +0 -43
 - data/test/tagging_test.rb +0 -39
 - data/test/test_helper.rb +0 -11
 - data/test/users_test.rb +0 -25
 - data/test/version_test.rb +0 -43
 - data/test/versioned_test.rb +0 -18
 - data/test/versions_test.rb +0 -172
 
    
        data/test/conditions_test.rb
    DELETED
    
    | 
         @@ -1,137 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.join(File.dirname(__FILE__), 'test_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class ConditionsTest < Test::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              context 'Converted :if conditions' do
         
     | 
| 
       5 
     | 
    
         
            -
                setup do
         
     | 
| 
       6 
     | 
    
         
            -
                  User.class_eval do
         
     | 
| 
       7 
     | 
    
         
            -
                    def true; true; end
         
     | 
| 
       8 
     | 
    
         
            -
                  end
         
     | 
| 
       9 
     | 
    
         
            -
                end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                should 'be an array' do
         
     | 
| 
       12 
     | 
    
         
            -
                  assert_kind_of Array, User.vestal_versions_options[:if]
         
     | 
| 
       13 
     | 
    
         
            -
                  User.prepare_versioned_options(:if => :true)
         
     | 
| 
       14 
     | 
    
         
            -
                  assert_kind_of Array, User.vestal_versions_options[:if]
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                should 'have proc values' do
         
     | 
| 
       18 
     | 
    
         
            -
                  User.prepare_versioned_options(:if => :true)
         
     | 
| 
       19 
     | 
    
         
            -
                  assert User.vestal_versions_options[:if].all?{|i| i.is_a?(Proc) }
         
     | 
| 
       20 
     | 
    
         
            -
                end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                teardown do
         
     | 
| 
       23 
     | 
    
         
            -
                  User.prepare_versioned_options(:if => [])
         
     | 
| 
       24 
     | 
    
         
            -
                end
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              context 'Converted :unless conditions' do
         
     | 
| 
       28 
     | 
    
         
            -
                setup do
         
     | 
| 
       29 
     | 
    
         
            -
                  User.class_eval do
         
     | 
| 
       30 
     | 
    
         
            -
                    def true; true; end
         
     | 
| 
       31 
     | 
    
         
            -
                  end
         
     | 
| 
       32 
     | 
    
         
            -
                end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                should 'be an array' do
         
     | 
| 
       35 
     | 
    
         
            -
                  assert_kind_of Array, User.vestal_versions_options[:unless]
         
     | 
| 
       36 
     | 
    
         
            -
                  User.prepare_versioned_options(:unless => :true)
         
     | 
| 
       37 
     | 
    
         
            -
                  assert_kind_of Array, User.vestal_versions_options[:unless]
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                should 'have proc values' do
         
     | 
| 
       41 
     | 
    
         
            -
                  User.prepare_versioned_options(:unless => :true)
         
     | 
| 
       42 
     | 
    
         
            -
                  assert User.vestal_versions_options[:unless].all?{|i| i.is_a?(Proc) }
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                teardown do
         
     | 
| 
       46 
     | 
    
         
            -
                  User.prepare_versioned_options(:unless => [])
         
     | 
| 
       47 
     | 
    
         
            -
                end
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
              context 'A new version' do
         
     | 
| 
       51 
     | 
    
         
            -
                setup do
         
     | 
| 
       52 
     | 
    
         
            -
                  User.class_eval do
         
     | 
| 
       53 
     | 
    
         
            -
                    def true; true; end
         
     | 
| 
       54 
     | 
    
         
            -
                    def false; false; end
         
     | 
| 
       55 
     | 
    
         
            -
                  end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                  @user = User.create(:name => 'Steve Richert')
         
     | 
| 
       58 
     | 
    
         
            -
                  @count = @user.versions.count
         
     | 
| 
       59 
     | 
    
         
            -
                end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                context 'with :if conditions' do
         
     | 
| 
       62 
     | 
    
         
            -
                  context 'that pass' do
         
     | 
| 
       63 
     | 
    
         
            -
                    setup do
         
     | 
| 
       64 
     | 
    
         
            -
                      User.prepare_versioned_options(:if => [:true])
         
     | 
| 
       65 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       66 
     | 
    
         
            -
                    end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                    should 'be created' do
         
     | 
| 
       69 
     | 
    
         
            -
                      assert_equal @count + 1, @user.versions.count
         
     | 
| 
       70 
     | 
    
         
            -
                    end
         
     | 
| 
       71 
     | 
    
         
            -
                  end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                  context 'that fail' do
         
     | 
| 
       74 
     | 
    
         
            -
                    setup do
         
     | 
| 
       75 
     | 
    
         
            -
                      User.prepare_versioned_options(:if => [:false])
         
     | 
| 
       76 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       77 
     | 
    
         
            -
                    end
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                    should 'not be created' do
         
     | 
| 
       80 
     | 
    
         
            -
                      assert_equal @count, @user.versions.count
         
     | 
| 
       81 
     | 
    
         
            -
                    end
         
     | 
| 
       82 
     | 
    
         
            -
                  end
         
     | 
| 
       83 
     | 
    
         
            -
                end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
                context 'with :unless conditions' do
         
     | 
| 
       86 
     | 
    
         
            -
                  context 'that pass' do
         
     | 
| 
       87 
     | 
    
         
            -
                    setup do
         
     | 
| 
       88 
     | 
    
         
            -
                      User.prepare_versioned_options(:unless => [:true])
         
     | 
| 
       89 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       90 
     | 
    
         
            -
                    end
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
                    should 'not be created' do
         
     | 
| 
       93 
     | 
    
         
            -
                      assert_equal @count, @user.versions.count
         
     | 
| 
       94 
     | 
    
         
            -
                    end
         
     | 
| 
       95 
     | 
    
         
            -
                  end
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                  context 'that fail' do
         
     | 
| 
       98 
     | 
    
         
            -
                    setup do
         
     | 
| 
       99 
     | 
    
         
            -
                      User.prepare_versioned_options(:unless => [:false])
         
     | 
| 
       100 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       101 
     | 
    
         
            -
                    end
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
                    should 'not be created' do
         
     | 
| 
       104 
     | 
    
         
            -
                      assert_equal @count + 1, @user.versions.count
         
     | 
| 
       105 
     | 
    
         
            -
                    end
         
     | 
| 
       106 
     | 
    
         
            -
                  end
         
     | 
| 
       107 
     | 
    
         
            -
                end
         
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
                context 'with :if and :unless conditions' do
         
     | 
| 
       110 
     | 
    
         
            -
                  context 'that pass' do
         
     | 
| 
       111 
     | 
    
         
            -
                    setup do
         
     | 
| 
       112 
     | 
    
         
            -
                      User.prepare_versioned_options(:if => [:true], :unless => [:true])
         
     | 
| 
       113 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       114 
     | 
    
         
            -
                    end
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
                    should 'not be created' do
         
     | 
| 
       117 
     | 
    
         
            -
                      assert_equal @count, @user.versions.count
         
     | 
| 
       118 
     | 
    
         
            -
                    end
         
     | 
| 
       119 
     | 
    
         
            -
                  end
         
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
                  context 'that fail' do
         
     | 
| 
       122 
     | 
    
         
            -
                    setup do
         
     | 
| 
       123 
     | 
    
         
            -
                      User.prepare_versioned_options(:if => [:false], :unless => [:false])
         
     | 
| 
       124 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       125 
     | 
    
         
            -
                    end
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                    should 'not be created' do
         
     | 
| 
       128 
     | 
    
         
            -
                      assert_equal @count, @user.versions.count
         
     | 
| 
       129 
     | 
    
         
            -
                    end
         
     | 
| 
       130 
     | 
    
         
            -
                  end
         
     | 
| 
       131 
     | 
    
         
            -
                end
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                teardown do
         
     | 
| 
       134 
     | 
    
         
            -
                  User.prepare_versioned_options(:if => [], :unless => [])
         
     | 
| 
       135 
     | 
    
         
            -
                end
         
     | 
| 
       136 
     | 
    
         
            -
              end
         
     | 
| 
       137 
     | 
    
         
            -
            end
         
     | 
    
        data/test/configuration_test.rb
    DELETED
    
    | 
         @@ -1,39 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.join(File.dirname(__FILE__), 'test_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class ConfigurationTest < Test::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              context 'Global configuration options' do
         
     | 
| 
       5 
     | 
    
         
            -
                setup do
         
     | 
| 
       6 
     | 
    
         
            -
                  module Extension; end
         
     | 
| 
       7 
     | 
    
         
            -
                  
         
     | 
| 
       8 
     | 
    
         
            -
                  @options = {
         
     | 
| 
       9 
     | 
    
         
            -
                    'class_name' => 'CustomVersion',
         
     | 
| 
       10 
     | 
    
         
            -
                    :extend => Extension,
         
     | 
| 
       11 
     | 
    
         
            -
                    :as => :parent
         
     | 
| 
       12 
     | 
    
         
            -
                  }
         
     | 
| 
       13 
     | 
    
         
            -
                  
         
     | 
| 
       14 
     | 
    
         
            -
                  VestalVersions.configure do |config|
         
     | 
| 
       15 
     | 
    
         
            -
                    @options.each do |key, value|
         
     | 
| 
       16 
     | 
    
         
            -
                      config.send("#{key}=", value)
         
     | 
| 
       17 
     | 
    
         
            -
                    end
         
     | 
| 
       18 
     | 
    
         
            -
                  end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                  @configuration = VestalVersions::Configuration.options
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                should 'should be a hash' do
         
     | 
| 
       24 
     | 
    
         
            -
                  assert_kind_of Hash, @configuration
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                should 'have symbol keys' do
         
     | 
| 
       28 
     | 
    
         
            -
                  assert @configuration.keys.all?{|k| k.is_a?(Symbol) }
         
     | 
| 
       29 
     | 
    
         
            -
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                should 'store values identical to those given' do
         
     | 
| 
       32 
     | 
    
         
            -
                  assert_equal @options.symbolize_keys, @configuration
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                teardown do
         
     | 
| 
       36 
     | 
    
         
            -
                  VestalVersions::Configuration.options.clear
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
            end
         
     | 
    
        data/test/control_test.rb
    DELETED
    
    | 
         @@ -1,152 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.join(File.dirname(__FILE__), 'test_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class ControlTest < Test::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              context 'Within a skip_version block,' do
         
     | 
| 
       5 
     | 
    
         
            -
                setup do
         
     | 
| 
       6 
     | 
    
         
            -
                  @user = User.create(:name => 'Steve Richert')
         
     | 
| 
       7 
     | 
    
         
            -
                  @count = @user.versions.count
         
     | 
| 
       8 
     | 
    
         
            -
                end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                context 'a model update' do
         
     | 
| 
       11 
     | 
    
         
            -
                  setup do
         
     | 
| 
       12 
     | 
    
         
            -
                    @user.skip_version do
         
     | 
| 
       13 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       14 
     | 
    
         
            -
                    end
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                  should 'not create a version' do
         
     | 
| 
       18 
     | 
    
         
            -
                    assert_equal @count, @user.versions.count
         
     | 
| 
       19 
     | 
    
         
            -
                  end
         
     | 
| 
       20 
     | 
    
         
            -
                end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                context 'multiple model updates' do
         
     | 
| 
       23 
     | 
    
         
            -
                  setup do
         
     | 
| 
       24 
     | 
    
         
            -
                    @user.skip_version do
         
     | 
| 
       25 
     | 
    
         
            -
                      @user.update_attribute(:first_name, 'Stephen')
         
     | 
| 
       26 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       27 
     | 
    
         
            -
                      @user.update_attribute(:first_name, 'Steve')
         
     | 
| 
       28 
     | 
    
         
            -
                    end
         
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  should 'not create a version' do
         
     | 
| 
       32 
     | 
    
         
            -
                    assert_equal @count, @user.versions.count
         
     | 
| 
       33 
     | 
    
         
            -
                  end
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
              context 'Within a merge_version block,' do
         
     | 
| 
       38 
     | 
    
         
            -
                setup do
         
     | 
| 
       39 
     | 
    
         
            -
                  @user = User.create(:name => 'Steve Richert')
         
     | 
| 
       40 
     | 
    
         
            -
                  @count = @user.versions.count
         
     | 
| 
       41 
     | 
    
         
            -
                end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                context 'a model update' do
         
     | 
| 
       44 
     | 
    
         
            -
                  setup do
         
     | 
| 
       45 
     | 
    
         
            -
                    @user.merge_version do
         
     | 
| 
       46 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       47 
     | 
    
         
            -
                    end
         
     | 
| 
       48 
     | 
    
         
            -
                  end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                  should 'create a version' do
         
     | 
| 
       51 
     | 
    
         
            -
                    assert_equal @count + 1, @user.versions.count
         
     | 
| 
       52 
     | 
    
         
            -
                  end
         
     | 
| 
       53 
     | 
    
         
            -
                end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                context 'multiple model updates' do
         
     | 
| 
       56 
     | 
    
         
            -
                  setup do
         
     | 
| 
       57 
     | 
    
         
            -
                    @user.merge_version do
         
     | 
| 
       58 
     | 
    
         
            -
                      @user.update_attribute(:first_name, 'Stephen')
         
     | 
| 
       59 
     | 
    
         
            -
                      @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       60 
     | 
    
         
            -
                      @user.update_attribute(:first_name, 'Steve')
         
     | 
| 
       61 
     | 
    
         
            -
                    end
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                  should 'create a version' do
         
     | 
| 
       65 
     | 
    
         
            -
                    assert_equal @count + 1, @user.versions.count
         
     | 
| 
       66 
     | 
    
         
            -
                  end
         
     | 
| 
       67 
     | 
    
         
            -
                end
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
              context 'Within a append_version block' do
         
     | 
| 
       71 
     | 
    
         
            -
                context '(when no versions exist),' do
         
     | 
| 
       72 
     | 
    
         
            -
                  setup do
         
     | 
| 
       73 
     | 
    
         
            -
                    @user = User.create(:name => 'Steve Richert')
         
     | 
| 
       74 
     | 
    
         
            -
                    @count = @user.versions.count
         
     | 
| 
       75 
     | 
    
         
            -
                  end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                  context 'a model update' do
         
     | 
| 
       78 
     | 
    
         
            -
                    setup do
         
     | 
| 
       79 
     | 
    
         
            -
                      @user.append_version do
         
     | 
| 
       80 
     | 
    
         
            -
                        @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       81 
     | 
    
         
            -
                      end
         
     | 
| 
       82 
     | 
    
         
            -
                    end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                    should 'create a version' do
         
     | 
| 
       85 
     | 
    
         
            -
                      assert_equal @count + 1, @user.versions.count
         
     | 
| 
       86 
     | 
    
         
            -
                    end
         
     | 
| 
       87 
     | 
    
         
            -
                  end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                  context 'multiple model updates' do
         
     | 
| 
       90 
     | 
    
         
            -
                    setup do
         
     | 
| 
       91 
     | 
    
         
            -
                      @user.append_version do
         
     | 
| 
       92 
     | 
    
         
            -
                        @user.update_attribute(:first_name, 'Stephen')
         
     | 
| 
       93 
     | 
    
         
            -
                        @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       94 
     | 
    
         
            -
                        @user.update_attribute(:first_name, 'Steve')
         
     | 
| 
       95 
     | 
    
         
            -
                      end
         
     | 
| 
       96 
     | 
    
         
            -
                    end
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
                    should 'create a version' do
         
     | 
| 
       99 
     | 
    
         
            -
                      assert_equal @count + 1, @user.versions.count
         
     | 
| 
       100 
     | 
    
         
            -
                    end
         
     | 
| 
       101 
     | 
    
         
            -
                  end
         
     | 
| 
       102 
     | 
    
         
            -
                end
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
                context '(when versions exist),' do
         
     | 
| 
       105 
     | 
    
         
            -
                  setup do
         
     | 
| 
       106 
     | 
    
         
            -
                    @user = User.create(:name => 'Steve Richert')
         
     | 
| 
       107 
     | 
    
         
            -
                    @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       108 
     | 
    
         
            -
                    @user.update_attribute(:last_name, 'Richert')
         
     | 
| 
       109 
     | 
    
         
            -
                    @last_version = @user.versions.last
         
     | 
| 
       110 
     | 
    
         
            -
                    @count = @user.versions.count
         
     | 
| 
       111 
     | 
    
         
            -
                  end
         
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
                  context 'a model update' do
         
     | 
| 
       114 
     | 
    
         
            -
                    setup do
         
     | 
| 
       115 
     | 
    
         
            -
                      @user.append_version do
         
     | 
| 
       116 
     | 
    
         
            -
                        @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       117 
     | 
    
         
            -
                      end
         
     | 
| 
       118 
     | 
    
         
            -
                    end
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                    should 'not create a version' do
         
     | 
| 
       121 
     | 
    
         
            -
                      assert_equal @count, @user.versions.count
         
     | 
| 
       122 
     | 
    
         
            -
                    end
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
                    should 'update the last version' do
         
     | 
| 
       125 
     | 
    
         
            -
                      last_version = @user.versions(true).last
         
     | 
| 
       126 
     | 
    
         
            -
                      assert_equal @last_version.id, last_version.id
         
     | 
| 
       127 
     | 
    
         
            -
                      assert_not_equal @last_version.attributes, last_version.attributes
         
     | 
| 
       128 
     | 
    
         
            -
                    end
         
     | 
| 
       129 
     | 
    
         
            -
                  end
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                  context 'multiple model updates' do
         
     | 
| 
       132 
     | 
    
         
            -
                    setup do
         
     | 
| 
       133 
     | 
    
         
            -
                      @user.append_version do
         
     | 
| 
       134 
     | 
    
         
            -
                        @user.update_attribute(:first_name, 'Stephen')
         
     | 
| 
       135 
     | 
    
         
            -
                        @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       136 
     | 
    
         
            -
                        @user.update_attribute(:first_name, 'Steve')
         
     | 
| 
       137 
     | 
    
         
            -
                      end
         
     | 
| 
       138 
     | 
    
         
            -
                    end
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
                    should 'not create a version' do
         
     | 
| 
       141 
     | 
    
         
            -
                      assert_equal @count, @user.versions.count
         
     | 
| 
       142 
     | 
    
         
            -
                    end
         
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
                    should 'update the last version' do
         
     | 
| 
       145 
     | 
    
         
            -
                      last_version = @user.versions(true).last
         
     | 
| 
       146 
     | 
    
         
            -
                      assert_equal @last_version.id, last_version.id
         
     | 
| 
       147 
     | 
    
         
            -
                      assert_not_equal @last_version.attributes, last_version.attributes
         
     | 
| 
       148 
     | 
    
         
            -
                    end
         
     | 
| 
       149 
     | 
    
         
            -
                  end
         
     | 
| 
       150 
     | 
    
         
            -
                end
         
     | 
| 
       151 
     | 
    
         
            -
              end
         
     | 
| 
       152 
     | 
    
         
            -
            end
         
     | 
    
        data/test/creation_test.rb
    DELETED
    
    | 
         @@ -1,110 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.join(File.dirname(__FILE__), 'test_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class CreationTest < Test::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              context 'The number of versions' do
         
     | 
| 
       5 
     | 
    
         
            -
                setup do
         
     | 
| 
       6 
     | 
    
         
            -
                  @name = 'Steve Richert'
         
     | 
| 
       7 
     | 
    
         
            -
                  @user = User.create(:name => @name)
         
     | 
| 
       8 
     | 
    
         
            -
                  @count = @user.versions.count
         
     | 
| 
       9 
     | 
    
         
            -
                end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                should 'initially equal zero' do
         
     | 
| 
       12 
     | 
    
         
            -
                  assert_equal 0, @count
         
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                should 'not increase when no changes are made in an update' do
         
     | 
| 
       16 
     | 
    
         
            -
                  @user.update_attribute(:name, @name)
         
     | 
| 
       17 
     | 
    
         
            -
                  assert_equal @count, @user.versions.count
         
     | 
| 
       18 
     | 
    
         
            -
                end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                should 'not increase when no changes are made before a save' do
         
     | 
| 
       21 
     | 
    
         
            -
                  @user.save
         
     | 
| 
       22 
     | 
    
         
            -
                  assert_equal @count, @user.versions.count
         
     | 
| 
       23 
     | 
    
         
            -
                end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                context 'after an update' do
         
     | 
| 
       26 
     | 
    
         
            -
                  setup do
         
     | 
| 
       27 
     | 
    
         
            -
                    @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       28 
     | 
    
         
            -
                  end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                  should 'increase by one' do
         
     | 
| 
       31 
     | 
    
         
            -
                    assert_equal @count + 1, @user.versions.count
         
     | 
| 
       32 
     | 
    
         
            -
                  end
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                context 'after multiple updates' do
         
     | 
| 
       36 
     | 
    
         
            -
                  setup do
         
     | 
| 
       37 
     | 
    
         
            -
                    @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       38 
     | 
    
         
            -
                    @user.update_attribute(:last_name, 'Richert')
         
     | 
| 
       39 
     | 
    
         
            -
                  end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                  should 'increase multiple times' do
         
     | 
| 
       42 
     | 
    
         
            -
                    assert_operator @count + 1, :<, @user.versions.count
         
     | 
| 
       43 
     | 
    
         
            -
                  end
         
     | 
| 
       44 
     | 
    
         
            -
                end
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
              context "A created version's changes" do
         
     | 
| 
       48 
     | 
    
         
            -
                setup do
         
     | 
| 
       49 
     | 
    
         
            -
                  @user = User.create(:name => 'Steve Richert')
         
     | 
| 
       50 
     | 
    
         
            -
                  @user.update_attribute(:last_name, 'Jobs')
         
     | 
| 
       51 
     | 
    
         
            -
                end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                should 'not contain Rails timestamps' do
         
     | 
| 
       54 
     | 
    
         
            -
                  %w(created_at created_on updated_at updated_on).each do |timestamp|
         
     | 
| 
       55 
     | 
    
         
            -
                    assert_does_not_contain @user.versions.last.changes.keys, timestamp
         
     | 
| 
       56 
     | 
    
         
            -
                  end
         
     | 
| 
       57 
     | 
    
         
            -
                end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                context '(with :only options)' do
         
     | 
| 
       60 
     | 
    
         
            -
                  setup do
         
     | 
| 
       61 
     | 
    
         
            -
                    @only = %w(first_name)
         
     | 
| 
       62 
     | 
    
         
            -
                    User.prepare_versioned_options(:only => @only)
         
     | 
| 
       63 
     | 
    
         
            -
                    @user.update_attribute(:name, 'Steven Tyler')
         
     | 
| 
       64 
     | 
    
         
            -
                  end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                  should 'only contain the specified columns' do
         
     | 
| 
       67 
     | 
    
         
            -
                    assert_equal @only, @user.versions.last.changes.keys
         
     | 
| 
       68 
     | 
    
         
            -
                  end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                  teardown do
         
     | 
| 
       71 
     | 
    
         
            -
                    User.prepare_versioned_options(:only => nil)
         
     | 
| 
       72 
     | 
    
         
            -
                  end
         
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                context '(with :except options)' do
         
     | 
| 
       76 
     | 
    
         
            -
                  setup do
         
     | 
| 
       77 
     | 
    
         
            -
                    @except = %w(first_name)
         
     | 
| 
       78 
     | 
    
         
            -
                    User.prepare_versioned_options(:except => @except)
         
     | 
| 
       79 
     | 
    
         
            -
                    @user.update_attribute(:name, 'Steven Tyler')
         
     | 
| 
       80 
     | 
    
         
            -
                  end
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                  should 'not contain the specified columns' do
         
     | 
| 
       83 
     | 
    
         
            -
                    @except.each do |column|
         
     | 
| 
       84 
     | 
    
         
            -
                      assert_does_not_contain @user.versions.last.changes.keys, column
         
     | 
| 
       85 
     | 
    
         
            -
                    end
         
     | 
| 
       86 
     | 
    
         
            -
                  end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
                  teardown do
         
     | 
| 
       89 
     | 
    
         
            -
                    User.prepare_versioned_options(:except => nil)
         
     | 
| 
       90 
     | 
    
         
            -
                  end
         
     | 
| 
       91 
     | 
    
         
            -
                end
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                context '(with both :only and :except options)' do
         
     | 
| 
       94 
     | 
    
         
            -
                  setup do
         
     | 
| 
       95 
     | 
    
         
            -
                    @only = %w(first_name)
         
     | 
| 
       96 
     | 
    
         
            -
                    @except = @only
         
     | 
| 
       97 
     | 
    
         
            -
                    User.prepare_versioned_options(:only => @only, :except => @except)
         
     | 
| 
       98 
     | 
    
         
            -
                    @user.update_attribute(:name, 'Steven Tyler')
         
     | 
| 
       99 
     | 
    
         
            -
                  end
         
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
                  should 'respect only the :only options' do
         
     | 
| 
       102 
     | 
    
         
            -
                    assert_equal @only, @user.versions.last.changes.keys
         
     | 
| 
       103 
     | 
    
         
            -
                  end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
                  teardown do
         
     | 
| 
       106 
     | 
    
         
            -
                    User.prepare_versioned_options(:only => nil, :except => nil)
         
     | 
| 
       107 
     | 
    
         
            -
                  end
         
     | 
| 
       108 
     | 
    
         
            -
                end
         
     | 
| 
       109 
     | 
    
         
            -
              end
         
     | 
| 
       110 
     | 
    
         
            -
            end
         
     | 
    
        data/test/options_test.rb
    DELETED
    
    | 
         @@ -1,52 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.join(File.dirname(__FILE__), 'test_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class OptionsTest < Test::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              context 'Configuration options' do
         
     | 
| 
       5 
     | 
    
         
            -
                setup do
         
     | 
| 
       6 
     | 
    
         
            -
                  @options = {:dependent => :destroy}
         
     | 
| 
       7 
     | 
    
         
            -
                  @configuration = {:class_name => 'MyCustomVersion'}
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                  VestalVersions::Configuration.options.clear
         
     | 
| 
       10 
     | 
    
         
            -
                  @configuration.each{|k,v| VestalVersions::Configuration.send("#{k}=", v) }
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                  @prepared_options = User.prepare_versioned_options(@options.dup)
         
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                should 'have symbolized keys' do
         
     | 
| 
       16 
     | 
    
         
            -
                  assert User.vestal_versions_options.keys.all?{|k| k.is_a?(Symbol) }
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                should 'combine class-level and global configuration options' do
         
     | 
| 
       20 
     | 
    
         
            -
                  combined_keys = (@options.keys + @configuration.keys).map(&:to_sym).uniq
         
     | 
| 
       21 
     | 
    
         
            -
                  combined_options = @configuration.symbolize_keys.merge(@options.symbolize_keys)
         
     | 
| 
       22 
     | 
    
         
            -
                  assert_equal @prepared_options.slice(*combined_keys), combined_options
         
     | 
| 
       23 
     | 
    
         
            -
                end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                teardown do
         
     | 
| 
       26 
     | 
    
         
            -
                  VestalVersions::Configuration.options.clear
         
     | 
| 
       27 
     | 
    
         
            -
                  User.prepare_versioned_options({})
         
     | 
| 
       28 
     | 
    
         
            -
                end
         
     | 
| 
       29 
     | 
    
         
            -
              end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              context 'Given no options, configuration options' do
         
     | 
| 
       32 
     | 
    
         
            -
                setup do
         
     | 
| 
       33 
     | 
    
         
            -
                  @prepared_options = User.prepare_versioned_options({})
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                should 'default to "VestalVersions::Version" for :class_name' do
         
     | 
| 
       37 
     | 
    
         
            -
                  assert_equal 'VestalVersions::Version', @prepared_options[:class_name]
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                should 'default to :delete_all for :dependent' do
         
     | 
| 
       41 
     | 
    
         
            -
                  assert_equal :delete_all, @prepared_options[:dependent]
         
     | 
| 
       42 
     | 
    
         
            -
                end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                should 'force the :as option value to :versioned' do
         
     | 
| 
       45 
     | 
    
         
            -
                  assert_equal :versioned, @prepared_options[:as]
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                should 'default to [VestalVersions::Versions] for :extend' do
         
     | 
| 
       49 
     | 
    
         
            -
                  assert_equal [VestalVersions::Versions], @prepared_options[:extend]
         
     | 
| 
       50 
     | 
    
         
            -
                end
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
            end
         
     |