Sha256: 6a5e689ff8550cff389bdd8f05ce2c68f7d80f79e502f0067da7d216885ed665

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'
require 'image_optim/cache_path'
require 'tempfile'

describe ImageOptim::CachePath do
  include CapabilityCheckHelpers

  before do
    stub_const('CachePath', ImageOptim::CachePath)
  end

  describe '#replace' do
    let(:src){ CachePath.temp_file_path }
    let(:dst){ CachePath.temp_file_path }

    it 'moves data to destination' do
      src.write('src')

      src.replace(dst)

      expect(dst.read).to eq('src')
    end

    it 'does not remove original file' do
      src.replace(dst)

      expect(src).to exist
    end

    it 'preserves attributes of destination file' do
      skip 'full file modes are not support' unless any_file_modes_allowed?
      mode = 0o666

      dst.chmod(mode)

      src.replace(dst)

      got = dst.stat.mode & 0o777
      expect(got).to eq(mode), format('expected %04o, got %04o', mode, got)
    end

    it 'does not preserve mtime of destination file' do
      time = src.mtime

      dst.utime(time - 1000, time - 1000)

      src.replace(dst)

      expect(dst.mtime).to be >= time
    end

    it 'changes inode of destination' do
      skip 'inodes are not supported' unless inodes_supported?
      expect{ src.replace(dst) }.to change{ dst.stat.ino }
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
image_optim-0.26.3 spec/image_optim/cache_path_spec.rb
image_optim-0.26.2 spec/image_optim/cache_path_spec.rb
discourse_image_optim-0.26.2 spec/image_optim/cache_path_spec.rb
discourse_image_optim-0.26.1 spec/image_optim/cache_path_spec.rb
image_optim-0.26.1 spec/image_optim/cache_path_spec.rb
image_optim-0.26.0 spec/image_optim/cache_path_spec.rb
image_optim-0.25.0 spec/image_optim/cache_path_spec.rb
discourse_image_optim-0.24.5 spec/image_optim/cache_path_spec.rb
image_optim-0.24.3 spec/image_optim/cache_path_spec.rb
discourse_image_optim-0.24.4 spec/image_optim/cache_path_spec.rb