Sha256: 96e9c313436a220fd4867130ae11ebc5f3001edfa39a290a9cb06e3f5b26297b

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe Imap::Backup::Utils do
  context '#check_permissions' do
    before :each do
      File.stub!(:exist?).and_return(true)
    end

    it 'should stat the file' do
      stat = stub('File::Stat', :mode => 0100)
      File.should_receive(:stat).with('foobar').and_return(stat)

      Imap::Backup::Utils.check_permissions('foobar', 0345)
    end

    it 'should succeed if file permissions are less than limit' do
      stat = stub('File::Stat', :mode => 0100)
      File.stub!(:stat).and_return(stat)

      expect do
        Imap::Backup::Utils.check_permissions('foobar', 0345)
      end.to_not raise_error
    end

    it 'should succeed if file permissions are equal to limit' do
      stat = stub('File::Stat', :mode => 0345)
      File.stub!(:stat).and_return(stat)

      expect do
        Imap::Backup::Utils.check_permissions('foobar', 0345)
      end.to_not raise_error
    end

    it 'should fail if file permissions are over the limit' do
      stat = stub('File::Stat', :mode => 0777)
      File.stub!(:stat).and_return(stat)

      expect do
        Imap::Backup::Utils.check_permissions('foobar', 0345)
      end.to raise_error(RuntimeError, "Permissions on 'foobar' should be 0345, not 0777")
    end
  end

  context '#make_folder' do
    it 'should do nothing if an empty path is supplied' do
      FileUtils.should_not_receive(:mkdir_p)

      Imap::Backup::Utils.make_folder('aaa', '', 0222)
    end

    it 'should create the path' do
      FileUtils.stub!(:chmod)

      FileUtils.should_receive(:mkdir_p).with('/base/path/new/folder')

      Imap::Backup::Utils.make_folder('/base/path', 'new/folder', 0222)
    end

    it 'should set permissions on the path' do
      FileUtils.stub!(:mkdir_p)

      FileUtils.should_receive(:chmod).with(0222, '/base/path/new/folder')

      Imap::Backup::Utils.make_folder('/base/path/new', 'folder', 0222)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
imap-backup-1.0.5 spec/unit/utils_spec.rb
imap-backup-1.0.4 spec/unit/utils_spec.rb
imap-backup-1.0.3 spec/unit/utils_spec.rb
imap-backup-1.0.2 spec/unit/utils_spec.rb
imap-backup-1.0.1 spec/unit/utils_spec.rb
imap-backup-1.0.0 spec/unit/utils_spec.rb