Sha256: f28b19f5f7db85d44f88acc454fab87f3dae5242a8223996b01ca16e5a5fab90

Contents?: true

Size: 979 Bytes

Versions: 3

Compression:

Stored size: 979 Bytes

Contents

require File.dirname(__FILE__) + '/test_helper'

class TrackChangesTest < Test::Unit::TestCase
  load_schema

  def test_schema_has_loaded_correctly
    assert_equal [], Audit.all
    assert_equal [], Post.all
    assert_equal [], User.all
  end

  def test_should_add_track_changes_method_to_models
    assert Post.new.respond_to?(:current_user)
    assert Post.new.respond_to?(:current_user=)
  end

  def test_should_add_association_to_models
    assert Post.new.respond_to?(:audits)
    assert_equal [], Post.new.audits.all
  end

  def test_should_audit_changes
    user = User.create!(:name => "John Public")
    post = Post.create!(:title => "Test Post", :body => "Hello, world!")

    post.update_attributes(:title => "Title Changed")

    audit = post.audits.desc.first
    expected_change = {"title" => ["Test Post", "Title Changed"]}

    assert_equal 2, post.audits.count
    assert_equal expected_change, audit.change_set
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
track_changes-1.0.0.pre3 test/track_changes_test.rb
track_changes-1.0.0.pre2 test/track_changes_test.rb
track_changes-1.0.0.pre1 test/track_changes_test.rb