DG MS; request makes sure http:// and an ending slash is present on a new request link

This commit is contained in:
maxwell 2010-07-12 12:33:31 -07:00
parent 5ba2e61ab8
commit f9f7f0fcc7
4 changed files with 15 additions and 6 deletions

View file

@ -18,7 +18,7 @@ class Bookmark < Post
def clean_link
if self.link
self.link = 'http://' + self.link unless self.link.match('http://' || 'https://')
self.link = 'http://' + self.link unless self.link.match('https?://')
self.link = self.link + '/' if self.link[-1,1] != '/'
end
end

View file

@ -17,6 +17,11 @@ class Request
validates_presence_of :destination_url, :callback_url
#validates_format_of :destination_url, :with =>
#/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
before_validation :clean_link
scope :for_user, lambda{ |user| where(:destination_url => user.url) }
scope :from_user, lambda{ |user| where(:destination_url.ne => user.url) }
@ -31,4 +36,13 @@ class Request
p.save
end
protected
def clean_link
if self.destination_url
self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://')
self.destination_url = self.destination_url + '/' if self.destination_url[-1,1] != '/'
end
end
end

View file

@ -19,7 +19,6 @@ class Retraction
attr_accessor :type
def perform
puts self.inspect
self.type.constantize.destroy(self.post_id)
end

View file

@ -144,12 +144,8 @@ describe "parser in application helper" do
it 'should marshal a retraction for a person' do
retraction = Retraction.for(@user)
request = Retraction.build_xml_for( [retraction] )
puts request.inspect
Person.count.should == 2
store_objects_from_xml( request )
Person.count.should == 1