summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-09-22 02:21:33 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-09-22 02:21:33 -0700
commit7be084b13a0bb056a6cd8065f74fd24f4f147551 (patch)
tree86874cc945970e5f8d5744a38813fd42707c519d
parent5bc07b2ad82492e8438f07363337bb5e80a22dfb (diff)
parent61a86101e81368b79bc9b99ef355518cde83facc (diff)
downloadgitlab-ce-7be084b13a0bb056a6cd8065f74fd24f4f147551.tar.gz
Merge pull request #5142 from karlhungus/bugfix-handle-empty-public-projects
Prevent empty public projects from throwing exceptions
-rw-r--r--app/controllers/public/projects_controller.rb12
-rw-r--r--app/views/public/projects/show.html.haml57
-rw-r--r--features/public/public_projects.feature5
-rw-r--r--features/steps/public/projects_feature.rb18
4 files changed, 60 insertions, 32 deletions
diff --git a/app/controllers/public/projects_controller.rb b/app/controllers/public/projects_controller.rb
index 85216cd3271..3504bd3f1a5 100644
--- a/app/controllers/public/projects_controller.rb
+++ b/app/controllers/public/projects_controller.rb
@@ -1,7 +1,7 @@
class Public::ProjectsController < ApplicationController
skip_before_filter :authenticate_user!,
- :reject_blocked, :set_current_user_for_observers,
- :add_abilities
+ :reject_blocked, :set_current_user_for_observers,
+ :add_abilities
layout 'public'
@@ -16,9 +16,11 @@ class Public::ProjectsController < ApplicationController
render_404 and return unless @project
@repository = @project.repository
- @recent_tags = @repository.tags.first(10)
+ unless @project.empty_repo?
+ @recent_tags = @repository.tags.first(10)
- @commit = @repository.commit(params[:ref])
- @tree = Tree.new(@repository, @commit.id)
+ @commit = @repository.commit(params[:ref])
+ @tree = Tree.new(@repository, @commit.id)
+ end
end
end
diff --git a/app/views/public/projects/show.html.haml b/app/views/public/projects/show.html.haml
index c4d8a4f5a5f..195b9bc07d2 100644
--- a/app/views/public/projects/show.html.haml
+++ b/app/views/public/projects/show.html.haml
@@ -15,32 +15,35 @@
%br
.row
- .span9
- = render 'tree', tree: @tree
- .span3
- %h5 Repository:
- %div
- %p
- %span.light Bare size is
- #{@project.repository.size} MB
+ - unless @project.empty_repo?
+ .span9
+ = render 'tree', tree: @tree
+ .span3
+ %h5 Repository:
+ %div
+ %p
+ %span.light Bare size is
+ #{@project.repository.size} MB
- %p
- = pluralize(@repository.round_commit_count, 'commit')
- %p
- = pluralize(@repository.branch_names.count, 'branch')
- %p
- = pluralize(@repository.tag_names.count, 'tag')
+ %p
+ = pluralize(@repository.round_commit_count, 'commit')
+ %p
+ = pluralize(@repository.branch_names.count, 'branch')
+ %p
+ = pluralize(@repository.tag_names.count, 'tag')
- - if @recent_tags.present?
- %hr
- %h5 Most Recent Tags:
- %ul.unstyled
- - @recent_tags.each do |tag|
- %li
- %p
- %i.icon-tag
- %strong= tag.name
- %small.light.pull-right
- %i.icon-calendar
- = time_ago_in_words(tag.commit.committed_date)
- ago
+ - if @recent_tags.present?
+ %hr
+ %h5 Most Recent Tags:
+ %ul.unstyled
+ - @recent_tags.each do |tag|
+ %li
+ %p
+ %i.icon-tag
+ %strong= tag.name
+ %small.light.pull-right
+ %i.icon-calendar
+ = time_ago_in_words(tag.commit.committed_date)
+ ago
+ - else
+ = 'Empty Repository'
diff --git a/features/public/public_projects.feature b/features/public/public_projects.feature
index c4f1b6203e7..1866d3f47fe 100644
--- a/features/public/public_projects.feature
+++ b/features/public/public_projects.feature
@@ -12,3 +12,8 @@ Feature: Public Projects Feature
When I visit public page for "Community" project
Then I should see public project details
And I should see project readme
+
+ Scenario: I visit an empty public project page
+ Given public empty project "Empty Public Project"
+ When I visit empty public project page
+ Then I should see empty public project details \ No newline at end of file
diff --git a/features/steps/public/projects_feature.rb b/features/steps/public/projects_feature.rb
index 8d612498fb9..2268e9b9c5e 100644
--- a/features/steps/public/projects_feature.rb
+++ b/features/steps/public/projects_feature.rb
@@ -9,6 +9,11 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
page.should_not have_content "Enterprise"
end
+ step 'I should see project "Empty Public Project"' do
+ page.should have_content "Empty Public Project"
+ puts page.save_page('foo.html')
+ end
+
step 'I should see public project details' do
page.should have_content '32 branches'
page.should have_content '16 tags'
@@ -22,6 +27,19 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
create :project_with_code, name: 'Community', public: true
end
+ step 'public empty project "Empty Public Project"' do
+ create :project, name: 'Empty Public Project', public: true
+ end
+
+ step 'I visit empty public project page' do
+ project = Project.find_by_name('Empty Public Project')
+ visit public_project_path(project)
+ end
+
+ step 'I should see empty public project details' do
+ page.should have_content 'Empty Repository'
+ end
+
step 'private project "Enterprise"' do
create :project, name: 'Enterprise'
end