mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 13:03:45 +08:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
55 lines
1.5 KiB
Ruby
55 lines
1.5 KiB
Ruby
# encoding: utf-8
|
|
# frozen_string_literal: true
|
|
|
|
RSpec.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
|