mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 00:51:03 +08:00
6be26f5316
Version 2 of Imgur's API is deprecated. Their documentation for v2 is no longer online, and applications can only be registered under version 3. Version 3 of their API has a slightly different endpoint but, more importantly, uses a Client ID/Secret pair instead of an API Key. This PR updates Discourse to use the new version of Imgur's API. Signed-off-by: David Celis <me@davidcel.is>
56 lines
1.4 KiB
Ruby
56 lines
1.4 KiB
Ruby
require 'spec_helper'
|
|
require 'imgur'
|
|
|
|
describe Imgur do
|
|
|
|
describe "upload_file" do
|
|
|
|
let(:file) { Rails.root.join('app', 'assets', 'images', 'logo.png') }
|
|
let(:params) { [SiteSetting.imgur_endpoint, { image: Base64.encode64(file.read) }, { 'Authorization' => "Client-ID #{SiteSetting.imgur_client_id}" }] }
|
|
|
|
it 'returns JSON of the Imgur upload if successful' do
|
|
json = {
|
|
data: {
|
|
id: 'fake',
|
|
link: 'http://imgur.com/fake.png',
|
|
deletehash: 'a3kaoad30'
|
|
},
|
|
success: true,
|
|
status: 200
|
|
}.to_json
|
|
|
|
response = mock
|
|
response.expects(:body).returns(json)
|
|
|
|
image_info = {
|
|
url: 'http://imgur.com/fake.png',
|
|
filesize: File.size(file)
|
|
}
|
|
|
|
RestClient.expects(:post).with(*params).returns(response)
|
|
result = Imgur.upload_file(file)
|
|
|
|
# Not testing what width/height actually are because ImageSizer is already tested
|
|
result[:url].should eq(image_info[:url])
|
|
result[:filesize].should eq(image_info[:filesize])
|
|
result[:width].should_not be_nil
|
|
result[:height].should_not be_nil
|
|
end
|
|
|
|
it 'returns nil if the request fails' do
|
|
json = {
|
|
success: false,
|
|
status: 400
|
|
}.to_json
|
|
|
|
response = mock
|
|
response.expects(:body).returns(json)
|
|
RestClient.expects(:post).with(*params).returns(response)
|
|
|
|
Imgur.upload_file(file).should be_nil
|
|
end
|
|
|
|
end
|
|
|
|
end
|