1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Merge pull request #1357 from townsen/set_repo_path

Set repo path variable - update Vagrantfile and spec tests
This commit is contained in:
Lee Hambley 2015-02-04 10:01:59 +01:00
commit 35d9f256b8
5 changed files with 175 additions and 158 deletions

View file

@ -19,6 +19,8 @@ Reverse Chronological Order:
* Add documentation regarding property filtering (@townsen)
* Clarify wording and recommendation in stage template. (@Kriechi)
* Both available syntaxes provide similar functionality, do not use both for the same server+role combination.
* Allow specification of repo_path using stage variable
default is as before (@townsen)
https://github.com/capistrano/capistrano/compare/v3.3.5...HEAD

View file

@ -54,7 +54,7 @@ module Capistrano
end
def repo_path
deploy_path.join('repo')
Pathname.new(fetch(:repo_path, ->(){deploy_path.join('repo')}))
end
def shared_path

View file

@ -415,112 +415,6 @@ describe Capistrano::DSL do
end
describe 'release path' do
before do
dsl.set(:deploy_to, '/var/www')
end
describe 'fetching release path' do
subject { dsl.release_path }
context 'where no release path has been set' do
before do
dsl.delete(:release_path)
end
it 'returns the `current_path` value' do
expect(subject.to_s).to eq '/var/www/current'
end
end
context 'where the release path has been set' do
before do
dsl.set(:release_path, '/var/www/release_path')
end
it 'returns the set `release_path` value' do
expect(subject.to_s).to eq '/var/www/release_path'
end
end
end
describe 'setting release path' do
let(:now) { Time.parse("Oct 21 16:29:00 2015") }
subject { dsl.release_path }
context 'without a timestamp' do
before do
dsl.env.expects(:timestamp).returns(now)
dsl.set_release_path
end
it 'returns the release path with the current env timestamp' do
expect(subject.to_s).to eq '/var/www/releases/20151021162900'
end
end
context 'with a timestamp' do
before do
dsl.set_release_path('timestamp')
end
it 'returns the release path with the timestamp' do
expect(subject.to_s).to eq '/var/www/releases/timestamp'
end
end
end
describe 'setting deploy configuration path' do
subject { dsl.deploy_config_path.to_s }
context 'where no config path is set' do
before do
dsl.delete(:deploy_config_path)
end
it 'returns "config/deploy.rb"' do
expect(subject).to eq 'config/deploy.rb'
end
end
context 'where a custom path is set' do
before do
dsl.set(:deploy_config_path, 'my/custom/path.rb')
end
it 'returns the custom path' do
expect(subject).to eq 'my/custom/path.rb'
end
end
end
describe 'setting stage configuration path' do
subject { dsl.stage_config_path.to_s }
context 'where no config path is set' do
before do
dsl.delete(:stage_config_path)
end
it 'returns "config/deploy"' do
expect(subject).to eq 'config/deploy'
end
end
context 'where a custom path is set' do
before do
dsl.set(:stage_config_path, 'my/custom/path')
end
it 'returns the custom path' do
expect(subject).to eq 'my/custom/path'
end
end
end
end
describe 'local_user' do
before do
dsl.set :local_user, -> { Etc.getlogin }

View file

@ -1,69 +1,190 @@
require 'spec_helper'
module Capistrano
module DSL
describe Capistrano::DSL::Paths do
class DummyPaths
include Paths
let(:dsl) { Class.new.extend Capistrano::DSL }
let(:parent) { Pathname.new('/var/shared') }
let(:paths) { Class.new.extend Capistrano::DSL::Paths }
let(:linked_dirs) { %w{log public/system} }
let(:linked_files) { %w{config/database.yml log/my.log} }
before do
dsl.set(:deploy_to, '/var/www')
end
describe '#linked_dirs' do
subject { paths.linked_dirs(parent) }
before do
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
end
describe Paths do
let(:paths) { DummyPaths.new }
let(:parent) { Pathname.new('/var/shared') }
let(:linked_dirs) { %w{log public/system} }
let(:linked_files) { %w{config/database.yml log/my.log} }
it 'returns the full pathnames' do
expect(subject).to eq [Pathname.new('/var/shared/log'), Pathname.new('/var/shared/public/system')]
end
end
describe '#linked_dirs' do
subject { paths.linked_dirs(parent) }
describe '#linked_files' do
subject { paths.linked_files(parent) }
before do
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
end
before do
paths.expects(:fetch).with(:linked_files).returns(linked_files)
end
it 'returns the full pathnames' do
expect(subject).to eq [Pathname.new('/var/shared/log'), Pathname.new('/var/shared/public/system')]
end
it 'returns the full pathnames' do
expect(subject).to eq [Pathname.new('/var/shared/config/database.yml'), Pathname.new('/var/shared/log/my.log')]
end
end
describe '#linked_file_dirs' do
subject { paths.linked_file_dirs(parent) }
before do
paths.expects(:fetch).with(:linked_files).returns(linked_files)
end
it 'returns the full paths names of the parent dirs' do
expect(subject).to eq [Pathname.new('/var/shared/config'), Pathname.new('/var/shared/log')]
end
end
describe '#linked_dir_parents' do
subject { paths.linked_dir_parents(parent) }
before do
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
end
it 'returns the full paths names of the parent dirs' do
expect(subject).to eq [Pathname.new('/var/shared'), Pathname.new('/var/shared/public')]
end
end
describe '#release path' do
subject { dsl.release_path }
context 'where no release path has been set' do
before do
dsl.delete(:release_path)
end
it 'returns the `current_path` value' do
expect(subject.to_s).to eq '/var/www/current'
end
end
describe '#linked_files' do
subject { paths.linked_files(parent) }
before do
paths.expects(:fetch).with(:linked_files).returns(linked_files)
end
it 'returns the full pathnames' do
expect(subject).to eq [Pathname.new('/var/shared/config/database.yml'), Pathname.new('/var/shared/log/my.log')]
end
context 'where the release path has been set' do
before do
dsl.set(:release_path,'/var/www/release_path')
end
describe '#linked_file_dirs' do
subject { paths.linked_file_dirs(parent) }
it 'returns the set `release_path` value' do
expect(subject.to_s).to eq '/var/www/release_path'
end
end
end
before do
paths.expects(:fetch).with(:linked_files).returns(linked_files)
end
describe '#set_release_path' do
let(:now) { Time.parse("Oct 21 16:29:00 2015") }
subject { dsl.release_path }
it 'returns the full paths names of the parent dirs' do
expect(subject).to eq [Pathname.new('/var/shared/config'), Pathname.new('/var/shared/log')]
end
context 'without a timestamp' do
before do
dsl.env.expects(:timestamp).returns(now)
dsl.set_release_path
end
describe '#linked_dir_parents' do
subject { paths.linked_dir_parents(parent) }
it 'returns the release path with the current env timestamp' do
expect(subject.to_s).to eq '/var/www/releases/20151021162900'
end
end
before do
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
end
it 'returns the full paths names of the parent dirs' do
expect(subject).to eq [Pathname.new('/var/shared'), Pathname.new('/var/shared/public')]
end
context 'with a timestamp' do
before do
dsl.set_release_path('timestamp')
end
it 'returns the release path with the timestamp' do
expect(subject.to_s).to eq '/var/www/releases/timestamp'
end
end
end
describe '#deploy_config_path' do
subject { dsl.deploy_config_path.to_s }
context 'when not specified' do
before do
dsl.delete(:deploy_config_path)
end
it 'returns "config/deploy.rb"' do
expect(subject).to eq 'config/deploy.rb'
end
end
context 'when the variable :deploy_config_path is set' do
before do
dsl.set(:deploy_config_path, 'my/custom/path.rb')
end
it 'returns the custom path' do
expect(subject).to eq 'my/custom/path.rb'
end
end
end
describe '#stage_config_path' do
subject { dsl.stage_config_path.to_s }
context 'when not specified' do
before do
dsl.delete(:stage_config_path)
end
it 'returns "config/deploy"' do
expect(subject).to eq 'config/deploy'
end
end
context 'when the variable :stage_config_path is set' do
before do
dsl.set(:stage_config_path, 'my/custom/path')
end
it 'returns the custom path' do
expect(subject).to eq 'my/custom/path'
end
end
end
describe '#repo_path' do
subject { dsl.repo_path.to_s }
context 'when not specified' do
before do
dsl.delete(:repo_path)
end
it 'returns the default #{deploy_to}/repo' do
dsl.set(:deploy_to, '/var/www')
expect(subject).to eq '/var/www/repo'
end
end
context 'when the variable :repo_path is set' do
before do
dsl.set(:repo_path, 'my/custom/path')
end
it 'returns the custom path' do
expect(subject).to eq 'my/custom/path'
end
end
end
end

View file

@ -1,13 +1,13 @@
Vagrant::Config.run do |config|
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
[:app].each_with_index do |role, i|
config.vm.define(role, primary: true) do |config|
config.vm.box = role
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
config.vm.forward_port 22, "222#{i}".to_i
config.vm.define role
config.vm.box = 'hashicorp/precise64'
config.vm.network "forwarded_port", guest: 22, host: "222#{i}".to_i
config.vm.provision :shell, inline: 'sudo apt-get -y install git-core'
end
end
end