Changeset 1201

Show
Ignore:
Timestamp:
07/12/08 16:29:28 (5 months ago)
Author:
alban
Message:

Passage a attachment_fu. Refs #1

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/models/image.rb

    r1193 r1201  
    11class Image < ActiveRecord::Base 
    22  belongs_to :show 
    3   acts_as_attachment :storage => :file_system, :max_size => 300.kilobytes, :content_type => :image, :thumbnails => { :normal => '200>', :thumb => '75' } 
     3  has_attachment :storage => :file_system, :max_size => 300.kilobytes, :content_type => :image, :thumbnails => { :normal => '200>', :thumb => '75' } 
    44  validates_as_attachment 
    55end 
  • trunk/vendor/plugins/attachment_fu/Rakefile

    r1193 r1201  
    66task :default => :test 
    77 
    8 desc 'Test the acts_as_attachment plugin.' 
     8desc 'Test the attachment_fu plugin.' 
    99Rake::TestTask.new(:test) do |t| 
    1010  t.libs << 'lib' 
     
    1313end 
    1414 
    15 desc 'Generate documentation for the acts_as_attachment plugin.' 
     15desc 'Generate documentation for the attachment_fu plugin.' 
    1616Rake::RDocTask.new(:rdoc) do |rdoc| 
    1717  rdoc.rdoc_dir = 'rdoc' 
  • trunk/vendor/plugins/attachment_fu/test/backends/file_system_test.rb

    r1193 r1201  
    1 class FileAttachmentTest < Test::Unit::TestCase 
     1require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper')) 
     2 
     3class FileSystemTest < Test::Unit::TestCase 
    24  include BaseAttachmentTests 
    35  attachment_model FileAttachment 
     
    4951    old_filename = attachment.full_filename 
    5052    assert_not_created do 
    51       attachment.filename        = 'rails2.png' 
    52       attachment.attachment_data = IO.read(File.join(File.dirname(__FILE__), 'fixtures/files/rails.png')) 
    53       attachment.save 
    54       assert  File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"     
    55       assert !File.exists?(old_filename),             "#{old_filename} still exists" 
     53      use_temp_file 'files/rails.png' do |file| 
     54        attachment.filename        = 'rails2.png' 
     55        attachment.temp_path = File.join(fixture_path, file) 
     56        attachment.save! 
     57        assert  File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"     
     58        assert !File.exists?(old_filename),             "#{old_filename} still exists" 
     59      end 
    5660    end 
    5761  end 
  • trunk/vendor/plugins/attachment_fu/test/database.yml

    r1193 r1201  
    11sqlite: 
    22  :adapter: sqlite 
    3   :dbfile: acts_as_attachment_plugin.sqlite.db 
     3  :dbfile: attachment_fu_plugin.sqlite.db 
    44sqlite3: 
    55  :adapter: sqlite3 
    6   :dbfile: acts_as_attachment_plugin.sqlite3.db 
     6  :dbfile: attachment_fu_plugin.sqlite3.db 
    77postgresql: 
    88  :adapter: postgresql 
    99  :username: postgres 
    1010  :password: postgres 
    11   :database: acts_as_attachment_plugin_test 
     11  :database: attachment_fu_plugin_test 
    1212  :min_messages: ERROR 
    1313mysql: 
     
    1616  :username: rails 
    1717  :password: 
    18   :database: acts_as_attachment_plugin_test 
     18  :database: attachment_fu_plugin_test 
  • trunk/vendor/plugins/attachment_fu/test/extra_attachment_test.rb

    r1193 r1201  
    1 require File.join(File.dirname(__FILE__), 'abstract_unit') 
    2  
    3 class DbAttachmentTest < Test::Unit::TestCase 
    4   include BaseAttachmentTests 
    5   attachment_model Attachment 
    6  
    7   def test_should_call_after_attachment_saved(klass = Attachment) 
    8     attachment_model Attachment 
    9     attachment_model.saves = 0 
    10     assert_created do 
    11       upload_file :filename => '/files/rails.png' 
    12     end 
    13     assert_equal 1, attachment_model.saves 
    14   end 
    15    
    16   test_against_subclass :test_should_call_after_attachment_saved, Attachment 
    17 end 
     1require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) 
    182 
    193class OrphanAttachmentTest < Test::Unit::TestCase 
     
    5539    attachment = upload_file :filename => '/files/rails.png' 
    5640     
    57     assert_raise Technoweenie::ActsAsAttachment::ThumbnailError do 
    58       attachment.create_or_update_thumbnail('thumb', 50, 50) 
     41    assert_raise Technoweenie::AttachmentFu::ThumbnailError do 
     42      attachment.create_or_update_thumbnail(attachment.create_temp_file, 'thumb', 50, 50) 
    5943    end 
    6044  end 
     
    6347   attachment = upload_file :filename => '/files/rails.png' 
    6448     
    65     assert_raise Technoweenie::ActsAsAttachment::ThumbnailError do 
    66       attachment.create_or_update_thumbnail('thumb', 'x50') 
     49    assert_raise Technoweenie::AttachmentFu::ThumbnailError do 
     50      attachment.create_or_update_thumbnail(attachment.create_temp_file, 'thumb', 'x50') 
    6751    end 
    6852  end 
  • trunk/vendor/plugins/attachment_fu/test/test_helper.rb

    r1193 r1201  
    11$:.unshift(File.dirname(__FILE__) + '/../lib') 
    22 
     3ENV['RAILS_ENV'] = 'test' 
     4ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..' 
     5 
    36require 'test/unit' 
    4 require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb')) 
    5 require 'breakpoint' 
     7require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb')) 
    68require 'active_record/fixtures' 
    79require 'action_controller/test_process' 
     
    911config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) 
    1012ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") 
    11 ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite']) 
     13 
     14db_adapter = ENV['DB'] 
     15 
     16# no db passed, try one of these fine config-free DBs before bombing. 
     17db_adapter ||=  
     18  begin 
     19    require 'rubygems' 
     20    require 'sqlite' 
     21    'sqlite' 
     22  rescue MissingSourceFile 
     23    begin 
     24      require 'sqlite3' 
     25      'sqlite3' 
     26    rescue MissingSourceFile 
     27    end 
     28  end 
     29 
     30if db_adapter.nil? 
     31  raise "No DB Adapter selected.  Pass the DB= option to pick one, or install Sqlite or Sqlite3." 
     32end 
     33 
     34ActiveRecord::Base.establish_connection(config[db_adapter]) 
    1235 
    1336load(File.dirname(__FILE__) + "/schema.rb") 
    1437 
    15 Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/
     38Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures
    1639$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path) 
    1740 
     
    2750 
    2851  def setup 
     52    Attachment.saves = 0 
     53    DbFile.transaction { [Attachment, FileAttachment, OrphanAttachment, MinimalAttachment, DbFile].each { |klass| klass.delete_all } } 
     54    attachment_model self.class.attachment_model 
     55  end 
     56   
     57  def teardown 
    2958    FileUtils.rm_rf File.join(File.dirname(__FILE__), 'files') 
    30     attachment_model self.class.attachment_model 
    3159  end 
    3260 
     
    5381  protected 
    5482    def upload_file(options = {}) 
    55       att = attachment_model.create :uploaded_data => fixture_file_upload(options[:filename], options[:content_type] || 'image/png') 
    56       att.reload unless att.new_record? 
    57       att 
     83      use_temp_file options[:filename] do |file| 
     84        att = attachment_model.create :uploaded_data => fixture_file_upload(file, options[:content_type] || 'image/png') 
     85        att.reload unless att.new_record? 
     86        return att 
     87      end 
    5888    end 
    59      
     89 
     90    def use_temp_file(fixture_filename) 
     91      temp_path = File.join('/tmp', File.basename(fixture_filename)) 
     92      FileUtils.mkdir_p File.join(fixture_path, 'tmp') 
     93      FileUtils.cp File.join(fixture_path, fixture_filename), File.join(fixture_path, temp_path) 
     94      yield temp_path 
     95    ensure 
     96      FileUtils.rm_rf File.join(fixture_path, 'tmp') 
     97    end 
     98 
    6099    def assert_created(num = 1) 
    61100      assert_difference attachment_model.base_class, :count, num do 
     
    101140 
    102141require File.join(File.dirname(__FILE__), 'fixtures/attachment') 
    103 require File.join(File.dirname(__FILE__), 'fixtures/base_attachment_tests') 
     142require File.join(File.dirname(__FILE__), 'base_attachment_tests')