Sha256: 072701f978dc3e52351a0bf7b6e413665ee41fcc2b1ec85a7664d65e71c7fa8c

Contents?: true

Size: 1.85 KB

Versions: 21

Compression:

Stored size: 1.85 KB

Contents

require 'test_helper'

class CreationTest < Test::Unit::TestCase
  context 'The number of versions' do
    setup do
      @name = 'Steve Richert'
      @user = User.create(:name => @name)
      @count = @user.versions.count
    end

    should 'initially equal one' do
      assert_equal 1, @count
    end

    should 'not increase when no changes are made in an update' do
      @user.update_attribute(:name, @name)
      assert_equal @count, @user.versions.count
    end

    should 'not increase when no changes are made before a save' do
      @user.save
      assert_equal @count, @user.versions.count
    end

    should 'not increase when reverting to the current version' do
      @user.revert_to!(@user.version)
      assert_equal @count, @user.versions.count
    end

    context 'after an update' do
      setup do
        @initial_count = @count
        @name = 'Steve Jobs'
        @user.update_attribute(:name, @name)
        @count = @user.versions.count
      end

      should 'increase by one' do
        assert_equal @initial_count + 1, @count
      end

      should 'increase by one when reverted' do
        @user.revert_to!(:first)
        assert_equal @count + 1, @user.versions.count
      end

      should 'not increase until a revert is saved' do
        @user.revert_to(:first)
        assert_equal @count, @user.versions.count
        @user.save
        assert_not_equal @count, @user.versions.count
      end
    end

    context 'after multiple updates' do
      setup do
        @initial_count = @count
        @new_name = 'Steve Jobs'
        @user.update_attribute(:name, @new_name)
        @user.update_attribute(:name, @name)
        @count = @user.versions.count
      end

      should 'not increase when reverting to an identical version' do
        @user.revert_to!(:first)
        assert_equal @count, @user.versions.count
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 4 rubygems

Version Path
andoq-vestal_versions-0.6.1 test/creation_test.rb
laserlemon-vestal_versions-0.4.4 test/creation_test.rb
laserlemon-vestal_versions-0.4.5 test/creation_test.rb
laserlemon-vestal_versions-0.5.0 test/creation_test.rb
laserlemon-vestal_versions-0.6.0 test/creation_test.rb
laserlemon-vestal_versions-0.7.0 test/creation_test.rb
laserlemon-vestal_versions-0.7.1 test/creation_test.rb
laserlemon-vestal_versions-0.8.0 test/creation_test.rb
sthapit-vestal_versions-0.7.0 test/creation_test.rb
sthapit-vestal_versions-0.7.1 test/creation_test.rb
sthapit-vestal_versions-0.8.0 test/creation_test.rb
vestal_versions-0.8.3 test/creation_test.rb
vestal_versions-0.8.1 test/creation_test.rb
vestal_versions-0.8.2 test/creation_test.rb
vestal_versions-0.8.0 test/creation_test.rb
vestal_versions-0.7.1 test/creation_test.rb
vestal_versions-0.7.0 test/creation_test.rb
vestal_versions-0.6.0 test/creation_test.rb
vestal_versions-0.5.0 test/creation_test.rb
vestal_versions-0.4.5 test/creation_test.rb