diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-03 03:19:37 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-03 03:19:37 +0000 |
commit | 3d4965765cd47df7f3f9d3db4cbb117936b1c939 (patch) | |
tree | a7dcd1024112bde8716f09c1e75da22cb640d38f /actionwebservice | |
parent | 94725b02bcc5e623dcbe1d73d57b2ede2c88440e (diff) | |
download | rails-3d4965765cd47df7f3f9d3db4cbb117936b1c939.tar.gz rails-3d4965765cd47df7f3f9d3db4cbb117936b1c939.tar.bz2 rails-3d4965765cd47df7f3f9d3db4cbb117936b1c939.zip |
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
Diffstat (limited to 'actionwebservice')
18 files changed, 322 insertions, 44 deletions
diff --git a/actionwebservice/CHANGELOG b/actionwebservice/CHANGELOG index 62d72d4e3d..ebbb975501 100644 --- a/actionwebservice/CHANGELOG +++ b/actionwebservice/CHANGELOG @@ -1,5 +1,19 @@ *SVN* +* Fix that marshaler couldn't handle ActiveRecord models defined in a different namespace (#2392). + +* Fix that marshaler couldn't handle structs with members of ActiveRecord type (#1889). + +* Fix that marshaler couldn't handle nil values for inner structs (#3576). + +* Fix that changes to ActiveWebService::API::Base required restarting of the server (#2390). + +* Fix scaffolding for signatures with :date, :time and :base64 types (#3321, #2769, #2078). + +* Fix for incorrect casting of TrueClass/FalseClass instances (#2633, #3421). + +* Fix for incompatibility problems with SOAP4R 1.5.5 (#2553) [Kent Sibilev] + * Update from LGPL to MIT license as per Minero Aoki's permission. [Marcel Molina Jr.] * Rename Version constant to VERSION. #2802 [Marcel Molina Jr.] diff --git a/actionwebservice/Rakefile b/actionwebservice/Rakefile index e128d1198a..23e1dc2cd5 100644 --- a/actionwebservice/Rakefile +++ b/actionwebservice/Rakefile @@ -30,6 +30,14 @@ Rake::TestTask.new { |t| t.verbose = true } +SCHEMA_PATH = File.join(File.dirname(__FILE__), *%w(test fixtures db_definitions)) + +desc 'Build the MySQL test database' +task :build_database do + %x( mysqladmin create activewebservice_unittest ) + %x( mysql activewebservice_unittest < #{File.join(SCHEMA_PATH, 'mysql.sql')} ) +end + # Generate the RDoc documentation Rake::RDocTask.new { |rdoc| diff --git a/actionwebservice/lib/action_web_service/api.rb b/actionwebservice/lib/action_web_service/api.rb index a0d0af6267..7193bd8a51 100644 --- a/actionwebservice/lib/action_web_service/api.rb +++ b/actionwebservice/lib/action_web_service/api.rb @@ -14,6 +14,10 @@ module ActionWebService # :nodoc: # See ActionWebService::Container::Direct::ClassMethods for an example # of use. class Base + # Action WebService API subclasses should be reloaded by the dispatcher in Rails + # when Dependencies.mechanism = :load. + include Reloadable::Subclasses + # Whether to transform the public API method names into camel-cased names class_inheritable_option :inflect_names, true diff --git a/actionwebservice/lib/action_web_service/base.rb b/actionwebservice/lib/action_web_service/base.rb index 16e4d87f41..5675a5bd2b 100644 --- a/actionwebservice/lib/action_web_service/base.rb +++ b/actionwebservice/lib/action_web_service/base.rb @@ -25,12 +25,16 @@ module ActionWebService # :nodoc: # api_method :delete_person, :expects => [:int] # end # - # class SearchCriteria < ActionStruct::Base + # class SearchCriteria < ActionWebService::Struct # member :firstname, :string # member :lastname, :string # member :email, :string # end class Base + # Action WebService subclasses should be reloaded by the dispatcher in Rails + # when Dependencies.mechanism = :load. + include Reloadable::Subclasses + # Whether to report exceptions back to the caller in the protocol's exception # format class_inheritable_option :web_service_exception_reporting, true diff --git a/actionwebservice/lib/action_web_service/casting.rb b/actionwebservice/lib/action_web_service/casting.rb index 3c0afbe9f9..8ccc7797ac 100644 --- a/actionwebservice/lib/action_web_service/casting.rb +++ b/actionwebservice/lib/action_web_service/casting.rb @@ -41,6 +41,11 @@ module ActionWebService # :nodoc: def cast(value, signature_type) # :nodoc: return value if signature_type.nil? # signature.length != params.length return nil if value.nil? + # XMLRPC protocol doesn't support nil values. It uses false instead. + # It should never happen for SOAP. + if signature_type.structured? && value.equal?(false) + return nil + end unless signature_type.array? || signature_type.structured? return value if canonical_type(value.class) == signature_type.type end @@ -108,6 +113,8 @@ module ActionWebService # :nodoc: value.each_pair do |name, val| type = klass.respond_to?(:member_type) ? klass.member_type(name) : nil val = cast(val, type) if type + # See http://dev.rubyonrails.com/ticket/3567 + val = val.to_time if val.is_a?(XMLRPC::DateTime) obj.__send__("#{name}=", val) if obj.respond_to?(name) end elsif value.respond_to?(:attributes) diff --git a/actionwebservice/lib/action_web_service/client/soap_client.rb b/actionwebservice/lib/action_web_service/client/soap_client.rb index f5ebe1629c..c7f3b9d594 100644 --- a/actionwebservice/lib/action_web_service/client/soap_client.rb +++ b/actionwebservice/lib/action_web_service/client/soap_client.rb @@ -80,12 +80,20 @@ module ActionWebService # :nodoc: if expects expects.each do |type| type_binding = @protocol.marshaler.lookup_type(type) - param_def << ['in', type.name, type_binding.mapping] + if SOAP::Version >= "1.5.5" + param_def << ['in', type.name.to_s, [type_binding.type.type_class.to_s]] + else + param_def << ['in', type.name, type_binding.mapping] + end end end if returns type_binding = @protocol.marshaler.lookup_type(returns[0]) - param_def << ['retval', 'return', type_binding.mapping] + if SOAP::Version >= "1.5.5" + param_def << ['retval', 'return', [type_binding.type.type_class.to_s]] + else + param_def << ['retval', 'return', type_binding.mapping] + end end driver.add_method(qname, action, method.name.to_s, param_def) end diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb index b36e029669..fa917ad4a5 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb @@ -32,7 +32,9 @@ module ActionWebService end def ruby_to_soap(obj) - SOAP::Mapping.obj2soap(obj, @registry) + soap = SOAP::Mapping.obj2soap(obj, @registry) + soap.elename = XSD::QName.new if SOAP::Version >= "1.5.5" && soap.elename == XSD::QName::EMPTY + soap end def register_type(type) @@ -63,12 +65,21 @@ module ActionWebService end @type2binding[type] = array_binding ? array_binding : type_binding + + if type.structured? + type.each_member do |m_name, m_type| + register_type(m_type) + end + end + @type2binding[type] end alias :lookup_type :register_type def annotate_arrays(binding, value) - if binding.type.array? + if value.nil? + return + elsif binding.type.array? mark_typed_array(value, binding.element_binding.qname) if binding.element_binding.type.custom? value.each do |element| diff --git a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb index 53b67ced4c..64992e7754 100644 --- a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb @@ -50,10 +50,10 @@ module ActionWebService # :nodoc: end def encode_response(method_name, return_value, return_type, protocol_options={}) - return_value = true if return_value.nil? - if return_type + if return_value && return_type return_value = value_to_xmlrpc_wire_format(return_value, return_type) end + return_value = false if return_value.nil? raw_response = XMLRPC::Marshal.dump_response(return_value) Response.new(raw_response, 'text/xml', return_value) end diff --git a/actionwebservice/lib/action_web_service/scaffolding.rb b/actionwebservice/lib/action_web_service/scaffolding.rb index 59fec0ef76..3f958df3ab 100644 --- a/actionwebservice/lib/action_web_service/scaffolding.rb +++ b/actionwebservice/lib/action_web_service/scaffolding.rb @@ -65,14 +65,23 @@ module ActionWebService when :xmlrpc @protocol = Protocol::XmlRpc::XmlRpcProtocol.create(self) end - @invocation_cgi = request.respond_to?(:cgi) ? request.cgi : nil bm = Benchmark.measure do @protocol.register_api(@scaffold_service.api) post_params = params['method_params'] ? params['method_params'].dup : nil params = [] if @scaffold_method.expects - @scaffold_method.expects.length.times do |i| - params << post_params[i.to_s] + @scaffold_method.expects.each_with_index do |spec, i| + case spec.type + when :date + date = post_params[i.to_s] + params << (date['2'] + '/' + date['3'] + '/' + date['1']) + when :datetime, :time + date = post_params[i.to_s] + params << (date['2'] + '/' + date['3'] + '/' + date['1'] + ' ' + + date['4'] + ':' + date['5'] + ':' + date['6']) + else + params << post_params[i.to_s] + end end end params = @scaffold_method.cast_expects(params) @@ -130,14 +139,8 @@ module ActionWebService end def reset_invocation_response - template = response.template - if @invocation_cgi - @response = ::ActionController::CgiResponse.new(@invocation_cgi) - else - @response = ::ActionController::TestResponse.new - end - response.template = template - @performed_render = false + erase_render_results + @response.headers = ::ActionController::AbstractResponse::DEFAULT_HEADERS.merge("cookie" => []) end def public_method_name(service_name, method_name) @@ -173,7 +176,7 @@ module ActionWebService end module Helpers # :nodoc: - def method_parameter_input_fields(method, type, field_name_base) + def method_parameter_input_fields(method, type, field_name_base, idx) if type.array? return content_tag('em', "Typed array input fields not supported yet (#{type.name})") end @@ -184,7 +187,7 @@ module ActionWebService nested_content = method_parameter_input_fields( method, member_type, - field_name_base + '[' + member_name.to_s + ']') + "#{field_name_base}[#{idx}][#{member_name}]") if member_type.custom? parameters << content_tag('li', label) parameters << content_tag('ul', nested_content) @@ -196,18 +199,30 @@ module ActionWebService else case type.type when :int - text_field_tag field_name_base + text_field_tag "#{field_name_base}[#{idx}]" when :string - text_field_tag field_name_base + text_field_tag "#{field_name_base}[#{idx}]" + when :base64 + text_area_tag "#{field_name_base}[#{idx}]", nil, :size => "40x5" when :bool - radio_button_tag(field_name_base, "true") + " True" + - radio_button_tag(field_name_base, "false") + "False" + radio_button_tag("#{field_name_base}[#{idx}]", "true") + " True" + + radio_button_tag("#{field_name_base}[#{idx}]", "false") + "False" when :float - text_field_tag field_name_base - when :time - select_datetime Time.now, 'name' => field_name_base + text_field_tag "#{field_name_base}[#{idx}]" + when :time, :datetime + time = Time.now + i = 0 + %w|year month day hour minute second|.map do |name| + i += 1 + send("select_#{name}", time, :prefix => "#{field_name_base}[#{idx}][#{i}]", :discard_type => true) + end.join when :date - select_date Date.today, 'name' => field_name_base + date = Date.today + i = 0 + %w|year month day|.map do |name| + i += 1 + send("select_#{name}", date, :prefix => "#{field_name_base}[#{idx}][#{i}]", :discard_type => true) + end.join end end end diff --git a/actionwebservice/lib/action_web_service/support/signature_types.rb b/actionwebservice/lib/action_web_service/support/signature_types.rb index 2100eab131..36224c645e 100644 --- a/actionwebservice/lib/action_web_service/support/signature_types.rb +++ b/actionwebservice/lib/action_web_service/support/signature_types.rb @@ -53,9 +53,9 @@ module ActionWebService # :nodoc: case name when :int, :integer, :fixnum, :bignum :int - when :string + when :string, :text :string - when :base64 + when :base64, :binary :base64 when :bool, :boolean :bool @@ -203,7 +203,7 @@ module ActionWebService # :nodoc: elsif @type_class.respond_to?(:columns) i = -1 @type_class.columns.each do |column| - yield column.name, canonical_signature_entry(column.klass, i += 1) + yield column.name, canonical_signature_entry(column.type, i += 1) end end end diff --git a/actionwebservice/lib/action_web_service/templates/scaffolds/parameters.rhtml b/actionwebservice/lib/action_web_service/templates/scaffolds/parameters.rhtml index a9d295aeee..ce755f7870 100644 --- a/actionwebservice/lib/action_web_service/templates/scaffolds/parameters.rhtml +++ b/actionwebservice/lib/action_web_service/templates/scaffolds/parameters.rhtml @@ -10,20 +10,19 @@ </p> <% if @scaffold_method.expects %> -<% i = 0 %> <strong>Method Parameters:</strong><br /> -<% @scaffold_method.expects.each do |type| %> +<% @scaffold_method.expects.each_with_index do |type, i| %> <p> <label for="method_params[<%= i %>]"><%= method_parameter_label(type.name, type) %> </label><br /> - <%= method_parameter_input_fields(@scaffold_method, type, "method_params[#{i}]") %> + <%= method_parameter_input_fields(@scaffold_method, type, "method_params", i) %> </p> - <% i += 1 %> <% end %> <% end %> <%= submit_tag "Invoke" %> +<%= end_form_tag %> <p> <%= link_to "Back", :action => @scaffold_action_name %> diff --git a/actionwebservice/test/abstract_client.rb b/actionwebservice/test/abstract_client.rb index 0efa1d7ec1..c5484b6b62 100644 --- a/actionwebservice/test/abstract_client.rb +++ b/actionwebservice/test/abstract_client.rb @@ -12,17 +12,44 @@ module ClientTest firstnames == other.firstnames && lastname == other.lastname end end + + class Inner < ActionWebService::Struct + member :name, :string + end + + class Outer < ActionWebService::Struct + member :name, :string + member :inner, Inner + end + + class User < ActiveRecord::Base + end + + module Accounting + class User < ActiveRecord::Base + end + end + + class WithModel < ActionWebService::Struct + member :user, User + member :users, [User] + end class API < ActionWebService::API::Base api_method :void - api_method :normal, :expects => [:int, :int], :returns => [:int] - api_method :array_return, :returns => [[Person]] - api_method :struct_pass, :expects => [[Person]], :returns => [:bool] - api_method :client_container, :returns => [:int] - api_method :named_parameters, :expects => [{:key=>:string}, {:id=>:int}] + api_method :normal, :expects => [:int, :int], :returns => [:int] + api_method :array_return, :returns => [[Person]] + api_method :struct_pass, :expects => [[Person]], :returns => [:bool] + api_method :nil_struct_return, :returns => [Person] + api_method :inner_nil, :returns => [Outer] + api_method :client_container, :returns => [:int] + api_method :named_parameters, :expects => [{:key=>:string}, {:id=>:int}] api_method :thrower + api_method :user_return, :returns => [User] + api_method :with_model_return, :returns => [WithModel] + api_method :scoped_model_return, :returns => [Accounting::User] end - + class NullLogOut def <<(*args); end end @@ -65,6 +92,14 @@ module ClientTest @value_struct_pass = @method_params true end + + def nil_struct_return + nil + end + + def inner_nil + Outer.new :name => 'outer', :inner => nil + end def client_container 50 @@ -77,6 +112,18 @@ module ClientTest def thrower raise "Hi" end + + def user_return + User.find(1) + end + + def with_model_return + WithModel.new :user => User.find(1), :users => User.find(:all) + end + + def scoped_model_return + Accounting::User.find(1) + end end class AbstractClientLet < WEBrick::HTTPServlet::AbstractServlet diff --git a/actionwebservice/test/abstract_unit.rb b/actionwebservice/test/abstract_unit.rb index a57299bea0..149f108c98 100644 --- a/actionwebservice/test/abstract_unit.rb +++ b/actionwebservice/test/abstract_unit.rb @@ -5,10 +5,27 @@ $:.unshift(File.dirname(__FILE__) + '/../../actionpack/lib') $:.unshift(File.dirname(__FILE__) + '/../../activerecord/lib') require 'test/unit' -require 'active_record' require 'action_web_service' require 'action_controller' require 'action_controller/test_process' ActionController::Base.logger = nil ActionController::Base.ignore_missing_templates = true + +begin + PATH_TO_AR = File.dirname(__FILE__) + '/../../activerecord' + require "#{PATH_TO_AR}/lib/active_record" unless Object.const_defined?(:ActiveRecord) + require "#{PATH_TO_AR}/lib/active_record/fixtures" unless Object.const_defined?(:Fixtures) +rescue Object => e + fail "\nFailed to load activerecord: #{e}" +end + +ActiveRecord::Base.establish_connection( + :adapter => "mysql", + :username => "rails", + :encoding => "utf8", + :database => "activewebservice_unittest" +) +ActiveRecord::Base.connection + +Test::Unit::TestCase.fixture_path = "#{File.dirname(__FILE__)}/fixtures/" diff --git a/actionwebservice/test/client_soap_test.rb b/actionwebservice/test/client_soap_test.rb index e118b4956e..ee02d919a4 100644 --- a/actionwebservice/test/client_soap_test.rb +++ b/actionwebservice/test/client_soap_test.rb @@ -49,6 +49,8 @@ end class TC_ClientSoap < Test::Unit::TestCase include ClientTest include ClientSoapTest + + fixtures :users def setup @server = SoapServer.instance @@ -88,6 +90,16 @@ class TC_ClientSoap < Test::Unit::TestCase assert_equal(true, @client.struct_pass([new_person])) assert_equal([[new_person]], @container.value_struct_pass) end + + def test_nil_struct_return + assert_nil @client.nil_struct_return + end + + def test_inner_nil + outer = @client.inner_nil + assert_equal 'outer', outer.name + assert_nil outer.inner + end def test_client_container assert_equal(50, ClientContainer.new.get_client.client_container) @@ -106,4 +118,28 @@ class TC_ClientSoap < Test::Unit::TestCase assert_equal([5, 6], @container.value_normal) @container.value_normal = nil end + + def test_model_return + user = @client.user_return + assert_equal 1, user.id + assert_equal 'Kent', user.name + assert user.active? + assert_kind_of Date, user.created_on + assert_equal Date.today, user.created_on + end + + def test_with_model + with_model = @client.with_model_return + assert_equal 'Kent', with_model.user.name + assert_equal 2, with_model.users.size + with_model.users.each do |user| + assert_kind_of User, user + end + end + + def test_scoped_model_return + scoped_model = @client.scoped_model_return + assert_kind_of Accounting::User, scoped_model + assert_equal 'Kent', scoped_model.name + end end diff --git a/actionwebservice/test/client_xmlrpc_test.rb b/actionwebservice/test/client_xmlrpc_test.rb index de24d9a975..a77942dc07 100644 --- a/actionwebservice/test/client_xmlrpc_test.rb +++ b/actionwebservice/test/client_xmlrpc_test.rb @@ -12,7 +12,7 @@ module ClientXmlRpcTest test_request.env['HTTP_CONTENT_TYPE'] = 'text/xml' test_request.env['RAW_POST_DATA'] = req.body response = ActionController::TestResponse.new - @controller.process(test_request, response) + @controller.process(test_request, response) res.header['content-type'] = 'text/xml' res.body = response.body # puts res.body @@ -44,6 +44,8 @@ end class TC_ClientXmlRpc < Test::Unit::TestCase include ClientTest include ClientXmlRpcTest + + fixtures :users def setup @server = XmlRpcServer.instance @@ -83,6 +85,16 @@ class TC_ClientXmlRpc < Test::Unit::TestCase assert_equal(true, @client.struct_pass([new_person])) assert_equal([[new_person]], @container.value_struct_pass) end + + def test_nil_struct_return + assert_equal false, @client.nil_struct_return + end + + def test_inner_nil + outer = @client.inner_nil + assert_equal 'outer', outer.name + assert_nil outer.inner + end def test_client_container assert_equal(50, ClientContainer.new.get_client.client_container) @@ -90,7 +102,7 @@ class TC_ClientXmlRpc < Test::Unit::TestCase def test_named_parameters assert(@container.value_named_parameters.nil?) - assert_equal(true, @client.named_parameters("xxx", 7)) + assert_equal(false, @client.named_parameters("xxx", 7)) assert_equal(["xxx", 7], @container.value_named_parameters) end @@ -105,4 +117,28 @@ class TC_ClientXmlRpc < Test::Unit::TestCase @client.normal end end + + def test_model_return + user = @client.user_return + assert_equal 1, user.id + assert_equal 'Kent', user.name + assert user.active? + assert_kind_of Time, user.created_on + assert_equal Time.now.getgm.beginning_of_day, user.created_on + end + + def test_with_model + with_model = @client.with_model_return + assert_equal 'Kent', with_model.user.name + assert_equal 2, with_model.users.size + with_model.users.each do |user| + assert_kind_of User, user + end + end + + def test_scoped_model_return + scoped_model = @client.scoped_model_return + assert_kind_of Accounting::User, scoped_model + assert_equal 'Kent', scoped_model.name + end end diff --git a/actionwebservice/test/fixtures/db_definitions/mysql.sql b/actionwebservice/test/fixtures/db_definitions/mysql.sql new file mode 100644 index 0000000000..026f2a2c64 --- /dev/null +++ b/actionwebservice/test/fixtures/db_definitions/mysql.sql @@ -0,0 +1,7 @@ +CREATE TABLE `users` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(30) default NULL, + `active` tinyint(4) default NULL, + `created_on` date default NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; diff --git a/actionwebservice/test/fixtures/users.yml b/actionwebservice/test/fixtures/users.yml new file mode 100644 index 0000000000..a97d8c8486 --- /dev/null +++ b/actionwebservice/test/fixtures/users.yml @@ -0,0 +1,10 @@ +user1: + id: 1 + name: Kent + active: 1 + created_on: <%= Date.today %> +user2: + id: 2 + name: David + active: 1 + created_on: <%= Date.today %> 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 |