From: Jean-Philippe Lang Date: Fri, 29 Feb 2008 19:46:58 +0000 (+0000) Subject: Adds an optional description to attachments. X-Git-Tag: 0.7.0-RC1~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9daf39ec5242a6a87efb9c862952e176d4314856;p=redmine.git Adds an optional description to attachments. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1180 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 3644c396a..7510d503e 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -160,16 +160,20 @@ class ApplicationController < ActionController::Base end # TODO: move to model - def attach_files(obj, files) - attachments = [] - if files && files.is_a?(Array) - files.each do |file| - next unless file.size > 0 - a = Attachment.create(:container => obj, :file => file, :author => User.current) - attachments << a unless a.new_record? + def attach_files(obj, attachments) + attached = [] + if attachments && attachments.is_a?(Hash) + attachments.each_value do |attachment| + file = attachment['file'] + next unless file && file.size > 0 + a = Attachment.create(:container => obj, + :file => file, + :description => attachment['description'].to_s.strip, + :author => User.current) + attached << a unless a.new_record? end end - attachments + attached end # Returns the number of objects that should be displayed diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 93f25c495..7e732b9b6 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -21,6 +21,8 @@ class DocumentsController < ApplicationController before_filter :find_document, :except => [:index, :new] before_filter :authorize + helper :attachments + def index @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' documents = @project.documents.find :all, :include => [:attachments, :category] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index af493b034..b9318a3f7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -396,7 +396,7 @@ module ApplicationHelper def labelled_tabular_form_for(name, object, options, &proc) options[:html] ||= {} - options[:html].store :class, "tabular" + options[:html][:class] = 'tabular' unless options[:html].has_key?(:class) form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) end diff --git a/app/views/attachments/_form.rhtml b/app/views/attachments/_form.rhtml index 18f08c6be..094668f9d 100644 --- a/app/views/attachments/_form.rhtml +++ b/app/views/attachments/_form.rhtml @@ -1,4 +1,9 @@ -

- -<%= file_field_tag 'attachments[]', :size => 30 %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)

+ +<%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil -%> +<%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil %> +<%= l(:label_optional_description) %> + +
+<%= link_to l(:label_add_another_file), {}, :onclick => 'addFileField(); return false;' %> +(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) + diff --git a/app/views/attachments/_links.rhtml b/app/views/attachments/_links.rhtml index cce11292e..4d485548b 100644 --- a/app/views/attachments/_links.rhtml +++ b/app/views/attachments/_links.rhtml @@ -1,12 +1,17 @@
<% for attachment in attachments %> -

<%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %> - (<%= number_to_human_size attachment.filesize %>) - <% unless options[:no_author] %> - <%= attachment.author.name %>, <%= format_date(attachment.created_on) %> - <% end %> +

<%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%> +<%= h(" - #{attachment.description}") unless attachment.description.blank? %> + (<%= number_to_human_size attachment.filesize %>) <% if options[:delete_url] %> - <%= link_to image_tag('delete.png'), options[:delete_url].update({:attachment_id => attachment}), :confirm => l(:text_are_you_sure), :method => :post %> + <%= link_to image_tag('delete.png'), options[:delete_url].update({:attachment_id => attachment}), + :confirm => l(:text_are_you_sure), + :method => :post, + :class => 'delete', + :title => l(:button_delete) %> + <% end %> + <% unless options[:no_author] %> + <%= attachment.author %>, <%= format_time(attachment.created_on) %> <% end %>

<% end %> diff --git a/app/views/common/_attachments_form.rhtml b/app/views/common/_attachments_form.rhtml deleted file mode 100644 index 673f4a52e..000000000 --- a/app/views/common/_attachments_form.rhtml +++ /dev/null @@ -1,6 +0,0 @@ -

- -<%= file_field_tag 'attachments[]', :size => 30 %> -(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) -

diff --git a/app/views/documents/index.rhtml b/app/views/documents/index.rhtml index ff58c2b2f..14d997360 100644 --- a/app/views/documents/index.rhtml +++ b/app/views/documents/index.rhtml @@ -10,7 +10,7 @@ <% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %> <%= render :partial => 'documents/form' %>
-<%= render :partial => 'common/attachments_form'%> +

<%= render :partial => 'attachments/form' %>

<%= submit_tag l(:button_create) %> <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %> diff --git a/app/views/documents/new.rhtml b/app/views/documents/new.rhtml index 4f728da79..639b4f292 100644 --- a/app/views/documents/new.rhtml +++ b/app/views/documents/new.rhtml @@ -4,7 +4,7 @@ <%= render :partial => 'documents/form' %>
-<%= render :partial => 'common/attachments_form'%> +

<%= render :partial => 'attachments/form' %>

<%= submit_tag l(:button_create) %> diff --git a/app/views/documents/show.rhtml b/app/views/documents/show.rhtml index 3014387bd..aa90c5518 100644 --- a/app/views/documents/show.rhtml +++ b/app/views/documents/show.rhtml @@ -10,29 +10,17 @@
<%= textilizable @document.description, :attachments => @document.attachments %>
-

<%= l(:label_attachment_plural) %>

- -
- +<%= link_to_attachments @attachments, :delete_url => (authorize_for('documents', 'destroy_attachment') ? {:controller => 'documents', :action => 'destroy_attachment', :id => @document} : nil) %> <% if authorize_for('documents', 'add_attachment') %> -

<%= toggle_link l(:label_attachment_new), "add_attachment_form" %>

- <% form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular", :id => "add_attachment_form", :style => "display:none;") do %> - <%= render :partial => 'attachments/form' %> +

<%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;", + :id => 'attach_files_link' %>

+ <% form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %> +
+

<%= render :partial => 'attachments/form' %>

+
<%= submit_tag l(:button_add) %> <% end %> <% end %> diff --git a/app/views/issues/_edit.rhtml b/app/views/issues/_edit.rhtml index f9b234d85..2e00ab520 100644 --- a/app/views/issues/_edit.rhtml +++ b/app/views/issues/_edit.rhtml @@ -1,12 +1,12 @@ <% labelled_tabular_form_for :issue, @issue, :url => {:action => 'edit', :id => @issue}, :html => {:id => 'issue-form', + :class => nil, :multipart => true} do |f| %> <%= error_messages_for 'issue' %>
<% if @edit_allowed || !@allowed_statuses.empty? %> -
- <%= l(:label_change_properties) %> +
<%= l(:label_change_properties) %> <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %> (<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>) <% end %> @@ -15,7 +15,7 @@
<% end %> <% if authorize_for('timelog', 'edit') %> -
<%= l(:button_log_time) %> +
<%= l(:button_log_time) %> <% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %>

<%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %>

@@ -32,9 +32,7 @@ <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> <%= wikitoolbar_for 'notes' %> -

- <%= file_field_tag 'attachments[]', :size => 30 %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)

+

<%=l(:label_attachment_plural)%>
<%= render :partial => 'attachments/form' %>

diff --git a/app/views/issues/_form.rhtml b/app/views/issues/_form.rhtml index 20ca666c4..1742d1391 100644 --- a/app/views/issues/_form.rhtml +++ b/app/views/issues/_form.rhtml @@ -44,9 +44,7 @@ <%= render :partial => 'form_custom_fields', :locals => {:values => @custom_values} %> <% if @issue.new_record? %> -

-<%= file_field_tag 'attachments[]', :size => 30 %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)

+

<%= render :partial => 'attachments/form' %>

<% end %> <%= wikitoolbar_for 'issue_description' %> diff --git a/app/views/messages/_form.rhtml b/app/views/messages/_form.rhtml index aa0355070..540811ec3 100644 --- a/app/views/messages/_form.rhtml +++ b/app/views/messages/_form.rhtml @@ -4,7 +4,7 @@


-<%= f.text_field :subject, :required => true, :size => 120 %> +<%= f.text_field :subject, :size => 120 %> <% if !replying && User.current.allowed_to?(:edit_messages, @project) %> @@ -12,11 +12,10 @@ <% end %>

-

<%= f.text_area :content, :required => true, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %>

+

<%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %>

<%= wikitoolbar_for 'message_content' %> - -<%= render :partial => 'attachments/form' %> - +

<%= l(:label_attachment_plural) %>
+<%= render :partial => 'attachments/form' %>

diff --git a/app/views/projects/add_file.rhtml b/app/views/projects/add_file.rhtml index 839275373..0ee55083d 100644 --- a/app/views/projects/add_file.rhtml +++ b/app/views/projects/add_file.rhtml @@ -7,7 +7,7 @@

<%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %>

-<%= render :partial => 'attachments/form' %> +

<%= render :partial => 'attachments/form' %>

<%= submit_tag l(:button_add) %> <% end %> \ No newline at end of file diff --git a/app/views/projects/list_files.rhtml b/app/views/projects/list_files.rhtml index 47b262388..e02077d8e 100644 --- a/app/views/projects/list_files.rhtml +++ b/app/views/projects/list_files.rhtml @@ -23,7 +23,8 @@ <% for file in version.attachments %> "> - <%= link_to file.filename, :controller => 'versions', :action => 'download', :id => version, :attachment_id => file %> + <%= link_to(file.filename, {:controller => 'versions', :action => 'download', :id => version, :attachment_id => file}, + :title => file.description) %> <%= format_date(file.created_on) %> <%= number_to_human_size(file.filesize) %> <%= file.downloads %> diff --git a/app/views/wiki/show.rhtml b/app/views/wiki/show.rhtml index 6f1df124b..77d82884f 100644 --- a/app/views/wiki/show.rhtml +++ b/app/views/wiki/show.rhtml @@ -25,10 +25,14 @@ <%= link_to_attachments @page.attachments, :delete_url => (authorize_for('wiki', 'destroy_attachment') ? {:controller => 'wiki', :action => 'destroy_attachment', :page => @page.title} : nil) %> <% if authorize_for('wiki', 'add_attachment') %> -

<%= toggle_link l(:label_attachment_new), "add_attachment_form" %>

-<% form_tag({ :controller => 'wiki', :action => 'add_attachment', :page => @page.title }, :multipart => true, :class => "tabular", :id => "add_attachment_form", :style => "display:none;") do %> - <%= render :partial => 'attachments/form' %> +

<%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;", + :id => 'attach_files_link' %>

+<% form_tag({ :controller => 'wiki', :action => 'add_attachment', :page => @page.title }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %> +
+

<%= render :partial => 'attachments/form' %>

+
<%= submit_tag l(:button_add) %> +<%= link_to l(:button_cancel), {}, :onclick => "Element.hide('add_attachment_form'); Element.show('attach_files_link'); return false;" %> <% end %> <% end %> diff --git a/db/migrate/089_add_attachments_description.rb b/db/migrate/089_add_attachments_description.rb new file mode 100644 index 000000000..411dfe4d6 --- /dev/null +++ b/db/migrate/089_add_attachments_description.rb @@ -0,0 +1,9 @@ +class AddAttachmentsDescription < ActiveRecord::Migration + def self.up + add_column :attachments, :description, :string + end + + def self.down + remove_column :attachments, :description + end +end diff --git a/lang/bg.yml b/lang/bg.yml index debb643cc..64fff5ae9 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/cs.yml b/lang/cs.yml index 2ff862372..6de5ee01b 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/de.yml b/lang/de.yml index b12f558d0..f2b1c2023 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/en.yml b/lang/en.yml index dadd0a4e5..b06977035 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -497,6 +497,8 @@ label_scm: SCM label_plugins: Plugins label_ldap_authentication: LDAP authentication label_downloads_abbr: D/L +label_optional_description: Optional description +label_add_another_file: Add another file button_login: Login button_submit: Submit diff --git a/lang/es.yml b/lang/es.yml index 1fd355cd2..9c72af18d 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -603,3 +603,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/fi.yml b/lang/fi.yml index 351c47c1b..350e5ba44 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -604,3 +604,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/fr.yml b/lang/fr.yml index 73d2e0af6..c2baa3b7e 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -497,6 +497,8 @@ label_scm: SCM label_plugins: Plugins label_ldap_authentication: Authentification LDAP label_downloads_abbr: D/L +label_optional_description: Description facultative +label_add_another_file: Ajouter un autre fichier button_login: Connexion button_submit: Soumettre diff --git a/lang/he.yml b/lang/he.yml index d0071e26f..680364714 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/it.yml b/lang/it.yml index 7c6f17986..b2eb1c9c6 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/ja.yml b/lang/ja.yml index bc5303f8f..2a742072d 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -601,3 +601,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/ko.yml b/lang/ko.yml index bb112c259..cce1480d8 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/lt.yml b/lang/lt.yml index eb5a5d6e9..7701280a0 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -601,3 +601,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/nl.yml b/lang/nl.yml index c9bd74db7..a0a5305e4 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -601,3 +601,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/pl.yml b/lang/pl.yml index 927025ece..6de13aea4 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 003940ced..83b640a43 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/pt.yml b/lang/pt.yml index 0649005e8..e100d153e 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/ro.yml b/lang/ro.yml index 7e71846b2..142a2a84f 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/ru.yml b/lang/ru.yml index d0c4ddef9..83e63115f 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -604,3 +604,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/sr.yml b/lang/sr.yml index f1ed25882..2cd92607f 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -601,3 +601,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/sv.yml b/lang/sv.yml index 9bd7e0d4c..a9b30ae2f 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -601,3 +601,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/uk.yml b/lang/uk.yml index b0c73b85b..0be41cf04 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -602,3 +602,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index ab2947676..c63e6c3bf 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -600,3 +600,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/lang/zh.yml b/lang/zh.yml index ae2faf23c..a50d8be48 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -603,3 +603,5 @@ label_date_range: Date range label_last_week: last week label_yesterday: yesterday label_last_month: last month +label_add_another_file: Add another file +label_optional_description: Optional description diff --git a/public/javascripts/application.js b/public/javascripts/application.js index d77362a06..4e8849842 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -10,15 +10,24 @@ function checkAll (id, checked) { } } +var fileFieldCount = 1; + function addFileField() { + if (fileFieldCount >= 10) return false + fileFieldCount++; var f = document.createElement("input"); f.type = "file"; - f.name = "attachments[]"; + f.name = "attachments[" + fileFieldCount + "][file]"; f.size = 30; - - p = document.getElementById("attachments_p"); + var d = document.createElement("input"); + d.type = "text"; + d.name = "attachments[" + fileFieldCount + "][description]"; + d.size = 60; + + p = document.getElementById("attachments_fields"); p.appendChild(document.createElement("br")); p.appendChild(f); + p.appendChild(d); } function showTab(name) { diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index b3dcac6b0..833937482 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -222,7 +222,11 @@ width: 200px; .required {color: #bb0000;} .summary {font-style: italic;} +#attachments_fields input[type=text] {margin-left: 8px; } + div.attachments p { margin:4px 0 2px 0; } +div.attachments img { vertical-align: middle; } +div.attachments span.author { font-size: 0.9em; color: #888; } /***** Flash & error messages ****/ #errorExplanation, div.flash, .nodata { diff --git a/test/functional/documents_controller_test.rb b/test/functional/documents_controller_test.rb index 7ba308ec5..f150a5b7a 100644 --- a/test/functional/documents_controller_test.rb +++ b/test/functional/documents_controller_test.rb @@ -44,7 +44,7 @@ class DocumentsControllerTest < Test::Unit::TestCase :document => { :title => 'DocumentsControllerTest#test_post_new', :description => 'This is a new document', :category_id => 2}, - :attachments => [ ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain') ] + :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} assert_redirected_to 'projects/ecookbook/documents' diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 4f28ab224..34b030d98 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -300,7 +300,7 @@ class IssuesControllerTest < Test::Unit::TestCase post :edit, :id => 1, :notes => '', - :attachments => [ test_uploaded_file('testfile.txt', 'text/plain') ] + :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} assert_redirected_to 'issues/show/1' j = Issue.find(1).journals.find(:first, :order => 'id DESC') assert j.notes.blank? diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb index eda4ef676..facd7c630 100644 --- a/test/integration/issues_test.rb +++ b/test/integration/issues_test.rb @@ -50,13 +50,14 @@ class IssuesTest < ActionController::IntegrationTest post 'issues/edit/1', :notes => 'Some notes', - :attachments => ([] << ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain')) + :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}} assert_redirected_to "issues/show/1" # make sure attachment was saved attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") assert_kind_of Attachment, attachment assert_equal Issue.find(1), attachment.container + assert_equal 'This is an attachment', attachment.description # verify the size of the attachment stored in db #assert_equal file_data_1.length, attachment.filesize # verify that the attachment was written to disk