PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/plugins/spider_test/test/spider_test_test.rb

https://github.com/grantneufeld/wayground-old
Ruby | 52 lines | 37 code | 14 blank | 1 comment | 0 complexity | 6515cb74412a5e8491bf8750d69b5a2f MD5 | raw file
  1. $:.unshift File.dirname(__FILE__) + '/../lib/'
  2. require 'rubygems'
  3. require 'active_support'
  4. require 'test/unit'
  5. require 'caboose/spider_integrator'
  6. # These are the tests for some of the spider integrator internal methods.
  7. class TestSpiderIntegrator < Test::Unit::TestCase
  8. include Caboose::SpiderIntegrator
  9. FakeLink = Struct.new( :attributes )
  10. def setup
  11. @links_to_visit = []
  12. end
  13. def test_queue_link_ignores_emails
  14. results = queue_link(FakeLink.new({ 'href' => 'mailto:joe@test.com' }), nil)
  15. assert @links_to_visit.empty?
  16. end
  17. def test_queue_link_follows_regular_links
  18. results = queue_link(FakeLink.new({ 'href' => '/users/foo/bar' }), nil)
  19. assert_equal 1, @links_to_visit.size
  20. end
  21. def test_queue_link_doesnt_follow_external_links
  22. results = queue_link(FakeLink.new({ 'href' => 'http://google.com/' }), nil)
  23. assert @links_to_visit.empty?
  24. end
  25. def test_queue_link_doesnt_follow_hex_encoded_emails
  26. results = queue_link(FakeLink.new({ 'href' => '&#109;&#97;&#105;&#108;&#116;&#111;&#58;' }), nil)
  27. assert @links_to_visit.empty?
  28. end
  29. def test_spider_should_ignore
  30. setup_spider( :ignore_urls => ['/logout', %r{/.*/delete/.*}],
  31. :ignore_forms => ['/login', %r{.*/destroy/.*}],
  32. :verbose => true )
  33. assert spider_should_ignore_url?('/logout')
  34. assert spider_should_ignore_url?('/posts/delete/1')
  35. assert spider_should_ignore_form?('/login')
  36. assert spider_should_ignore_form?('/posts/destroy/1')
  37. end
  38. end