MS DG added specs for posting to twitter, and basic services controller tests
This commit is contained in:
parent
d66e986971
commit
154b6e0ee7
6 changed files with 91 additions and 34 deletions
|
|
@ -15,7 +15,7 @@ class StatusMessagesController < ApplicationController
|
||||||
if params[:status_message][:public] == '1'
|
if params[:status_message][:public] == '1'
|
||||||
current_user.post_to_twitter(message)
|
current_user.post_to_twitter(message)
|
||||||
if logged_into_fb?
|
if logged_into_fb?
|
||||||
current_user.post_to_message_fb(message, @access_token)
|
current_user.post_to_facebook(message, @access_token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ class User
|
||||||
intitial_post(class_name, aspect_ids, options)
|
intitial_post(class_name, aspect_ids, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_to_message_fb(message, access_token)
|
def post_to_facebook(message, access_token)
|
||||||
id = 'me'
|
id = 'me'
|
||||||
type = 'feed'
|
type = 'feed'
|
||||||
Rails.logger.info("Sending a message: #{message} to Facebook")
|
Rails.logger.info("Sending a message: #{message} to Facebook")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ describe AlbumsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should update the name of an album" do
|
it "should update the name of an album" do
|
||||||
sign_in :user, @user
|
|
||||||
put :update, :id => @album.id, :album => { :name => "new_name"}
|
put :update, :id => @album.id, :album => { :name => "new_name"}
|
||||||
@album.reload.name.should eql("new_name")
|
@album.reload.name.should eql("new_name")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
48
spec/controllers/omniauth_services_controller_spec.rb
Normal file
48
spec/controllers/omniauth_services_controller_spec.rb
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe OmniauthServicesController do
|
||||||
|
render_views
|
||||||
|
let(:user) { Factory(:user) }
|
||||||
|
let!(:aspect) { user.aspect(:name => "lame-os") }
|
||||||
|
|
||||||
|
let!(:service1) {a = Factory(:omniauth_service); user.services << a; a}
|
||||||
|
let!(:service2) {a = Factory(:omniauth_service); user.services << a; a}
|
||||||
|
let!(:service3) {a = Factory(:omniauth_service); user.services << a; a}
|
||||||
|
let!(:service4) {a = Factory(:omniauth_service); user.services << a; a}
|
||||||
|
|
||||||
|
let(:mock_access_token) { Object.new }
|
||||||
|
|
||||||
|
let(:omniauth_auth) {{ 'provider' => 'twitter', 'uid' => '2',
|
||||||
|
'user_info' => { 'nickname' => 'grimmin' },
|
||||||
|
'extra' => { 'access_token' => mock_access_token }}}
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in :user, user
|
||||||
|
mock_access_token.stub!(:token).and_return("12345")
|
||||||
|
mock_access_token.stub!(:secret).and_return("56789")
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#index' do
|
||||||
|
it 'displays all connected serivices for a user' do
|
||||||
|
get :index
|
||||||
|
assigns[:services].should == user.services
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#create' do
|
||||||
|
it 'creates a new OmniauthService' do
|
||||||
|
request.env['omniauth.auth'] = omniauth_auth
|
||||||
|
lambda{post :create}.should change(user.services, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#destroy' do
|
||||||
|
it 'should destroy a service of a users with the id' do
|
||||||
|
lambda{delete :destroy, :id => service1.id.to_s}.should change(user.services, :count).by(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -12,27 +12,42 @@ describe StatusMessagesController do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in :user, user
|
sign_in :user, user
|
||||||
|
@controller.stub!(:current_user).and_return(user)
|
||||||
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"=>"1", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}}
|
||||||
|
|
||||||
before do
|
|
||||||
@controller.stub!(:logged_into_fb?).and_return(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should post to facebook when public is set' do
|
|
||||||
my_mock = mock("http")
|
context "posting out to facebook" do
|
||||||
my_mock.stub!(:post)
|
before do
|
||||||
EventMachine::HttpRequest.should_receive(:new).and_return(my_mock)
|
@controller.stub!(:logged_into_fb?).and_return(true)
|
||||||
post :create, status_message_hash
|
end
|
||||||
end
|
|
||||||
|
it 'should post to facebook when public is set' do
|
||||||
it 'should not post to facebook when public in not set' do
|
user.should_receive(:post_to_facebook)
|
||||||
status_message_hash['status_message']['public'] = '0'
|
post :create, status_message_hash
|
||||||
EventMachine::HttpRequest.should_not_receive(:new)
|
end
|
||||||
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'
|
||||||
|
user.should_not_receive(:post_to_facebook)
|
||||||
|
post :create, status_message_hash
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context "posting to twitter" do
|
||||||
|
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'
|
||||||
|
user.should_not_receive(:post_to_twitter)
|
||||||
|
post :create, status_message_hash
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,22 +52,17 @@ Factory.define :status_message do |m|
|
||||||
m.person
|
m.person
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define :blog do |b|
|
|
||||||
b.sequence(:title) {|n| "bobby's #{n} penguins"}
|
|
||||||
b.sequence(:body) {|n| "jimmy's huge #{n} whales"}
|
|
||||||
end
|
|
||||||
|
|
||||||
Factory.define :bookmark do |b|
|
|
||||||
b.link "http://www.yahooligans.com/"
|
|
||||||
end
|
|
||||||
|
|
||||||
Factory.define :post do |p|
|
|
||||||
end
|
|
||||||
|
|
||||||
Factory.define :photo do |p|
|
Factory.define :photo do |p|
|
||||||
p.image File.open( File.dirname(__FILE__) + '/fixtures/button.png')
|
p.image File.open( File.dirname(__FILE__) + '/fixtures/button.png')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define(:comment) {}
|
Factory.define :omniauth_service do |service|
|
||||||
|
service.nickname "sirrobertking"
|
||||||
|
service.provider "twitter"
|
||||||
|
|
||||||
|
service.sequence(:uid) { |token| "000#{token}" }
|
||||||
|
service.sequence(:access_token) { |token| "12345#{token}" }
|
||||||
|
service.sequence(:access_secret) { |token| "98765#{token}" }
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue