mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 18:29:52 +01:00
Add tests for SocialHelper::TumblrMethods
This commit is contained in:
parent
b202a1f7e7
commit
4ddfba9a79
1 changed files with 50 additions and 0 deletions
50
spec/helpers/social_helper/tumblr_methods_spec.rb
Normal file
50
spec/helpers/social_helper/tumblr_methods_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
# 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
|
Loading…
Reference in a new issue