summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/graphs_controller_spec.rb
blob: e0de62e4454706c5859834a2984bec698d1a948c (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'spec_helper'

describe Projects::GraphsController do
  let(:project) { create(:project, :repository) }
  let(:user)    { create(:user) }

  before do
    sign_in(user)
    project.team << [user, :master]
  end

  describe 'GET languages' do
    it "redirects_to action charts" do
      get(:commits, namespace_id: project.namespace.path, project_id: project.path, id: 'master')

      expect(response).to redirect_to action: :charts
    end
  end

  describe 'GET commits' do
    it "redirects_to action charts" do
      get(:commits, namespace_id: project.namespace.path, project_id: project.path, id: 'master')

      expect(response).to redirect_to action: :charts
    end
  end

  describe 'GET charts' do
    let(:linguist_repository) do
      double(languages: {
               'Ruby'         => 1000,
               'CoffeeScript' => 350,
               'NSIS'         => 15
             })
    end

    let(:expected_values) do
      nsis_color = "##{Digest::SHA256.hexdigest('NSIS')[0...6]}"
      [
        # colors from Linguist:
        { label: "Ruby",         color: "#701516",  highlight: "#701516" },
        { label: "CoffeeScript", color: "#244776",  highlight: "#244776" },
        # colors from SHA256 fallback:
        { label: "NSIS",         color: nsis_color, highlight: nsis_color }
      ]
    end

    before do
      allow(Linguist::Repository).to receive(:new).and_return(linguist_repository)
    end

    it 'sets the correct colour according to language' do
      get(:charts, namespace_id: project.namespace, project_id: project, id: 'master')

      expected_values.each do |val|
        expect(assigns(:languages)).to include(a_hash_including(val))
      end
    end
  end
end