before_filter :delete_authorize, :only => :destroy
before_filter :authorize_global, :only => :upload
- accept_api_auth :show, :download, :upload
+ accept_api_auth :show, :download, :thumbnail, :upload
def show
respond_to do |format|
api.content_type attachment.content_type
api.description attachment.description
api.content_url download_named_attachment_url(attachment, attachment.filename)
+ if attachment.thumbnailable?
+ api.thumbnail_url thumbnail_url(attachment)
+ end
+ api.content_url download_named_attachment_url(attachment, attachment.filename)
api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author
api.created_on attachment.created_on
end
end
end
+ test "GET /attachments/:id.xml for image should include thumbnail_url" do
+ get '/attachments/16.xml', {}, credentials('jsmith')
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_select 'attachment id:content(16)' do
+ assert_select '~ thumbnail_url', :text => 'http://www.example.com/attachments/thumbnail/16'
+ end
+ end
+
test "GET /attachments/:id.xml should deny access without credentials" do
get '/attachments/7.xml'
assert_response 401
set_tmp_attachments_directory
end
+ test "GET /attachments/thumbnail/:id should return the thumbnail" do
+ skip unless convert_installed?
+ get '/attachments/thumbnail/16', {}, credentials('jsmith')
+ assert_response :success
+ end
+
test "POST /uploads.xml should return the token" do
set_tmp_attachments_directory
assert_difference 'Attachment.count' do
Redmine::Thumbnail.convert_available?
end
+ def convert_installed?
+ self.class.convert_installed?
+ end
+
# Returns the path to the test +vendor+ repository
def self.repository_path(vendor)
path = Rails.root.join("tmp/test/#{vendor.downcase}_repository").to_s