Permalink
Browse files

Merge pull request #294 from t3hk0d3/master

Fixed used server connection credentials (also fixes 1.9 tests)
  • Loading branch information...
2 parents 9768c57 + 1b4d4d2 commit ece11df6f9adb4b9edaface5507ea97be5f560b5 @javan committed Jan 10, 2013
Showing with 23 additions and 9 deletions.
  1. +0 −1 .travis.yml
  2. +1 −1 lib/whenever/capistrano/support.rb
  3. +2 −2 test/test_helper.rb
  4. +20 −5 test/unit/capistrano_support_test.rb
View
1 .travis.yml
@@ -6,4 +6,3 @@ rvm:
- jruby
- jruby-18mode
- jruby-19mode
- - jruby-head
View
2 lib/whenever/capistrano/support.rb
@@ -31,7 +31,7 @@ def whenever_run_commands(args)
roles_arg = roles.empty? ? "" : " --roles #{roles.join(',')}"
command = "cd #{args[:path]} && #{args[:command]} #{args[:flags]}#{roles_arg}"
- run command, whenever_options.merge(:hosts => server.host)
+ run command, whenever_options.merge(:hosts => server)
end
end
View
4 test/test_helper.rb
@@ -1,7 +1,7 @@
# Want to test the files here, in lib, not in an installed version of the gem.
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'whenever'
-
+require 'test/unit'
require 'shoulda'
require 'mocha'
@@ -15,4 +15,4 @@ def two_hours
class Test::Unit::TestCase
include TestExtensions
-end
+end
View
25 test/unit/capistrano_support_test.rb
@@ -99,9 +99,10 @@ class CapistranoSupportTest < Test::Unit::TestCase
context "with some servers defined" do
setup do
- @mock_server1, @mock_server2 = mock(), mock()
+ @mock_server1, @mock_server2, @mock_server3 = mock("Server1"), mock("Server2"), mock("Server3")
@mock_server1.stubs(:host).returns("server1.foo.com")
@mock_server2.stubs(:host).returns("server2.foo.com")
+ @mock_server3.stubs(:host => "server3.foo.com", :port => 1022, :user => 'test')
@mock_servers = [@mock_server1, @mock_server2]
end
@@ -112,8 +113,8 @@ class CapistranoSupportTest < Test::Unit::TestCase
roles = [:role1, :role2]
@capistrano.stubs(:whenever_options).returns({:roles => roles})
- @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1', {:roles => [:role1, :role2], :hosts => 'server1.foo.com'})
- @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role2', {:roles => [:role1, :role2], :hosts => 'server2.foo.com'})
+ @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1', {:roles => roles, :hosts => @mock_server1})
+ @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role2', {:roles => roles, :hosts => @mock_server2})
@capistrano.whenever_run_commands(:command => "whenever",
:path => "/foo/bar",
@@ -122,11 +123,25 @@ class CapistranoSupportTest < Test::Unit::TestCase
should "call run w/ all role args for servers w/ >1 role" do
@capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1, :role3])
- @capistrano.stubs(:whenever_servers).returns([@mock_servers.first])
+ @capistrano.stubs(:whenever_servers).returns([@mock_server1])
roles = [:role1, :role2, :role3]
@capistrano.stubs(:whenever_options).returns({:roles => roles})
- @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1,role3', {:roles => [:role1, :role2, :role3], :hosts => 'server1.foo.com'})
+ @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1,role3', {:roles => roles, :hosts => @mock_server1})
+
+ @capistrano.whenever_run_commands(:command => "whenever",
+ :path => "/foo/bar",
+ :flags => "--flag1 --flag2")
+ end
+
+ should "call run w/ proper server options (port, user)" do
+ @capistrano.stubs(:role_names_for_host).with(@mock_server3).returns([:role3])
+ @capistrano.stubs(:whenever_servers).returns([@mock_server3])
+ @capistrano.stubs(:whenever_options).returns({:roles => [:role3]})
+
+ @capistrano.expects(:run).once.with do |command, options|
+ options[:hosts].user == "test" && options[:hosts].port == 1022
+ end
@capistrano.whenever_run_commands(:command => "whenever",
:path => "/foo/bar",

0 comments on commit ece11df

Please sign in to comment.