Added teardown to all tests which resets Thread.current[:user] and friends to
authorPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 23 Apr 2014 17:36:16 +0000 (13:36 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 23 Apr 2014 17:36:16 +0000 (13:36 -0400)
nil.  Fixed one faulty test that turned up as a result of this change.

services/api/test/test_helper.rb
services/api/test/unit/user_test.rb

index e9133b6467f9b73d093684426919613f39b28257..fea983bf95901a9e9ce45e05f732a4d307f91178 100644 (file)
@@ -9,6 +9,14 @@ class ActiveSupport::TestCase
   # -- they do not yet inherit this setting
   fixtures :all
 
+  teardown do
+    Thread.current[:api_client_ip_address] = nil
+    Thread.current[:api_client_authorization] = nil
+    Thread.current[:api_client_uuid] = nil
+    Thread.current[:api_client] = nil
+    Thread.current[:user] = nil
+  end
+
   def expect_json
     self.request.headers["Accept"] = "text/json"
   end
@@ -21,9 +29,19 @@ class ActiveSupport::TestCase
 end
 
 class ActionDispatch::IntegrationTest
+
+  teardown do
+    Thread.current[:api_client_ip_address] = nil
+    Thread.current[:api_client_authorization] = nil
+    Thread.current[:api_client_uuid] = nil
+    Thread.current[:api_client] = nil
+    Thread.current[:user] = nil
+  end
+
   def jresponse
     @jresponse ||= ActiveSupport::JSON.decode @response.body
   end
+
   def auth auth_fixture
     {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(auth_fixture).api_token}"}
   end
index fd56a745a84a989eced4b0719437dc93fa979ff6..2d2db160cd3a0e971dd7ae56073b1de85216cfd0 100644 (file)
@@ -88,6 +88,8 @@ class UserTest < ActiveSupport::TestCase
   end
 
   test "full name should not contain spurious whitespace" do
+    Thread.current[:user] = @admin_user   # set admin user as the current user
+
     user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: 'foo@example.com' })
 
     assert_equal '', user.full_name