vendor/rails/actionpack/lib/action_controller/assertions/selector_assertions.rb in radiant-0.7.2 vs vendor/rails/actionpack/lib/action_controller/assertions/selector_assertions.rb in radiant-0.8.0

- old
+ new

@@ -1,13 +1,10 @@ #-- # Copyright (c) 2006 Assaf Arkin (http://labnotes.org) # Under MIT and/or CC By license. #++ -require 'rexml/document' -require 'html/document' - module ActionController module Assertions unless const_defined?(:NO_STRIP) NO_STRIP = %w{pre script style textarea} end @@ -19,14 +16,12 @@ # # Use +css_select+ to select elements without making an assertions, either # from the response HTML or elements selected by the enclosing assertion. # # In addition to HTML responses, you can make the following assertions: - # * +assert_select_rjs+ - Assertions on HTML content of RJS update and - # insertion operations. - # * +assert_select_encoded+ - Assertions on HTML encoded inside XML, - # for example for dealing with feed item descriptions. + # * +assert_select_rjs+ - Assertions on HTML content of RJS update and insertion operations. + # * +assert_select_encoded+ - Assertions on HTML encoded inside XML, for example for dealing with feed item descriptions. # * +assert_select_email+ - Assertions on the HTML body of an e-mail. # # Also see HTML::Selector to learn how to use selectors. module SelectorAssertions # :call-seq: @@ -112,24 +107,31 @@ # # If the first argument is an element, selects all matching elements # starting from (and including) that element and all its children in # depth-first order. # - # If no element if specified, calling +assert_select+ will select from the - # response HTML. Calling #assert_select inside an +assert_select+ block will - # run the assertion for each element selected by the enclosing assertion. + # If no element if specified, calling +assert_select+ selects from the + # response HTML unless +assert_select+ is called from within an +assert_select+ block. # + # When called with a block +assert_select+ passes an array of selected elements + # to the block. Calling +assert_select+ from the block, with no element specified, + # runs the assertion on the complete set of elements selected by the enclosing assertion. + # Alternatively the array may be iterated through so that +assert_select+ can be called + # separately for each element. + # + # # ==== Example - # assert_select "ol>li" do |elements| + # If the response contains two ordered lists, each with four list elements then: + # assert_select "ol" do |elements| # elements.each do |element| - # assert_select element, "li" + # assert_select element, "li", 4 # end # end # - # Or for short: - # assert_select "ol>li" do - # assert_select "li" + # will pass, as will: + # assert_select "ol" do + # assert_select "li", 8 # end # # The selector may be a CSS selector expression (String), an expression # with substitution values, or an HTML::Selector object. # @@ -405,10 +407,11 @@ # for (update, replace, insertion, etc). Otherwise, we're looking for just about # any RJS statement. if rjs_type if rjs_type == :insert position = args.shift + id = args.shift insertion = "insert_#{position}".to_sym raise ArgumentError, "Unknown RJS insertion type #{position}" unless RJS_STATEMENTS[insertion] statement = "(#{RJS_STATEMENTS[insertion]})" else raise ArgumentError, "Unknown RJS statement type #{rjs_type}" unless RJS_STATEMENTS[rjs_type] @@ -449,11 +452,17 @@ end end matches else # RJS statement not found. - flunk args.shift || "No RJS statement that replaces or inserts HTML content." + case rjs_type + when :remove, :show, :hide, :toggle + flunk_message = "No RJS statement that #{rjs_type.to_s}s '#{id}' was rendered." + else + flunk_message = "No RJS statement that replaces or inserts HTML content." + end + flunk args.shift || flunk_message end end # :call-seq: # assert_select_encoded(element?) { |elements| ... } @@ -584,10 +593,10 @@ # +assert_select+ and +css_select+ call this to obtain the content in the HTML # page, or from all the RJS statements, depending on the type of response. def response_from_page_or_rjs() content_type = @response.content_type - if content_type && content_type =~ /text\/javascript/ + if content_type && Mime::JS =~ content_type body = @response.body.dup root = HTML::Node.new(nil) while true next if body.sub!(RJS_STATEMENTS[:any]) do |match|