From 287d633c443ad383cd4a9463701cc2ab2260380f Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 25 Oct 2010 17:22:03 -0700 Subject: [PATCH] user#post now handles posting to services. --- app/controllers/status_messages_controller.rb | 7 ------ app/models/user.rb | 19 +++++++++------- spec/models/user/posting_spec.rb | 22 +++++++++++++++++-- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 47caf4bf9..89cf59f32 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -11,14 +11,7 @@ class StatusMessagesController < ApplicationController def create data = clean_hash params[:status_message] message = params[:status_message][:message] - - if params[:status_message][:public] == '1' - current_user.post_to_twitter(message) - current_user.post_to_facebook(message) - end - @status_message = current_user.post(:status_message, data) - render :nothing => true end diff --git a/app/models/user.rb b/app/models/user.rb index 48420e577..8c179c239 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -151,7 +151,17 @@ class User aspect_ids = validate_aspect_permissions(aspect_ids) - intitial_post(class_name, aspect_ids, options) + post = build_post(class_name, options) + post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) + push_to_aspects(post, aspect_ids) + + if options[:public] + self.services.each do |service| + self.send("post_to_#{service.provider}".to_sym) + end + end + + post end def post_to_facebook(message) @@ -172,13 +182,6 @@ class User end end - def intitial_post(class_name, aspect_ids, options = {}) - post = build_post(class_name, options) - post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) - push_to_aspects(post, aspect_ids) - post - end - def update_post(post, post_hash = {}) if self.owns? post post.update_attributes(post_hash) diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 70438bbec..f21bad8a7 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -7,12 +7,16 @@ require 'spec_helper' describe User do let!(:user) { Factory(:user) } + let!(:user2) { Factory(:user) } + let!(:aspect) { user.aspect(:name => 'heroes') } let!(:aspect1) { user.aspect(:name => 'other') } - - let!(:user2) { Factory(:user) } let!(:aspect2) { user2.aspect(:name => 'losers') } + let!(:service1) { user.services << Factory(:service, :provider => 'twitter') } + let!(:service2) { user.services << Factory(:service, :provider => 'facebook') } + + describe '#validate_aspect_permissions' do it 'requires an aspect' do proc { @@ -44,11 +48,25 @@ describe User do aspect.reload aspect.posts.should include album end + it "should add the post to that user's visible posts" do status_message = user.post :status_message, :message => "hi", :to => aspect.id user.reload user.raw_visible_posts.include?(status_message).should be true end + + it "posts to services if post is public" do + user.should_receive(:post_to_twitter).exactly(1).times + user.should_receive(:post_to_facebook).exactly(1).times + user.post :status_message, :message => "hi", :to => "all", :public => true + end + + it "does not post to services if post is not public" do + user.should_receive(:post_to_twitter).exactly(0).times + user.should_receive(:post_to_facebook).exactly(0).times + user.post :status_message, :message => "hi", :to => "all" + end + end describe '#update_post' do