From 46cba55fce99779fd5dc4a72806da5495500186d Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Thu, 27 Dec 2007 23:24:15 +0000 Subject: [PATCH] ActionItem24: adding attachment_fu stuff --- app/models/uploaded_file.rb | 10 ++++++++++ db/migrate/007_create_articles.rb | 14 ++++++++++++++ test/unit/uploaded_file_test.rb | 11 +++++++++++ 3 files changed, 35 insertions(+), 0 deletions(-) create mode 100644 app/models/uploaded_file.rb create mode 100644 test/unit/uploaded_file_test.rb diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb new file mode 100644 index 0000000..ded15b6 --- /dev/null +++ b/app/models/uploaded_file.rb @@ -0,0 +1,10 @@ +class UploadedFile < Article + + # FIXME need to define min/max file size + has_attachment :thumbnails => { :icon => [24,24] } + + def icon_name + public_filename(:icon) + end + +end diff --git a/db/migrate/007_create_articles.rb b/db/migrate/007_create_articles.rb index bf562c9..f46312f 100644 --- a/db/migrate/007_create_articles.rb +++ b/db/migrate/007_create_articles.rb @@ -26,6 +26,20 @@ class CreateArticles < ActiveRecord::Migration # single-table inheritance t.column :type, :string + + # attachment_fu data for all uploaded files + t.column :size, :integer # file size in bytes + t.column :content_type, :string # mime type, ex: application/mp3 + t.column :filename, :string # sanitized filename + + # attachment_fu data for images + t.column :height, :integer # in pixels + t.column :width, :integer # in pixels + + # attachment_fu data for thumbnails + t.column :parent_id, :integer # id of parent image (on the same table, a self-referencing foreign-key). + t.column :thumbnail, :string # the 'type' of thumbnail this attachment record describes. + end Article.create_versioned_table diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb new file mode 100644 index 0000000..65f28d3 --- /dev/null +++ b/test/unit/uploaded_file_test.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class UploadedFileTest < Test::Unit::TestCase + + should 'return a thumbnail as icon' do + f = UploadedFile.new + f.expects(:public_filename).with(:icon).returns('/path/to/file.xyz') + assert_equal '/path/to/file.xyz', f.icon_name + end + +end -- libgit2 0.21.2