2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2015-05-26 13:41:50 +08:00
|
|
|
|
|
|
|
describe UserAvatarsController do
|
|
|
|
|
2016-07-28 06:59:58 +08:00
|
|
|
context 'show_proxy_letter' do
|
|
|
|
it 'returns not found if external avatar is set somewhere else' do
|
|
|
|
SiteSetting.external_system_avatars_url = "https://somewhere.else.com/avatar.png"
|
|
|
|
response = get :show_proxy_letter, version: 'v2', letter: 'a', color: 'aaaaaa', size: 20
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an avatar if we are allowing the proxy' do
|
|
|
|
response = get :show_proxy_letter, version: 'v2', letter: 'a', color: 'aaaaaa', size: 20
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-26 13:41:50 +08:00
|
|
|
context 'show' do
|
2015-05-27 10:02:57 +08:00
|
|
|
it 'handles non local content correctly' do
|
2015-05-26 13:41:50 +08:00
|
|
|
SiteSetting.avatar_sizes = "100|49"
|
|
|
|
SiteSetting.enable_s3_uploads = true
|
|
|
|
SiteSetting.s3_access_key_id = "XXX"
|
|
|
|
SiteSetting.s3_secret_access_key = "XXX"
|
|
|
|
SiteSetting.s3_upload_bucket = "test"
|
2015-05-27 10:02:57 +08:00
|
|
|
SiteSetting.s3_cdn_url = "http://cdn.com"
|
2015-05-26 13:41:50 +08:00
|
|
|
|
2015-12-16 10:48:49 +08:00
|
|
|
FakeWeb.register_uri(:get, "http://cdn.com/something/else", :body => 'image')
|
|
|
|
|
2015-05-26 13:41:50 +08:00
|
|
|
GlobalSetting.expects(:cdn_url).returns("http://awesome.com/boom")
|
|
|
|
|
|
|
|
|
2015-05-27 23:50:49 +08:00
|
|
|
upload = Fabricate(:upload, url: "//test.s3.amazonaws.com/something")
|
2015-05-27 10:02:57 +08:00
|
|
|
Fabricate(:optimized_image,
|
|
|
|
sha1: SecureRandom.hex << "A"*8,
|
|
|
|
upload: upload,
|
|
|
|
width: 98,
|
|
|
|
height: 98,
|
2015-05-27 23:50:49 +08:00
|
|
|
url: "//test.s3.amazonaws.com/something/else")
|
2015-05-27 10:02:57 +08:00
|
|
|
|
2015-05-26 13:41:50 +08:00
|
|
|
user = Fabricate(:user, uploaded_avatar_id: upload.id)
|
|
|
|
|
|
|
|
get :show, size: 97, username: user.username, version: upload.id, hostname: 'default'
|
|
|
|
|
2015-05-27 23:50:49 +08:00
|
|
|
# 98 is closest which is 49 * 2 for retina
|
2015-05-30 00:51:17 +08:00
|
|
|
expect(response).to redirect_to("http://awesome.com/boom/user_avatar/default/#{user.username_lower}/98/#{upload.id}_#{OptimizedImage::VERSION}.png")
|
2015-05-27 10:02:57 +08:00
|
|
|
|
|
|
|
get :show, size: 98, username: user.username, version: upload.id, hostname: 'default'
|
2015-12-16 10:48:49 +08:00
|
|
|
expect(response.body).to eq("image")
|
2015-05-26 13:41:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'serves image even if size missing and its in local mode' do
|
|
|
|
SiteSetting.avatar_sizes = "50"
|
|
|
|
|
|
|
|
upload = Fabricate(:upload)
|
|
|
|
user = Fabricate(:user, uploaded_avatar_id: upload.id)
|
|
|
|
|
|
|
|
get :show, size: 51, username: user.username, version: upload.id, hostname: 'default'
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|