diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-04-14 07:33:09 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-04-14 07:33:09 +0000 |
commit | 4632983c8c7fb7a6b7b61b89a4fbb168adb0a5b3 (patch) | |
tree | e0986bfec2802269d9bf245c09d65f6d6c1df271 /spec/helpers | |
parent | 4ab717ea6a65beca3e069ca8590c22c49085dc8c (diff) | |
parent | cd590bf1f4f795df92b724efede13a8234705271 (diff) | |
download | gitlab-ce-4632983c8c7fb7a6b7b61b89a4fbb168adb0a5b3.tar.gz |
Merge branch 'rs-link-to-performance' into 'master'
Speed up the overridden `link_to` helper
Only bothers to check the provided link's external status if it's a String that doesn't begin with a path or anchor character.
See merge request !1767
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 4c11709ed6e..015a66f7fa0 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -225,25 +225,29 @@ describe ApplicationHelper do end describe 'link_to' do - it 'should not include rel=nofollow for internal links' do - expect(link_to('Home', root_path)).to eq("<a href=\"/\">Home</a>") + expect(link_to('Home', root_path)).to eq('<a href="/">Home</a>') end it 'should include rel=nofollow for external links' do - expect(link_to('Example', 'http://www.example.com')).to eq("<a href=\"http://www.example.com\" rel=\"nofollow\">Example</a>") + expect(link_to('Example', 'http://www.example.com')). + to eq '<a href="http://www.example.com" rel="nofollow">Example</a>' + end + + it 'should include rel=nofollow for external links and honor existing html_options' do + expect(link_to('Example', 'http://www.example.com', class: 'toggle', data: {toggle: 'dropdown'})) + .to eq '<a class="toggle" data-toggle="dropdown" href="http://www.example.com" rel="nofollow">Example</a>' end - it 'should include re=nofollow for external links and honor existing html_options' do - expect( - link_to('Example', 'http://www.example.com', class: 'toggle', data: {toggle: 'dropdown'}) - ).to eq("<a class=\"toggle\" data-toggle=\"dropdown\" href=\"http://www.example.com\" rel=\"nofollow\">Example</a>") + it 'should include rel=nofollow for external links and preserve other rel values' do + expect(link_to('Example', 'http://www.example.com', rel: 'noreferrer')) + .to eq '<a href="http://www.example.com" rel="noreferrer nofollow">Example</a>' end - it 'should include rel=nofollow for external links and preserver other rel values' do - expect( - link_to('Example', 'http://www.example.com', rel: 'noreferrer') - ).to eq("<a href=\"http://www.example.com\" rel=\"noreferrer nofollow\">Example</a>") + it 'should not include rel=nofollow for external links on the same host as GitLab' do + expect(Gitlab.config.gitlab).to receive(:host).and_return('example.foo') + expect(link_to('Example', 'http://example.foo/bar')). + to eq '<a href="http://example.foo/bar">Example</a>' end end |