1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionwebservice/test/test_invoke_test.rb
Leon Breedt aaea48fe98 * collapse 'ws' back into protocols, it just added complexity and indirection, and was hard to extend.
* extract casting into seperate support file
* ensure casting always does the right thing for return values, should fix interoperability issues with Ecto and possibly other XML-RPC clients
* add functional unit tests for scaffolding
* represent signature items with classes instead of symbols/Class objects, much more flexible
* tweak logging to always show casted versions of parameters and return values, if possible.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1072 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-04-02 21:03:36 +00:00

77 lines
2 KiB
Ruby

require File.dirname(__FILE__) + '/abstract_unit'
require 'action_web_service/test_invoke'
class TestInvokeAPI < ActionWebService::API::Base
api_method :add, :expects => [:int, :int], :returns => [:int]
end
class TestInvokeService < ActionWebService::Base
web_service_api TestInvokeAPI
attr :invoked
def add(a, b)
@invoked = true
a + b
end
end
class TestController < ActionController::Base
def rescue_action(e); raise e; end
end
class TestInvokeDirectController < TestController
web_service_api TestInvokeAPI
attr :invoked
def add
@invoked = true
@method_params[0] + @method_params[1]
end
end
class TestInvokeDelegatedController < TestController
web_service_dispatching_mode :delegated
web_service :service, TestInvokeService.new
end
class TestInvokeLayeredController < TestController
web_service_dispatching_mode :layered
web_service :one, TestInvokeService.new
web_service :two, TestInvokeService.new
end
class TestInvokeTest < Test::Unit::TestCase
def setup
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_direct_add
@controller = TestInvokeDirectController.new
assert_equal nil, @controller.invoked
result = invoke :add, 25, 25
assert_equal 50, result
assert_equal true, @controller.invoked
end
def test_delegated_add
@controller = TestInvokeDelegatedController.new
assert_equal nil, @controller.web_service_object(:service).invoked
result = invoke_delegated :service, :add, 100, 50
assert_equal 150, result
assert_equal true, @controller.web_service_object(:service).invoked
end
def test_layered_add
@protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.new
@controller = TestInvokeLayeredController.new
[:one, :two].each do |service|
assert_equal nil, @controller.web_service_object(service).invoked
result = invoke_layered service, :add, 200, -50
assert_equal 150, result
assert_equal true, @controller.web_service_object(service).invoked
end
end
end