From bf56364019ae6982afffba04b83d616312b8d803 Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 9 Dec 2010 16:16:29 -0800 Subject: [PATCH] tests for post to services resque job --- app/models/user.rb | 4 ++-- spec/models/user/posting_spec.rb | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 54c0689e1..d992fc0eb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -153,11 +153,11 @@ class User Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}") push_to_aspects(post, aspects_from_ids(aspect_ids)) - post_to_services(post, opts[:url]) + Resque.enqueue(Jobs::PostToServices, self.id, post.id, opts[:url]) if post.public end def post_to_services(post, url) - if post.public && post.respond_to?(:message) + if post.respond_to?(:message) self.services.each do |service| service.post(post, url) end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 047fd2b05..c19ecef1a 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -74,7 +74,8 @@ describe User do describe '#post_to_services' do it 'only iterates through services if the post is public' do user.should_receive(:services).and_return([]) - user.post(:status_message, :message => "foo", :public => true, :to => user.aspects.first.id) + post = user.build_post(:status_message, :message => "foo", :public => true, :to => user.aspects.first.id) + user.post_to_services(post, "dfds") end end @@ -98,8 +99,9 @@ describe User do } end - it "calls post_to_services" do - user.should_receive(:post_to_services) + it "calls post_to_services if status is public" do + Resque.should_receive(:enqueue).with(Jobs::PostToServices, anything, anything, anything) + status.public = true user.dispatch_post(status, :to => "all") end