<commit_before>require 'test_helper'

describe Kiitos::Message do
  describe 'after create' do
    it 'sends an email' do
      ActionMailer::Base.deliveries = []
      Kiitos::Message.create from: '<EMAIL>', to: '<EMAIL>', kiitos_kiito_id: 1, message: '3 weeks ago', created_at: 3.weeks.ago
      assert ActionMailer::Base.deliveries.count == 1, "Email wasn't sent"
    end
  end

  describe '.a_month_ago' do
    it 'returns messages sent up to a month ago' do
      Kiitos::Message.create from: '<EMAIL>', to: '<EMAIL>', kiitos_kiito_id: 1, message: '3 weeks ago', created_at: 3.weeks.ago
      Kiitos::Message.create from: '<EMAIL>', to: '<EMAIL>', kiitos_kiito_id: 1, message: '3 months ago', created_at: 3.months.ago
      kiitos = Kiitos::Message.a_month_ago

      kiitos.length.must_equal 1
      kiitos.first.message.must_equal '3 weeks ago'
    end
  end
end<commit_msg>add message sender_email test<commit_after>require 'test_helper'

describe Kiitos::Message do
  describe 'after create' do
    it 'sends an email' do
      ActionMailer::Base.deliveries = []
      Kiitos::Message.create from: '<EMAIL>', to: '<EMAIL>', kiitos_kiito_id: 1, message: '3 weeks ago', created_at: 3.weeks.ago
      assert ActionMailer::Base.deliveries.count == 1, "Email wasn't sent"
    end
  end

  describe '.a_month_ago' do
    it 'returns messages sent up to a month ago' do
      Kiitos::Message.create from: '<EMAIL>', to: '<EMAIL>', kiitos_kiito_id: 1, message: '3 weeks ago', created_at: 3.weeks.ago
      Kiitos::Message.create from: '2<EMAIL>', to: '<EMAIL>', kiitos_kiito_id: 1, message: '3 months ago', created_at: 3.months.ago
      kiitos = Kiitos::Message.a_month_ago

      kiitos.length.must_equal 1
      kiitos.first.message.must_equal '3 weeks ago'
    end
  end

  describe '#sender_email' do
    before do
      @user = User.create name: 'test', email: '<EMAIL>'
    end

    context 'when anonymous' do
      it 'does not return the sender email' do
        user = @kiito = Kiitos::Message.create from: @user.id, to: 2, kiitos_kiito_id: 1, message: '3 weeks ago', created_at: 3.weeks.ago, anonymous: true
        user.sender_email.must_equal 'Anonymous'
      end
    end

    context 'when not anonymous' do
      it 'returns the sender email' do
        user = @kiito = Kiitos::Message.create from: @user.id, to: 2, kiitos_kiito_id: 1, message: '3 weeks ago', created_at: 3.weeks.ago
        user.sender_email.must_equal user.sender.email
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12278582930756844, 'fraction_numerical': 0.013285024154589372, 'mean_word_length': 3.445438282647585, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, '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': '6065772', 'n_tokens_mistral': 867, 'n_tokens_neox': 836, 'n_words': 250}