Browse files

Make sure role() can declare roles without servers

  • Loading branch information...
1 parent 42ff8b9 commit 2ce539d87c928f41d82f7bfda84e228d3948d82b @jamis jamis committed Feb 13, 2009
Showing with 14 additions and 0 deletions.
  1. +5 −0 CHANGELOG.rdoc
  2. +8 −0 lib/capistrano/configuration/roles.rb
  3. +1 −0 test/configuration/roles_test.rb
View
5 CHANGELOG.rdoc
@@ -1,3 +1,8 @@
+== (unreleased)
+
+* Make sure role(:foo) actually declares an (empty) role for :foo, even without server arguments [Jamis Buck]
+
+
== 2.5.4 / 4 Feb 2009
* When using rsync with the remote_cache strategy include -t switch to preserve file times [Kevin McCarthy]
View
8 lib/capistrano/configuration/roles.rb
@@ -45,6 +45,14 @@ def initialize_with_roles(*args) #:nodoc:
def role(which, *args, &block)
options = args.last.is_a?(Hash) ? args.pop : {}
which = which.to_sym
+
+ # The roles Hash is defined so that unrecognized keys always auto-initialize
+ # to a new Role instance (see the assignment in the initialize_with_roles method,
+ # above). However, we explicitly assign here so that role declarations will
+ # vivify the role object even if there are no server arguments. (Otherwise,
+ # role(:app) won't actually instantiate a Role object for :app.)
+ roles[which] ||= Role.new
+
roles[which].push(block, options) if block_given?
args.each { |host| roles[which] << ServerDefinition.new(host, options) }
end
View
1 test/configuration/roles_test.rb
@@ -24,6 +24,7 @@ def test_initialize_should_initialize_roles_collection
def test_role_should_allow_empty_list
@config.role :app
+ assert @config.roles.keys.include?(:app)
assert @config.roles[:app].empty?
end

0 comments on commit 2ce539d

Please sign in to comment.