added a dependant destroy to the service_users
This commit is contained in:
parent
8a9a95d854
commit
9abe22d5d2
2 changed files with 23 additions and 1 deletions
|
|
@ -6,7 +6,7 @@ class Service < ActiveRecord::Base
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_many :service_users
|
has_many :service_users, :dependent => :destroy
|
||||||
|
|
||||||
def public_message(post, length, url = "")
|
def public_message(post, length, url = "")
|
||||||
url = "" if post.respond_to?(:photos) && post.photos.count == 0
|
url = "" if post.respond_to?(:photos) && post.photos.count == 0
|
||||||
|
|
|
||||||
22
spec/models/service_spec.rb
Normal file
22
spec/models/service_spec.rb
Normal 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
|
||||||
Loading…
Reference in a new issue