Merge branch 'stable' into develop

This commit is contained in:
Jonne Haß 2015-09-07 13:25:14 +02:00
commit ba61ca4bdf
3 changed files with 53 additions and 33 deletions

View file

@ -79,6 +79,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure.
## Features ## Features
* Show spinner on initial stream load [#6384](https://github.com/diaspora/diaspora/pull/6384) * 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) * 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 # 0.5.3.0

View file

@ -16,16 +16,18 @@ class Services::Tumblr < Service
def post(post, url='') def post(post, url='')
body = build_tumblr_post(post, url) body = build_tumblr_post(post, url)
user_info = JSON.parse(client.get("/v2/user/info").body) user_info = JSON.parse(client.get("/v2/user/info").body)
blogs = user_info["response"]["user"]["blogs"].map { |blog| URI.parse(blog['url']) } blogs = user_info["response"]["user"]["blogs"]
primaryblog = blogs.find {|blog| blog["primary"] } || blogs[0]
tumblr_ids = {} tumblr_ids = {}
blogs.each do |blog|
resp = client.post("/v2/blog/#{blog.host}/post", body) blogurl = URI.parse(primaryblog["url"])
if resp.code == "201" resp = client.post("/v2/blog/#{blogurl.host}/post", body)
tumblr_ids[blog.host.to_s] = JSON.parse(resp.body)["response"]["id"] if resp.code == "201"
end tumblr_ids[blogurl.host.to_s] = JSON.parse(resp.body)["response"]["id"]
end
post.tumblr_ids = tumblr_ids.to_json post.tumblr_ids = tumblr_ids.to_json
post.save post.save
end
end end
def build_tumblr_post(post, url) def build_tumblr_post(post, url)

View file

@ -1,39 +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 describe "#post" do
@user = alice let(:post_id) { "bla" }
@post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id) let(:post_request) { {body: service.build_tumblr_post(post, "")} }
@service = Services::Tumblr.new(:access_token => "yeah", :access_secret => "foobar") let(:post_response) { {status: 201, body: {response: {id: post_id}}.to_json} }
@user.services << @service
end
describe '#post' do before do
it 'posts a status message to tumblr and saves the returned ids' do user.services << service
response = double(body: '{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}') stub_request(:get, "http://api.tumblr.com/v2/user/info").to_return(status: 200, body: user_info)
expect_any_instance_of(OAuth::AccessToken).to receive(:get) end
.with("/v2/user/info")
.and_return(response)
response = double(code: "201", body: '{"response": {"id": "bla"}}') context "with multiple blogs" do
expect_any_instance_of(OAuth::AccessToken).to receive(:post) let(:user_info) {
.with("/v2/blog/foo.tumblr.com/post", @service.build_tumblr_post(@post, '')) {response: {user: {blogs: [
.and_return(response) {primary: false, url: "http://foo.tumblr.com"},
{primary: true, url: "http://bar.tumblr.com"}
]}}}.to_json
}
expect(@post).to receive(:tumblr_ids=).with({"foo.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
end end
describe '#delete_post' do describe "#delete_post" do
it 'removes posts from tumblr' do it "removes posts from tumblr" do
stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete"). stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete")
to_return(:status => 200) .to_return(status: 200)
@service.delete_post(@post) service.delete_post(post)
end end
end end
end end