<commit_before>require 'retrobot/tweet'
require 'retrobot/tweet_filters'
require 'retrobot/config'
require 'logger'
require 'timecop'

describe Retrobot::TweetFilters do
  let(:retrobot) {
    double(:retrobot, logger: Logger.new('/dev/null'), config: config)
  }

  let(:filter) { filter_class.new retrobot }
  let(:config) do
    Retrobot::Config.new
  end

  describe 'AddInReplyToUrl#filter' do
    let(:filter_class) { Retrobot::TweetFilters::AddInReplyToUrl }

    it 'adds in_reply_to_url' do
      # https://twitter.com/mirakui/status/419483601634205696
      tweet_before = Retrobot::Tweet.new.tap do |t|
        t.in_reply_to_status_id = 419483520973565952
        t.text = '@mirakui_retro おめでとうございます'
      end
      tweet_after = filter.filter tweet_before
      expect(tweet_after.text).to eq('@mirakui_retro おめでとうございます https://twitter.com/mirakui_retro/status/419483520973565952')
    end
  end

  describe 'RetroDays' do
    let(:filter_class) { Retrobot::TweetFilters::RetroDays }
    let(:now) { Time.new(2014,01,01).localtime }
    let(:config) do
      Retrobot::Config.new retro_days: 365
    end

    it 'retrys if newer than retro_days' do
      Timecop.freeze(now) do
        tweet_before = Retrobot::Tweet.new.tap do |t|
          t.timestamp = now - 364.days
        end
        expect{ filter.filter(tweet_before) }.to raise_error(Retrobot::TweetFilters::RetryLater)
      end
    end

    it 'tweets tweet older than retro_days' do
      Timecop.freeze(now) do
        tweet_before = Retrobot::Tweet.new.tap do |t|
          t.timestamp = now - 365.days
        end
        expect(filter.filter(tweet_before)).to eq(tweet_before)
      end
    end
  end

  describe 'RemoveAtmark' do
    let(:filter_class) { Retrobot::TweetFilters::RemoveAtmark }

    it 'removes atmark' do
      tweet_before = Retrobot::Tweet.new.tap do |t|
        t.text = '@mirakui_retro hello'
      end
      tweet_after = filter.filter(tweet_before)
      expect(tweet_after.text).to eq('mirakui_retro hello')
    end
  end

  describe 'Unescape' do
    let(:filter_class) { Retrobot::TweetFilters::Unescape }

    it 'unescapes text' do
      tweet_before = Retrobot::Tweet.new.tap do |t|
        t.text = '&gt;_&lt;'
      end
      tweet_after = filter.filter(tweet_before)
      expect(tweet_after.text).to eq('>_<')
    end
  end
end<commit_msg>Add spec for retweet filter<commit_after>require 'retrobot/tweet'
require 'retrobot/tweet_filters'
require 'retrobot/config'
require 'logger'
require 'timecop'

describe Retrobot::TweetFilters do
  let(:retrobot) {
    double(:retrobot,
           logger: Logger.new('/dev/null'),
           config: config,
           client: client
          )
  }

  let(:client) { double('client', retweet: nil, update: nil) }
  let(:filter) { filter_class.new retrobot }
  let(:config) do
    Retrobot::Config.new
  end

  describe 'AddInReplyToUrl#filter' do
    let(:filter_class) { Retrobot::TweetFilters::AddInReplyToUrl }

    it 'adds in_reply_to_url' do
      # https://twitter.com/mirakui/status/419483601634205696
      tweet_before = Retrobot::Tweet.new.tap do |t|
        t.in_reply_to_status_id = 419483520973565952
        t.text = '@mirakui_retro おめでとうございます'
      end
      tweet_after = filter.filter tweet_before
      expect(tweet_after.text).to eq('@mirakui_retro おめでとうございます https://twitter.com/mirakui_retro/status/419483520973565952')
    end
  end

  describe 'RetroDays' do
    let(:filter_class) { Retrobot::TweetFilters::RetroDays }
    let(:now) { Time.new(2014,01,01).localtime }
    let(:config) do
      Retrobot::Config.new retro_days: 365
    end

    it 'retrys if newer than retro_days' do
      Timecop.freeze(now) do
        tweet_before = Retrobot::Tweet.new.tap do |t|
          t.timestamp = now - 364.days
        end
        expect{ filter.filter(tweet_before) }.to raise_error(Retrobot::TweetFilters::RetryLater)
      end
    end

    it 'tweets tweet older than retro_days' do
      Timecop.freeze(now) do
        tweet_before = Retrobot::Tweet.new.tap do |t|
          t.timestamp = now - 365.days
        end
        expect(filter.filter(tweet_before)).to eq(tweet_before)
      end
    end
  end

  describe 'RemoveAtmark' do
    let(:filter_class) { Retrobot::TweetFilters::RemoveAtmark }

    it 'removes atmark' do
      tweet_before = Retrobot::Tweet.new.tap do |t|
        t.text = '@mirakui_retro hello'
      end
      tweet_after = filter.filter(tweet_before)
      expect(tweet_after.text).to eq('mirakui_retro hello')
    end
  end

  describe 'Unescape' do
    let(:filter_class) { Retrobot::TweetFilters::Unescape }

    it 'unescapes text' do
      tweet_before = Retrobot::Tweet.new.tap do |t|
        t.text = '&gt;_&lt;'
      end
      tweet_after = filter.filter(tweet_before)
      expect(tweet_after.text).to eq('>_<')
    end
  end

  describe 'Retweet' do
    let(:filter_class) { Retrobot::TweetFilters::Retweet }

    context 'retweeted_status_id is present' do
      let(:tweet_before) do
        Retrobot::Tweet.new.tap do |t|
          t.retweeted_status_id = 123456
        end
      end

      context 'config.retweet is true' do
        let(:config) { Retrobot::Config.new retweet: true }

        it 'retweets' do
          tweet_after = filter.filter(tweet_before)
          expect(tweet_after).to be(nil)
          expect(retrobot.client).to have_received(:retweet).with(123456)
        end
      end

      context 'config.retweet is false' do
        let(:config) { Retrobot::Config.new retweet: false }

        it 'does not retweet' do
          tweet_after = filter.filter(tweet_before)
          expect(tweet_after).to be(nil)
          expect(retrobot.client).not_to have_received(:retweet)
        end
      end
    end

    context 'retweeted_status_id is blank' do
      let(:tweet_before) do
        Retrobot::Tweet.new.tap do |t|
          t.retweeted_status_id = nil
        end
      end
      let(:config) { Retrobot::Config.new retweet: true }

      it 'does not retweet' do
        tweet_after = filter.filter(tweet_before)
        expect(tweet_after).to eq(tweet_before)
        expect(retrobot.client).not_to have_received(:retweet)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10774193548387097, 'fraction_numerical': 0.024838709677419354, 'mean_word_length': 2.846774193548387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4426790', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2193, 'n_words': 425}