Skip to content
Snippets Groups Projects
Commit 287d633c authored by danielvincent's avatar danielvincent
Browse files

user#post now handles posting to services.

parent b2e8ebd0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment