Commit 1b752968 authored by Tim Zallmann's avatar Tim Zallmann

Fixed Linting errors + tests

parent 892b02e8
...@@ -9,7 +9,7 @@ module LazyImageTagHelper ...@@ -9,7 +9,7 @@ module LazyImageTagHelper
unless options.delete(:lazy) == false unless options.delete(:lazy) == false
options[:data] ||= {} options[:data] ||= {}
unless options.delete(:use_original_source) == true unless options.delete(:use_original_source)
options[:data][:src] = path_to_image(source) options[:data][:src] = path_to_image(source)
else else
options[:data][:src] = source options[:data][:src] = source
......
...@@ -13,10 +13,8 @@ module Avatarable ...@@ -13,10 +13,8 @@ module Avatarable
# If asset_host is set then it is expected that assets are handled by a standalone host. # If asset_host is set then it is expected that assets are handled by a standalone host.
# That means we do not want to get GitLab's relative_url_root option anymore. # That means we do not want to get GitLab's relative_url_root option anymore.
host = asset_host.present? ? asset_host : gitlab_host host = asset_host.present? ? asset_host : gitlab_host
[host, avatar.url].join
else
[host, avatar.url].join
end end
[host, avatar.url].join
end end
end end
...@@ -57,6 +57,8 @@ describe ApplicationHelper do ...@@ -57,6 +57,8 @@ describe ApplicationHelper do
end end
describe 'project_icon' do describe 'project_icon' do
let(:asset_host) { 'http://assets' }
it 'returns an url for the avatar' do it 'returns an url for the avatar' do
project = create(:project, avatar: File.open(uploaded_image_temp_path)) project = create(:project, avatar: File.open(uploaded_image_temp_path))
avatar_url = "/uploads/-/system/project/avatar/#{project.id}/banana_sample.gif" avatar_url = "/uploads/-/system/project/avatar/#{project.id}/banana_sample.gif"
...@@ -64,8 +66,8 @@ describe ApplicationHelper do ...@@ -64,8 +66,8 @@ describe ApplicationHelper do
expect(helper.project_icon(project.full_path).to_s) expect(helper.project_icon(project.full_path).to_s)
.to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />" .to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />"
allow(ActionController::Base).to receive(:asset_host).and_return(gitlab_host) allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
avatar_url = "#{gitlab_host}/uploads/-/system/project/avatar/#{project.id}/banana_sample.gif" avatar_url = "#{asset_host}/uploads/-/system/project/avatar/#{project.id}/banana_sample.gif"
expect(helper.project_icon(project.full_path).to_s) expect(helper.project_icon(project.full_path).to_s)
.to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />" .to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />"
......
...@@ -3,6 +3,7 @@ require 'spec_helper' ...@@ -3,6 +3,7 @@ require 'spec_helper'
describe GroupsHelper do describe GroupsHelper do
include ApplicationHelper include ApplicationHelper
let(:asset_host) { 'http://assets' }
describe 'group_icon' do describe 'group_icon' do
avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif')
...@@ -17,16 +18,14 @@ describe GroupsHelper do ...@@ -17,16 +18,14 @@ describe GroupsHelper do
expect(group_icon(group).to_s) expect(group_icon(group).to_s)
.to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />" .to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />"
allow(ActionController::Base).to receive(:asset_host).and_return(gitlab_host) allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
avatar_url = "#{gitlab_host}/uploads/-/system/group/avatar/#{group.id}/banana_sample.gif" avatar_url = "#{asset_host}/uploads/-/system/group/avatar/#{group.id}/banana_sample.gif"
expect(group_icon(group).to_s) expect(group_icon(group).to_s)
.to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />" .to eq "<img data-src=\"#{avatar_url}\" class=\" lazy\" src=\"#{LazyImageTagHelper.placeholder_image}\" />"
end end
end end
describe 'group_icon_url' do describe 'group_icon_url' do
avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif')
...@@ -39,16 +38,16 @@ describe GroupsHelper do ...@@ -39,16 +38,16 @@ describe GroupsHelper do
end end
it 'returns an CDN url for the avatar' do it 'returns an CDN url for the avatar' do
allow(ActionController::Base).to receive(:asset_host).and_return(gitlab_host) allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
group = create(:group) group = create(:group)
group.avatar = fixture_file_upload(avatar_file_path) group.avatar = fixture_file_upload(avatar_file_path)
group.save! group.save!
expect(group_icon_url(group.path).to_s) expect(group_icon_url(group.path).to_s)
.to match("#{gitlab_host}/uploads/-/system/group/avatar/#{group.id}/banana_sample.gif") .to match("#{asset_host}/uploads/-/system/group/avatar/#{group.id}/banana_sample.gif")
end end
it 'returns an based url for the avatar if private' do it 'returns an based url for the avatar if private' do
allow(ActionController::Base).to receive(:asset_host).and_return(gitlab_host) allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
group = create(:group) group = create(:group)
group.avatar = fixture_file_upload(avatar_file_path) group.avatar = fixture_file_upload(avatar_file_path)
group.private = true group.private = true
......
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