Sha256: 590853430278c3157da8ebef0d7ca074b86a60bc5914a30f31611cd18b1d2162
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
require 'test_helper' class RecordsTest < ActiveSupport::TestCase test 'should save/update/destroy from the database and save/destroy the file' do # Save image_fixture_path = ::File.join(ActiveSupport::TestCase.fixture_path, 'image.jpg') record = FileUpload.create(:file => Rack::Test::UploadedFile.new(image_fixture_path, 'image/jpeg')) image_filename = record.file.filename assert_equal image_filename, FileUpload.first.file.filename image_upload_path = record.file.realpath assert File.exists?(image_upload_path) # Update doc_fixture_path = ::File.join(ActiveSupport::TestCase.fixture_path, 'file.txt') record.update_attributes :file => Rack::Test::UploadedFile.new(doc_fixture_path, 'text/plain') doc_filename = record.file.filename assert_not_equal image_filename, doc_filename assert_equal doc_filename, FileUpload.first.file.filename doc_upload_path = record.file.realpath assert !File.exists?(image_upload_path) assert File.exists?(doc_upload_path) # Destroy record.destroy assert !FileUpload.first assert !File.exists?(doc_upload_path) end test 'should take default file/image and shouldn\'t store/delete it' do # File record = FileUpload.create assert_equal ::File.join('', 'file.txt'), record.file.path # Image record = ImageUpload.create assert_equal ::File.join('', 'assets', 'image.jpg'), record.image.path assert_equal ::File.join('', 'assets', 'image-small.jpg'), record.image.path(:small) assert_equal ::File.join('', 'assets', 'image-big.jpg'), record.image.path(:big) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_uploads-0.1.4 | test/records_test.rb |