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