From 34127b070aca434fcca1b4f0fb1e268982ca63eb Mon Sep 17 00:00:00 2001
From: Raphael Sofaer <raphael@joindiaspora.com>
Date: Tue, 15 Jun 2010 20:38:14 -0700
Subject: [PATCH] IZ Made the specs pass, time to clean

---
 app/models/status_message.rb       |  5 +++++
 spec/models/status_message_spec.rb | 36 +++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/app/models/status_message.rb b/app/models/status_message.rb
index 9ed8b1f95e..d8ff07edc4 100644
--- a/app/models/status_message.rb
+++ b/app/models/status_message.rb
@@ -26,6 +26,11 @@ class StatusMessage
   def self.retrieve_from_friend(friend)
       StatusMessages.from_xml `curl #{friend.url}status_messages.xml --user a@a.com:aaaaaa`
   end
+
+  def ==(other)
+    (self.message == other.message) && (self.owner == other.owner)
+  end
+
   protected
   
   def set_default_owner
diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb
index fd82f8075d..fee3381075 100644
--- a/spec/models/status_message_spec.rb
+++ b/spec/models/status_message_spec.rb
@@ -53,20 +53,44 @@ describe StatusMessage do
   describe "retrieving" do
     before do
       @remote = Factory.create(:friend, :url => "http://localhost:1254/")
-      @remote_xml = (0..5).collect{Factory.create(:status_message).to_xml}
       StatusMessages = StatusMessagesHelper::StatusMessages
       #@remote_messages = (0..5).collect {|a| Factory.build(:status_message)}
       #stub with response of @remote_msg.xml
     end
-    it "should marshal xml and serialize it" do
-      messages = StatusMessages.new(@remote_xml)
-      unreadable_xml = messages.to_xml.to_s.sub("\t\t","\t")
-      unreadable_xml.include?(remote_xml.first.to_s).should be true
+    it "should marshal xml and serialize it without error" do
+      StatusMessages.from_xml(@@remote_xml).to_xml.to_s.sub("/t<","<").should == @@remote_xml
     end
     it "marshal retrieved xml" do
-      StatusMessage.retrieve_from_friend(@remote).to_xml.should == StatusMessages.from_xml(@remote_xml).to_xml
+      remote_msgs = StatusMessage.retrieve_from_friend(@remote)
+      local_msgs = StatusMessages.from_xml(@@remote_xml)
+      remote_msgs.statusmessages.each{ |m| local_msgs.statusmessages.include?(m).should be_true}
+      local_msgs.statusmessages.each{ |m| remote_msgs.statusmessages.include?(m).should be_true}
 
         # .from_xml == @remote_messages
     end
   end
 end
+
+@@remote_xml = 
+"<statusmessages>
+  <statusmessage>
+    <message>jimmy's 22 whales</message>
+    <owner>tester@yahoo.com</owner>
+  </statusmessage>
+  <statusmessage>
+    <message>jimmy's 23 whales</message>
+    <owner>tester@yahoo.com</owner>
+  </statusmessage>
+  <statusmessage>
+    <message>jimmy's 24 whales</message>
+    <owner>tester@yahoo.com</owner>
+  </statusmessage>
+  <statusmessage>
+    <message>jimmy's 25 whales</message>
+    <owner>tester@yahoo.com</owner>
+  </statusmessage>
+  <statusmessage>
+    <message>jimmy's 26 whales</message>
+    <owner>tester@yahoo.com</owner>
+  </statusmessage>
+</statusmessages>"
-- 
GitLab