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
This commit is contained in:
Rick Olson
2006-03-19 19:38:38 +00:00
parent 9a72cd22cf
commit a6cfb4e0e4
3 changed files with 17 additions and 2 deletions

View File

@@ -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]

View File

@@ -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]

View File

@@ -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