Commit 46cba55fce99779fd5dc4a72806da5495500186d

Authored by AntonioTerceiro
1 parent f0218b1c

ActionItem24: adding attachment_fu stuff



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1134 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/uploaded_file.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class UploadedFile < Article
  2 +
  3 + # FIXME need to define min/max file size
  4 + has_attachment :thumbnails => { :icon => [24,24] }
  5 +
  6 + def icon_name
  7 + public_filename(:icon)
  8 + end
  9 +
  10 +end
... ...
db/migrate/007_create_articles.rb
... ... @@ -26,6 +26,20 @@ class CreateArticles &lt; ActiveRecord::Migration
26 26  
27 27 # single-table inheritance
28 28 t.column :type, :string
  29 +
  30 + # attachment_fu data for all uploaded files
  31 + t.column :size, :integer # file size in bytes
  32 + t.column :content_type, :string # mime type, ex: application/mp3
  33 + t.column :filename, :string # sanitized filename
  34 +
  35 + # attachment_fu data for images
  36 + t.column :height, :integer # in pixels
  37 + t.column :width, :integer # in pixels
  38 +
  39 + # attachment_fu data for thumbnails
  40 + t.column :parent_id, :integer # id of parent image (on the same table, a self-referencing foreign-key).
  41 + t.column :thumbnail, :string # the 'type' of thumbnail this attachment record describes.
  42 +
29 43 end
30 44  
31 45 Article.create_versioned_table
... ...
test/unit/uploaded_file_test.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class UploadedFileTest < Test::Unit::TestCase
  4 +
  5 + should 'return a thumbnail as icon' do
  6 + f = UploadedFile.new
  7 + f.expects(:public_filename).with(:icon).returns('/path/to/file.xyz')
  8 + assert_equal '/path/to/file.xyz', f.icon_name
  9 + end
  10 +
  11 +end
... ...