Last active
April 25, 2016 19:12
-
-
Save marcioj/6f40f3d6fbec0b3c1ed1 to your computer and use it in GitHub Desktop.
Url normalization. Appends http to url which doesn't have it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def expand_url(url) | |
return url if url.blank? || /(http:\/\/|https:\/\/)/ =~ url | |
"http://#{url}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe ApplicationHelper do | |
RSpec.describe '#expand_url' do | |
it { expect(helper.expand_url('google.com')).to eq('http://google.com') } | |
it { expect(helper.expand_url('http://google.com')).to eq('http://google.com') } | |
it { expect(helper.expand_url('https://google.com')).to eq('https://google.com') } | |
it { expect(helper.expand_url('')).to eq('') } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment