add tests for object_should_be_processed_as_public? and delegegated public to the parent of relayable objects

This commit is contained in:
Maxwell Salzberg 2011-09-16 11:23:39 -07:00
parent 01f7625649
commit 6c414d8562
4 changed files with 21 additions and 2 deletions

View file

@ -76,4 +76,5 @@ class Comment < ActiveRecord::Base
def parent= parent
self.post = parent
end
end

View file

@ -15,6 +15,8 @@ module Diaspora
validates_associated :parent
validates :author, :presence => true
delegate :public?, :to => :parent
end
end

View file

@ -27,8 +27,6 @@ class Postzord::Dispatcher
def self.object_should_be_processed_as_public?(object)
if object.respond_to?(:public?) && object.public?
true
elsif object.respond_to?(:relayable?) && object.parent.respond_to?(:public?) && object.parent.public?
true
else
false
end

View file

@ -256,6 +256,24 @@ describe Postzord::Dispatcher do
end
end
describe '#object_should_be_processed_as_public?' do
it 'returns true with a comment on a public post' do
f = Factory(:comment, :post => Factory(:status_message, :public => true))
Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be_true
end
it 'returns false with a comment on a private post' do
f = Factory(:comment, :post => Factory(:status_message, :public => false))
Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be_false
end
it 'returns true with a like on a comment on a private post' do
f = Factory(:like, :target => Factory(:comment, :post => Factory(:status_message, :public => true)))
Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be_true
end
end
describe '#deliver_to_services' do
before do
alice.aspects.create(:name => "whatever")