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

fix remote_task inside a namespace

Previously defining `remote_task` inside a namespace resulted in
scoping the file name to the namespace. For example file named
config/database.yaml inside shared namespace would result in:
shared:config/database.yml

That is surely unwanted behaviour. Fix is simple. Introducing
Capistrano::UploadTask that inherits from Rake::FileCreationTask.
These Rake File tasks are not carrying the namespace in their name.
This commit is contained in:
Michal Cichra 2014-10-02 12:20:57 +02:00
parent 6973e5ee3f
commit e52af0ac20
5 changed files with 47 additions and 1 deletions

View file

@ -47,6 +47,7 @@ Breaking Changes:
* Bug Fixes: * Bug Fixes:
* Fixed compatibility with FreeBSD tar (@robbertkl) * Fixed compatibility with FreeBSD tar (@robbertkl)
* remote_file can be used inside a namespace (@mikz)
* Minor Changes * Minor Changes
* Remove -v flag from mkdir call. (@caligo-mentis) * Remove -v flag from mkdir call. (@caligo-mentis)

View file

@ -1,3 +1,5 @@
require 'capistrano/upload_task'
module Capistrano module Capistrano
module TaskEnhancements module TaskEnhancements
def before(task, prerequisite, *args, &block) def before(task, prerequisite, *args, &block)
@ -19,7 +21,7 @@ module Capistrano
end end
def define_remote_file_task(task, target_roles) def define_remote_file_task(task, target_roles)
Rake::Task.define_task(task) do |t| Capistrano::UploadTask.define_task(task) do |t|
prerequisite_file = t.prerequisites.first prerequisite_file = t.prerequisites.first
file = shared_path.join(t.name) file = shared_path.join(t.name)

View file

@ -0,0 +1,9 @@
require 'rake/file_creation_task'
module Capistrano
class UploadTask < Rake::FileCreationTask
def needed?
true # always needed because we can't check remote hosts
end
end
end

View file

@ -69,5 +69,20 @@ module Capistrano
end end
end end
describe 'remote_file' do
subject(:remote_file) { task_enhancements.remote_file('source' => 'destination') }
it { expect(remote_file.name).to eq('source') }
it { is_expected.to be_a(Capistrano::UploadTask) }
describe 'namespaced' do
let(:app) { Rake.application }
around { |ex| app.in_namespace('namespace', &ex) }
it { expect(remote_file.name).to eq('source') }
it { is_expected.to be_a(Capistrano::UploadTask) }
end
end
end end
end end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe Capistrano::UploadTask do
let(:app) { Rake.application = Rake::Application.new }
subject(:upload_task) { described_class.define_task('path/file.yml') }
it { is_expected.to be_a(Rake::FileCreationTask) }
it { is_expected.to be_needed }
context 'inside namespace' do
let(:normal_task) { Rake::Task.define_task('path/other_file.yml') }
around { |ex| app.in_namespace('namespace', &ex) }
it { expect(upload_task.name).to eq('path/file.yml') }
it { expect(upload_task.scope.path).to eq('namespace') }
end
end