Introduce pages_deployed? to Project model

This commit is contained in:
Kamil Trzcinski 2016-02-19 20:12:56 +01:00 committed by James Edwards-Jones
parent 8a861c87bf
commit 06d96a9a62
6 changed files with 30 additions and 17 deletions

View file

@ -1164,9 +1164,11 @@ class Project < ActiveRecord::Base
ensure_runners_token!
end
def pages_url
return unless Dir.exist?(public_pages_path)
def pages_deployed?
Dir.exist?(public_pages_path)
end
def pages_url
# The hostname always needs to be in downcased
# All web servers convert hostname to lowercase
host = "#{namespace.path}.#{Settings.pages.host}".downcase

View file

@ -1,4 +1,4 @@
- if @project.pages_url
- if @project.pages_deployed?
.panel.panel-default
.panel-heading
Access pages

View file

@ -1,4 +1,4 @@
- if can?(current_user, :remove_pages, @project) && @project.pages_url
- if can?(current_user, :remove_pages, @project) && @project.pages_deployed?
.panel.panel-default.panel.panel-danger
.panel-heading Remove pages
.errors-holder

View file

@ -1,4 +1,4 @@
- unless @project.pages_url
- unless @project.pages_deployed?
.panel.panel-info
.panel-heading
Configure pages

View file

@ -1068,6 +1068,23 @@ describe Project, models: true do
end
end
describe '#pages_deployed?' do
let(:project) { create :empty_project }
subject { project.pages_deployed? }
context 'if public folder does exist' do
before { FileUtils.mkdir_p(project.public_pages_path) }
after { FileUtils.rmdir(project.public_pages_path) }
it { is_expected.to be_truthy }
end
context "if public folder doesn't exist" do
it { is_expected.to be_falsey }
end
end
describe '.search' do
let(:project) { create(:empty_project, description: 'kitten mittens') }
@ -1854,16 +1871,10 @@ describe Project, models: true do
subject { project.pages_url }
before do
FileUtils.mkdir_p(project.public_pages_path)
allow(Settings.pages).to receive(:host).and_return(domain)
allow(Gitlab.config.pages).to receive(:url).and_return('http://example.com')
end
after do
FileUtils.rmdir(project.public_pages_path)
end
context 'group page' do
let(:group_name) { 'Group' }
let(:project_name) { 'group.example.com' }

View file

@ -27,9 +27,9 @@ describe Projects::UpdatePagesService do
end
it 'succeeds' do
expect(project.pages_url).to be_nil
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
expect(project.pages_url).to_not be_nil
expect(project.pages_deployed?).to be_truthy
end
it 'limits pages size' do
@ -39,11 +39,11 @@ describe Projects::UpdatePagesService do
it 'removes pages after destroy' do
expect(PagesWorker).to receive(:perform_in)
expect(project.pages_url).to be_nil
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
expect(project.pages_url).to_not be_nil
expect(project.pages_deployed?).to be_truthy
project.destroy
expect(Dir.exist?(project.public_pages_path)).to be_falsey
expect(project.pages_deployed?).to be_falsey
end
it 'fails if sha on branch is not latest' do
@ -61,7 +61,7 @@ describe Projects::UpdatePagesService do
it 'fails to remove project pages when no pages is deployed' do
expect(PagesWorker).to_not receive(:perform_in)
expect(project.pages_url).to be_nil
expect(project.pages_deployed?).to be_falsey
project.destroy
end