DG MS; fixed some bugs with posting publicly.
This commit is contained in:
parent
6ff94e67b3
commit
060d8f9c7b
5 changed files with 30 additions and 37 deletions
|
|
@ -9,9 +9,13 @@ class StatusMessagesController < ApplicationController
|
|||
respond_to :json, :only => :show
|
||||
|
||||
def create
|
||||
public_flag = params[:status_message][:public]
|
||||
public_flag.match(/(true)/) ? public_flag = true : public_flag = false
|
||||
params[:status_message][:public] = public_flag
|
||||
|
||||
data = clean_hash params[:status_message]
|
||||
message = params[:status_message][:message]
|
||||
@status_message = current_user.post(:status_message, data)
|
||||
status_message = current_user.post(:status_message, data)
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
|
@ -23,12 +27,8 @@ class StatusMessagesController < ApplicationController
|
|||
|
||||
def show
|
||||
@status_message = current_user.find_visible_post_by_id params[:id]
|
||||
unless @status_message
|
||||
render :status => 404
|
||||
else
|
||||
respond_with @status_message
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def clean_hash(params)
|
||||
|
|
|
|||
|
|
@ -155,32 +155,26 @@ class User
|
|||
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]
|
||||
if options[:public] == true
|
||||
self.services.each do |service|
|
||||
self.send("post_to_#{service.provider}".to_sym)
|
||||
self.send("post_to_#{service.provider}".to_sym, service, post.message)
|
||||
end
|
||||
end
|
||||
|
||||
post
|
||||
end
|
||||
|
||||
def post_to_facebook(message)
|
||||
facebook = self.services.find_by_provider("facebook")
|
||||
if facebook
|
||||
def post_to_facebook(service, message)
|
||||
Rails.logger.info("Sending a message: #{message} to Facebook")
|
||||
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{facebook.access_token}").post
|
||||
end
|
||||
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{service.access_token}").post
|
||||
end
|
||||
|
||||
def post_to_twitter(message)
|
||||
twitter = self.services.find_by_provider("twitter")
|
||||
if twitter
|
||||
def post_to_twitter(service, message)
|
||||
oauth = Twitter::OAuth.new(SERVICES['twitter']['consumer_token'], SERVICES['twitter']['consumer_secret'])
|
||||
oauth.authorize_from_access(twitter.access_token, twitter.access_secret)
|
||||
oauth.authorize_from_access(service.access_token, service.access_secret)
|
||||
client = Twitter::Base.new(oauth)
|
||||
client.update(message)
|
||||
end
|
||||
end
|
||||
|
||||
def update_post(post, post_hash = {})
|
||||
if self.owns? post
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
- if aspect == :all
|
||||
.public_toggle
|
||||
= status.check_box( :public, :value => false )
|
||||
= status.check_box( :public, {}, true, false )
|
||||
make public
|
||||
= link_to '(?)', "#question_mark_pane", :class => 'question_mark'
|
||||
|
||||
|
|
|
|||
|
|
@ -16,35 +16,33 @@ describe StatusMessagesController do
|
|||
end
|
||||
|
||||
describe '#create' do
|
||||
let(:status_message_hash) {{"status_message"=>{"public"=>"1", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}}
|
||||
|
||||
let(:status_message_hash) {{"status_message"=>{"public"=>"true", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}}
|
||||
|
||||
context "posting out to facebook" do
|
||||
before do
|
||||
@controller.stub!(:logged_into_fb?).and_return(true)
|
||||
end
|
||||
let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s }
|
||||
|
||||
it 'should post to facebook when public is set' do
|
||||
user.should_receive(:post_to_facebook)
|
||||
post :create, status_message_hash
|
||||
end
|
||||
|
||||
it 'should not post to facebook when public in not set' do
|
||||
status_message_hash['status_message']['public'] = '0'
|
||||
it 'should not post to facebook when public is not set' do
|
||||
status_message_hash['status_message']['public'] = 'false'
|
||||
user.should_not_receive(:post_to_facebook)
|
||||
post :create, status_message_hash
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "posting to twitter" do
|
||||
let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s }
|
||||
|
||||
it 'should post to twitter if public is set' do
|
||||
user.should_receive(:post_to_twitter).and_return(true)
|
||||
post :create, status_message_hash
|
||||
end
|
||||
|
||||
it 'should not post to twitter when public in not set' do
|
||||
status_message_hash['status_message']['public'] = '0'
|
||||
status_message_hash['status_message']['public'] = 'false'
|
||||
user.should_not_receive(:post_to_twitter)
|
||||
post :create, status_message_hash
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ describe User do
|
|||
let!(:aspect1) { user.aspect(:name => 'other') }
|
||||
let!(:aspect2) { user2.aspect(:name => 'losers') }
|
||||
|
||||
let!(:service1) { user.services << Factory(:service, :provider => 'twitter') }
|
||||
let!(:service2) { user.services << Factory(:service, :provider => 'facebook') }
|
||||
let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s }
|
||||
let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s }
|
||||
|
||||
|
||||
describe '#validate_aspect_permissions' do
|
||||
|
|
@ -56,9 +56,10 @@ describe User do
|
|||
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
|
||||
message = "hello, world!"
|
||||
user.should_receive(:post_to_twitter).with(service1, message).exactly(1).times
|
||||
user.should_receive(:post_to_facebook).with(service2, message).exactly(1).times
|
||||
user.post :status_message, :message => message, :to => "all", :public => true
|
||||
end
|
||||
|
||||
it "does not post to services if post is not public" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue