discourse/spec/lib/current_user_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

22 lines
547 B
Ruby

# frozen_string_literal: true
describe CurrentUser do
it "allows us to lookup a user from our environment" do
user = Fabricate(:user, active: true)
token = UserAuthToken.generate!(user_id: user.id)
cookie = create_auth_cookie(
token: token.unhashed_auth_token,
user_id: user.id,
trust_level: user.trust_level,
issued_at: 5.minutes.ago,
)
env = create_request_env(path: "/test").merge(
"HTTP_COOKIE" => "_t=#{cookie};"
)
expect(CurrentUser.lookup_from_env(env)).to eq(user)
end
end