PageRenderTime 31ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/plugins/attachment_fu/test/backends/file_system_test.rb

https://github.com/grantneufeld/wayground-old
Ruby | 80 lines | 67 code | 13 blank | 0 comment | 0 complexity | 7a762d7c7a725dda486019e312bef8ec MD5 | raw file
  1. require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
  2. class FileSystemTest < Test::Unit::TestCase
  3. include BaseAttachmentTests
  4. attachment_model FileAttachment
  5. def test_filesystem_size_for_file_attachment(klass = FileAttachment)
  6. attachment_model klass
  7. assert_created 1 do
  8. attachment = upload_file :filename => '/files/rails.png'
  9. assert_equal attachment.size, File.open(attachment.full_filename).stat.size
  10. end
  11. end
  12. test_against_subclass :test_filesystem_size_for_file_attachment, FileAttachment
  13. def test_should_not_overwrite_file_attachment(klass = FileAttachment)
  14. attachment_model klass
  15. assert_created 2 do
  16. real = upload_file :filename => '/files/rails.png'
  17. assert_valid real
  18. assert !real.new_record?, real.errors.full_messages.join("\n")
  19. assert !real.size.zero?
  20. fake = upload_file :filename => '/files/fake/rails.png'
  21. assert_valid fake
  22. assert !fake.size.zero?
  23. assert_not_equal File.open(real.full_filename).stat.size, File.open(fake.full_filename).stat.size
  24. end
  25. end
  26. test_against_subclass :test_should_not_overwrite_file_attachment, FileAttachment
  27. def test_should_store_file_attachment_in_filesystem(klass = FileAttachment)
  28. attachment_model klass
  29. attachment = nil
  30. assert_created do
  31. attachment = upload_file :filename => '/files/rails.png'
  32. assert_valid attachment
  33. assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
  34. end
  35. attachment
  36. end
  37. test_against_subclass :test_should_store_file_attachment_in_filesystem, FileAttachment
  38. def test_should_delete_old_file_when_updating(klass = FileAttachment)
  39. attachment_model klass
  40. attachment = upload_file :filename => '/files/rails.png'
  41. old_filename = attachment.full_filename
  42. assert_not_created do
  43. use_temp_file 'files/rails.png' do |file|
  44. attachment.filename = 'rails2.png'
  45. attachment.temp_path = File.join(fixture_path, file)
  46. attachment.save!
  47. assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
  48. assert !File.exists?(old_filename), "#{old_filename} still exists"
  49. end
  50. end
  51. end
  52. test_against_subclass :test_should_delete_old_file_when_updating, FileAttachment
  53. def test_should_delete_old_file_when_renaming(klass = FileAttachment)
  54. attachment_model klass
  55. attachment = upload_file :filename => '/files/rails.png'
  56. old_filename = attachment.full_filename
  57. assert_not_created do
  58. attachment.filename = 'rails2.png'
  59. attachment.save
  60. assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
  61. assert !File.exists?(old_filename), "#{old_filename} still exists"
  62. assert !attachment.reload.size.zero?
  63. assert_equal 'rails2.png', attachment.filename
  64. end
  65. end
  66. test_against_subclass :test_should_delete_old_file_when_renaming, FileAttachment
  67. end