Sha256: 37991ca6d3d78f469433e2023d119a1e86a3be1c998191349fc1d2c629b64aaf

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 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 equal its parent's attributes" do
      assert_equal @user.attributes, @user.versions.first.changes
    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 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

8 entries across 8 versions & 2 rubygems

Version Path
laserlemon-vestal_versions-0.4.2 test/changes_test.rb
laserlemon-vestal_versions-0.4.3 test/changes_test.rb
laserlemon-vestal_versions-0.4.4 test/changes_test.rb
laserlemon-vestal_versions-0.4.5 test/changes_test.rb
laserlemon-vestal_versions-0.5.0 test/changes_test.rb
vestal_versions-0.5.0 test/changes_test.rb
vestal_versions-0.4.5 test/changes_test.rb
vestal_versions-0.4.4 test/changes_test.rb