Commit 06d96a9a authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by James Edwards-Jones

Introduce pages_deployed? to Project model

parent 8a861c87
...@@ -1164,9 +1164,11 @@ class Project < ActiveRecord::Base ...@@ -1164,9 +1164,11 @@ class Project < ActiveRecord::Base
ensure_runners_token! ensure_runners_token!
end end
def pages_url def pages_deployed?
return unless Dir.exist?(public_pages_path) Dir.exist?(public_pages_path)
end
def pages_url
# The hostname always needs to be in downcased # The hostname always needs to be in downcased
# All web servers convert hostname to lowercase # All web servers convert hostname to lowercase
host = "#{namespace.path}.#{Settings.pages.host}".downcase host = "#{namespace.path}.#{Settings.pages.host}".downcase
......
- if @project.pages_url - if @project.pages_deployed?
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
Access pages Access pages
......
- 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.panel-default.panel.panel-danger
.panel-heading Remove pages .panel-heading Remove pages
.errors-holder .errors-holder
......
- unless @project.pages_url - unless @project.pages_deployed?
.panel.panel-info .panel.panel-info
.panel-heading .panel-heading
Configure pages Configure pages
......
...@@ -1068,6 +1068,23 @@ describe Project, models: true do ...@@ -1068,6 +1068,23 @@ describe Project, models: true do
end end
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 describe '.search' do
let(:project) { create(:empty_project, description: 'kitten mittens') } let(:project) { create(:empty_project, description: 'kitten mittens') }
...@@ -1854,16 +1871,10 @@ describe Project, models: true do ...@@ -1854,16 +1871,10 @@ describe Project, models: true do
subject { project.pages_url } subject { project.pages_url }
before do before do
FileUtils.mkdir_p(project.public_pages_path)
allow(Settings.pages).to receive(:host).and_return(domain) allow(Settings.pages).to receive(:host).and_return(domain)
allow(Gitlab.config.pages).to receive(:url).and_return('http://example.com') allow(Gitlab.config.pages).to receive(:url).and_return('http://example.com')
end end
after do
FileUtils.rmdir(project.public_pages_path)
end
context 'group page' do context 'group page' do
let(:group_name) { 'Group' } let(:group_name) { 'Group' }
let(:project_name) { 'group.example.com' } let(:project_name) { 'group.example.com' }
......
...@@ -27,9 +27,9 @@ describe Projects::UpdatePagesService do ...@@ -27,9 +27,9 @@ describe Projects::UpdatePagesService do
end end
it 'succeeds' do it 'succeeds' do
expect(project.pages_url).to be_nil expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success) expect(execute).to eq(:success)
expect(project.pages_url).to_not be_nil expect(project.pages_deployed?).to be_truthy
end end
it 'limits pages size' do it 'limits pages size' do
...@@ -39,11 +39,11 @@ describe Projects::UpdatePagesService do ...@@ -39,11 +39,11 @@ describe Projects::UpdatePagesService do
it 'removes pages after destroy' do it 'removes pages after destroy' do
expect(PagesWorker).to receive(:perform_in) 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(execute).to eq(:success)
expect(project.pages_url).to_not be_nil expect(project.pages_deployed?).to be_truthy
project.destroy project.destroy
expect(Dir.exist?(project.public_pages_path)).to be_falsey expect(project.pages_deployed?).to be_falsey
end end
it 'fails if sha on branch is not latest' do it 'fails if sha on branch is not latest' do
...@@ -61,7 +61,7 @@ describe Projects::UpdatePagesService do ...@@ -61,7 +61,7 @@ describe Projects::UpdatePagesService do
it 'fails to remove project pages when no pages is deployed' do it 'fails to remove project pages when no pages is deployed' do
expect(PagesWorker).to_not receive(:perform_in) expect(PagesWorker).to_not receive(:perform_in)
expect(project.pages_url).to be_nil expect(project.pages_deployed?).to be_falsey
project.destroy project.destroy
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