Commit b31462ae authored by Gabriel Mazetto's avatar Gabriel Mazetto

Specs for displaying avatars in Geo secondary node

parent 0a74ee3f
require 'spec_helper'
describe GroupsHelper do
let(:group) { create(:group) }
describe 'group_icon' do
avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif')
it 'returns an url for the avatar' do
group = create(:group)
group.avatar = File.open(avatar_file_path)
group.save!
expect(group_icon(group.path).to_s).
to match("/uploads/group/avatar/#{group.id}/banana_sample.gif")
expect(group_icon(group.path).to_s).to match("/uploads/group/avatar/#{group.id}/banana_sample.gif")
end
it 'gives default avatar_icon when no avatar is present' do
group = create(:group)
group.save!
expect(group_icon(group.path)).to match('group_avatar.png')
end
context 'in a geo secondary node' do
let(:geo_url) { 'http://geo.example.com' }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_url }
end
it 'returns an url for the avatar pointing to the primary node base url' do
group.avatar = File.open(avatar_file_path)
group.save!
expect(group_icon(group.path).to_s).to match("#{geo_url}/uploads/group/avatar/#{group.id}/banana_sample.gif")
end
it 'gives default avatar_icon when no avatar is present' do
group.save!
expect(group_icon(group.path)).to match('group_avatar.png')
end
end
end
describe 'group_lfs_status' do
let(:group) { create(:group) }
let!(:project) { create(:empty_project, namespace_id: group.id) }
before do
......
......@@ -140,6 +140,36 @@ describe Group, models: true do
end
end
describe '#avatar_url' do
let(:user) { create(:user) }
subject { group.avatar_url }
context 'when avatar file is uploaded' do
before do
group.add_user(user, GroupMember::MASTER)
group.update_columns(avatar: 'avatar.png')
allow(group.avatar).to receive(:present?) { true }
end
let(:avatar_path) do
"/uploads/group/avatar/#{group.id}/avatar.png"
end
it { should eq "http://#{Gitlab.config.gitlab.host}#{avatar_path}" }
context 'when in a geo secondary node' do
let(:geo_url) { 'http://geo.example.com' }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_url }
end
it { should eq "#{geo_url}#{avatar_path}" }
end
end
end
describe '.search' do
it 'returns groups with a matching name' do
expect(described_class.search(group.name)).to eq([group])
......
......@@ -811,6 +811,17 @@ describe Project, models: true do
end
it { should eq "http://#{Gitlab.config.gitlab.host}#{avatar_path}" }
context 'When in a geo secondary node' do
let(:geo_url) { 'http://geo.example.com' }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_url }
end
it { should eq "#{geo_url}#{avatar_path}" }
end
end
context 'When avatar file in git' do
......
......@@ -803,6 +803,35 @@ describe User, models: true do
end
end
describe '#avatar_url' do
let(:user) { create(:user) }
subject { user.avatar_url }
context 'when avatar file is uploaded' do
before do
user.update_columns(avatar: 'uploads/avatar.png')
allow(user.avatar).to receive(:present?) { true }
end
let(:avatar_path) do
"/uploads/user/avatar/#{user.id}/uploads/avatar.png"
end
it { should eq "http://#{Gitlab.config.gitlab.host}#{avatar_path}" }
context 'when in a geo secondary node' do
let(:geo_url) { 'http://geo.example.com' }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_url }
end
it { should eq "#{geo_url}#{avatar_path}" }
end
end
end
describe '#requires_ldap_check?' do
let(:user) { User.new }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment