require File.dirname(__FILE__) + '/../test_helper' class PostsControllerTest < ActionController::TestCase load_schema def setup @post = Post.create(:title => "Hello", :body => "Hello World") end def test_should_audit_changes put :update, :id => @post.to_param, :post => { :title => "Changed" } @post.reload expected_change = { "title" => ["Hello", "Changed"]} assert_equal "Changed", @post.title assert_equal 2, @post.audits.count assert_equal expected_change, @post.audits.desc.first.change_set end def test_should_respect_current_user User.delete_all @user = User.create!(:name => "ControllerTest") User.create!(:name => "Someone Else") put :update, :id => @post.to_param, :post => { :title => "Changed User Test"}, :user_id => @user.id @post.reload audit = @post.audits.desc.first assert_equal @user.id, audit.user_id end def test_should_not_fail_if_current_user_nil User.delete_all put :update, :id => @post.to_param, :post => { :title => "Changed User Test"}, :user_id => nil @post.reload audit = @post.audits.desc.first assert_equal nil, audit.user_id end end