Commit a4633537 authored by Robert Speicher's avatar Robert Speicher

Add "empty_repo?" method to Repository role

Replaces two calls that this method simplifies
parent 7e76610d
...@@ -135,7 +135,7 @@ class ApplicationController < ActionController::Base ...@@ -135,7 +135,7 @@ class ApplicationController < ActionController::Base
end end
def require_non_empty_project def require_non_empty_project
redirect_to @project unless @project.repo_exists? && @project.has_commits? redirect_to @project if @project.empty_repo?
end end
def no_cache_headers def no_cache_headers
......
...@@ -50,7 +50,7 @@ class ProjectsController < ApplicationController ...@@ -50,7 +50,7 @@ class ProjectsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html do format.html do
if @project.repo_exists? && @project.has_commits? unless @project.empty_repo?
@last_push = current_user.recent_push(@project.id) @last_push = current_user.recent_push(@project.id)
render :show render :show
else else
......
...@@ -8,6 +8,10 @@ module Repository ...@@ -8,6 +8,10 @@ module Repository
false false
end end
def empty_repo?
!repo_exists? || !has_commits?
end
def commit(commit_id = nil) def commit(commit_id = nil)
Commit.find_or_first(repo, commit_id, root_ref) Commit.find_or_first(repo, commit_id, root_ref)
end end
......
require 'spec_helper'
describe Project, "Repository" do
let(:project) { build(:project) }
describe "#empty_repo?" do
it "should return true if the repo doesn't exist" do
project.stub(repo_exists?: false, has_commits?: true)
project.should be_empty_repo
end
it "should return true if the repo has commits" do
project.stub(repo_exists?: true, has_commits?: false)
project.should be_empty_repo
end
it "should return false if the repo exists and has commits" do
project.stub(repo_exists?: true, has_commits?: true)
project.should_not be_empty_repo
end
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