diff --git a/app/logical/session_loader.rb b/app/logical/session_loader.rb index 851291022..d62f4748f 100644 --- a/app/logical/session_loader.rb +++ b/app/logical/session_loader.rb @@ -14,9 +14,7 @@ class SessionLoader CurrentUser.user = User.anonymous CurrentUser.ip_addr = request.remote_ip - if Rails.env.test? && Thread.current[:test_user_id] - load_for_test(Thread.current[:test_user_id]) - elsif session[:user_id] + if session[:user_id] load_session_user elsif cookie_password_hash_valid? load_cookie_user @@ -34,11 +32,6 @@ class SessionLoader private - def load_for_test(user_id) - CurrentUser.user = User.find(user_id) - CurrentUser.ip_addr = "127.0.0.1" - end - def set_statement_timeout timeout = CurrentUser.user.statement_timeout ActiveRecord::Base.connection.execute("set statement_timeout = #{timeout}") diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb index 49fc2048b..49e70ed93 100644 --- a/test/functional/comments_controller_test.rb +++ b/test/functional/comments_controller_test.rb @@ -93,13 +93,13 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest end should "update the body" do - put_auth comment_path(@comment.id), @comment.creator, params: {comment: {body: "abc"}} + put_auth comment_path(@comment.id), @user, params: {comment: {body: "abc"}} assert_equal("abc", @comment.reload.body) assert_redirected_to post_path(@comment.post) end should "allow changing the body and is_deleted" do - put_auth comment_path(@comment.id), @comment.creator, params: {comment: {body: "herp derp", is_deleted: true}} + put_auth comment_path(@comment.id), @user, params: {comment: {body: "herp derp", is_deleted: true}} assert_equal("herp derp", @comment.reload.body) assert_equal(true, @comment.is_deleted) assert_redirected_to post_path(@post) diff --git a/test/test_helper.rb b/test/test_helper.rb index d28ab0787..bc15e5c76 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -98,10 +98,8 @@ class ActionDispatch::IntegrationTest include TestHelpers def method_authenticated(method_name, url, user, options) - Thread.current[:test_user_id] = user.id + post session_path, params: { name: user.name, password: user.password } self.send(method_name, url, options) - ensure - Thread.current[:test_user_id] = nil end def get_auth(url, user, options = {})