mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
aaea48fe98
* 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
67 lines
1.9 KiB
Ruby
67 lines
1.9 KiB
Ruby
require File.dirname(__FILE__) + '/abstract_unit'
|
|
|
|
ActionController::Routing::Routes.draw do |map|
|
|
map.connect '', :controller => 'scaffolded'
|
|
end
|
|
|
|
class ScaffoldPerson < ActionWebService::Struct
|
|
member :id, :int
|
|
member :name, :string
|
|
|
|
def ==(other)
|
|
self.id == other.id && self.name == other.name
|
|
end
|
|
end
|
|
|
|
class ScaffoldedControllerTestAPI < ActionWebService::API::Base
|
|
api_method :hello, :expects => [{:integer=>:int}, :string], :returns => [:bool]
|
|
api_method :bye, :returns => [[ScaffoldPerson]]
|
|
end
|
|
|
|
class ScaffoldedController < ActionController::Base
|
|
web_service_api ScaffoldedControllerTestAPI
|
|
web_service_scaffold :scaffold_invoke
|
|
|
|
def hello(int, string)
|
|
0
|
|
end
|
|
|
|
def bye
|
|
[ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")]
|
|
end
|
|
|
|
def rescue_action(e)
|
|
raise e
|
|
end
|
|
end
|
|
|
|
class ScaffoldedControllerTest < Test::Unit::TestCase
|
|
def setup
|
|
@controller = ScaffoldedController.new
|
|
@request = ActionController::TestRequest.new
|
|
@response = ActionController::TestResponse.new
|
|
end
|
|
|
|
def test_scaffold_invoke
|
|
get :scaffold_invoke
|
|
assert_rendered_file 'methods.rhtml'
|
|
end
|
|
|
|
def test_scaffold_invoke_method_params
|
|
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'Hello'
|
|
assert_rendered_file 'parameters.rhtml'
|
|
end
|
|
|
|
def test_scaffold_invoke_submit_hello
|
|
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Hello', :method_params => ['5', 'hello world']
|
|
assert_rendered_file 'result.rhtml'
|
|
assert_equal false, @controller.instance_eval{ @method_return_value }
|
|
end
|
|
|
|
def test_scaffold_invoke_submit_bye
|
|
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Bye'
|
|
assert_rendered_file 'result.rhtml'
|
|
persons = [ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")]
|
|
assert_equal persons, @controller.instance_eval{ @method_return_value }
|
|
end
|
|
end
|