mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 12:28:59 +08:00
fab8b8649e
These two classes were running very similar queries, which could be expensive on large topics
57 lines
1.5 KiB
Ruby
57 lines
1.5 KiB
Ruby
# encoding: utf-8
|
|
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe UserLookup do
|
|
fab!(:user) { Fabricate(:user, username: "john_doe", name: "John Doe") }
|
|
|
|
describe '#[]' do
|
|
before do
|
|
@user_lookup = UserLookup.new([user.id, nil])
|
|
end
|
|
|
|
it 'returns nil if user_id does not exists' do
|
|
expect(@user_lookup[0]).to eq(nil)
|
|
end
|
|
|
|
it 'returns nil if user_id is nil' do
|
|
expect(@user_lookup[nil]).to eq(nil)
|
|
end
|
|
|
|
it 'returns user if user_id exists' do
|
|
user_lookup_user = @user_lookup[user.id]
|
|
expect(user_lookup_user).to eq(user)
|
|
expect(user_lookup_user.username).to eq("john_doe")
|
|
expect(user_lookup_user.name).to eq("John Doe")
|
|
end
|
|
end
|
|
|
|
describe '#primary_groups' do
|
|
fab!(:group) { Fabricate(:group, name: 'testgroup') }
|
|
fab!(:user2) { Fabricate(:user, username: "jane_doe", name: "Jane Doe", primary_group: group) }
|
|
|
|
before do
|
|
@user_lookup = UserLookup.new([user.id, user2.id, nil])
|
|
end
|
|
|
|
it 'returns nil if user_id does not exists' do
|
|
expect(@user_lookup.primary_groups[0]).to eq(nil)
|
|
end
|
|
|
|
it 'returns nil if user_id is nil' do
|
|
expect(@user_lookup.primary_groups[nil]).to eq(nil)
|
|
end
|
|
|
|
it 'returns nil if user has no primary group' do
|
|
expect(@user_lookup.primary_groups[user.id]).to eq(nil)
|
|
end
|
|
|
|
it 'returns group if user has primary group' do
|
|
user_lookup_group = @user_lookup.primary_groups[user2.id]
|
|
expect(user_lookup_group).to eq(group)
|
|
expect(user_lookup_group.name).to eq("testgroup")
|
|
end
|
|
end
|
|
end
|