Skip to content
Extraits de code Groupes Projets
Valider 1c67211e rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Move post dispatching to dispatch_post

parent 0ecc27a9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -150,19 +150,34 @@ class User ...@@ -150,19 +150,34 @@ class User
post = build_post(class_name, options) post = build_post(class_name, options)
if post.persisted? if post.save
Rails.logger.info("Pushing: #{post.inspect} out to aspects") raise 'MongoMapper failed to catch a failed save' unless post.id
push_to_aspects(post, aspect_ids) dispatch_post(post, :to => aspect_ids)
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
if options[:public] == true
self.services.each do |service|
self.send("post_to_#{service.provider}".to_sym, service, post.message)
end
end
end end
post post
end end
def build_post(class_name, options = {})
options[:person] = self.person
options[:diaspora_handle] = self.person.diaspora_handle
model_class = class_name.to_s.camelize.constantize
model_class.instantiate(options)
end
def dispatch_post(post, opts = {})
self.raw_visible_posts << post
self.save
Rails.logger.info("Pushing: #{post.inspect} out to aspects")
push_to_aspects(post, opts[:to])
post.socket_to_uid(id, :aspect_ids => opts[:to]) if post.respond_to?(:socket_to_uid)
if post.public
self.services.each do |service|
self.send("post_to_#{service.provider}".to_sym, service, post.message)
end
end
end
def post_to_facebook(service, message) def post_to_facebook(service, message)
Rails.logger.info("Sending a message: #{message} to Facebook") Rails.logger.info("Sending a message: #{message} to Facebook")
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{service.access_token}").post EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{service.access_token}").post
...@@ -203,20 +218,6 @@ class User ...@@ -203,20 +218,6 @@ class User
aspect_ids aspect_ids
end end
def build_post(class_name, options = {})
options[:person] = self.person
options[:diaspora_handle] = self.person.diaspora_handle
model_class = class_name.to_s.camelize.constantize
post = model_class.instantiate(options)
if post.save
raise 'MongoMapper failed to catch a failed save' unless post.id
self.raw_visible_posts << post
self.save
end
post
end
def push_to_aspects(post, aspect_ids) def push_to_aspects(post, aspect_ids)
if aspect_ids == :all || aspect_ids == "all" if aspect_ids == :all || aspect_ids == "all"
aspects = self.aspects aspects = self.aspects
......
...@@ -9,6 +9,7 @@ describe Diaspora::WebSocket do ...@@ -9,6 +9,7 @@ describe Diaspora::WebSocket do
@user = make_user @user = make_user
@aspect = @user.aspects.create(:name => "losers") @aspect = @user.aspects.create(:name => "losers")
@post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id) @post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id)
@post.save
end end
it 'should queue a job' do it 'should queue a job' do
......
...@@ -36,7 +36,19 @@ describe User do ...@@ -36,7 +36,19 @@ describe User do
end end
end end
describe '#post' do describe '#build_post' do
it 'does not save a status_message' do
post = user.build_post(:status_message, :message => "hey", :to => aspect.id)
post.persisted?.should be_false
end
it 'does not save an album' do
post = user.build_post(:album, :name => "hey", :to => aspect.id)
post.persisted?.should be_false
end
end
describe '#dispatch_post' do
it 'should put the post in the aspect post array' do it 'should put the post in the aspect post array' do
post = user.post(:status_message, :message => "hey", :to => aspect.id) post = user.post(:status_message, :message => "hey", :to => aspect.id)
aspect.reload aspect.reload
...@@ -67,7 +79,6 @@ describe User do ...@@ -67,7 +79,6 @@ describe User do
user.should_receive(:post_to_facebook).exactly(0).times user.should_receive(:post_to_facebook).exactly(0).times
user.post :status_message, :message => "hi", :to => "all" user.post :status_message, :message => "hi", :to => "all"
end end
end end
describe '#update_post' do describe '#update_post' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter