Permalink
Browse files

add API::Method#expects_to_hash convenience as well

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1092 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7a5bac1 commit 9b42cd8cc1d52e5a8d80b67b17e5887c15e90904 @leonbreedt leonbreedt committed Apr 5, 2005
Showing with 15 additions and 0 deletions.
  1. +9 −0 actionwebservice/lib/action_web_service/api.rb
  2. +6 −0 actionwebservice/test/api_test.rb
@@ -192,6 +192,15 @@ def expects_index_of(param_name)
-1
end
+ # Returns a hash keyed by parameter name for the given
+ # parameter list
+ def expects_to_hash(params)
+ return {} if @expects.nil?
+ h = {}
+ @expects.zip(params){ |type, param| h[type.name] = param }
+ h
+ end
+
# String representation of this method
def to_s
fqn = ""
@@ -85,6 +85,12 @@ def test_parameter_names
assert_equal -1, API.api_methods[:void].expects_index_of('test')
end
+ def test_parameter_hash
+ method = API.api_methods[:named_signature]
+ hash = method.expects_to_hash([5, false])
+ assert_equal({:appkey => 5, :publish => false}, hash)
+ end
+
def test_to_s
assert_equal 'void Expects(int param0, bool param1)', APITest::API.api_methods[:expects].to_s
end

0 comments on commit 9b42cd8

Please sign in to comment.