Commit b110245e075254d1f384c5df4675c7ec7a96f555
1 parent
eff1b783
Exists in
staging
and in
42 other branches
ActionItem24: checkpoint
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1157 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
64 additions
and
7 deletions
Show diff stats
app/models/uploaded_file.rb
| ... | ... | @@ -5,7 +5,10 @@ |
| 5 | 5 | class UploadedFile < Article |
| 6 | 6 | |
| 7 | 7 | # FIXME need to define min/max file size |
| 8 | - has_attachment :thumbnails => { :icon => [24,24] }, :storage => :file_system | |
| 8 | + has_attachment :storage => :file_system, | |
| 9 | + :thumbnails => { :icon => [24,24] }, | |
| 10 | + :thumbnail_class => Thumbnail | |
| 11 | + | |
| 9 | 12 | |
| 10 | 13 | validates_as_attachment |
| 11 | 14 | ... | ... |
db/migrate/007_create_articles.rb
| ... | ... | @@ -35,11 +35,6 @@ class CreateArticles < ActiveRecord::Migration |
| 35 | 35 | # attachment_fu data for images |
| 36 | 36 | t.column :height, :integer # in pixels |
| 37 | 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 | - | |
| 43 | 38 | end |
| 44 | 39 | |
| 45 | 40 | Article.create_versioned_table | ... | ... |
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +class CreateThumbnails < ActiveRecord::Migration | |
| 2 | + def self.up | |
| 3 | + create_table :thumbnails do |t| | |
| 4 | + # attachment_fu data for all uploaded files | |
| 5 | + t.column :size, :integer # file size in bytes | |
| 6 | + t.column :content_type, :string # mime type, ex: application/mp3 | |
| 7 | + t.column :filename, :string # sanitized filename | |
| 8 | + | |
| 9 | + # attachment_fu data for images | |
| 10 | + t.column :height, :integer # in pixels | |
| 11 | + t.column :width, :integer # in pixels | |
| 12 | + | |
| 13 | + # attachment_fu data for thumbnails | |
| 14 | + t.column :parent_id, :integer # id of parent image (on the same table, a self-referencing foreign-key). | |
| 15 | + t.column :thumbnail, :string # the 'type' of thumbnail this attachment record describes. | |
| 16 | + end | |
| 17 | + end | |
| 18 | + | |
| 19 | + def self.down | |
| 20 | + drop_table :thumbnails | |
| 21 | + end | |
| 22 | +end | ... | ... |
doc/README_FOR_APP
| ... | ... | @@ -16,10 +16,11 @@ You need to have a Subversion client (svn) installed, as well as: |
| 16 | 16 | * Ruby-sqlite3: http://rubyforge.org/projects/sqlite-ruby |
| 17 | 17 | * rcov: http://eigenclass.org/hiki/rcov |
| 18 | 18 | * Ferret: http://ferret.davebalmain.com/trac |
| 19 | +* RMagick: http://rmagick.rubyforge.org/ | |
| 19 | 20 | |
| 20 | 21 | There are Debian packages available for all of them but ferret. Try: |
| 21 | 22 | |
| 22 | - # aptitude install subversion ruby rake libgettext-ruby libmocha-ruby libsqlite3-ruby rcov | |
| 23 | + # aptitude install subversion ruby rake libgettext-ruby libmocha-ruby libsqlite3-ruby rcov librmagick-ruby | |
| 23 | 24 | |
| 24 | 25 | Ferret shall enter Debian soon (as <tt>libferret-ruby</tt>). until there you have two options: |
| 25 | 26 | ... | ... |
1.75 KB
test/functional/cms_controller_test.rb
| ... | ... | @@ -179,6 +179,12 @@ class CmsControllerTest < Test::Unit::TestCase |
| 179 | 179 | assert_equal 2, file.versions(true).size |
| 180 | 180 | end |
| 181 | 181 | |
| 182 | + should 'be able to upload an image' do | |
| 183 | + assert_difference UploadedFile, :count do | |
| 184 | + post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} | |
| 185 | + end | |
| 186 | + end | |
| 187 | + | |
| 182 | 188 | should 'offer to create children' do |
| 183 | 189 | Article.any_instance.stubs(:allow_children?).returns(true) |
| 184 | 190 | ... | ... |
test/unit/uploaded_file_test.rb
| ... | ... | @@ -2,6 +2,11 @@ require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | |
| 3 | 3 | class UploadedFileTest < Test::Unit::TestCase |
| 4 | 4 | |
| 5 | + def setup | |
| 6 | + @profile = create_user('testinguser').person | |
| 7 | + end | |
| 8 | + attr_reader :profile | |
| 9 | + | |
| 5 | 10 | should 'return a thumbnail as icon for images ' do |
| 6 | 11 | f = UploadedFile.new |
| 7 | 12 | f.expects(:image?).returns(true) |
| ... | ... | @@ -49,4 +54,10 @@ class UploadedFileTest < Test::Unit::TestCase |
| 49 | 54 | assert_equal false, UploadedFile.new.allow_children? |
| 50 | 55 | end |
| 51 | 56 | |
| 57 | + should 'properly save images' do | |
| 58 | + file = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
| 59 | + file.profile = profile | |
| 60 | + assert file.save | |
| 61 | + end | |
| 62 | + | |
| 52 | 63 | end | ... | ... |