2021-12-26 13:07:58 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe SocialHelper::TumblrMethods, :type => :helper do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
let(:answer) { FactoryBot.create(:answer, user: user,
|
|
|
|
content: 'aaaa',
|
|
|
|
question_content: 'q') }
|
|
|
|
|
2021-12-27 05:15:19 -08:00
|
|
|
before do
|
|
|
|
stub_const("APP_CONFIG", {
|
|
|
|
'hostname' => 'example.com',
|
|
|
|
'anonymous_name' => 'Anonymous',
|
|
|
|
'https' => true,
|
|
|
|
'items_per_page' => 5,
|
|
|
|
'sharing' => {
|
|
|
|
'tumblr' => {
|
|
|
|
'consumer_key' => 'AAA',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2021-12-26 13:07:58 -08:00
|
|
|
describe '#tumblr_title' do
|
|
|
|
context 'Asker is anonymous' do
|
|
|
|
subject { tumblr_title(answer) }
|
|
|
|
|
|
|
|
it 'should return a proper title' do
|
|
|
|
expect(subject).to eq('Anonymous asked: q')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Asker is known' do
|
|
|
|
before do
|
|
|
|
@user = FactoryBot.create(:user)
|
|
|
|
answer.question.user = @user
|
|
|
|
answer.question.author_is_anonymous = false
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { tumblr_title(answer) }
|
|
|
|
|
|
|
|
it 'should return a proper title' do
|
|
|
|
expect(subject).to eq("#{answer.question.user.profile.display_name} asked: q")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#tumblr_body' do
|
|
|
|
subject { tumblr_body(answer) }
|
|
|
|
|
|
|
|
it 'should return a proper body' do
|
2021-12-27 05:15:19 -08:00
|
|
|
expect(subject).to eq("aaaa\n\n[Smile or comment on the answer here](https://example.com/#{answer.user.screen_name}/a/#{answer.id})")
|
2021-12-26 13:07:58 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#tumblr_share_url' do
|
|
|
|
subject { tumblr_share_url(answer) }
|
|
|
|
|
|
|
|
it 'should return a proper share link' do
|
2021-12-27 05:15:19 -08:00
|
|
|
expect(subject).to eq("https://www.tumblr.com/widgets/share/tool?shareSource=legacy&posttype=text&title=#{CGI.escape(tumblr_title(answer))}&url=#{CGI.escape("https://example.com/#{answer.user.screen_name}/a/#{answer.id}")}&caption=&content=#{CGI.escape(tumblr_body(answer))}")
|
2021-12-26 13:07:58 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|