Sha256: 8e5ff7911efd6fe87d5dcd840df5a6e624200a6f5a2a6451631a54a53972b299

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'test_helper'

class ChangesTest < Test::Unit::TestCase
  context "A version's changes" do
    setup do
      @user = User.create(:name => 'Steve Richert')
    end

    should "initially be blank" do
      assert @user.versions.first.changes.blank?
    end

    should 'contain all changed attributes' do
      @user.name = 'Steve Jobs'
      changes = @user.changes
      @user.save
      assert_equal changes, @user.versions.last.changes.slice(*changes.keys)
    end

    should 'contain timestamp changes when applicable' do
      timestamp = 'updated_at'
      @user.update_attribute(:name, 'Steve Jobs')
      assert @user.class.content_columns.map(&:name).include?(timestamp)
      assert_contains @user.versions.last.changes.keys, timestamp
    end

    should 'contain no more than the changed attributes and not timestamps' do
      timestamps = %w(created_at created_on updated_at updated_on)
      @user.name = 'Steve Jobs'
      changes = @user.changes
      @user.save
      assert_equal changes, @user.versions.last.changes.except(*timestamps)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
andoq-vestal_versions-0.6.1 test/changes_test.rb