eBooru/test/unit/current_user_test.rb

31 lines
825 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require "test_helper"
2010-08-18 18:44:18 -04:00
2013-05-25 19:09:30 -04:00
class CurrentUserTest < ActiveSupport::TestCase
2010-08-27 16:59:59 -04:00
context "A scoped current user" do
should "reset the current user after the block has exited" do
user1 = create(:user)
user2 = create(:user)
2010-08-27 16:59:59 -04:00
CurrentUser.user = user1
as(user2, nil) do
2010-08-27 16:59:59 -04:00
assert_equal(user2.id, CurrentUser.user.id)
end
assert_equal(user1.id, CurrentUser.user.id)
end
2013-03-19 08:10:10 -04:00
2010-08-27 16:59:59 -04:00
should "reset the current user even if an exception is thrown" do
user1 = create(:user)
user2 = create(:user)
2010-08-27 16:59:59 -04:00
CurrentUser.user = user1
assert_raises(RuntimeError) do
as(user2, nil) do
2010-08-27 16:59:59 -04:00
assert_equal(user2.id, CurrentUser.user.id)
raise "ERROR"
end
end
assert_equal(user1.id, CurrentUser.user.id)
end
end
end