builds_controller_spec.rb 1.72 KB
Newer Older
Shinya Maeda's avatar
Shinya Maeda committed
1 2 3 4 5 6 7 8 9 10 11 12
require 'spec_helper'

describe Projects::BuildsController do
  include ApiHelpers

  let(:user) { create(:user) }
  let(:project) { create(:empty_project, :public) }

  before do
    sign_in(user)
  end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
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
  describe 'GET index' do
    context 'number of queries' do
      before do
        Ci::Build::AVAILABLE_STATUSES.each do |status|
          create_build(status, status)
        end

        RequestStore.begin!
      end

      after do
        RequestStore.end!
        RequestStore.clear!
      end

      def render
        get :index, namespace_id: project.namespace,
                    project_id: project
      end

      it "verifies number of queries" do
        recorded = ActiveRecord::QueryRecorder.new { render }
        expect(recorded.count).to be_within(5).of(8)
      end

      def create_build(name, status)
        pipeline = create(:ci_pipeline, project: project)
        create(:ci_build, :tags, :triggered, :artifacts,
          pipeline: pipeline, name: name, status: status)
      end
    end
  end

Shinya Maeda's avatar
Shinya Maeda committed
46
  describe 'GET status.json' do
47 48 49
    let(:pipeline) { create(:ci_pipeline, project: project) }
    let(:build) { create(:ci_build, pipeline: pipeline) }
    let(:status) { build.detailed_status(double('user')) }
Shinya Maeda's avatar
Shinya Maeda committed
50

51 52 53 54 55 56
    before do
      get :status, namespace_id: project.namespace,
                   project_id: project,
                   id: build.id,
                   format: :json
    end
Shinya Maeda's avatar
Shinya Maeda committed
57

58 59 60 61 62 63
    it 'return a detailed build status in json' do
      expect(response).to have_http_status(:ok)
      expect(json_response['text']).to eq status.text
      expect(json_response['label']).to eq status.label
      expect(json_response['icon']).to eq status.icon
      expect(json_response['favicon']).to eq status.favicon
Shinya Maeda's avatar
Shinya Maeda committed
64 65 66
    end
  end
end