Commit 7be084b13a0bb056a6cd8065f74fd24f4f147551
Exists in
master
and in
4 other branches
Merge pull request #5142 from karlhungus/bugfix-handle-empty-public-projects
Prevent empty public projects from throwing exceptions
Showing
4 changed files
with
60 additions
and
32 deletions
Show diff stats
app/controllers/public/projects_controller.rb
1 | 1 | class Public::ProjectsController < ApplicationController |
2 | 2 | skip_before_filter :authenticate_user!, |
3 | - :reject_blocked, :set_current_user_for_observers, | |
4 | - :add_abilities | |
3 | + :reject_blocked, :set_current_user_for_observers, | |
4 | + :add_abilities | |
5 | 5 | |
6 | 6 | layout 'public' |
7 | 7 | |
... | ... | @@ -16,9 +16,11 @@ class Public::ProjectsController < ApplicationController |
16 | 16 | render_404 and return unless @project |
17 | 17 | |
18 | 18 | @repository = @project.repository |
19 | - @recent_tags = @repository.tags.first(10) | |
19 | + unless @project.empty_repo? | |
20 | + @recent_tags = @repository.tags.first(10) | |
20 | 21 | |
21 | - @commit = @repository.commit(params[:ref]) | |
22 | - @tree = Tree.new(@repository, @commit.id) | |
22 | + @commit = @repository.commit(params[:ref]) | |
23 | + @tree = Tree.new(@repository, @commit.id) | |
24 | + end | |
23 | 25 | end |
24 | 26 | end | ... | ... |
app/views/public/projects/show.html.haml
... | ... | @@ -15,32 +15,35 @@ |
15 | 15 | |
16 | 16 | %br |
17 | 17 | .row |
18 | - .span9 | |
19 | - = render 'tree', tree: @tree | |
20 | - .span3 | |
21 | - %h5 Repository: | |
22 | - %div | |
23 | - %p | |
24 | - %span.light Bare size is | |
25 | - #{@project.repository.size} MB | |
18 | + - unless @project.empty_repo? | |
19 | + .span9 | |
20 | + = render 'tree', tree: @tree | |
21 | + .span3 | |
22 | + %h5 Repository: | |
23 | + %div | |
24 | + %p | |
25 | + %span.light Bare size is | |
26 | + #{@project.repository.size} MB | |
26 | 27 | |
27 | - %p | |
28 | - = pluralize(@repository.round_commit_count, 'commit') | |
29 | - %p | |
30 | - = pluralize(@repository.branch_names.count, 'branch') | |
31 | - %p | |
32 | - = pluralize(@repository.tag_names.count, 'tag') | |
28 | + %p | |
29 | + = pluralize(@repository.round_commit_count, 'commit') | |
30 | + %p | |
31 | + = pluralize(@repository.branch_names.count, 'branch') | |
32 | + %p | |
33 | + = pluralize(@repository.tag_names.count, 'tag') | |
33 | 34 | |
34 | - - if @recent_tags.present? | |
35 | - %hr | |
36 | - %h5 Most Recent Tags: | |
37 | - %ul.unstyled | |
38 | - - @recent_tags.each do |tag| | |
39 | - %li | |
40 | - %p | |
41 | - %i.icon-tag | |
42 | - %strong= tag.name | |
43 | - %small.light.pull-right | |
44 | - %i.icon-calendar | |
45 | - = time_ago_in_words(tag.commit.committed_date) | |
46 | - ago | |
35 | + - if @recent_tags.present? | |
36 | + %hr | |
37 | + %h5 Most Recent Tags: | |
38 | + %ul.unstyled | |
39 | + - @recent_tags.each do |tag| | |
40 | + %li | |
41 | + %p | |
42 | + %i.icon-tag | |
43 | + %strong= tag.name | |
44 | + %small.light.pull-right | |
45 | + %i.icon-calendar | |
46 | + = time_ago_in_words(tag.commit.committed_date) | |
47 | + ago | |
48 | + - else | |
49 | + = 'Empty Repository' | ... | ... |
features/public/public_projects.feature
... | ... | @@ -12,3 +12,8 @@ Feature: Public Projects Feature |
12 | 12 | When I visit public page for "Community" project |
13 | 13 | Then I should see public project details |
14 | 14 | And I should see project readme |
15 | + | |
16 | + Scenario: I visit an empty public project page | |
17 | + Given public empty project "Empty Public Project" | |
18 | + When I visit empty public project page | |
19 | + Then I should see empty public project details | |
15 | 20 | \ No newline at end of file | ... | ... |
features/steps/public/projects_feature.rb
... | ... | @@ -9,6 +9,11 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
9 | 9 | page.should_not have_content "Enterprise" |
10 | 10 | end |
11 | 11 | |
12 | + step 'I should see project "Empty Public Project"' do | |
13 | + page.should have_content "Empty Public Project" | |
14 | + puts page.save_page('foo.html') | |
15 | + end | |
16 | + | |
12 | 17 | step 'I should see public project details' do |
13 | 18 | page.should have_content '32 branches' |
14 | 19 | page.should have_content '16 tags' |
... | ... | @@ -22,6 +27,19 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
22 | 27 | create :project_with_code, name: 'Community', public: true |
23 | 28 | end |
24 | 29 | |
30 | + step 'public empty project "Empty Public Project"' do | |
31 | + create :project, name: 'Empty Public Project', public: true | |
32 | + end | |
33 | + | |
34 | + step 'I visit empty public project page' do | |
35 | + project = Project.find_by_name('Empty Public Project') | |
36 | + visit public_project_path(project) | |
37 | + end | |
38 | + | |
39 | + step 'I should see empty public project details' do | |
40 | + page.should have_content 'Empty Repository' | |
41 | + end | |
42 | + | |
25 | 43 | step 'private project "Enterprise"' do |
26 | 44 | create :project, name: 'Enterprise' |
27 | 45 | end | ... | ... |