BigW Consortium Gitlab

summary_spec.rb 1.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
require 'spec_helper'

describe CycleAnalytics::Summary, models: true do
  let(:project) { create(:project) }
  let(:from) { Time.now }
  let(:user) { create(:user, :admin) }
  subject { described_class.new(project, from: from) }

  describe "#new_issues" do
    it "finds the number of issues created after the 'from date'" do
      Timecop.freeze(5.days.ago) { create(:issue, project: project) }
      Timecop.freeze(5.days.from_now) { create(:issue, project: project) }

      expect(subject.new_issues).to eq(1)
    end

    it "doesn't find issues from other projects" do
      Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project)) }

      expect(subject.new_issues).to eq(0)
    end
  end

  describe "#commits" do
    it "finds the number of commits created after the 'from date'" do
      Timecop.freeze(5.days.ago) { create_commit("Test message", project, user, 'master') }
      Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master') }

      expect(subject.commits).to eq(1)
    end

    it "doesn't find commits from other projects" do
      Timecop.freeze(5.days.from_now) { create_commit("Test message", create(:project), user, 'master') }

      expect(subject.commits).to eq(0)
    end
37 38 39 40 41 42

    it "finds a large (> 100) snumber of commits if present" do
      Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master', count: 100) }

      expect(subject.commits).to eq(100)
    end
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  end

  describe "#deploys" do
    it "finds the number of deploys made created after the 'from date'" do
      Timecop.freeze(5.days.ago) { create(:deployment, project: project) }
      Timecop.freeze(5.days.from_now) { create(:deployment, project: project) }

      expect(subject.deploys).to eq(1)
    end

    it "doesn't find commits from other projects" do
      Timecop.freeze(5.days.from_now) { create(:deployment, project: create(:project)) }

      expect(subject.deploys).to eq(0)
    end
  end
end