Sha256: 4471449db46e7e9df8a0ab2c14e14ab4988e04eff5a94a98804d3eb42c71680c

Contents?: true

Size: 1.26 KB

Versions: 17

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'

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

    should 'be blank' do
      assert @user.latest_changes.blank?
    end
  end

  context "An updated model's last changes" do
    setup do
      @user = User.create(:name => 'Steve Richert')
      @previous_attributes = @user.attributes
      @user.update_attribute(:name, 'Steve Jobs')
      @current_attributes = @user.attributes
    end

    should 'values of two-element arrays with unique values' do
      @user.latest_changes.values.each do |value|
        assert_kind_of Array, value
        assert_equal 2, value.size
        assert_equal value, value.uniq
      end
    end

    should 'begin with the previous attribute values' do
      changes = @user.latest_changes.inject({}){|h,(k,v)| h.update(k => v.first) }
      previous = @previous_attributes.slice(*@user.latest_changes.keys)
      assert_equal previous, changes
    end

    should 'end with the current attribute values' do
      changes = @user.latest_changes.inject({}){|h,(k,v)| h.update(k => v.last) }
      current = @current_attributes.slice(*@user.latest_changes.keys)
      assert_equal current, changes
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

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