Sha256: 56604473c16ff9edbd3815363f2017f3a10dbe91bca49f1cd76e45443d36c2cf

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'
require 'nokogiri'

describe OpenConferenceWare::DisplayLinkToHelper do
  def elem_for(*args)
    return Nokogiri::HTML::DocumentFragment.parse(helper.display_link_to(*args)).children.first
  end

  describe "when creating link" do
    it "should create link" do
      url = "http://foo.bar/"
      elem = elem_for(url)

      elem['href'].should == url
      elem.inner_html.should == url
    end

    it "should escape characters" do
      url = "<evil>&</evil>"
      elem = elem_for(url)

      elem.to_html.should =~ %r{<a href=\"&lt;evil&gt;&amp;&lt;/evil&gt;\"}
      elem.inner_html.should_not == url
      elem.inner_html.should == "&lt;evil&gt;&amp;&lt;/evil&gt;"
    end

    it "should truncate long URL" do
      url = "http://foo.bar/abcdefghijklmnopqrstuvwxyz"
      maxlength = 16
      elem = elem_for(url, maxlength: maxlength)

      elem['href'].should == url
      elem.inner_html.should_not == url
      elem.inner_html.should == "http://foo.ba..."
      elem.inner_html.size.should == maxlength
    end

    it "should add norelfollow" do
      url = "http://foo.bar/"
      elem = elem_for(url)

      elem['rel'].should == "nofollow"
    end

    it "should not add norelfollow optionally" do
      url = "http://foo.bar/"
      elem = elem_for(url, nofollow: false)

      elem['rel'].should be_blank
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
open_conference_ware-1.0.0.pre4 spec/helpers/open_conference_ware/display_link_to_helper_spec.rb
open_conference_ware-1.0.0.pre3 spec/helpers/open_conference_ware/display_link_to_helper_spec.rb
open_conference_ware-1.0.0.pre2 spec/helpers/open_conference_ware/display_link_to_helper_spec.rb
open_conference_ware-1.0.0.pre1 spec/helpers/open_conference_ware/display_link_to_helper_spec.rb