<commit_before>require 'rails_helper'

RSpec.describe ProjectDecorator do
  let(:project){ create(:project, about: 'Foo Bar http://www.foo.bar <javascript>xss()</javascript>"Click here":http://click.here') }

  describe "#state_warning_template" do
    subject{ project.state_warning_template }
    context "when project is in analysis" do
      let(:project){ Project.new state: 'in_analysis' }
      it{ is_expected.to eq('in_analysis_warning') }
    end

    context "when project is a draft" do
      let(:project){ Project.new state: 'draft' }
      it{ is_expected.to eq('draft_warning') }
    end
  end


  describe "#time_to_go" do
    let(:project){ build(:project) }
    let(:expires_at){ Time.zone.parse("23:00:00") }
    subject{ project.time_to_go }
    before do
      I18n.locale = :pt
      allow(project).to receive(:expires_at).and_return(expires_at)
    end

    context "when there is more than 1 day to go" do
      let(:expires_at){ Time.zone.now + 2.days }
      it{ is_expected.to eq({time:1, unit:"dia"}) }
    end

    context "when there is less than 1 day to go" do
      let(:expires_at){ Time.zone.now + 13.hours }
      it{ is_expected.to eq({time:12, unit:"horas"}) }
    end

    context "when there is less than 1 hour to go" do
      let(:expires_at){ Time.zone.now + 59.minutes }
      it{ is_expected.to eq({time:58, unit:"minutos"}) }
    end
  end

  describe "#progress" do
    subject{ project.progress }
    let(:pledged){ 0.0 }
    let(:goal){ 0.0 }
    before do
        allow(project).to receive(:pledged).and_return(pledged)
        allow(project).to receive(:goal).and_return(goal)
    end

    context "when goal == pledged > 0" do
      let(:goal){ 10.0 }
      let(:pledged){ 10.0 }
      it{ is_expected.to eq(100) }
    end

    context "when goal is > 0 and pledged is 0.0" do
      let(:goal){ 10.0 }
      it{ is_expected.to eq(0) }
    end

    context "when goal is 0.0 and pledged > 0.0" do
      let(:pledged){ 10.0 }
      it{ is_expected.to eq(0) }
    end

    context "when goal is 0.0 and pledged is 0.0" do
      it{ is_expected.to eq(0) }
    end
  end

  describe "#display_traffic_sources" do
    subject{ project.display_traffic_sources }

    context "when trafic_sources is nil" do
      it{ is_expected.to be_nil }
    end

    context "when traffic_sources has elements" do
      let(:project){ create(:project, traffic_sources: ['foo', 'bar']) }
      it{ is_expected.to eq(project.traffic_sources.join(', ')) }
    end
  end

  describe "#display_expires_at" do
    subject{ project.display_expires_at }

    context "when online_date is nil" do
      let(:project){ create(:project, online_date: nil) }
      it{ is_expected.to eq('') }
    end

    context "when we have an online_date" do
      let(:project){ create(:project, online_date: Time.now) }
      before do
        expect(I18n).to receive(:l).with(project.expires_at.in_time_zone(Rails.application.config.time_zone).to_date)
      end
      it("should call I18n with date"){ subject }
    end
  end

  describe "#display_online_date" do
    subject{ project.display_online_date }

    context "when online_date is nil" do
      let(:project){ create(:project, online_date: nil) }
      it{ is_expected.to eq('') }
    end

    context "when we have an online_date" do
      let(:project){ create(:project, online_date: Time.now) }
      before do
        expect(I18n).to receive(:l).with(project.online_date.to_date)<commit_msg>fix specs<commit_after>require 'rails_helper'

RSpec.describe ProjectDecorator do
  let(:project){ create(:project, about: 'Foo Bar http://www.foo.bar <javascript>xss()</javascript>"Click here":http://click.here') }

  describe "#state_warning_template" do
    subject{ project.state_warning_template }
    context "when project is in analysis" do
      let(:project){ Project.new state: 'in_analysis' }
      it{ is_expected.to eq('in_analysis_warning') }
    end

    context "when project is a draft" do
      let(:project){ Project.new state: 'draft' }
      it{ is_expected.to eq('draft_warning') }
    end
  end


  describe "#time_to_go" do
    let(:project){ build(:project) }
    let(:expires_at){ Time.zone.parse("23:00:00") }
    subject{ project.time_to_go }
    before do
      I18n.locale = :pt
      allow(project).to receive(:expires_at).and_return(expires_at)
    end

    context "when there is more than 1 day to go" do
      let(:expires_at){ Time.zone.now + 2.days }
      it{ is_expected.to eq({time:1, unit:"dia"}) }
    end

    context "when there is less than 1 day to go" do
      let(:expires_at){ Time.zone.now + 13.hours }
      it{ is_expected.to eq({time:12, unit:"horas"}) }
    end

    context "when there is less than 1 hour to go" do
      let(:expires_at){ Time.zone.now + 59.minutes }
      it{ is_expected.to eq({time:58, unit:"minutos"}) }
    end
  end

  describe "#progress" do
    subject{ project.progress }
    let(:pledged){ 0.0 }
    let(:goal){ 0.0 }
    before do
        allow(project).to receive(:pledged).and_return(pledged)
        allow(project).to receive(:goal).and_return(goal)
    end

    context "when goal == pledged > 0" do
      let(:goal){ 10.0 }
      let(:pledged){ 10.0 }
      it{ is_expected.to eq(100) }
    end

    context "when goal is > 0 and pledged is 0.0" do
      let(:goal){ 10.0 }
      it{ is_expected.to eq(0) }
    end

    context "when goal is 0.0 and pledged > 0.0" do
      let(:pledged){ 10.0 }
      it{ is_expected.to eq(0) }
    end

    context "when goal is 0.0 and pledged is 0.0" do
      it{ is_expected.to eq(0) }
    end
  end

  describe "#display_expires_at" do
    subject{ project.display_expires_at }

    context "when online_date is nil" do
      let(:project){ create(:project, online_date: nil) }
      it{ is_expected.to eq('') }
    end

    context "when we have an online_date" do
      let(:project){ create(:project, online_date: Time.now) }
      before do
        expect(I18n).to receive(:l).with(project.expires_at.in_time_zone(Rails.application.config.time_zone).to_date)
      end
      it("should call I18n with date"){ subject }
    end
  end

  describe "#display_online_date" do
    subject{ project.display_online_date }

    context "when online_date is nil" do
      let(:project){ create(:project, online_date: nil) }
      it{ is_expected.to eq('') }
    end

    context "when we have an online_date" do
      let(:project){ create(:project, online_date: Time.now) }
      before do
        expect(I18n).to receive(:l).with(project.online_date.to_date)
{'fraction_non_alphanumeric': 0.12704229653382196, 'fraction_numerical': 0.01862879828981524, 'mean_word_length': 2.9221556886227544, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '239774', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2150, 'n_words': 583}