Add test for `Services::Tumblr`

This commit is contained in:
Andreas Nedbal 2021-12-27 13:56:30 +01:00 committed by Andreas Nedbal
parent 4529fa0d18
commit 719e393ed1
1 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'rails_helper'
describe Services::Tumblr do
describe "#post" do
let(:user) { FactoryBot.create(:user) }
let(:service) { Services::Tumblr.create(user: user) }
let(:answer) { FactoryBot.create(:answer, user: user,
content: 'a' * 255,
question_content: 'q' * 255) }
let(:tumblr_client) { instance_double(Tumblr::Client) }
before do
allow(Tumblr::Client).to receive(:new).and_return(tumblr_client)
allow(tumblr_client).to receive(:text)
stub_const("APP_CONFIG", {
'hostname' => 'example.com',
'anonymous_name' => 'Anonymous',
'https' => true,
'items_per_page' => 5,
'sharing' => {
'tumblr' => {
'consumer_key' => 'AAA',
}
}
})
end
it "posts a text-post" do
answer.question.content = 'Why are raccoons so good?'
answer.question.author_is_anonymous = true
answer.question.save!
answer.content = 'Because they are good cunes.'
answer.save!
service.post(answer)
expect(tumblr_client).to have_received(:text).with(
service.uid,
title: 'Anonymous asked: Why are raccoons so good?',
body: "Because they are good cunes.\n\n[Smile or comment on the answer here](https://example.com/#{user.screen_name}/a/#{answer.id})",
format: 'markdown',
tweet: 'off'
)
end
end
end