Sha256: a87a5c3af1597e31a4d1cafee4083b75ff9dda8515ea0d34b22667f7b4150b95

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

require 'test_helper'

class LastChangesTest < 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.last_changes.blank?
      assert @user.last_changed.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 'have keys matching its last changed attributes' do
      assert_equal @user.last_changes.keys, @user.last_changed
    end

    should 'values of two-element arrays with unique values' do
      @user.last_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.last_changes.inject({}){|h,(k,v)| h.update(k => v.first) }
      previous = @previous_attributes.slice(*@user.last_changed)
      assert_equal previous, changes
    end

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

Version data entries

6 entries across 6 versions & 2 rubygems

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