find_file_controller_spec.rb 1.55 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5
require 'spec_helper'

describe Projects::FindFileController do
6
  let(:project) { create(:project, :repository) }
7 8 9 10 11
  let(:user)    { create(:user) }

  before do
    sign_in(user)

12
    project.add_maintainer(user)
13 14 15 16 17 18 19 20 21
    controller.instance_variable_set(:@project, project)
  end

  describe "GET #show" do
    # Make sure any errors accessing the tree in our views bubble up to this spec
    render_views

    before do
      get(:show,
blackst0ne's avatar
blackst0ne committed
22 23 24 25 26
          params: {
            namespace_id: project.namespace,
            project_id: project,
            id: id
          })
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    end

    context "valid branch" do
      let(:id) { 'master' }
      it { is_expected.to respond_with(:success) }
    end

    context "invalid branch" do
      let(:id) { 'invalid-branch' }
      it { is_expected.to respond_with(:not_found) }
    end
  end

  describe "GET #list" do
    def go(format: 'json')
      get :list,
blackst0ne's avatar
blackst0ne committed
43 44 45 46 47
          params: {
            namespace_id: project.namespace,
            project_id: project,
            id: id
          },
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
          format: format
    end

    context "valid branch" do
      let(:id) { 'master' }
      it 'returns an array of file path list' do
        go

        json = JSON.parse(response.body)
        is_expected.to respond_with(:success)
        expect(json).not_to eq(nil)
        expect(json.length).to be >= 0
      end
    end

    context "invalid branch" do
      let(:id) { 'invalid-branch' }

      it 'responds with status 404' do
        go
        is_expected.to respond_with(:not_found)
      end
    end
  end
end