Commit 7be084b1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #5142 from karlhungus/bugfix-handle-empty-public-projects

Prevent empty public projects from throwing exceptions
parents 5bc07b2a 61a86101
class Public::ProjectsController < ApplicationController class Public::ProjectsController < ApplicationController
skip_before_filter :authenticate_user!, skip_before_filter :authenticate_user!,
:reject_blocked, :set_current_user_for_observers, :reject_blocked, :set_current_user_for_observers,
:add_abilities :add_abilities
layout 'public' layout 'public'
...@@ -16,9 +16,11 @@ class Public::ProjectsController < ApplicationController ...@@ -16,9 +16,11 @@ class Public::ProjectsController < ApplicationController
render_404 and return unless @project render_404 and return unless @project
@repository = @project.repository @repository = @project.repository
@recent_tags = @repository.tags.first(10) unless @project.empty_repo?
@recent_tags = @repository.tags.first(10)
@commit = @repository.commit(params[:ref]) @commit = @repository.commit(params[:ref])
@tree = Tree.new(@repository, @commit.id) @tree = Tree.new(@repository, @commit.id)
end
end end
end end
...@@ -15,32 +15,35 @@ ...@@ -15,32 +15,35 @@
%br %br
.row .row
.span9 - unless @project.empty_repo?
= render 'tree', tree: @tree .span9
.span3 = render 'tree', tree: @tree
%h5 Repository: .span3
%div %h5 Repository:
%p %div
%span.light Bare size is %p
#{@project.repository.size} MB %span.light Bare size is
#{@project.repository.size} MB
%p %p
= pluralize(@repository.round_commit_count, 'commit') = pluralize(@repository.round_commit_count, 'commit')
%p %p
= pluralize(@repository.branch_names.count, 'branch') = pluralize(@repository.branch_names.count, 'branch')
%p %p
= pluralize(@repository.tag_names.count, 'tag') = pluralize(@repository.tag_names.count, 'tag')
- if @recent_tags.present? - if @recent_tags.present?
%hr %hr
%h5 Most Recent Tags: %h5 Most Recent Tags:
%ul.unstyled %ul.unstyled
- @recent_tags.each do |tag| - @recent_tags.each do |tag|
%li %li
%p %p
%i.icon-tag %i.icon-tag
%strong= tag.name %strong= tag.name
%small.light.pull-right %small.light.pull-right
%i.icon-calendar %i.icon-calendar
= time_ago_in_words(tag.commit.committed_date) = time_ago_in_words(tag.commit.committed_date)
ago ago
- else
= 'Empty Repository'
...@@ -12,3 +12,8 @@ Feature: Public Projects Feature ...@@ -12,3 +12,8 @@ Feature: Public Projects Feature
When I visit public page for "Community" project When I visit public page for "Community" project
Then I should see public project details Then I should see public project details
And I should see project readme 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
...@@ -9,6 +9,11 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps ...@@ -9,6 +9,11 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
page.should_not have_content "Enterprise" page.should_not have_content "Enterprise"
end 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 step 'I should see public project details' do
page.should have_content '32 branches' page.should have_content '32 branches'
page.should have_content '16 tags' page.should have_content '16 tags'
...@@ -22,6 +27,19 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps ...@@ -22,6 +27,19 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
create :project_with_code, name: 'Community', public: true create :project_with_code, name: 'Community', public: true
end 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 step 'private project "Enterprise"' do
create :project, name: 'Enterprise' create :project, name: 'Enterprise'
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment