Sha256: 40fcf9dee1560199b0d281b3ffcbc098f0ebf909878b1213050eb7d0fc50176a

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

require File.expand_path('../../test_helper', File.dirname(__FILE__))

class CmsFileTest < ActiveSupport::TestCase
  
  def test_fixtures_validity
    Cms::File.all.each do |file|
      assert file.valid?, file.errors.full_messages.to_s
    end
  end
  
  def test_validations
    assert_no_difference 'Cms::File.count' do
      file = Cms::File.create
      assert file.errors.present?
      assert_has_errors_on file, [:file_file_name]
    end
  end
  
  def test_create
    assert_difference 'Cms::File.count' do
      file = cms_sites(:default).files.create(
        :file => fixture_file_upload('files/image.jpg', 'image/jpeg')
      )
      assert_equal 'Image', file.label
      assert_equal 'image.jpg', file.file_file_name
      assert_equal 'image/jpeg', file.file_content_type
      assert file.file_file_size > 6000
      assert_equal 1, file.position
    end
  end
  
  def test_create_with_dimensions
    assert_difference 'Cms::File.count' do
      file = cms_sites(:default).files.create!(
        :dimensions => '10x10#',
        :file       => fixture_file_upload('files/image.jpg', 'image/jpeg')
      )
      assert_equal 'Image', file.label
      assert_equal 'image.jpg', file.file_file_name
      assert_equal 'image/jpeg', file.file_content_type
      assert file.file_file_size < 6000
      assert_equal 1, file.position
    end
  end
  
  def test_create_failure
    assert_no_difference 'Cms::File.count' do
      cms_sites(:default).files.create(:file => '')
    end
  end
  
  def test_image_mimetypes
    assert_equal %w(image/gif image/jpeg image/pjpeg image/png image/svg+xml image/tiff),
      Cms::File::IMAGE_MIMETYPES
  end
  
  def test_images_scope
    file = cms_files(:default)
    assert_equal 'image/jpeg', file.file_content_type
    assert_equal 1, Cms::File.images.count
    assert_equal 0, Cms::File.not_images.count
    
    file.update_attribute(:file_content_type, 'application/pdf')
    assert_equal 0, Cms::File.images.count
    assert_equal 1, Cms::File.not_images.count
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.5.11 test/unit/models/file_test.rb
comfortable_mexican_sofa-1.5.10 test/unit/models/file_test.rb
comfortable_mexican_sofa-1.5.9 test/unit/models/file_test.rb
comfortable_mexican_sofa-1.5.8 test/unit/models/file_test.rb
comfortable_mexican_sofa-1.5.7 test/unit/models/file_test.rb