<commit_before># frozen_string_literal: true

require 'rails_helper'

describe SocialHelper::TwitterMethods, :type => :helper do
  let(:user) { FactoryBot.create(:user) }
  let(:answer) { FactoryBot.create(:answer, user: user,
                                  content: 'a' * 255,
                                  question_content: 'q' * 255) }

  describe '#prepare_tweet' do
    context 'when the question and answer need to be shortened' do
      subject { prepare_tweet(answer) }

      it 'should return a properly formatted tweet' do
        expect(subject).to eq("#{'q' * 123}… — #{'a' * 124}… https://justask.rrerr.net/#{user.screen_name}/a/#{answer.id}")
      end
    end

    context 'when the question and answer are short' do
      before do
        answer.question.content = 'Why are raccoons so good?'
        answer.question.save!
        answer.content = 'Because they are good cunes.'
        answer.save!
      end

      subject { prepare_tweet(answer) }

      it 'should return a properly formatted tweet' do
        expect(subject).to eq("#{answer.question.content} — #{answer.content} https://justask.rrerr.net/#{user.screen_name}/a/#{answer.id}")
      end
    end
  end

  describe '#twitter_share_url' do
    subject { twitter_share_url(answer) }

    it 'should return a proper share link' do
      expect(subject).to eq("https://twitter.com/intent/tweet?text=#{CGI.escape(prepare_tweet(answer))}")
    end
  end
end<commit_msg>Fix `SocialHelper::TwitterMethods` tests so they work anywhere<commit_after># frozen_string_literal: true

require 'rails_helper'

describe SocialHelper::TwitterMethods, :type => :helper do
  let(:user) { FactoryBot.create(:user) }
  let(:answer) { FactoryBot.create(:answer, user: user,
                                  content: 'a' * 255,
                                  question_content: 'q' * 255) }

  before do
    stub_const("APP_CONFIG", {
      'hostname' => 'example.<EMAIL>',
      'https' => true,
      'items_per_page' => 5
    })
  end

  describe '#prepare_tweet' do
    context 'when the question and answer need to be shortened' do
      subject { prepare_tweet(answer) }

      it 'should return a properly formatted tweet' do
        expect(subject).to eq("#{'q' * 123}… — #{'a' * 124}… https://example.com/#{user.screen_name}/a/#{answer.id}")
      end
    end

    context 'when the question and answer are short' do
      before do
        answer.question.content = 'Why are raccoons so good?'
        answer.question.save!
        answer.content = 'Because they are good cunes.'
        answer.save!
      end

      subject { prepare_tweet(answer) }

      it 'should return a properly formatted tweet' do
        expect(subject).to eq("#{answer.question.content} — #{answer.content} https://example.com/#{user.screen_name}/a/#{answer.id}")
      end
    end
  end

  describe '#twitter_share_url' do
    subject { twitter_share_url(answer) }

    it 'should return a proper share link' do
      expect(subject).to eq("https://twitter.com/intent/tweet?text=#{CGI.escape(prepare_tweet(answer))}")
    end
  end
end
{'fraction_non_alphanumeric': 0.1265332472562944, 'fraction_numerical': 0.008069722401549387, 'mean_word_length': 2.7158273381294964, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6031722', 'n_tokens_mistral': 971, 'n_tokens_neox': 917, 'n_words': 249}