Add option to omit URL to `prepare_tweet` helper
This commit is contained in:
parent
bdedd92817
commit
dc8c5fbf82
|
@ -3,7 +3,7 @@ require 'cgi'
|
|||
module SocialHelper::TwitterMethods
|
||||
include MarkdownHelper
|
||||
|
||||
def prepare_tweet(answer, post_tag = nil)
|
||||
def prepare_tweet(answer, post_tag = nil, omit_url = false)
|
||||
question_content = twitter_markdown answer.question.content.gsub(/\@(\w+)/, '\1')
|
||||
original_question_length = question_content.length
|
||||
answer_content = twitter_markdown answer.content
|
||||
|
@ -13,7 +13,7 @@ module SocialHelper::TwitterMethods
|
|||
username: answer.user.screen_name,
|
||||
host: APP_CONFIG['hostname'],
|
||||
protocol: (APP_CONFIG['https'] ? :https : :http)
|
||||
)
|
||||
) unless omit_url
|
||||
|
||||
parsed_tweet = { :valid => false }
|
||||
tweet_text = ""
|
||||
|
|
|
@ -38,6 +38,17 @@ describe SocialHelper::TwitterMethods, :type => :helper do
|
|||
end
|
||||
end
|
||||
|
||||
context "when the url should be omitted" do
|
||||
let(:question_content) { "question" }
|
||||
let(:answer_content) { "answer" }
|
||||
|
||||
subject { prepare_tweet(answer, nil, true) }
|
||||
|
||||
it "should include the suffix after the link" do
|
||||
expect(subject).to eq("question — answer")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a suffix has been passed and the tweet needs to be shortened' do
|
||||
subject { prepare_tweet(answer, '#askracc') }
|
||||
|
||||
|
|
Loading…
Reference in New Issue