From dd56dc7da6970dbfff634b4115973ad278ab19d6 Mon Sep 17 00:00:00 2001 From: Kush Kella Date: Thu, 22 May 2014 11:11:06 -0700 Subject: [PATCH] added test for update_tracked_fields method --- test/models/trackable_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/models/trackable_test.rb b/test/models/trackable_test.rb index 6abcd76c..c63682f3 100644 --- a/test/models/trackable_test.rb +++ b/test/models/trackable_test.rb @@ -10,4 +10,32 @@ class TrackableTest < ActiveSupport::TestCase :sign_in_count ] end + + test 'update_tracked_fields should only set attributes but not save the record' do + user = create_user + request = mock + request.stubs(:remote_ip).returns("127.0.0.1") + + assert_nil user.current_sign_in_ip + assert_nil user.last_sign_in_ip + assert_nil user.current_sign_in_at + assert_nil user.last_sign_in_at + assert_equal 0, user.sign_in_count + + user.update_tracked_fields(request) + + assert_equal "127.0.0.1", user.current_sign_in_ip + assert_equal "127.0.0.1", user.last_sign_in_ip + assert_not_nil user.current_sign_in_at + assert_not_nil user.last_sign_in_at + assert_equal 1, user.sign_in_count + + user.reload + + assert_nil user.current_sign_in_ip + assert_nil user.last_sign_in_ip + assert_nil user.current_sign_in_at + assert_nil user.last_sign_in_at + assert_equal 0, user.sign_in_count + end end