Sha256: a2df63fff4a63200ca9ed1a94a5b4c4e109cfb3d208c769fbcf3c4b67b97426a

Contents?: true

Size: 1.28 KB

Versions: 121

Compression:

Stored size: 1.28 KB

Contents

require 'helper'

describe Bearcat::Client::CanvasFiles do
  before do
    @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
  end

  it 'uploads a file' do
    stub_post(@client, "/my/upload/path").
      with(:body => {"name" => "bearcat.jpg", "size" => "121363"}).
      to_return(json_response('canvas_files', 'declare_file.json'))

    stub_request(:post, "https://upload-url.invalid/").
      to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})

    stub_post(@client, "/confirm").
      with(:body => {"param" => ["true"]}).to_return(json_response('canvas_files', 'upload_success.json'))

    response = @client.upload_file('my/upload/path', fixture('bearcat.jpg'))
    expect(response['id']).to eq 123
  end

  it 'throws an error on a failed file upload' do
    stub_post(@client, "/my/upload/path").
      with(:body => {"name" => "bearcat.jpg", "size" => "121363"}).
      to_return(json_response('canvas_files', 'declare_file.json'))

    stub_request(:post, "https://upload-url.invalid/").
      to_return(status: 400, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})

    expect { @client.upload_file('my/upload/path', fixture('bearcat.jpg')) }.to raise_exception
  end

end

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
bearcat-1.4.12 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.11 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.10 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.9 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.8 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.7 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.6 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.5 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.4 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.3 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.2 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.1 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.4.0 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.3.55 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.3.53 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.3.52 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.3.51 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.3.49 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.3.48 spec/bearcat/client/canvas_files_spec.rb
bearcat-1.3.47 spec/bearcat/client/canvas_files_spec.rb