Sha256: db96c51e7aec7d489e1b72245fc041b0ca3bc5f8d4ea705f96e93aadeddd3ff1

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

require "test_helper"

include MongoMapper::Grip

class GripAttachmentTest < Test::Unit::TestCase
  context "An Attachment" do
    setup do
      @attachment   = Attachment.new( :name => "image", :owner_type => "Mock", :owner_id => Mongo::ObjectID.new )
      @dir          = File.dirname(__FILE__) + '/fixtures'
      @image        = File.open("#{@dir}/cthulhu.png", 'r')
      @file_system  = MongoMapper.database['fs.files']
    end
    
    teardown do
      @file_system.drop
      @image.close
    end

    should "be an Attachment" do
      assert @attachment.is_a?(Attachment)
    end
    
    should "belong to :owner" do
      name,assoc = Attachment.associations.first
      #assert_equal(:owner, assoc.name)
      #assert_equal(:belongs_to, assoc.type)
    end
    
    context "with a valid file" do
      setup do
        @attachment.file = @image
      end

      should "have correct :content_type" do
        assert_equal("image/png", @attachment.content_type)
      end
      
      should "have correct :file_size" do
        assert_equal(27582, @attachment.file_size)
      end
      
      should "have correct :file_name" do
        assert_equal("cthulhu.png", @attachment.file_name)
      end
      
      should "read file from grid store" do
        assert_equal "image/png", @file_system.find_one(:filename => @attachment.grid_key)['contentType']
      end
      
      should "return a GridStore" do
        assert_equal(GridFS::GridStore, @attachment.file.class)
      end
      
    end
    
    context "with an invalid file" do
      should "raise Grip::InvalidFile" do
        assert_raise(InvalidFile) { @attachment.file = Hash.new }
      end
    end

  end
    
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grip-0.6.2 test/grip_attachment_test.rb
grip-0.6.1 test/test_grip_attachment.rb
grip-0.6.0 test/test_grip_attachment.rb