diff --git a/app/helpers/social_helper/twitter_methods.rb b/app/helpers/social_helper/twitter_methods.rb index 7f025f71..716060f8 100644 --- a/app/helpers/social_helper/twitter_methods.rb +++ b/app/helpers/social_helper/twitter_methods.rb @@ -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 = "" diff --git a/spec/helpers/social_helper/twitter_methods_spec.rb b/spec/helpers/social_helper/twitter_methods_spec.rb index 7074f6e6..ad630bc4 100644 --- a/spec/helpers/social_helper/twitter_methods_spec.rb +++ b/spec/helpers/social_helper/twitter_methods_spec.rb @@ -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') } @@ -69,4 +80,4 @@ describe SocialHelper::TwitterMethods, :type => :helper do expect(subject).to eq("https://twitter.com/intent/tweet?text=#{CGI.escape(prepare_tweet(answer))}") end end -end \ No newline at end of file +end