Sha256: 2a687db5e03e74a03768aba7f4208b86e5f98fbb36df760702318c2b050e35e7

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

require "spec_helper"

describe NightcrawlerSwift::List do

  let(:connection) { NightcrawlerSwift::Connection.new }
  let(:token) { "token" }
  let(:expires_at) { (DateTime.now + 60).to_time }
  let(:upload_url) { "server-url" }

  subject do
    NightcrawlerSwift::List.new
  end

  before do
    allow(NightcrawlerSwift).to receive(:connection).and_return(connection)
    allow(connection).to receive(:token_id).and_return(token)
    allow(connection).to receive(:expires_at).and_return(expires_at)
    allow(connection).to receive(:upload_url).and_return(upload_url)
  end

  describe "#execute" do
    let :json_response do
      [{"name" => "file"}]
    end

    let :response do
      double(:response, code: 200, body: json_response.to_json)
    end

    before do
      allow(subject).to receive(:get).and_return(response)
    end

    it "gets upload url without parameters" do
      subject.execute
      expect(subject).to have_received(:get).with(connection.upload_url, headers: { accept: :json }, params: {})
    end

    it "gets upload url with accepted parameters" do
      subject.execute prefix: 'some/prefix', limit: 2
      expect(subject).to have_received(:get).with(connection.upload_url, headers: { accept: :json }, params: { prefix: 'some/prefix', limit: 2 })
    end

    it "gets upload url without unknown parameters" do
      subject.execute prefix: 'some/prefix', a: 'b'
      expect(subject).to have_received(:get).with(connection.upload_url, headers: { accept: :json }, params: { prefix: 'some/prefix' })
    end

    it "returns the parsed json" do
      result = subject.execute
      expect(result).to eql json_response
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nightcrawler_swift-1.0.0 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.11.1 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.11.0 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.10.0 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.9.0 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.8.1 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.8.0 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.7.0 spec/lib/nightcrawler_swift/commands/list_spec.rb
nightcrawler_swift-0.6.0 spec/lib/nightcrawler_swift/commands/list_spec.rb