Sha256: 4657393a8b664d66619f6813ba9ea9a727b3385acd4f036fc77be93dff28d5d3

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

require "test_helper"
require "minitest/spec"
require "minitest/autorun"

describe Concen::GridFile do
  before do
    DatabaseCleaner.clean
  end

  it "can 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"
    grid_file.read.must_equal File.read("#{Rails.root}/public/404.html")
  end

  it "must 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
    lambda { grid.get(grid_id).read }.must_raise(Mongo::GridFileNotFound)
  end

  it "must 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

  it "must 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"
    grid_file.original_filename.must_equal "404.html"
  end

  it "must 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"
    grid_file.filename.must_include grid_file.grid_id.to_s
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
concen-0.2.6 test/unit/grid_file_test.rb
concen-0.2.5 test/unit/grid_file_test.rb
concen-0.2.4 test/unit/grid_file_test.rb
concen-0.2.3 test/unit/grid_file_test.rb