added a dependant destroy to the service_users

This commit is contained in:
zhitomirskiyi 2011-03-23 11:56:15 -07:00
parent 8a9a95d854
commit 9abe22d5d2
2 changed files with 23 additions and 1 deletions

View file

@ -6,7 +6,7 @@ class Service < ActiveRecord::Base
include ActionView::Helpers::TextHelper
belongs_to :user
has_many :service_users
has_many :service_users, :dependent => :destroy
def public_message(post, length, url = "")
url = "" if post.respond_to?(:photos) && post.photos.count == 0

View file

@ -0,0 +1,22 @@
require 'spec_helper'
describe Service do
before do
@user = alice
@post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id)
@service = Services::Facebook.new(:access_token => "yeah")
@user.services << @service
end
it 'destroys the associated service_user' do
@service.service_users = [ServiceUser.create(:service_id => @service.id,
:uid => "abc123",
:photo_url => "a.jpg",
:name => "a",
:person_id => bob.person.id)]
lambda{
@service.destroy
}.should change(ServiceUser, :count).by(-1)
end
end