Retrospring/spec/helpers/social_helper/tumblr_methods_spec.rb

50 lines
1.6 KiB
Ruby
Raw Normal View History

# 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') }
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
expect(subject).to eq("aaaa\n\n[Smile or comment on the answer here](https://justask.rrerr.net/#{answer.user.screen_name}/a/#{answer.id})")
end
end
describe '#tumblr_share_url' do
subject { tumblr_share_url(answer) }
it 'should return a proper share link' do
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://justask.rrerr.net/#{answer.user.screen_name}/a/#{answer.id}")}&caption=&content=#{CGI.escape(tumblr_body(answer))}")
end
end
end