Sha256: c247d0d4fd22afa8efe1edb52aac529def4e846f7e3d0ee7bd2801c16a696916

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

require 'rails_helper'
require 'shrine/plugins/kithe_accept_remote_url'

describe Shrine::Plugins::KitheAcceptRemoteUrl, queue_adapter: :inline do
  temporary_class("RemoteUrlUploader") do
    Class.new(Kithe::AssetUploader) do
      plugin :kithe_accept_remote_url
    end
  end

  temporary_class("MyAsset") do
    Class.new(Kithe::Asset) do
      set_shrine_uploader(RemoteUrlUploader)
    end
  end

  let(:asset) { MyAsset.create!(title: "test") }

  it "can assign and promote" do
    stub_request(:any, "www.example.com/bar.html?foo=bar").
      to_return(body: "Example Response" )

    asset.file = {"id" => "http://www.example.com/bar.html?foo=bar", "storage" => "remote_url"}
    asset.save!
    asset.reload

    expect(asset.file.storage_key).to eq(asset.file_attacher.store.storage_key.to_sym)
    expect(asset.stored?).to be true
    expect(asset.file.read).to include("Example Response")
    expect(asset.file.id).to end_with(".html") # no query params
  end

  it "will fetch headers" do
    stubbed = stub_request(:any, "www.example.com/bar.html?foo=bar").
                to_return(body: "Example Response" )

    asset.file = {"id" => "http://www.example.com/bar.html?foo=bar",
                  "storage" => "remote_url",
                  "headers" => {"Authorization" => "Bearer TestToken"}}

    asset.save!

    expect(
      a_request(:get, "www.example.com/bar.html?foo=bar").with(
        headers: {'Authorization'=>'Bearer TestToken', 'User-Agent' => /.+/}
      )
    ).to have_been_made.times(1)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kithe-2.0.2 spec/shrine/kithe_accept_remote_url_spec.rb
kithe-2.0.1 spec/shrine/kithe_accept_remote_url_spec.rb
kithe-2.0.0 spec/shrine/kithe_accept_remote_url_spec.rb
kithe-2.0.0.pre.rc1 spec/shrine/kithe_accept_remote_url_spec.rb
kithe-2.0.0.pre.beta1 spec/shrine/kithe_accept_remote_url_spec.rb