Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8794: link_to_with_blank_options_uses_first_arg_for_url_3.1.diff

File link_to_with_blank_options_uses_first_arg_for_url_3.1.diff, 2.0 kB (added by gbuesing, 2 years ago)

added a test, & test method has more descriptive name

  • test/template/url_helper_test.rb

    old new  
    1414        url 
    1515      end 
    1616    end 
     17     
     18    def polymorphic_path(options) 
     19      @controller.url 
     20    end 
     21     
    1722    @controller = @controller.new 
    1823    @controller.url = "http://www.example.com" 
    1924  end 
     
    98103  def test_link_with_nil_html_options 
    99104    assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil) 
    100105  end 
     106   
     107  def test_link_tag_first_arg_used_for_url_when_options_blank 
     108    @workshop, @session = Workshop.new('foo workshop', true), Session.new('foo session', true) 
     109    assert_dom_equal "<a href=\"http://www.example.com\">foo session</a>", link_to(@session) 
     110    assert_dom_equal "<a href=\"http://www.example.com\">foo session</a>", link_to([@workshop, @session]) 
     111    assert_dom_equal "<a href=\"http://www.example.com/foo\">http://www.example.com/foo</a>", link_to("http://www.example.com/foo") 
     112  end 
    101113 
    102114  def test_link_tag_with_custom_onclick 
    103115    assert_dom_equal "<a href=\"http://www.example.com\" onclick=\"alert('yay!')\">Hello</a>", link_to("Hello", "http://www.example.com", :onclick => "alert('yay!')") 
  • lib/action_view/helpers/url_helper.rb

    old new  
    133133      #        var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');  
    134134      #        m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete Image</a> 
    135135      def link_to(name, options = {}, html_options = nil) 
     136        options = name if options.blank? 
     137        name = name.last if name.is_a?(Array) 
    136138        url = options.is_a?(String) ? options : self.url_for(options) 
    137139 
    138140        if html_options