tree_controller_spec.rb 1.39 KB
Newer Older
1 2
require 'spec_helper'

3
describe Projects::TreeController do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
  let(:project) { create(:project) }
5 6 7 8 9
  let(:user)    { create(:user) }

  before do
    sign_in(user)

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10
    project.team << [user, :master]
11 12 13 14 15 16 17 18 19 20

    project.stub(:branches).and_return(['master', 'foo/bar/baz'])
    project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
    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

21
    before { get :show, project_id: project.to_param, id: id }
22 23 24 25 26 27 28

    context "valid branch, no path" do
      let(:id) { 'master' }
      it { should respond_with(:success) }
    end

    context "valid branch, valid path" do
29
      let(:id) { 'master/app/' }
30 31 32 33
      it { should respond_with(:success) }
    end

    context "valid branch, invalid path" do
34
      let(:id) { 'master/invalid-path/' }
35 36 37 38
      it { should respond_with(:not_found) }
    end

    context "invalid branch, valid path" do
39
      let(:id) { 'invalid-branch/app/' }
40 41 42
      it { should respond_with(:not_found) }
    end
  end
Marin Jankovski's avatar
Marin Jankovski committed
43 44 45 46 47 48 49 50 51 52 53 54 55

  describe 'GET show with blob path' do
    render_views

    before do
      get :show, project_id: project.to_param, id: id
    end

    context 'redirect to blob' do
      let(:id) { 'master/README.md' }
      it { should redirect_to("/#{project.path_with_namespace}/blob/master/README.md") }
    end
  end
56
end