Sha256: aa3c956691ad7b73fd65d9a1d1cbd5cad3b8d2e490da7fea03ce2ea5f85046db

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

require './test/helper'

class FileSystemTest < Test::Unit::TestCase
  context "Filesystem" do
    setup do
      rebuild_model :styles => { :thumbnail => "25x25#" }
      @dummy = Dummy.create!

      @dummy.avatar = File.open(fixture_file('5k.png'))
    end

    should "allow file assignment" do
      assert @dummy.save
    end

    should "store the original" do
      @dummy.save
      assert File.exists?(@dummy.avatar.path)
    end

    should "store the thumbnail" do
      @dummy.save
      assert File.exists?(@dummy.avatar.path(:thumbnail))
    end

    should "clean up file objects" do
      File.stubs(:exist?).returns(true)
      Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
      Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()

      @dummy.save!
    end

    should "always be rewound when returning from #to_file" do
      assert_equal 0, @dummy.avatar.to_file.pos
      @dummy.avatar.to_file.seek(10)
      assert_equal 0, @dummy.avatar.to_file.pos
    end
        
    context "with file that has space in file name" do
      setup do
        rebuild_model :styles => { :thumbnail => "25x25#" }
        @dummy = Dummy.create!

        @dummy.avatar = File.open(fixture_file('spaced file.png'))
        @dummy.save
      end

      should "store the file" do
        assert File.exists?(@dummy.avatar.path)
      end

      should "return a replaced version for path" do
        assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
      end

      should "return a replaced version for url" do
        assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
paperclip-v2_7-patched-ruby-1_8_6-2.7.5 test/storage/filesystem_test.rb
paperclip-2.7.5 test/storage/filesystem_test.rb
paperclip-2.7.4 test/storage/filesystem_test.rb
paperclip-2.7.2 test/storage/filesystem_test.rb
paperclip-2.8.0 test/storage/filesystem_test.rb
paperclip-2.7.1 test/storage/filesystem_test.rb
paperclip-2.7.0 test/storage/filesystem_test.rb
paperclip-2.6.0 test/storage/filesystem_test.rb