Strip trailing slashes from ScreeningUrl records
This commit is contained in:
parent
6183e9bb6c
commit
b15e629f46
|
@ -11,13 +11,16 @@ class ScreenedUrl < ActiveRecord::Base
|
|||
|
||||
default_action :do_nothing
|
||||
|
||||
before_validation :strip_http
|
||||
before_validation :normalize
|
||||
|
||||
validates :url, presence: true, uniqueness: true
|
||||
validates :domain, presence: true
|
||||
|
||||
def strip_http
|
||||
self.url.gsub!(/http(s?):\/\//i, '')
|
||||
def normalize
|
||||
if self.url
|
||||
self.url.gsub!(/http(s?):\/\//i, '')
|
||||
self.url.gsub!(/(\/)+$/, '') # trim trailing slashes
|
||||
end
|
||||
end
|
||||
|
||||
def self.watch(url, domain, opts={})
|
||||
|
|
|
@ -21,6 +21,14 @@ describe ScreenedUrl do
|
|||
described_class.create(valid_params.merge(url: url.gsub('http://', prefix))).url.should == url.gsub('http://', '')
|
||||
end
|
||||
end
|
||||
|
||||
it "strips trailing slash" do
|
||||
described_class.create(valid_params.merge(url: 'silverbullet.in/')).url.should == 'silverbullet.in'
|
||||
end
|
||||
|
||||
it "strips trailing slashes" do
|
||||
described_class.create(valid_params.merge(url: 'silverbullet.in/buy///')).url.should == 'silverbullet.in/buy'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#watch' do
|
||||
|
|
Loading…
Reference in New Issue