Sha256: cf7e011db461ee43d99e323ddce34b44dca164f924c5607d127017f94221a7b3

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 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_options) }
  let(:s3_options) { 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_options).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

      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
end

Version data entries

1 entries across 1 versions & 1 rubygems

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