parent
2ace9b47b1
commit
0e64d8de2a
3 changed files with 45 additions and 29 deletions
|
|
@ -7,6 +7,7 @@
|
|||
## Features
|
||||
* Show spinner on initial stream load [#6384](https://github.com/diaspora/diaspora/pull/6384)
|
||||
* Add new moderator role. Moderators can view and act on reported posts [#6351](https://github.com/diaspora/diaspora/pull/6351)
|
||||
* Only post to the primary tumblr blog [#6386](https://github.com/diaspora/diaspora/pull/6386)
|
||||
|
||||
# 0.5.3.0
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Services::Tumblr < Service
|
|||
body = build_tumblr_post(post, url)
|
||||
user_info = JSON.parse(client.get("/v2/user/info").body)
|
||||
blogs = user_info["response"]["user"]["blogs"]
|
||||
primaryblog = blogs.find(blogs[0]) {|blog| blog["primary"] }
|
||||
primaryblog = blogs.find {|blog| blog["primary"] } || blogs[0]
|
||||
tumblr_ids = {}
|
||||
|
||||
blogurl = URI.parse(primaryblog["url"])
|
||||
|
|
|
|||
|
|
@ -1,41 +1,56 @@
|
|||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
describe Services::Tumblr, :type => :model do
|
||||
describe Services::Tumblr, type: :model do
|
||||
let(:user) { alice }
|
||||
let(:post) { user.post(:status_message, text: "hello", to: user.aspects.first.id) }
|
||||
let(:service) { Services::Tumblr.new(access_token: "yeah", access_secret: "foobar") }
|
||||
|
||||
before do
|
||||
@user = alice
|
||||
@post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id)
|
||||
@service = Services::Tumblr.new(:access_token => "yeah", :access_secret => "foobar")
|
||||
@user.services << @service
|
||||
end
|
||||
describe "#post" do
|
||||
let(:post_id) { "bla" }
|
||||
let(:post_request) { {body: service.build_tumblr_post(post, "")} }
|
||||
let(:post_response) { {status: 201, body: {response: {id: post_id}}.to_json} }
|
||||
|
||||
describe '#post' do
|
||||
it 'posts a status message to tumblr and saves the returned ids' do
|
||||
response = double(body: '{"response": {"user": {"blogs":
|
||||
[{"primary": false, "url": "http://foo.tumblr.com"},
|
||||
{"primary": true, "url": "http://bar.tumblr.com"}]}}}')
|
||||
expect_any_instance_of(OAuth::AccessToken).to receive(:get)
|
||||
.with("/v2/user/info")
|
||||
.and_return(response)
|
||||
before do
|
||||
user.services << service
|
||||
stub_request(:get, "http://api.tumblr.com/v2/user/info").to_return(status: 200, body: user_info)
|
||||
end
|
||||
|
||||
response = double(code: "201", body: '{"response": {"id": "bla"}}')
|
||||
expect_any_instance_of(OAuth::AccessToken).to receive(:post)
|
||||
.with("/v2/blog/bar.tumblr.com/post", @service.build_tumblr_post(@post, ""))
|
||||
.and_return(response)
|
||||
context "with multiple blogs" do
|
||||
let(:user_info) {
|
||||
{response: {user: {blogs: [
|
||||
{primary: false, url: "http://foo.tumblr.com"},
|
||||
{primary: true, url: "http://bar.tumblr.com"}
|
||||
]}}}.to_json
|
||||
}
|
||||
|
||||
expect(@post).to receive(:tumblr_ids=).with({"bar.tumblr.com" => "bla"}.to_json)
|
||||
it "posts a status message to the primary blog and stores the id" do
|
||||
stub_request(:post, "http://api.tumblr.com/v2/blog/bar.tumblr.com/post")
|
||||
.with(post_request).to_return(post_response)
|
||||
|
||||
@service.post(@post)
|
||||
expect(post).to receive(:tumblr_ids=).with({"bar.tumblr.com" => post_id}.to_json)
|
||||
|
||||
service.post(post)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a single blog" do
|
||||
let(:user_info) { {response: {user: {blogs: [{url: "http://foo.tumblr.com"}]}}}.to_json }
|
||||
|
||||
it "posts a status message to the returned blog" do
|
||||
stub_request(:post, "http://api.tumblr.com/v2/blog/foo.tumblr.com/post")
|
||||
.with(post_request).to_return(post_response)
|
||||
|
||||
service.post(post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete_post' do
|
||||
it 'removes posts from tumblr' do
|
||||
stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete").
|
||||
to_return(:status => 200)
|
||||
describe "#delete_post" do
|
||||
it "removes posts from tumblr" do
|
||||
stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete")
|
||||
.to_return(status: 200)
|
||||
|
||||
@service.delete_post(@post)
|
||||
service.delete_post(post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue