summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/graphs/commits_spec.rb
blob: 3f9382a9143a5ed1963ac994d0a43fccc45a131f (plain)
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
37
38
39
require 'spec_helper'

describe Gitlab::Graphs::Commits do
  let!(:project) { create(:empty_project, :public) }

  let!(:commit1) { create(:commit, git_commit: RepoHelpers.sample_commit, project: project, committed_date: Time.now) }
  let!(:commit1_yesterday) { create(:commit, git_commit: RepoHelpers.sample_commit, project: project, committed_date: 1.day.ago)}

  let!(:commit2) { create(:commit, git_commit: RepoHelpers.another_sample_commit, project: project, committed_date: Time.now) }

  describe '#commit_per_day' do
    context 'when range is only commits from today' do
      subject { described_class.new([commit2, commit1]).commit_per_day }
      it { is_expected.to eq 2 }
    end
  end

  context 'when range is only commits from today' do
    subject { described_class.new([commit2, commit1]) }
    describe '#commit_per_day' do
      it { expect(subject.commit_per_day).to eq 2 }
    end

    describe '#duration' do
      it { expect(subject.duration).to eq 0 }
    end
  end

  context 'with commits from yesterday and today' do
    subject { described_class.new([commit2, commit1_yesterday]) }
    describe '#commit_per_day' do
      it { expect(subject.commit_per_day).to eq 1 }
    end

    describe '#duration' do
      it { expect(subject.duration).to eq 1 }
    end
  end
end