diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 3df470a39..340643716 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index b1e24890a..c60f74968 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -2,10 +2,11 @@ class Person include MongoMapper::Document include ROXML + xml_accessor :_id xml_accessor :email xml_accessor :url xml_accessor :profile, :as => Profile - xml_accessor :_id + key :email, String key :url, String diff --git a/app/models/request.rb b/app/models/request.rb index 95623d9a8..f59c57d37 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -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) } @@ -30,5 +35,14 @@ class Request p.active = true 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 diff --git a/app/models/retraction.rb b/app/models/retraction.rb index c799df5fd..2e9a29f77 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -19,7 +19,6 @@ class Retraction attr_accessor :type def perform - puts('GO GO GO') self.type.constantize.destroy(self.post_id) end @@ -35,7 +34,7 @@ class Retraction def self.type_name(object) if object.is_a? Post object.class - elsif object.is_a? User + elsif object.is_a? Person 'Person' else 'Clowntown' diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index 36150b3ea..c6650fb75 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -141,6 +141,17 @@ describe "parser in application helper" do Person.where(:url => @person.url).first.active.should be true end + + it 'should marshal a retraction for a person' do + retraction = Retraction.for(@user) + request = Retraction.build_xml_for( [retraction] ) + + Person.count.should == 2 + store_objects_from_xml( request ) + Person.count.should == 1 + + end + end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 8c6dd30bf..a882b9849 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -62,11 +62,9 @@ describe Person do f = Factory.create(:person, :active => true) - Person.friends.all.count.should == 1 u.unfriend(f.id) Person.friends.all.count.should == 0 - end end