2013-05-25 14:50:39 +08:00
|
|
|
# encoding: utf-8
|
2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
2013-05-25 14:50:39 +08:00
|
|
|
|
2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2013-06-29 01:55:34 +08:00
|
|
|
require_dependency 'avatar_lookup'
|
2013-05-25 14:50:39 +08:00
|
|
|
|
|
|
|
describe AvatarLookup do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user) { Fabricate(:user, username: "john_doe", name: "John Doe") }
|
2013-05-25 14:50:39 +08:00
|
|
|
|
|
|
|
describe '#[]' do
|
|
|
|
before do
|
2013-07-13 05:07:54 +08:00
|
|
|
@avatar_lookup = AvatarLookup.new([user.id, nil])
|
2013-05-25 14:50:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil if user_id does not exists' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(@avatar_lookup[0]).to eq(nil)
|
2013-05-25 14:50:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil if user_id is nil' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(@avatar_lookup[nil]).to eq(nil)
|
2013-05-25 14:50:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns user if user_id exists' do
|
2018-08-21 19:58:11 +08:00
|
|
|
avatar_lookup_user = @avatar_lookup[user.id]
|
|
|
|
expect(avatar_lookup_user).to eq(user)
|
|
|
|
expect(avatar_lookup_user.username).to eq("john_doe")
|
|
|
|
expect(avatar_lookup_user.name).to eq("John Doe")
|
2013-05-25 14:50:39 +08:00
|
|
|
end
|
|
|
|
end
|
2014-09-25 23:44:48 +08:00
|
|
|
end
|