require 'spec_helper'

describe LinkHelper do

  describe '#tel_to' do
    def link(input)
      link = helper.tel_to(input)
      Nokogiri::HTML(link) % 'a'
    end

    it 'creates a link to the given phone number' do
      link('123456')['href'].should == 'tel:123456'
    end

    it 'keeps the input string as link text' do
      link('23 42').text.should == '23 42'
    end

    it 'replaces whitespace and similar with dashes' do
      link('(0821) 12345')['href'].should == 'tel:0821-12345'
    end

    it 'allows international numbers' do
      link('+1 555 12345')['href'].should == 'tel:+1-555-12345'
    end

    it 'strips an "optional zero"' do
      link('+49 (0)821 12345')['href'].should == 'tel:+49-821-12345'
    end
  end

end
