Sha256: 4a0f6106f5da44326f7eb4c6cc0b3990496dae6960b59ae7164ea9a10dfa87b4

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

require "spec_helper"
require "fileutils"

describe MassiveSitemap::Writer::S3 do
  let(:object) { mock('object', :"content=" => [], :save => nil) }
  let(:objects) { mock('objects', :find_all => [], :build => object) }
  let(:bucket) { mock('bucket', :objects => objects) }
  let(:service) { mock('service', :buckets => mock('buckets', :find =>  bucket)) }
  let(:writer) { MassiveSitemap::Writer::S3.new(s3_cfg, :keep => true) }
  let(:s3_cfg) { Hash.new(:access_key_id => "ak", :secret_access_key => "sa", :bucket => "bucket") }

  before do
    ::S3::Service.stub(:new).and_return(service)
  end

  describe "initialize" do
    it "creates service" do
      ::S3::Service.should_receive(:new).with(s3_cfg).and_return(service)
      writer
    end

    it "get S3 object service" do
      bucket.should_receive(:objects).and_return(objects)
      writer
    end
  end

  describe "close_stream" do
    let(:filename) { "sitemap.xml.gz" }

    before do
      writer.init!
    end

    context "with keep option" do
      after do
        FileUtils.rm(filename)
      end

      it "uploads to amazon" do
        objects.should_receive(:build).with(filename).and_return(object)
        writer.close!
      end

      it "retries on fails" do
        object.should_receive(:"content=").once().and_raise
        object.should_receive(:"content=").once().and_return(true)
        writer.close!
      end
    end

    context "without keep option" do
      let(:writer) { MassiveSitemap::Writer::S3.new(s3_cfg, :keep => false) }

      it "deletes file on local system" do
        writer.close!
        File.exists?(filename).should be_false
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
massive_sitemap-writer-s3-0.0.1 spec/s3_spec.rb
massive_sitemap-writer-s3-0.0.1.rc4 spec/s3_spec.rb