Files
danbooru/test/unit/session_loader_test.rb
evazion 1d2bac7b95 Remove CurrentUser.ip_addr.
Remove the `CurrentUser.ip_addr` global variable and replace it with
`request.remote_ip`. Before we had to track the current user's IP in a
global variable so that when we edited a post for example, we could pass
down the user's IP to the model and save it in the post_versions table.
Now that we now longer save IPs in version tables, we don't need a global
variable to get access to the current user's IP outside of controllers.
2022-09-18 05:02:10 -05:00

49 lines
1.5 KiB
Ruby

require 'test_helper'
class SessionLoaderTest < ActiveSupport::TestCase
context "SessionLoader" do
setup do
@request = mock
@request.stubs(:host).returns("danbooru")
@request.stubs(:remote_ip).returns("127.0.0.1")
@request.stubs(:path).returns("/")
@request.stubs(:authorization).returns(nil)
@request.stubs(:cookie_jar).returns({})
@request.stubs(:cookies).returns({})
@request.stubs(:parameters).returns({})
@request.stubs(:session).returns({})
@request.stubs(:headers).returns({})
SessionLoader.any_instance.stubs(:initialize_session_cookies)
end
teardown do
CurrentUser.user = nil
CurrentUser.safe_mode = nil
end
context ".safe_mode?" do
should "return true if the hostname is safebooru.donmai.us" do
@request.stubs(:host).returns("safebooru.donmai.us")
SessionLoader.new(@request).load
assert_equal(true, CurrentUser.safe_mode?)
end
should "return false if the host contains the string danbooru" do
@request.stubs(:host).returns("danbooru")
SessionLoader.new(@request).load
assert_equal(false, CurrentUser.safe_mode?)
end
should "return true if the user has enabled the safe mode account setting" do
@user = create(:user, enable_safe_mode: true)
@request.stubs(:session).returns(user_id: @user.id)
SessionLoader.new(@request).load
assert_equal(true, CurrentUser.safe_mode?)
end
end
end
end