From b110245e075254d1f384c5df4675c7ec7a96f555 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 28 Dec 2007 22:03:41 +0000 Subject: [PATCH] ActionItem24: checkpoint --- app/models/thumbnail.rb | 5 +++++ app/models/uploaded_file.rb | 5 ++++- db/migrate/007_create_articles.rb | 5 ----- db/migrate/020_create_thumbnails.rb | 22 ++++++++++++++++++++++ doc/README_FOR_APP | 3 ++- test/fixtures/files/rails.png | Bin 0 -> 1787 bytes test/functional/cms_controller_test.rb | 6 ++++++ test/mocks/test/uploaded_file.rb | 7 +++++++ test/unit/thumbnail_test.rb | 7 +++++++ test/unit/uploaded_file_test.rb | 11 +++++++++++ 10 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 app/models/thumbnail.rb create mode 100644 db/migrate/020_create_thumbnails.rb create mode 100644 test/fixtures/files/rails.png create mode 100644 test/mocks/test/uploaded_file.rb create mode 100644 test/unit/thumbnail_test.rb diff --git a/app/models/thumbnail.rb b/app/models/thumbnail.rb new file mode 100644 index 0000000..b74df9e --- /dev/null +++ b/app/models/thumbnail.rb @@ -0,0 +1,5 @@ +class Thumbnail < ActiveRecord::Base + has_attachment :storage => :file_system, + :content_type => :image + validates_as_attachment +end diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index 385bf4a..71d2f57 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -5,7 +5,10 @@ class UploadedFile < Article # FIXME need to define min/max file size - has_attachment :thumbnails => { :icon => [24,24] }, :storage => :file_system + has_attachment :storage => :file_system, + :thumbnails => { :icon => [24,24] }, + :thumbnail_class => Thumbnail + validates_as_attachment diff --git a/db/migrate/007_create_articles.rb b/db/migrate/007_create_articles.rb index f46312f..f9aff5c 100644 --- a/db/migrate/007_create_articles.rb +++ b/db/migrate/007_create_articles.rb @@ -35,11 +35,6 @@ class CreateArticles < ActiveRecord::Migration # 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/db/migrate/020_create_thumbnails.rb b/db/migrate/020_create_thumbnails.rb new file mode 100644 index 0000000..67d5538 --- /dev/null +++ b/db/migrate/020_create_thumbnails.rb @@ -0,0 +1,22 @@ +class CreateThumbnails < ActiveRecord::Migration + def self.up + create_table :thumbnails do |t| + # 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 + end + + def self.down + drop_table :thumbnails + end +end diff --git a/doc/README_FOR_APP b/doc/README_FOR_APP index 53c28c9..1cd621f 100644 --- a/doc/README_FOR_APP +++ b/doc/README_FOR_APP @@ -16,10 +16,11 @@ You need to have a Subversion client (svn) installed, as well as: * Ruby-sqlite3: http://rubyforge.org/projects/sqlite-ruby * rcov: http://eigenclass.org/hiki/rcov * Ferret: http://ferret.davebalmain.com/trac +* RMagick: http://rmagick.rubyforge.org/ There are Debian packages available for all of them but ferret. Try: - # aptitude install subversion ruby rake libgettext-ruby libmocha-ruby libsqlite3-ruby rcov + # aptitude install subversion ruby rake libgettext-ruby libmocha-ruby libsqlite3-ruby rcov librmagick-ruby Ferret shall enter Debian soon (as libferret-ruby). until there you have two options: diff --git a/test/fixtures/files/rails.png b/test/fixtures/files/rails.png new file mode 100644 index 0000000..b8441f1 Binary files /dev/null and b/test/fixtures/files/rails.png differ diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 279520a..a90ef60 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -179,6 +179,12 @@ class CmsControllerTest < Test::Unit::TestCase assert_equal 2, file.versions(true).size end + should 'be able to upload an image' do + assert_difference UploadedFile, :count do + post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} + end + end + should 'offer to create children' do Article.any_instance.stubs(:allow_children?).returns(true) diff --git a/test/mocks/test/uploaded_file.rb b/test/mocks/test/uploaded_file.rb new file mode 100644 index 0000000..d162867 --- /dev/null +++ b/test/mocks/test/uploaded_file.rb @@ -0,0 +1,7 @@ +require 'app/models/uploaded_file' + +class UploadedFile < Article + + has_attachment(attachment_options.merge(:path_prefix => "test/tmp")) + +end diff --git a/test/unit/thumbnail_test.rb b/test/unit/thumbnail_test.rb new file mode 100644 index 0000000..d5b90b3 --- /dev/null +++ b/test/unit/thumbnail_test.rb @@ -0,0 +1,7 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ThumbnailTest < Test::Unit::TestCase + + # FIXME add some tests + +end diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index b11dfef..a99e206 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -2,6 +2,11 @@ require File.dirname(__FILE__) + '/../test_helper' class UploadedFileTest < Test::Unit::TestCase + def setup + @profile = create_user('testinguser').person + end + attr_reader :profile + should 'return a thumbnail as icon for images ' do f = UploadedFile.new f.expects(:image?).returns(true) @@ -49,4 +54,10 @@ class UploadedFileTest < Test::Unit::TestCase assert_equal false, UploadedFile.new.allow_children? end + should 'properly save images' do + file = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + file.profile = profile + assert file.save + end + end -- libgit2 0.21.2