mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-18 07:38:42 +00:00
Convert media_proxy
controller spec to request spec (#31600)
This commit is contained in:
parent
4118688fba
commit
48f4e5444d
|
@ -1,42 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe MediaProxyController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
it 'redirects when attached to a status' do
|
||||
status = Fabricate(:status)
|
||||
media_attachment = Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png')
|
||||
get :show, params: { id: media_attachment.id }
|
||||
|
||||
expect(response).to have_http_status(302)
|
||||
end
|
||||
|
||||
it 'responds with missing when there is not an attached status' do
|
||||
media_attachment = Fabricate(:media_attachment, status: nil, remote_url: 'http://example.com/attachment.png')
|
||||
get :show, params: { id: media_attachment.id }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it 'raises when id cant be found' do
|
||||
get :show, params: { id: 'missing' }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it 'raises when not permitted to view' do
|
||||
status = Fabricate(:status, visibility: :direct)
|
||||
media_attachment = Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png')
|
||||
get :show, params: { id: media_attachment.id }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
67
spec/requests/media_proxy_spec.rb
Normal file
67
spec/requests/media_proxy_spec.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Media Proxy' do
|
||||
describe 'GET /media_proxy/:id' do
|
||||
before do
|
||||
integration_session.https! # TODO: Move to global rails_helper for all request specs?
|
||||
host! Rails.configuration.x.local_domain # TODO: Move to global rails_helper for all request specs?
|
||||
|
||||
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
|
||||
end
|
||||
|
||||
context 'when attached to a status' do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
||||
|
||||
it 'redirects to correct original url' do
|
||||
get "/media_proxy/#{media_attachment.id}"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(302)
|
||||
.and redirect_to media_attachment.file.url(:original)
|
||||
end
|
||||
|
||||
it 'redirects to small style url' do
|
||||
get "/media_proxy/#{media_attachment.id}/small"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(302)
|
||||
.and redirect_to media_attachment.file.url(:small)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is not an attached status' do
|
||||
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
||||
|
||||
it 'responds with missing' do
|
||||
get "/media_proxy/#{media_attachment.id}"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when id cannot be found' do
|
||||
it 'responds with missing' do
|
||||
get '/media_proxy/missing'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not permitted to view' do
|
||||
let(:status) { Fabricate(:status, visibility: :direct) }
|
||||
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
||||
|
||||
it 'responds with missing' do
|
||||
get "/media_proxy/#{media_attachment.id}"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue