diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index f759100..0de16dc 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -39,4 +39,3 @@ class ProfileEditorController < MyProfileController end end - diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index 614939a..a8ac8eb 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -13,7 +13,11 @@ class UploadedFile < Article :thumbnails => { :icon => [24,24] }, :thumbnail_class => Thumbnail - validates_attachment :size => _('The file you uploaded was larger than the maximum size of 1MB') + def self.max_size + UploadedFile.attachment_options[:max_size] + end + + validates_attachment :size => _("The file you uploaded was larger than the maximum size of %s") % UploadedFile.max_size.to_humanreadable def icon_name self.image? ? public_filename(:icon) : self.content_type.gsub('/', '-') diff --git a/app/views/cms/_uploaded_file.rhtml b/app/views/cms/_uploaded_file.rhtml index 5cd7fc9..cf55592 100644 --- a/app/views/cms/_uploaded_file.rhtml +++ b/app/views/cms/_uploaded_file.rhtml @@ -1,3 +1,3 @@ -<%= labelled_form_field(_('Select the file you want to upload.'), file_field(:article, :uploaded_data)) %> +<%= labelled_form_field(_("Select the file you want to upload (max size %s).") % UploadedFile.max_size.to_humanreadable, file_field(:article, :uploaded_data)) %> <%= labelled_form_field(_('Describe this file:'), text_area(:article, :abstract)) %> diff --git a/lib/noosfero/core_ext.rb b/lib/noosfero/core_ext.rb index a09b9d1..77e5530 100644 --- a/lib/noosfero/core_ext.rb +++ b/lib/noosfero/core_ext.rb @@ -1 +1,2 @@ require 'noosfero/core_ext/string' +require 'noosfero/core_ext/integer' diff --git a/lib/noosfero/core_ext/integer.rb b/lib/noosfero/core_ext/integer.rb new file mode 100644 index 0000000..d5e1d70 --- /dev/null +++ b/lib/noosfero/core_ext/integer.rb @@ -0,0 +1,39 @@ +class Integer + def to_humanreadable + value = self + if value < 1023 + return "%i bytes" % value + end + value /= 1024 + + if value < 1023 + return "%1.1f KB" % value + end + value /= 1024 + + if value < 1023 + return "%1.1f MB" % value + end + value /= 1024 + + if value < 1023 + return "%1.1f GB" % value + end + value /= 1024 + + if value < 1023 + return "%1.1f TB" % value + end + value /= 1024 + + if value < 1023 + return "%1.1f PB" % value + end + value /= 1024 + + if value < 1023 + return "%1.1f EB" % value + end + value /= 1024 + end +end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index f028cf7..1fd358a 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -248,6 +248,11 @@ class CmsControllerTest < Test::Unit::TestCase end end + should 'display max size of uploaded file' do + get :new, :type => UploadedFile.name, :profile => profile.identifier + assert_tag :tag => 'label', :attributes => { :for => 'article_uploaded_data' }, :content => /max size #{UploadedFile.max_size.to_humanreadable}/ + end + should 'display checkboxes for selecting categories' do env = Environment.default top = env.categories.build(:display_in_menu => true, :name => 'Top-Level category'); top.save! diff --git a/test/unit/integer_core_ext_test.rb b/test/unit/integer_core_ext_test.rb new file mode 100644 index 0000000..12535c0 --- /dev/null +++ b/test/unit/integer_core_ext_test.rb @@ -0,0 +1,34 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# tests for Integer core extension. See lib/noosfero/core_ext/integer.rb +class IntegerCoreExtTest < Test::Unit::TestCase + + should 'display bytes in human readable' do + assert_equal '2 bytes', 2.bytes.to_humanreadable + end + + should 'display kilobytes in human readable' do + assert_equal '1.0 KB', 1.kilobytes.to_humanreadable + end + + should 'display megabytes in human readable' do + assert_equal '1.0 MB', 1.megabytes.to_humanreadable + end + + should 'display gigabytes in human readable' do + assert_equal '1.0 GB', 1.gigabytes.to_humanreadable + end + + should 'display terabytes in human readable' do + assert_equal '1.0 TB', 1.terabytes.to_humanreadable + end + + should 'display petabytes in human readable' do + assert_equal '1.0 PB', 1.petabytes.to_humanreadable + end + + should 'display exabytes in human readable' do + assert_equal '1.0 EB', 1.exabytes.to_humanreadable + end + +end -- libgit2 0.21.2