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 1, post.audits.count assert_equal expected_change, audit.change_set end def test_should_not_audit_creation old_count = Audit.count User.create!(:name => "John Public") Post.create!(:title => "Test Post", :body => "Hello, world!") assert_equal old_count, Audit.count, Audit.all.map {|a| a.change_set.inspect }.join(" ") end end