From a415ff5c5fe6bd2f31041cebe28a757d624dbb50 Mon Sep 17 00:00:00 2001
From: maxwell <maxwell@joindiaspora.com>
Date: Sat, 4 Dec 2010 23:31:57 -0800
Subject: [PATCH] fixed the build.  made photos dependent destroy with parent
 status message

---
 app/models/status_message.rb                |  2 +-
 spec/controllers/publics_controller_spec.rb |  8 ++------
 spec/models/photo_spec.rb                   | 13 ++++++++++++-
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/app/models/status_message.rb b/app/models/status_message.rb
index 4806d60cda..fd51c33977 100644
--- a/app/models/status_message.rb
+++ b/app/models/status_message.rb
@@ -12,7 +12,7 @@ class StatusMessage < Post
   xml_reader :message
 
   key :message, String
-  many :photos, :class => Photo, :foreign_key => :status_message_id
+  many :photos, :class => Photo, :foreign_key => :status_message_id, :dependent => :destroy
   validate :message_or_photos_present?
 
   attr_accessible :message
diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb
index 58a6e1b062..fed735aa83 100644
--- a/spec/controllers/publics_controller_spec.rb
+++ b/spec/controllers/publics_controller_spec.rb
@@ -13,14 +13,10 @@ describe PublicsController do
   describe '#receive' do
     let(:xml) { "<walruses></walruses>" }
      context 'success cases' do
-      it 'should 200 on successful receipt of a request' do
-        post :receive, :id =>user.person.id, :xml => xml
-        response.code.should == '200'
-      end
-
-      it 'enqueues a receive job' do
+      it 'should 200 on successful receipt of a request, and queues a job' do
         Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once
         post :receive, :id =>user.person.id, :xml => xml
+        response.code.should == '200'
       end
     end
 
diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb
index 95686ab363..d4444142de 100644
--- a/spec/models/photo_spec.rb
+++ b/spec/models/photo_spec.rb
@@ -121,7 +121,6 @@ describe Photo do
     it 'should set the remote_photo on marshalling' do
       @photo.image.store! File.open(@fixture_name)
 
-
       #security hax
       user2 = Factory.create(:user)
       aspect2 = user2.aspects.create(:name => "foobars")
@@ -157,4 +156,16 @@ describe Photo do
       proc{ @user.comment("big willy style", :on => @photo) }.should change(@photo.comments, :count).by(1)
     end
   end
+
+  context "deletion" do
+    it 'is deleted with parent status message' do
+      status_message = @user.build_post(:status_message, :message => "whattup", :to => @aspect.id)
+      status_message.photos << @photo2
+      status_message.save
+
+      proc {
+        status_message.destroy
+      }.should change(Photo, :count).by(-1)
+    end
+  end
 end
-- 
GitLab