diff options
Diffstat (limited to 'actionwebservice')
-rw-r--r-- | actionwebservice/lib/action_web_service/api.rb | 10 | ||||
-rw-r--r-- | actionwebservice/test/api_test.rb | 11 |
2 files changed, 21 insertions, 0 deletions
diff --git a/actionwebservice/lib/action_web_service/api.rb b/actionwebservice/lib/action_web_service/api.rb index 4548856d86..edc2ff17f4 100644 --- a/actionwebservice/lib/action_web_service/api.rb +++ b/actionwebservice/lib/action_web_service/api.rb @@ -182,6 +182,16 @@ module ActionWebService # :nodoc: @caster.cast_returns(return_value) end + # Returns the index of the first expected parameter + # with the given name + def expects_index_of(param_name) + return -1 if @expects.nil? + (0..(@expects.length-1)).each do |i| + return i if @expects[i].name.to_s == param_name.to_s + end + -1 + end + # String representation of this method def to_s fqn = "" diff --git a/actionwebservice/test/api_test.rb b/actionwebservice/test/api_test.rb index f6d73866b7..986df47a14 100644 --- a/actionwebservice/test/api_test.rb +++ b/actionwebservice/test/api_test.rb @@ -74,6 +74,17 @@ class TC_API < Test::Unit::TestCase end end + def test_parameter_names + method = API.api_methods[:named_signature] + assert_equal 0, method.expects_index_of(:appkey) + assert_equal 1, method.expects_index_of(:publish) + assert_equal 1, method.expects_index_of('publish') + assert_equal 0, method.expects_index_of('appkey') + assert_equal -1, method.expects_index_of('blah') + assert_equal -1, method.expects_index_of(:missing) + assert_equal -1, API.api_methods[:void].expects_index_of('test') + end + def test_to_s assert_equal 'void Expects(int param0, bool param1)', APITest::API.api_methods[:expects].to_s end |