Sha256: f4be5db0bca18408bf3fa6424ced01b09adcc72e01ecd1a6e2fc487a1bd11983

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require "spec_helper"
require_relative "../../lib/dribbble_bucket_sync/folder"

describe DribbbleBucketSync::Folder do
	let(:directory) { File.join(File.dirname(__FILE__), "../tmp") }
	let(:name) { "bucket-name" }
	
	subject { DribbbleBucketSync::Folder.new(directory, name) }
	
	after(:all) do
		FileUtils.remove_dir(directory)
	end

	describe "::new" do
		let(:name) { "_a;rand0m-bucKet-()$" }
		
		it "should sanitize the name" do
			folder = File.join(directory, "a-rand0m-bucket")
			expect(subject.path).to eq(folder)
		end
		
		it "should create the folder" do
			expect(File.directory?(subject.path)).to be_true
		end
	end
	
	describe "#add_shot" do
		let(:url) { "http://example.com/file.jpg" }
		let(:shot) { mock("shot", id: 123456, image_url: url) }
		let(:destination) { File.join(subject.path, "#{shot.id}.jpg") }

		it "should add the file to the shots" do
			FileUtils.rm(destination) if File.exist?(destination)
			subject.should_receive(:download).with(url, destination).and_return(true)
			subject.add_shot(shot)
			expect(subject.shots).to include("123456.jpg")
		end
	end
	
	describe "#remove_old_shots" do
		let(:old_shot) { File.join(subject.path, "98765.png") }

		before(:each) do
			FileUtils.touch(old_shot)
		end
		
		it "should delete any shots no longer in the bucket" do
			expect(File.exist?(old_shot)).to be_true
			subject.remove_old_shots
			expect(File.exist?(old_shot)).to be_false
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dribbble-bucket-sync-0.0.2 spec/dribbble_bucket_sync/folder_spec.rb
dribbble-bucket-sync-0.0.1 spec/dribbble_bucket_sync/folder_spec.rb