PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/amexsbs/railsapp/vendor/plugins/paperclip/test/iostream_test.rb

https://bitbucket.org/AcireStudios/social-app-demo
Ruby | 78 lines | 63 code | 15 blank | 0 comment | 0 complexity | 77cd56cf4bfb709c7ec14f23b497e336 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, MIT
  1. require 'test/helper'
  2. class IOStreamTest < Test::Unit::TestCase
  3. context "IOStream" do
  4. should "be included in IO, File, Tempfile, and StringIO" do
  5. [IO, File, Tempfile, StringIO].each do |klass|
  6. assert klass.included_modules.include?(IOStream), "Not in #{klass}"
  7. end
  8. end
  9. end
  10. context "A file" do
  11. setup do
  12. @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
  13. end
  14. teardown { @file.close }
  15. context "that is sent #stream_to" do
  16. context "and given a String" do
  17. setup do
  18. FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
  19. assert @result = @file.stream_to(File.join(ROOT, 'tmp', 'iostream.string.test'))
  20. end
  21. should "return a File" do
  22. assert @result.is_a?(File)
  23. end
  24. should "contain the same data as the original file" do
  25. @file.rewind; @result.rewind
  26. assert_equal @file.read, @result.read
  27. end
  28. end
  29. context "and given a Tempfile" do
  30. setup do
  31. tempfile = Tempfile.new('iostream.test')
  32. tempfile.binmode
  33. assert @result = @file.stream_to(tempfile)
  34. end
  35. should "return a Tempfile" do
  36. assert @result.is_a?(Tempfile)
  37. end
  38. should "contain the same data as the original file" do
  39. @file.rewind; @result.rewind
  40. assert_equal @file.read, @result.read
  41. end
  42. end
  43. end
  44. context "that is sent #to_tempfile" do
  45. setup do
  46. assert @tempfile = @file.to_tempfile
  47. end
  48. should "convert it to a Paperclip Tempfile" do
  49. assert @tempfile.is_a?(Paperclip::Tempfile)
  50. end
  51. should "have the name be based on the original_filename" do
  52. name = File.basename(@file.path)
  53. extension = File.extname(name)
  54. basename = File.basename(name, extension)
  55. assert_match %r[^stream.*?#{Regexp.quote(extension)}], File.basename(@tempfile.path)
  56. end
  57. should "have the Tempfile contain the same data as the file" do
  58. @file.rewind; @tempfile.rewind
  59. assert_equal @file.read, @tempfile.read
  60. end
  61. end
  62. end
  63. end