eBooru/test/unit/session_loader_test.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

44 lines
1.3 KiB
Ruby

# frozen_string_literal: true
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(:authorization).returns(nil)
cookie_jar = mock
cookie_jar.stubs(:encrypted).returns({})
@request.stubs(:cookie_jar).returns(cookie_jar)
@request.stubs(:parameters).returns({})
@request.stubs(:session).returns({})
end
context ".safe_mode?" do
should "return true if the config has safe mode enabled" do
Danbooru.config.stubs(:safe_mode?).returns(true)
SessionLoader.new(@request).load
assert_equal(true, CurrentUser.safe_mode?)
end
should "return false if the config has safe mode disabled" do
Danbooru.config.stubs(:safe_mode?).returns(false)
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, ph: @user.password_token)
SessionLoader.new(@request).load
assert_equal(true, CurrentUser.safe_mode?)
end
end
end
end