Browse files

deployer class must know about port option as well

  • Loading branch information...
1 parent 4a56686 commit 2e63a63be7f0117454b4bcc98214d58dea7bfd05 @rafaelss committed Apr 9, 2012
Showing with 53 additions and 11 deletions.
  1. +17 −8 lib/yads/deployer.rb
  2. +9 −0 test/fixtures/config/deploy_with_port.yml
  3. +27 −3 test/yads/test_deployer.rb
View
25 lib/yads/deployer.rb
@@ -26,16 +26,25 @@ def deploy
private
- def config
- @config ||= begin
- YAML.load(File.open("config/deploy.yml"))
- rescue Errno::ENOENT
- raise Yads::ConfigNotFound, "config/deploy.yml not found"
- end
+ def config
+ @config ||= begin
+ YAML.load(File.open("config/deploy.yml"))
+ rescue Errno::ENOENT
+ raise Yads::ConfigNotFound, "config/deploy.yml not found"
end
+ end
+
+ def connection
+ @connection ||= begin
+ options = {
+ :host => config["host"],
+ :user => config["user"],
+ :forward_agent => config["forward_agent"]
+ }
+ options[:port] = config["port"] if config["port"]
- def connection
- @connection ||= SSH.new(:host => config["host"], :user => config["user"], :forward_agent => config["forward_agent"])
+ SSH.new(options)
end
+ end
end
end
View
9 test/fixtures/config/deploy_with_port.yml
@@ -0,0 +1,9 @@
+host: rafaelss.com
+port: 2222
+user: deploy
+forward_agent: true
+path: /tmp/yads
+repository: git@repohost.com:myrepo.git
+commands:
+ migrate: rake db:migrate
+ touch: touch test
View
30 test/yads/test_deployer.rb
@@ -35,6 +35,18 @@ def test_setup
end
end
+ def test_setup_using_non_standard_port
+ inside_project_root do
+ ssh = mock
+ ssh.expects(:execute).with("mkdir -p /tmp/yads && cd /tmp/yads && git clone --depth 1 git@repohost.com:myrepo.git .")
+ Yads::SSH.expects(:new).with(:host => "rafaelss.com", :user => "deploy", :forward_agent => true, :port => 2222).returns(ssh)
+
+ deployer = Yads::Deployer.new(@log_file)
+ deployer.stubs(:config => YAML.load(File.open("config/deploy_with_port.yml")).merge("port" => 2222))
+ deployer.setup
+ end
+ end
+
def test_deploy
inside_project_root do
ssh = mock
@@ -46,9 +58,21 @@ def test_deploy
end
end
- private
+ def test_deploy_using_non_standard_port
+ inside_project_root do
+ ssh = mock
+ ssh.expects(:execute).with("cd /tmp/yads && rake db:migrate && touch test")
+ Yads::SSH.expects(:new).with(:host => "rafaelss.com", :user => "deploy", :forward_agent => true, :port => 2222).returns(ssh)
- def inside_project_root(&block)
- Dir.chdir(File.expand_path("../../fixtures", __FILE__), &block)
+ deployer = Yads::Deployer.new(@log_file)
+ deployer.stubs(:config => YAML.load(File.open("config/deploy_with_port.yml")).merge("port" => 2222))
+ deployer.deploy
end
+ end
+
+ private
+
+ def inside_project_root(&block)
+ Dir.chdir(File.expand_path("../../fixtures", __FILE__), &block)
+ end
end

0 comments on commit 2e63a63

Please sign in to comment.