Sha256: fc8b6b8b2c1cfd880848ea6a1301bf99e43b73663b18ce7115a9ecbaf4730a3a

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

require "test_helper"

class GridFileTest < ActiveSupport::TestCase
  test "should store file in GridFS" do
    page = Fabricate "concen/page"
    grid_file = page.grid_files.build
    grid_file.store File.read("#{Rails.root}/public/404.html"), "404.html"
    assert_equal grid_file.read, File.read("#{Rails.root}/public/404.html")
  end

  test "should delete file from GridFS when page is deleted" do
    page = Fabricate "concen/page"
    grid_file = page.grid_files.build
    grid_file.store File.read("#{Rails.root}/public/404.html"), "404.html"
    grid_id = grid_file.grid_id.dup
    page.destroy
    grid = Mongo::Grid.new Mongoid.database
    assert_raise(Mongo::GridFileNotFound) { grid.get(grid_id).read }
  end

  test "should delete associated grid_file when page is deleted" do
    page = Fabricate "concen/page"
    grid_file = page.grid_files.build
    grid_file.store File.read("#{Rails.root}/public/404.html"), "404.html"
    page.destroy
  end

  test "should store correct original_filename" do
    page = Fabricate "concen/page"
    grid_file = page.grid_files.build
    grid_file.store File.read("#{Rails.root}/public/404.html"), "404.html"
    assert_equal grid_file.original_filename, "404.html"
  end

  test "should include id in filename" do
    page = Fabricate "concen/page"
    grid_file = page.grid_files.build
    grid_file.store File.read("#{Rails.root}/public/404.html"), "404.html"
    assert grid_file.filename.include?(grid_file.id.to_s), "Filename does not include grid_file id."
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
concen-0.1.4 test/unit/grid_file_test.rb
concen-0.1.3 test/unit/grid_file_test.rb
concen-0.1.2 test/unit/grid_file_test.rb