From 3d4965765cd47df7f3f9d3db4cbb117936b1c939 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 3 Mar 2006 03:19:37 +0000 Subject: Fix a ton of issues with AWS (yes, Kent saved it from being unbundled in 1.1) #4038 [Kent Sibilev] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3750 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../test/scaffolded_controller_test.rb | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'actionwebservice/test/scaffolded_controller_test.rb') diff --git a/actionwebservice/test/scaffolded_controller_test.rb b/actionwebservice/test/scaffolded_controller_test.rb index fc617a149a..b41d5afe09 100644 --- a/actionwebservice/test/scaffolded_controller_test.rb +++ b/actionwebservice/test/scaffolded_controller_test.rb @@ -2,8 +2,11 @@ require File.dirname(__FILE__) + '/abstract_unit' ActionController::Routing::Routes.draw do |map| map.connect '', :controller => 'scaffolded' + map.connect ':controller/:action/:id' end +ActionController::Base.template_root = '.' + class ScaffoldPerson < ActionWebService::Struct member :id, :int member :name, :string @@ -16,6 +19,9 @@ end class ScaffoldedControllerTestAPI < ActionWebService::API::Base api_method :hello, :expects => [{:integer=>:int}, :string], :returns => [:bool] api_method :bye, :returns => [[ScaffoldPerson]] + api_method :date_diff, :expects => [{:start_date => :date}, {:end_date => :date}], :returns => [:int] + api_method :time_diff, :expects => [{:start_time => :time}, {:end_time => :time}], :returns => [:int] + api_method :base64_upcase, :expects => [:base64], :returns => [:base64] end class ScaffoldedController < ActionController::Base @@ -33,6 +39,18 @@ class ScaffoldedController < ActionController::Base def rescue_action(e) raise e end + + def date_diff(start_date, end_date) + end_date - start_date + end + + def time_diff(start_time, end_time) + end_time - start_time + end + + def base64_upcase(data) + data.upcase + end end class ScaffoldedControllerTest < Test::Unit::TestCase @@ -64,4 +82,41 @@ class ScaffoldedControllerTest < Test::Unit::TestCase persons = [ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")] assert_equal persons, @controller.instance_eval{ @method_return_value } end + + def test_scaffold_date_params + get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'DateDiff' + (0..1).each do |param| + (1..3).each do |date_part| + assert_tag :tag => 'select', :attributes => {:name => "method_params[#{param}][#{date_part}]"}, + :children => {:greater_than => 1, :only => {:tag => 'option'}} + end + end + + post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'DateDiff', + :method_params => {'0' => {'1' => '2006', '2' => '2', '3' => '1'}, '1' => {'1' => '2006', '2' => '2', '3' => '2'}} + assert_equal 1, @controller.instance_eval{ @method_return_value } + end + + def test_scaffold_time_params + get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'TimeDiff' + (0..1).each do |param| + (1..6).each do |date_part| + assert_tag :tag => 'select', :attributes => {:name => "method_params[#{param}][#{date_part}]"}, + :children => {:greater_than => 1, :only => {:tag => 'option'}} + end + end + + post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'TimeDiff', + :method_params => {'0' => {'1' => '2006', '2' => '2', '3' => '1', '4' => '1', '5' => '1', '6' => '1'}, + '1' => {'1' => '2006', '2' => '2', '3' => '2', '4' => '1', '5' => '1', '6' => '1'}} + assert_equal 86400, @controller.instance_eval{ @method_return_value } + end + + def test_scaffold_base64 + get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'Base64Upcase' + assert_tag :tag => 'textarea', :attributes => {:name => 'method_params[0]'} + + post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Base64Upcase', :method_params => {'0' => 'scaffold'} + assert_equal 'SCAFFOLD', @controller.instance_eval{ @method_return_value } + end end -- cgit v1.2.3