after_commit :reset_parent_cache, on: :update
before_create :prepare_description, unless: :local?
- before_create :set_shortcode
+ before_create :set_unknown_type
before_create :set_processing
after_post_process :set_meta
private
- def set_shortcode
+ def set_unknown_type
self.type = :unknown if file.blank? && !type_changed?
-
- return unless local?
-
- loop do
- self.shortcode = SecureRandom.urlsafe_base64(14)
- break if MediaAttachment.find_by(shortcode: shortcode).nil?
- end
end
def prepare_description
%p
- status.media_attachments.each do |a|
- if status.local?
- = link_to medium_url(a), medium_url(a)
+ = link_to full_asset_url(a.file.url(:original)), full_asset_url(a.file.url(:original))
- else
= link_to a.remote_url, a.remote_url
describe '#show' do
it 'redirects to the file url when attached to a status' do
status = Fabricate(:status)
- media_attachment = Fabricate(:media_attachment, status: status)
+ media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'foo')
get :show, params: { id: media_attachment.to_param }
expect(response).to redirect_to(media_attachment.file.url(:original))
end
it 'responds with missing when there is not an attached status' do
- media_attachment = Fabricate(:media_attachment, status: nil)
+ media_attachment = Fabricate(:media_attachment, status: nil, shortcode: 'foo')
get :show, params: { id: media_attachment.to_param }
expect(response).to have_http_status(404)
it 'raises when not permitted to view' do
status = Fabricate(:status, visibility: :direct)
- media_attachment = Fabricate(:media_attachment, status: status)
+ media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'foo')
get :show, params: { id: media_attachment.to_param }
expect(response).to have_http_status(404)