Thursday, September 20, 2007

Arts patch for assert_rjs :replace_html bug

You can use the slick Rails Arts plugin to test your rjs renders. But the plugin breaks while testing assert_rjs :replace_html

If you have the following construct in your action method:
render :update do |page|
page['elemid'].replace_html some_string
end
The Rails Javascript helper replaces the replace_html call with the following call:
$('elemid').update(some_string)
This breaks the arts plugin which only expects
Element.update('elemid', some_string)

So here is a simple patch to make your assert_rjs :replace_html to work.
53,54c53,55
<> #assert_match Regexp.new("Element.update(.*#{div}.*,.*#{content.source}.*);"),
> assert_match /(\$\(['"]#{div}['"]\).update\(|Element.update\(.*#{div}.*,)['"].*#{content.source}.*['"]\);/, #'
> @response.body
56c57,59
<> #assert_response_contains("Element.update(\"#{div}\", #{content});",
>
> assert_response_contains(["Element.update(\"#{div}\", #{content});", %Q!$("#{div}").update(#{content});!],
63c66,67
<> #assert_match Regexp.new("Element.update(.*#{div}.*,.*?);"), @response.body
> assert_match /(\$\(['"]#{div}['"]\).update\(['"]|Element.update\(.*#{div}.*,['"]).*?\);/, @response.body
98c102,107
<> if str.class == Array
> strA = str
> else
> strA = [str]
> end
> assert strA.detect {|s| @response.body.to_s.index(s) != nil }, message
133c142
<> end

No comments: