Sha256: ab0127a2667d740028b2388446c15ee893ba2c22851e6eaad736e48a329a8705

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe TBird::Transmitter do
  include TBirdSpecData
  before do
    TBird::Configuration.configure do |config|
      config.aws_key = 'abc'
      config.aws_secret = '123'
      config.aws_bucket = 'bucket'
    end

    @stored_filename = '1/sample_original.jpg'
    @upload = upload_file
    @opts = { acl: :public_read, content_type: 'image/jpeg', metadata: {} }
    @aws_config = stub_everything('aws_config')
    @s3object = stub(public_url: "https://bucket.s3.amazonaws.com/#{@stored_filename}")    
    @bucket = mock('bucket').responds_like(AWS::S3::Bucket.new(TBird::Configuration.aws_bucket, config: @aws_config))
    @bucket_collection = { TBird::Configuration.aws_bucket => @bucket }
  end

  it "can connect to s3" do
    AWS::S3.expects(:new).with(access_key_id: TBird::Configuration.aws_key, secret_access_key: TBird::Configuration.aws_secret)
    TBird::Transmitter.new
  end

  it "can select s3 bucket" do
    AWS::S3::BucketCollection.expects(:new).returns(@bucket_collection)
    TBird::Transmitter.new.send(:s3bucket)
  end

  it "can transmit file to s3" do
    @bucket.expects(:objects).returns({ @stored_filename => @s3object })
    @s3object.expects(:write).with(@upload, { acl: :public_read, content_type: 'image/jpeg', metadata: {} }).returns(@s3object)
    AWS::S3.stubs(:new).returns(stub(buckets: @bucket_collection))
    TBird::Transmitter.new.transmit!(@stored_filename, @upload, { content_type: 'image/jpeg' }).must_equal "https://bucket.s3.amazonaws.com/1/sample_original.jpg"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
t_bird-0.0.5 spec/t_bird/transmitter_spec.rb
t_bird-0.0.4 spec/t_bird/transmitter_spec.rb
t_bird-0.0.3 spec/t_bird/transmitter_spec.rb