Merged ajax_upload branch (#3957).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10977 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -223,12 +223,21 @@ class AttachmentsControllerTest < ActionController::TestCase
|
||||
set_tmp_attachments_directory
|
||||
end
|
||||
|
||||
def test_show_file_without_container_should_be_denied
|
||||
def test_show_file_without_container_should_be_allowed_to_author
|
||||
set_tmp_attachments_directory
|
||||
attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
get :show, :id => attachment.id
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
def test_show_file_without_container_should_be_allowed_to_author
|
||||
set_tmp_attachments_directory
|
||||
attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
|
||||
|
||||
@request.session[:user_id] = 3
|
||||
get :show, :id => attachment.id
|
||||
assert_response 403
|
||||
end
|
||||
|
||||
|
||||
@@ -1000,7 +1000,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
get :show, :id => 1
|
||||
|
||||
assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
|
||||
assert_select 'input[type=file][name=?]', 'attachments[1][file]'
|
||||
assert_select 'input[type=file][name=?]', 'attachments_files'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1569,8 +1569,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
get :new, :project_id => 1, :tracker_id => 1
|
||||
|
||||
assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
|
||||
assert_select 'input[name=?][type=file]', 'attachments[1][file]'
|
||||
assert_select 'input[name=?][maxlength=255]', 'attachments[1][description]'
|
||||
assert_select 'input[name=?][type=file]', 'attachments_files'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2165,7 +2164,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
assert_nil attachment.container
|
||||
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
|
||||
assert_tag 'span', :content => /testfile.txt/
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'}
|
||||
end
|
||||
|
||||
def test_post_create_with_failure_should_keep_saved_attachments
|
||||
@@ -2184,7 +2183,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
|
||||
assert_tag 'span', :content => /testfile.txt/
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'}
|
||||
end
|
||||
|
||||
def test_post_create_should_attach_saved_attachments
|
||||
@@ -2967,7 +2966,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
assert_nil attachment.container
|
||||
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
|
||||
assert_tag 'span', :content => /testfile.txt/
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'}
|
||||
end
|
||||
|
||||
def test_put_update_with_failure_should_keep_saved_attachments
|
||||
@@ -2986,7 +2985,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
|
||||
assert_tag 'span', :content => /testfile.txt/
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'}
|
||||
end
|
||||
|
||||
def test_put_update_should_attach_saved_attachments
|
||||
|
||||
@@ -104,7 +104,7 @@ class IssuesControllerTransactionTest < ActionController::TestCase
|
||||
assert_template 'edit'
|
||||
attachment = Attachment.first(:order => 'id DESC')
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
|
||||
assert_tag 'span', :content => /testfile.txt/
|
||||
assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'}
|
||||
end
|
||||
|
||||
def test_update_stale_issue_without_notes_should_not_show_add_notes_option
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class AttachmentsTest < ActionController::IntegrationTest
|
||||
fixtures :projects, :enabled_modules,
|
||||
:users, :roles, :members, :member_roles,
|
||||
:trackers, :projects_trackers,
|
||||
:issue_statuses, :enumerations
|
||||
|
||||
def test_upload_as_js_and_attach_to_an_issue
|
||||
log_user('jsmith', 'jsmith')
|
||||
|
||||
token = ajax_upload('myupload.txt', 'File content')
|
||||
|
||||
assert_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
:issue => {:tracker_id => 1, :subject => 'Issue with upload'},
|
||||
:attachments => {'1' => {:filename => 'myupload.txt', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
assert_response 302
|
||||
end
|
||||
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_equal 'Issue with upload', issue.subject
|
||||
assert_equal 1, issue.attachments.count
|
||||
|
||||
attachment = issue.attachments.first
|
||||
assert_equal 'myupload.txt', attachment.filename
|
||||
assert_equal 'My uploaded file', attachment.description
|
||||
assert_equal 'File content'.length, attachment.filesize
|
||||
end
|
||||
|
||||
def test_upload_as_js_and_preview_as_inline_attachment
|
||||
log_user('jsmith', 'jsmith')
|
||||
|
||||
token = ajax_upload('myupload.jpg', 'JPEG content')
|
||||
|
||||
post '/issues/preview/new/ecookbook', {
|
||||
:issue => {:tracker_id => 1, :description => 'Inline upload: !myupload.jpg!'},
|
||||
:attachments => {'1' => {:filename => 'myupload.jpg', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
assert_response :success
|
||||
|
||||
attachment_path = response.body.match(%r{<img src="(/attachments/download/\d+)"})[1]
|
||||
assert_not_nil token, "No attachment path found in response:\n#{response.body}"
|
||||
|
||||
get attachment_path
|
||||
assert_response :success
|
||||
assert_equal 'JPEG content', response.body
|
||||
end
|
||||
|
||||
def test_upload_and_resubmit_after_validation_failure
|
||||
log_user('jsmith', 'jsmith')
|
||||
|
||||
token = ajax_upload('myupload.txt', 'File content')
|
||||
|
||||
assert_no_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
:issue => {:tracker_id => 1, :subject => ''},
|
||||
:attachments => {'1' => {:filename => 'myupload.txt', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
assert_response :success
|
||||
end
|
||||
assert_select 'input[type=hidden][name=?][value=?]', 'attachments[p0][token]', token
|
||||
assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'myupload.txt'
|
||||
assert_select 'input[name=?][value=?]', 'attachments[p0][description]', 'My uploaded file'
|
||||
|
||||
assert_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
:issue => {:tracker_id => 1, :subject => 'Issue with upload'},
|
||||
:attachments => {'p0' => {:filename => 'myupload.txt', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
assert_response 302
|
||||
end
|
||||
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_equal 'Issue with upload', issue.subject
|
||||
assert_equal 1, issue.attachments.count
|
||||
|
||||
attachment = issue.attachments.first
|
||||
assert_equal 'myupload.txt', attachment.filename
|
||||
assert_equal 'My uploaded file', attachment.description
|
||||
assert_equal 'File content'.length, attachment.filesize
|
||||
end
|
||||
|
||||
def test_upload_as_js_and_destroy
|
||||
log_user('jsmith', 'jsmith')
|
||||
|
||||
token = ajax_upload('myupload.txt', 'File content')
|
||||
|
||||
attachment = Attachment.order('id DESC').first
|
||||
attachment_path = "/attachments/#{attachment.id}.js?attachment_id=1"
|
||||
assert_include "href: '#{attachment_path}'", response.body, "Path to attachment: #{attachment_path} not found in response:\n#{response.body}"
|
||||
|
||||
assert_difference 'Attachment.count', -1 do
|
||||
delete attachment_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
assert_include "$('#attachments_1').remove();", response.body
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ajax_upload(filename, content, attachment_id=1)
|
||||
assert_difference 'Attachment.count' do
|
||||
post "/uploads.js?attachment_id=#{attachment_id}&filename=#{filename}", content, {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
assert_response :success
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
end
|
||||
|
||||
token = response.body.match(/\.val\('(\d+\.[0-9a-f]+)'\)/)[1]
|
||||
assert_not_nil token, "No upload token found in response:\n#{response.body}"
|
||||
token
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user