<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

describe CiMonitorHelper do
  before do
    @status = stub(ProjectStatus, :published_at => publish_time)
    @project = stub(Project, :status => @status)
  end

  describe "#relative_status_messages_for" do
    def publish_time
      Time.now - 1.day
    end

    context "when the project is online" do
      before do
        @project.stub!(:online?).and_return(true)
        @project.stub!(:red?).and_return(false)
      end

      context "when the project isn't red" do
        it "should include the last built date" do
          messages = helper.relative_status_messages_for(@project)
          messages.should have(1).message
          last_built_message = messages.first
          last_built_message.should == ['project_published_at', 'Last built 1 day ago']
        end
      end

      context "when the project is red" do
        before do
          @project.stub!(:red?).and_return(true)
          @project.stub!(:red_build_count).and_return(20)
          @project.stub!(:red_since).and_return(@status.published_at - 2.days)
        end

        it "should include the oldest continuous failure date" do
          messages = helper.relative_status_messages_for(@project)
          messages.should have(2).messages

          failure_message = messages.last
          failure_message.should == ['project_red_since', 'Red since 3 days ago (20 builds)']
        end
      end
    end

    context "when the project is inaccessible" do
      before do
        @project.stub!(:online?).and_return(false)
      end

      it "should an appropriate message" do
        messages = helper.relative_status_messages_for(@project)
        messages.should have(1).message

        offline_message = messages.first
        offline_message.should == ['project_invalid', 'Could not retrieve status']
      end
    end
  end

  describe "#static_status_messages_for" do
    def publish_time
      Time.parse('Fri May 28 17:27:11 -0700 2010')
    end

    context "when the project is online" do
      before do
        @project.stub!(:online?).and_return(true)
        @project.stub!(:red?).and_return(false)
      end

      context "when the project isn't red" do
        it "should include the last built date" do
          messages = helper.static_status_messages_for(@project)
          messages.should have(1).message
          last_built_message = messages.first
          last_built_message.should == "Last built Fri May 28 17:27:11 -0700 2010"
        end
      end

      context "when the project is red" do
        before do
          @project.stub!(:red?).and_return(true)
          @project.stub!(:red_build_count).and_return(20)
          @project.stub!(:red_since).and_return(@status.published_at - 2.days)
        end

        it "should include the oldest continuous failure date" do
          messages = helper.static_status_messages_for(@project)
          messages.should have(2).messages

          failure_message = messages.last
          failure_message.should == 'Red since Wed May 26 17:27:11 -0700 2010 (20 builds)'
        end
      end
    end

    context "when the project is inaccessible" do
      before do
        @project.stub!(:online?).and_return(false)
      end

      it "should an appropriate message" do
        messages = helper.static_status_messages_for(@project)
        messages.should have(1).message

        offline_message = messages.first
        offline_message.should == 'Could not retrieve status'
      end
    end
  end
end
<commit_msg>the world does not work on west coast time.<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe CiMonitorHelper do
  before do
    @status = stub(ProjectStatus, :published_at => publish_time)
    @project = stub(Project, :status => @status)
  end

  describe "#relative_status_messages_for" do
    def publish_time
      Time.now - 1.day
    end

    context "when the project is online" do
      before do
        @project.stub!(:online?).and_return(true)
        @project.stub!(:red?).and_return(false)
      end

      context "when the project isn't red" do
        it "should include the last built date" do
          messages = helper.relative_status_messages_for(@project)
          messages.should have(1).message
          last_built_message = messages.first
          last_built_message.should == ['project_published_at', 'Last built 1 day ago']
        end
      end

      context "when the project is red" do
        before do
          @project.stub!(:red?).and_return(true)
          @project.stub!(:red_build_count).and_return(20)
          @project.stub!(:red_since).and_return(@status.published_at - 2.days)
        end

        it "should include the oldest continuous failure date" do
          messages = helper.relative_status_messages_for(@project)
          messages.should have(2).messages

          failure_message = messages.last
          failure_message.should == ['project_red_since', 'Red since 3 days ago (20 builds)']
        end
      end
    end

    context "when the project is inaccessible" do
      before do
        @project.stub!(:online?).and_return(false)
      end

      it "should an appropriate message" do
        messages = helper.relative_status_messages_for(@project)
        messages.should have(1).message

        offline_message = messages.first
        offline_message.should == ['project_invalid', 'Could not retrieve status']
      end
    end
  end

  describe "#static_status_messages_for" do
    def publish_time
      Time.parse('Fri May 28 17:27:11 -0700 2010')
    end

    context "when the project is online" do
      before do
        @project.stub!(:online?).and_return(true)
        @project.stub!(:red?).and_return(false)
      end

      context "when the project isn't red" do
        it "should include the last built date" do
          messages = helper.static_status_messages_for(@project)
          messages.should have(1).message
          last_built_message = messages.first
          last_built_message.should == "Last built #{publish_time.to_s}"
        end
      end

      context "when the project is red" do
        before do
          @red_since_time = @status.published_at - 2.days
          @project.stub!(:red?).and_return(true)
          @project.stub!(:red_build_count).and_return(20)
          @project.stub!(:red_since).and_return(@red_since_time)
        end

        it "should include the oldest continuous failure date" do
          messages = helper.static_status_messages_for(@project)
          messages.should have(2).messages

          failure_message = messages.last
          failure_message.should == "Red since #{@red_since_time.to_s} (20 builds)"
        end
      end
    end

    context "when the project is inaccessible" do
      before do
        @project.stub!(:online?).and_return(false)
      end

      it "should an appropriate message" do
        messages = helper.static_status_messages_for(@project)
        messages.should have(1).message

        offline_message = messages.first
        offline_message.should == 'Could not retrieve status'
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09075700543705563, 'fraction_numerical': 0.014219991635299039, 'mean_word_length': 2.508068459657702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6525510', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1981, 'n_words': 542}