diff --git a/actionwebservice/CHANGELOG b/actionwebservice/CHANGELOG index d630b13e44..3ebb50958d 100644 --- a/actionwebservice/CHANGELOG +++ b/actionwebservice/CHANGELOG @@ -1,5 +1,11 @@ *SVN* +* Make ActiveWebService::Struct type reloadable + +* Fix scaffolding action when one of the members of a structural type has date or time type + +* Remove extra index hash when generating scaffold html for parameters of structural type #4374 [joe@mjg2.com] + * Fix Scaffold Fails with Struct as a Parameter #4363 [joe@mjg2.com] * Fix soap type registration of multidimensional arrays (#4232) diff --git a/actionwebservice/lib/action_web_service/casting.rb b/actionwebservice/lib/action_web_service/casting.rb index 8ccc7797ac..4fb5a8db25 100644 --- a/actionwebservice/lib/action_web_service/casting.rb +++ b/actionwebservice/lib/action_web_service/casting.rb @@ -96,10 +96,13 @@ def cast_base_type(value, signature_type) # :nodoc: when :float Float(value) when :time + value = "#{value['2']}/#{value['3']}/#{value['1']} #{value['4']}:#{value['5']}:#{value['6']}" if value.kind_of?(Hash) Time.parse(value.to_s) when :date + value = "#{value['2']}/#{value['3']}/#{value['1']}" if value.kind_of?(Hash) Date.parse(value.to_s) when :datetime + value = "#{value['2']}/#{value['3']}/#{value['1']} #{value['4']}:#{value['5']}:#{value['6']}" if value.kind_of?(Hash) DateTime.parse(value.to_s) end end diff --git a/actionwebservice/lib/action_web_service/scaffolding.rb b/actionwebservice/lib/action_web_service/scaffolding.rb index 21689da990..e0e00d831b 100644 --- a/actionwebservice/lib/action_web_service/scaffolding.rb +++ b/actionwebservice/lib/action_web_service/scaffolding.rb @@ -69,21 +69,9 @@ def #{action_name}_submit @protocol.register_api(@scaffold_service.api) post_params = params['method_params'] ? params['method_params'].dup : nil params = [] - if @scaffold_method.expects - @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 + @scaffold_method.expects.each_with_index do |spec, i| + params << post_params[i.to_s] + end if @scaffold_method.expects params = @scaffold_method.cast_expects(params) method_name = public_method_name(@scaffold_service.name, @scaffold_method.public_name) @method_request_xml = @protocol.encode_request(method_name, params, @scaffold_method.expects) @@ -176,11 +164,12 @@ def handle_invocation_exception(obj) end module Helpers # :nodoc: - def method_parameter_input_fields(method, type, field_name_base, idx) + def method_parameter_input_fields(method, type, field_name_base, idx, was_structured=false) if type.array? return content_tag('em', "Typed array input fields not supported yet (#{type.name})") end if type.structured? + return content_tag('em', "Nested structural types not supported yet (#{type.name})") if was_structured parameters = "" type.each_member do |member_name, member_type| label = method_parameter_label(member_name, member_type) @@ -188,7 +177,8 @@ def method_parameter_input_fields(method, type, field_name_base, idx) method, member_type, "#{field_name_base}[#{idx}][#{member_name}]", - idx) + idx, + true) if member_type.custom? parameters << content_tag('li', label) parameters << content_tag('ul', nested_content) @@ -198,31 +188,34 @@ def method_parameter_input_fields(method, type, field_name_base, idx) end content_tag('ul', parameters) else + # If the data source was structured previously we already have the index set + field_name_base = "#{field_name_base}[#{idx}]" unless was_structured + case type.type when :int - text_field_tag "#{field_name_base}[#{idx}]" + text_field_tag "#{field_name_base}" when :string - text_field_tag "#{field_name_base}[#{idx}]" + text_field_tag "#{field_name_base}" when :base64 - text_area_tag "#{field_name_base}[#{idx}]", nil, :size => "40x5" + text_area_tag "#{field_name_base}", nil, :size => "40x5" when :bool - radio_button_tag("#{field_name_base}[#{idx}]", "true") + " True" + - radio_button_tag("#{field_name_base}[#{idx}]", "false") + "False" + radio_button_tag("#{field_name_base}", "true") + " True" + + radio_button_tag("#{field_name_base}", "false") + "False" when :float - text_field_tag "#{field_name_base}[#{idx}]" + text_field_tag "#{field_name_base}" 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) + send("select_#{name}", time, :prefix => "#{field_name_base}[#{i}]", :discard_type => true) end.join when :date 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) + send("select_#{name}", date, :prefix => "#{field_name_base}[#{i}]", :discard_type => true) end.join end end diff --git a/actionwebservice/lib/action_web_service/struct.rb b/actionwebservice/lib/action_web_service/struct.rb index 536207aa95..d065dae03b 100644 --- a/actionwebservice/lib/action_web_service/struct.rb +++ b/actionwebservice/lib/action_web_service/struct.rb @@ -19,6 +19,9 @@ module ActionWebService # Active Record model classes are already implicitly supported in method # signatures. class Struct + # Action WebService Struct subclasses should be reloaded by the dispatcher in Rails + # when Dependencies.mechanism = :load. + include Reloadable::Subclasses # If a Hash is given as argument to an ActionWebService::Struct constructor, # it can contain initial values for the structure member. diff --git a/actionwebservice/test/scaffolded_controller_test.rb b/actionwebservice/test/scaffolded_controller_test.rb index 0aa034c3b4..123a7043eb 100644 --- a/actionwebservice/test/scaffolded_controller_test.rb +++ b/actionwebservice/test/scaffolded_controller_test.rb @@ -8,8 +8,9 @@ ActionController::Base.template_root = '.' class ScaffoldPerson < ActionWebService::Struct - member :id, :int - member :name, :string + member :id, :int + member :name, :string + member :birth, :date def ==(other) self.id == other.id && self.name == other.name @@ -19,6 +20,7 @@ def ==(other) class ScaffoldedControllerTestAPI < ActionWebService::API::Base api_method :hello, :expects => [{:integer=>:int}, :string], :returns => [:bool] api_method :hello_struct_param, :expects => [{:person => ScaffoldPerson}], :returns => [:bool] + api_method :date_of_birth, :expects => [ScaffoldPerson], :returns => [:string] 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] @@ -36,6 +38,10 @@ def hello(int, string) def hello_struct_param(person) 0 end + + def date_of_birth(person) + person.birth.to_s + end def bye [ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")] @@ -78,6 +84,7 @@ def test_scaffold_invoke_method_params def test_scaffold_invoke_method_params_with_struct get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'HelloStructParam' assert_rendered_file 'parameters.rhtml' + assert_tag :tag => 'input', :attributes => {:name => "method_params[0][name]"} end def test_scaffold_invoke_submit_hello @@ -106,6 +113,12 @@ def test_scaffold_date_params :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_struct_date_params + post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'DateOfBirth', + :method_params => {'0' => {'birth' => {'1' => '2006', '2' => '2', '3' => '1'}, 'id' => '1', 'name' => 'person'}} + assert_equal '2006-02-01', @controller.instance_eval{ @method_return_value } + end def test_scaffold_time_params get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'TimeDiff'