From a6cfb4e0e4209e06b4ba561b688ee2c3b942e3dd Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 19 Mar 2006 19:38:38 +0000 Subject: Fix mixed case enumerable methods in the JavaScript Collection Proxy (closes #4314) [codyfauser@gmail.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3984 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/prototype_helper.rb | 4 ++-- actionpack/test/template/prototype_helper_test.rb | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 82a00d166b..75c22e8e98 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix mixed case enumerable methods in the JavaScript Collection Proxy (closes #4314) [codyfauser@gmail.com] + * Undo accidental escaping for mail_to; add regression test. [Nicholas Seckar] * Added nicer message for assert_redirected_to (closes #4294) [court3nay] diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 35a671c081..3d15f2ecfd 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -807,7 +807,7 @@ module ActionView end class JavaScriptCollectionProxy < JavaScriptProxy #:nodoc: - ENUMERABLE_METHODS_WITH_RETURN = [:all, :any, :collect, :map, :detect, :find, :findAll, :select, :max, :min, :partition, :reject, :sortBy] + ENUMERABLE_METHODS_WITH_RETURN = [:all, :any, :collect, :map, :detect, :find, :find_all, :select, :max, :min, :partition, :reject, :sort_by] ENUMERABLE_METHODS = ENUMERABLE_METHODS_WITH_RETURN + [:each] attr_reader :generator delegate :arguments_for_call, :to => :generator @@ -865,7 +865,7 @@ module ActionView method_args = arguments_for_call options[:method_args] # foo, bar, function method_args << ', ' unless method_args.blank? add_variable_assignment!(options[:variable]) if options[:variable] - append_enumerable_function!("#{enumerable}(#{method_args}function(#{yield_args}) {") + append_enumerable_function!("#{enumerable.to_s.first}#{enumerable.to_s.camelize[1..-1]}(#{method_args}function(#{yield_args}) {") # only yield as many params as were passed in the block yield *options[:yield_args].collect { |p| JavaScriptVariableProxy.new(@generator, p) }[0..block.arity-1] add_return_statement! if options[:return] diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index eb8de1ff40..65e8cf9b96 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -391,6 +391,18 @@ return array.reverse(); EOS end + def test_collection_proxy_with_find_all + @generator.select('p').find_all 'a' do |value, index| + @generator << '(value.className == "welcome")' + end + + assert_equal <<-EOS.strip, @generator.to_s +var a = $$("p").findAll(function(value, index) { +return (value.className == "welcome"); +}); + EOS + end + def test_debug_rjs ActionView::Base.debug_rjs = true @generator['welcome'].replace_html 'Welcome' @@ -404,3 +416,4 @@ return array.reverse(); assert_equal "Form.focus(\"my_field\");", @generator.to_s end end + -- cgit v1.2.3