<commit_before>require 'spec_helper'
require 'action_mailer'
require 'support/active_record'
require 'support/matchers'

describe Travis::Mailer::Build do
  include Support::ActiveRecord

  let(:build)      { Factory(:build, :state => :finished, :started_at => Time.utc(2011, 6, 23, 15, 30, 45), :finished_at => Time.utc(2011, 6, 23, 16, 47, 52)) }
  let(:recipients) { ['<EMAIL>', '<EMAIL>', '<EMAIL>'] }
  let(:email)      { Travis::Mailer::Build.finished_email(build, recipients) }

  before :each do
    Travis::Mailer.setup
    ActionMailer::Base.delivery_method = :test
  end

  describe 'finished build email notification' do

    it 'delivers to the repository owner, committer and commit author' do
      email.should deliver_to(recipients)
    end

    it 'is a multipart email' do
      email.should be_multipart
    end

    it 'contains the expected text part' do
      email.text_part.body.should include_lines(%(
        Build : #1
        Duration : 1 hour, 17 minutes, and 7 seconds
        Commit : 62aae5f7 (master)
        Author : <NAME>
        Message : the commit message
        Status : Failed
        View the changeset : https://github.com/svenfuchs/minimal/compare/master...develop
        View the full build log and details : http://travis-ci.org/svenfuchs/minimal/builds/#{build.id}
      ))
    end

    it 'contains the expected html part' do
      email.text_part.body.should include_lines(%(
        1 hour, 17 minutes, and 7 seconds
        62aae5f7 (master)
        Author
        the commit message
        Failed
        View the changeset
        https://github.com/svenfuchs/minimal/compare/master...develop
        View the full build log and details
        http://travis-ci.org/svenfuchs/minimal/builds/#{build.id}
      ))
    end

    context 'in HTML' do
      it 'escapes newlines in the commit message' do
        build.commit.message = "bar\nbaz"
        email.deliver # inline css interceptor is called before delivery.
        email.html_part.decoded.should include("bar<br />baz")  # premailer converts <br> to <br />
      end

      it 'inlines css' do
        email.deliver
        email.html_part.decoded.should include('<div style="')
      end
    end
  end

  describe 'finished_email' do
    describe 'for a successful build' do
      let(:build) { Factory(:successful_build) }

      it 'subject' do
        email.subject.should == '[Passed] svenfuchs/successful_build#1 (master - 62aae5f)'
      end

      it 'should have the "success" css class on alert-message' do
        email.deliver
        email.html_part.decoded.should include('<div class="alert-message block-message success"')
      end
    end

    describe 'for a broken build' do
      let(:build) { Factory(:broken_build) }

      it 'subject' do
        email.subject.should == '[Failed] svenfuchs/broken_build#1 (master - 62aae5f)'
      end

      it 'should have the "error" css class on alert-message' do
        email.deliver
        email.html_part.decoded.should include('<div class="alert-message block-message error"')
      end<commit_msg>fix mailer spec for nokogiri on jruby<commit_after>require 'spec_helper'
require 'action_mailer'
require 'support/active_record'
require 'support/matchers'

describe Travis::Mailer::Build do
  include Support::ActiveRecord

  let(:build)      { Factory(:build, :state => :finished, :started_at => Time.utc(2011, 6, 23, 15, 30, 45), :finished_at => Time.utc(2011, 6, 23, 16, 47, 52)) }
  let(:recipients) { ['<EMAIL>', '<EMAIL>', '<EMAIL>'] }
  let(:email)      { Travis::Mailer::Build.finished_email(build, recipients) }

  before :each do
    Travis::Mailer.setup
    ActionMailer::Base.delivery_method = :test
  end

  describe 'finished build email notification' do

    it 'delivers to the repository owner, committer and commit author' do
      email.should deliver_to(recipients)
    end

    it 'is a multipart email' do
      email.should be_multipart
    end

    it 'contains the expected text part' do
      email.text_part.body.should include_lines(%(
        Build : #1
        Duration : 1 hour, 17 minutes, and 7 seconds
        Commit : 62aae5f7 (master)
        Author : <NAME>
        Message : the commit message
        Status : Failed
        View the changeset : https://github.com/svenfuchs/minimal/compare/master...develop
        View the full build log and details : http://travis-ci.org/svenfuchs/minimal/builds/#{build.id}
      ))
    end

    it 'contains the expected html part' do
      email.text_part.body.should include_lines(%(
        1 hour, 17 minutes, and 7 seconds
        62aae5f7 (master)
        Author
        the commit message
        Failed
        View the changeset
        https://github.com/svenfuchs/minimal/compare/master...develop
        View the full build log and details
        http://travis-ci.org/svenfuchs/minimal/builds/#{build.id}
      ))
    end

    context 'in HTML' do
      it 'escapes newlines in the commit message' do
        build.commit.message = "bar\nbaz"
        email.deliver # inline css interceptor is called before delivery.
        email.html_part.decoded.should =~ %r(bar<br( /)?>baz) # nokogiri seems to convert <br> to <br /> on mri, but not jruby?
      end

      it 'inlines css' do
        email.deliver
        email.html_part.decoded.should =~ %r(<div[^>]+style=")
      end
    end
  end

  describe 'finished_email' do
    describe 'for a successful build' do
      let(:build) { Factory(:successful_build) }

      it 'subject' do
        email.subject.should == '[Passed] svenfuchs/successful_build#1 (master - 62aae5f)'
      end

      it 'should have the "success" css class on alert-message' do
        email.deliver
        email.html_part.decoded.should include('<div class="alert-message block-message success"')
      end
    end

    describe 'for a broken build' do
      let(:build) { Factory(:broken_build) }

      it 'subject' do
        email.subject.should == '[Failed] svenfuchs/broken_build#1 (master - 62aae5f)'
      end

      it 'should have the "error" css class on alert-message' do
        email.deliver
        email.html_part.decoded.should include('<div class="alert-message block-message error"')
      end
{'fraction_non_alphanumeric': 0.10785576303927881, 'fraction_numerical': 0.016419832582099163, 'mean_word_length': 2.685053380782918, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, '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': '3724138', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1874, 'n_words': 545}