Sha256: 945adc7bfee2f38514e0043f10a2bc35bdcd785521ea155eff8b255706547584

Contents?: true

Size: 1.81 KB

Versions: 10

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe FileAttachment do
  
  include ActionDispatch::TestProcess # for fixture_file_upload
  
  before(:each) do
    @path = File.join(Rails.root.to_s, 'public', 'files')
    @full_path = File.join(@path, 'somefile.txt')
    @trash_path = File.join(@path, 'trash', 'somefile.txt')
    
    raise "Please back up and clean out public/files before running this spec" if File.exists?(@full_path) || File.exists?(File.join(@path, 'somefile-1.txt'))
    
    @file_attachment = FileAttachment.create!({
      :description => 'unique description',
      :uploaded_file => fixture_file_upload(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt'), 'text/plain')
    })
  end
  
  after(:each) do  
    if File.exists?(@full_path)
      File.delete(@full_path)
    end
    if File.exists?(@trash_path)
      File.delete(@trash_path)
    end
  end
  
  it "should generate a unique name" do
    FileUtils.mkdir_p @path
    
    new_file = FileAttachment.create!({
      :description => 'other description',
      :uploaded_file => fixture_file_upload(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt'), 'text/plain')
    })
    
    new_file.filepath.should_not == 'files/somefile.txt'
    new_file.filepath.should == 'files/somefile-1.txt'
    File.exists?(@full_path).should be_true
    
    File.delete(File.join(@path, 'somefile-1.txt'))
  end
  
  it "should know whether its file actually exists" do
    @file_attachment.file_saved?.should be_true
    File.exists?(@full_path).should be_true
    File.delete(@full_path)
    @file_attachment.file_saved?.should be_false
  end
  
  it "should move its file to the trash when destroyed" do
    File.exists?(@full_path).should be_true
    @file_attachment.destroy
    File.exists?(@full_path).should be_false
    File.exists?(@trash_path).should be_true
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
file_share-0.1.9 spec/models/file_attachment_spec.rb
file_share-0.1.8 spec/models/file_attachment_spec.rb
file_share-0.1.7 spec/models/file_attachment_spec.rb
file_share-0.1.6 spec/models/file_attachment_spec.rb
file_share-0.1.5 spec/models/file_attachment_spec.rb
file_share-0.1.4 spec/models/file_attachment_spec.rb
file_share-0.1.3 spec/models/file_attachment_spec.rb
file_share-0.1.2 spec/models/file_attachment_spec.rb
file_share-0.1.1 spec/models/file_attachment_spec.rb
file_share-0.1.0 spec/models/file_attachment_spec.rb