Changeset 5110
- Timestamp:
- 09/14/06 17:50:46 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/assertions/selector_assertions.rb (modified) (6 diffs)
- trunk/actionpack/test/controller/assert_select_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r5095 r5110 1 1 *SVN* 2 3 * Add chained replace/update support for assert_select_rjs [Rick Olson] 4 5 Given RJS like... 6 7 page['test1'].replace "<div id=\"1\">foo</div>" 8 page['test2'].replace_html "<div id=\"2\">foo</div>" 9 10 Test it with... 11 12 assert_select_rjs :chained_replace 13 assert_select_rjs :chained_replace, "test1" 14 15 assert_select_rjs :chained_replace_html 16 assert_select_rjs :chained_replace_html, "test2" 2 17 3 18 * Load helpers in alphabetical order for consistency. Resolve cyclic javascript_helper dependency. #6132, #6178 [choonkeat@gmail.com] trunk/actionpack/lib/action_controller/assertions/selector_assertions.rb
r4935 r5110 344 344 # === Examples 345 345 # 346 # # Updating the element foo. 347 # assert_select_rjs :update, "foo" 346 # # Replacing the element foo. 347 # # page.replace 'foo', ... 348 # assert_select_rjs :replace, "foo" 349 # 350 # # Replacing with the chained RJS proxy. 351 # # page[:foo].replace ... 352 # assert_select_rjs :chained_replace, 'foo' 348 353 # 349 354 # # Inserting into the element bar, top position. 350 # assert_select rjs,:insert, :top, "bar"355 # assert_select_rjs :insert, :top, "bar" 351 356 # 352 357 # # Changing the element foo, with an image. … … 363 368 # assert_select "ol>li", 4 364 369 def assert_select_rjs(*args, &block) 365 arg = args.shift 370 rjs_type = nil 371 arg = args.shift 366 372 367 373 # If the first argument is a symbol, it's the type of RJS statement we're looking … … 369 375 # any RJS statement. 370 376 if arg.is_a?(Symbol) 371 if arg == :insert 377 rjs_type = arg 378 if rjs_type == :insert 372 379 arg = args.shift 373 380 insertion = "insert_#{arg}".to_sym … … 375 382 statement = "(#{RJS_STATEMENTS[insertion]})" 376 383 else 377 raise ArgumentError, "Unknown RJS statement type #{ arg}" unless RJS_STATEMENTS[arg]378 statement = "(#{RJS_STATEMENTS[ arg]})"384 raise ArgumentError, "Unknown RJS statement type #{rjs_type}" unless RJS_STATEMENTS[rjs_type] 385 statement = "(#{RJS_STATEMENTS[rjs_type]})" 379 386 end 380 387 arg = args.shift … … 392 399 end 393 400 394 pattern = Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 401 pattern = 402 case rjs_type 403 when :chained_replace, :chained_replace_html 404 Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 405 else 406 Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 407 end 395 408 396 409 # Duplicate the body since the next step involves destroying it. … … 508 521 unless const_defined?(:RJS_STATEMENTS) 509 522 RJS_STATEMENTS = { 510 :replace => /Element\.replace/, 511 :replace_html => /Element\.update/ 523 :replace => /Element\.replace/, 524 :replace_html => /Element\.update/, 525 :chained_replace => /\.replace/, 526 :chained_replace_html => /\.update/, 512 527 } 513 528 RJS_INSERTIONS = [:top, :bottom, :before, :after] trunk/actionpack/test/controller/assert_select_test.rb
r4949 r5110 341 341 end 342 342 343 def test_assert_select_rjs_for_chained_replace 344 render_rjs do |page| 345 page['test1'].replace "<div id=\"1\">foo</div>" 346 page['test2'].replace_html "<div id=\"2\">foo</div>" 347 page.insert_html :top, "test3", "<div id=\"3\">foo</div>" 348 end 349 # Replace. 350 assert_select_rjs :chained_replace do 351 assert_select "div", 1 352 assert_select "#1" 353 end 354 assert_select_rjs :chained_replace, "test1" do 355 assert_select "div", 1 356 assert_select "#1" 357 end 358 assert_raises(AssertionFailedError) { assert_select_rjs :chained_replace, "test2" } 359 # Replace HTML. 360 assert_select_rjs :chained_replace_html do 361 assert_select "div", 1 362 assert_select "#2" 363 end 364 assert_select_rjs :chained_replace_html, "test2" do 365 assert_select "div", 1 366 assert_select "#2" 367 end 368 assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" } 369 end 343 370 344 371 def test_assert_select_rjs_for_insert