Wednesday, December 3, 2008

custom assert_select_rjs matcher

Background:
I wanted to test rjs redirection:

assert_select_rjs :redirect_to, '/'
view raw gistfile1.rb hosted with ❤ by GitHub

Problem:
ActionController::Assertions::SelectorAssertions#assert_select_rjs don't know about :redirect_to

Solution:
I don't know if this is the right solution but I added this at the end of my test_helper.rb then I can assert by :redirect_to now

module ActionController::Assertions::SelectorAssertions
RJS_STATEMENTS[:redirect_to] = "window\\.location\\.href = #{RJS_ANY_ID}"
end
view raw gistfile1.rb hosted with ❤ by GitHub