Sha256: 94e70eb92e7d9e2d1ae166b9b2cc2db90f797ae31fa6fe326c9ab3182fb29bfc

Contents?: true

Size: 1.46 KB

Versions: 15

Compression:

Stored size: 1.46 KB

Contents

require 'test_helper'

class UploadTest < ActiveSupport::TestCase

  context 'upload instance' do

    should_belong_to :uploadable
    should_belong_to :creator
    
    should_have_attached_file :local
    should_have_attached_file :remote
    should_not_allow_mass_assignment_of :creator_id, :uploadable_id, :uploadable_type
    should_validate_attachment_size :local, :less_than => 10.megabytes

    should 'use id_partitioning' do
      upload = Upload.new
      upload.stubs(:id).returns(12345)
      upload.local = VALID_FILE
      assert_equal "#{RAILS_ROOT}/public/system/locals/000/012/345/original/rails.png", upload.local.path
      assert_equal '/system/locals/000/012/345/original/rails.png', upload.local.url(:original, false)
    end

    should 'transliterate the filename' do
      upload = Upload.new
      file = fixture_file %Q{IT'sUPPERCASE!AND WeIRD.JPG}
      upload.local = file
      assert_equal 'it-suppercase-and-weird.jpg', upload.local.original_filename
      file.close
    end
 
  end

  # Named scopes
  should_have_named_scope :newest_first
  should_have_named_scope :alphabetic
  should_have_named_scope :recent
  should_have_named_scope :public
  should_have_named_scope :images
  should_have_named_scope :documents
  should_have_named_scope :files
  should_have_named_scope :since
  should_have_named_scope :pending_s3_migration
  
  private
    def fixture_file(name)
      File.new(File.join(RAILS_ROOT, 'test', 'fixtures', 'files', name), 'rb')
    end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
uploader-0.2.8 test/rails_root/test/unit/upload_test.rb
uploader-0.2.7 test/rails_root/test/unit/upload_test.rb
uploader-0.2.6 test/rails_root/test/unit/upload_test.rb
uploader-0.2.5 test/rails_root/test/unit/upload_test.rb
uploader-0.2.4 test/rails_root/test/unit/upload_test.rb
uploader-0.2.3 test/rails_root/test/unit/upload_test.rb
uploader-0.2.2 test/rails_root/test/unit/upload_test.rb
uploader-0.2.1 test/rails_root/test/unit/upload_test.rb
uploader-0.2.0 test/rails_root/test/unit/upload_test.rb
uploader-0.1.19 test/rails_root/test/unit/upload_test.rb
uploader-0.1.20 test/rails_root/test/unit/upload_test.rb
uploader-0.1.16 test/rails_root/test/unit/upload_test.rb
uploader-0.1.17 test/rails_root/test/unit/upload_test.rb
uploader-0.1.18 test/rails_root/test/unit/upload_test.rb
uploader-0.1.15 test/rails_root/test/unit/upload_test.rb