Sha256: dcb4dc8b2f7898ede09040b3d1d522a2e9f25e65e87262ed02230305814e3730

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require File.join(File.dirname(__FILE__), "..", "..", "test_helper.rb")
include Relevance::Tarantula

describe "Relevance::Tarantula::Link" do
  include ActionView::Helpers::UrlHelper
  
  it "parses anchor tags" do
    link = Relevance::Tarantula::Link.new(Hpricot('<a href="/foo">foo</a>').at('a'))
    assert_equal "/foo", link.href
    assert_equal :get, link.method
  end

  it "parses anchor tags with POST 'method'" do
    link = Relevance::Tarantula::Link.new(Hpricot(%Q{<a href="/foo" onclick="#{method_javascript_function(:post)}">foo</a>}).at('a'))
    assert_equal "/foo", link.href
    assert_equal :post, link.method
  end

  it "parses anchor tags with PUT 'method'" do
    link = Relevance::Tarantula::Link.new(Hpricot(%Q{<a href="/foo" onclick="#{method_javascript_function(:put)}">foo</a>}).at('a'))
    assert_equal "/foo", link.href
    assert_equal :put, link.method
  end

  it "parses anchor tags with DELETE 'method'" do
    link = Relevance::Tarantula::Link.new(Hpricot(%Q{<a href="/foo" onclick="#{method_javascript_function(:delete)}">foo</a>}).at('a'))
    assert_equal "/foo", link.href
    assert_equal :delete, link.method
  end

  it "parses link tags with text" do
    link = Relevance::Tarantula::Link.new(Hpricot('<link href="/bar">bar</a>').at('link'))
    assert_equal "/bar", link.href
    assert_equal :get, link.method
  end
  
  it "parses link tags without text" do
    link = Relevance::Tarantula::Link.new(Hpricot('<link href="/bar" />').at('link'))
    assert_equal "/bar", link.href
    assert_equal :get, link.method
  end
  
  # method_javascript_function needs this method
  def protect_against_forgery?
    false
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relevance-tarantula-0.0.1 test/relevance/tarantula/link_test.rb
relevance-tarantula-0.0.2 test/relevance/tarantula/link_test.rb
relevance-tarantula-0.0.3 test/relevance/tarantula/link_test.rb