Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
0c8e6b0ba1
9 changed files with 192 additions and 62 deletions
16
app/models/jobs/post_to_service.rb
Normal file
16
app/models/jobs/post_to_service.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
#
|
||||||
|
module Jobs
|
||||||
|
class PostToService
|
||||||
|
extend ResqueJobLogging
|
||||||
|
@queue = :http
|
||||||
|
|
||||||
|
def self.perform(service_id, post_id, url)
|
||||||
|
service = Service.find_by_id(service_id)
|
||||||
|
post = Post.find_by_id(post_id)
|
||||||
|
service.post(post, url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -23,6 +23,6 @@
|
||||||
= render 'aspects/no_contacts_message', :aspect => @aspect, :contact_count => @aspect_contacts_count, :options => false
|
= render 'aspects/no_contacts_message', :aspect => @aspect, :contact_count => @aspect_contacts_count, :options => false
|
||||||
= render 'aspects/no_posts_message', :post_count => @post_count, :contact_count=> @aspect_contacts_count
|
= render 'aspects/no_posts_message', :post_count => @post_count, :contact_count=> @aspect_contacts_count
|
||||||
|
|
||||||
%ul{:class => 'stream', :id => 'main_stream'}
|
#main_stream.stream
|
||||||
= render 'shared/stream', :posts => @post_hashes
|
= render 'shared/stream', :posts => @post_hashes
|
||||||
=will_paginate @posts
|
=will_paginate @posts
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,14 @@
|
||||||
|
|
||||||
|
|
||||||
class PubSubHubbub
|
class PubSubHubbub
|
||||||
|
|
||||||
H = {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"}
|
H = {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"}
|
||||||
|
|
||||||
def initialize(hub, options={})
|
def initialize(hub, options={})
|
||||||
@headers = H.merge(options[:head]) if options[:head]
|
@headers = H.merge(options[:head]) if options[:head]
|
||||||
@hub = hub.kind_of?(URI) ? hub : URI::parse(hub)
|
@hub = hub
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish(feed)
|
def publish(feed)
|
||||||
RestClient.post @hub, :headers => H, 'hub.url' => feed, 'hub.mode' => 'publish'
|
RestClient.post(@hub, :headers => @headers, 'hub.url' => feed, 'hub.mode' => 'publish')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,75 @@ namespace :fixtures do
|
||||||
UserFixer.regenerate_user_fixtures
|
UserFixer.regenerate_user_fixtures
|
||||||
puts "Fixture regeneration complete."
|
puts "Fixture regeneration complete."
|
||||||
end
|
end
|
||||||
|
task :for_mysql_export do
|
||||||
|
puts "Populating DB for export."
|
||||||
|
require File.join(Rails.root,"config/environment")
|
||||||
|
require File.join(Rails.root,"spec/helper_methods")
|
||||||
|
require File.join(Rails.root,"spec/factories")
|
||||||
|
require File.join(Rails.root,"spec/support/user_methods")
|
||||||
|
require File.join(Rails.root,"spec/support/fake_resque")
|
||||||
|
|
||||||
|
include HelperMethods
|
||||||
|
|
||||||
|
Jobs::HttpPost.class_eval do
|
||||||
|
def self.perform(*args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
fantasy_resque do
|
||||||
|
models = []
|
||||||
|
Factory(:person)
|
||||||
|
Factory(:person)
|
||||||
|
Factory(:person)
|
||||||
|
user1 = Factory(:user_with_aspect)
|
||||||
|
user2 = Factory(:user_with_aspect)
|
||||||
|
connect_users(user1, user1.aspects.first, user2, user2.aspects.first)
|
||||||
|
user2.activate_contact(Factory(:person), user2.aspects.first)
|
||||||
|
user2.reload
|
||||||
|
|
||||||
|
user3 = Factory(:user_with_aspect)
|
||||||
|
user4 = Factory(:user_with_aspect)
|
||||||
|
user3.send_contact_request_to(user4.person, user3.aspects.first)
|
||||||
|
user3.reload; user4.reload
|
||||||
|
user3.send_contact_request_to(Factory(:person), user3.aspects.first)
|
||||||
|
|
||||||
|
batch_invitee = Invitation.create_invitee(:email => "random@example.com", :name => "Curious George", :invites => 3)
|
||||||
|
invitee = user1.invite_user("random2@example.net", user1.aspects.first.id, "Hello!")
|
||||||
|
user1.reload
|
||||||
|
|
||||||
|
u1post = user1.post(:status_message, :message => "User2 can see this", :to => [user1.aspects.first.id])
|
||||||
|
user1.reload
|
||||||
|
u3post = user3.post(:status_message, :message => "User3 can see this", :to => [user3.aspects.first.id])
|
||||||
|
user3.reload
|
||||||
|
user3.comment("Hey me!", :on => u3post)
|
||||||
|
user3.reload
|
||||||
|
user2.comment("Hey you!", :on => u1post)
|
||||||
|
user2.reload
|
||||||
|
|
||||||
|
user2.post(:photo, :user_file => uploaded_photo, :to => [user2.aspects.first.id])
|
||||||
|
user2.reload
|
||||||
|
user3.post(:photo, :user_file => uploaded_photo, :to => [user3.aspects.first.id])
|
||||||
|
user3.reload
|
||||||
|
|
||||||
|
remote_user = Factory(:user_with_aspect)
|
||||||
|
user4.activate_contact(remote_user.person, user4.aspects.first)
|
||||||
|
user4.reload
|
||||||
|
remote_message = remote_user.build_post(:photo, :user_file => uploaded_photo, :to => remote_user.aspects.first.id)
|
||||||
|
remote_photo = remote_user.build_post(:status_message, :message => "from another server!", :to => remote_user.aspects.first.id)
|
||||||
|
request = remote_user.send_contact_request_to(user2.person, remote_user.aspects.first)
|
||||||
|
remote_user.reload
|
||||||
|
remote_user.delete
|
||||||
|
Contact.where(:user_id => remote_user.id).each{|c| c.delete}
|
||||||
|
Aspect.where(:user_id => remote_user.id).each{|c| c.delete}
|
||||||
|
remote_person = remote_user.person
|
||||||
|
remote_person.owner_id = nil
|
||||||
|
remote_person.save
|
||||||
|
|
||||||
|
user4.receive(remote_message.to_diaspora_xml, remote_person)
|
||||||
|
user3.reload
|
||||||
|
user4.receive(remote_photo.to_diaspora_xml, remote_person)
|
||||||
|
user3.reload
|
||||||
|
end
|
||||||
|
puts "Done generating fixtures, you can now export"
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
31
spec/lib/pubsubhubbub_spec.rb
Normal file
31
spec/lib/pubsubhubbub_spec.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# 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 PubSubHubbub do
|
||||||
|
before :all do
|
||||||
|
RestClient.unstub!(:post)
|
||||||
|
end
|
||||||
|
|
||||||
|
after :all do
|
||||||
|
RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success))
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#initialize' do
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#publish' do
|
||||||
|
it 'posts the feed to the given hub' do
|
||||||
|
hub = "http://hubzord.com/"
|
||||||
|
feed = 'http://rss.com/dom.atom'
|
||||||
|
body = {'hub.url' => feed, 'hub.mode' => 'publish'}
|
||||||
|
|
||||||
|
stub_request(:post, "http://hubzord.com/").
|
||||||
|
with(:body => "hub.url=http%3A%2F%2Frss.com%2Fdom.atom&headers=&hub.mode=publish",
|
||||||
|
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'65', 'Content-Type'=>'application/x-www-form-urlencoded'}).to_return(:status => [202, 'you are awesome'])
|
||||||
|
PubSubHubbub.new(hub).publish(feed).code.should == 202
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
16
spec/models/jobs/post_to_service_spec.rb
Normal file
16
spec/models/jobs/post_to_service_spec.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Jobs::PostToService do
|
||||||
|
it 'calls service#post with the given service' do
|
||||||
|
user = make_user
|
||||||
|
aspect = user.aspects.create(:name => "yeah")
|
||||||
|
post = user.post(:status_message, :message => 'foo', :to => aspect.id)
|
||||||
|
User.stub!(:find_by_id).with(user.id.to_s).and_return(user)
|
||||||
|
m = mock()
|
||||||
|
url = "foobar"
|
||||||
|
m.should_receive(:post).with(anything, url)
|
||||||
|
Service.stub!(:find_by_id).and_return(m)
|
||||||
|
Jobs::PostToService.perform("123", post.id.to_s, url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
@ -54,61 +54,8 @@ class FakeRedis
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
module Resque
|
|
||||||
def enqueue(klass, *args)
|
|
||||||
if $process_queue
|
|
||||||
klass.send(:perform, *args)
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ImageUploader.enable_processing = false
|
ImageUploader.enable_processing = false
|
||||||
class User
|
|
||||||
def send_contact_request_to(desired_contact, aspect)
|
|
||||||
fantasy_resque do
|
|
||||||
contact = Contact.new(:person => desired_contact,
|
|
||||||
:user => self,
|
|
||||||
:pending => true)
|
|
||||||
contact.aspects << aspect
|
|
||||||
|
|
||||||
if contact.save!
|
|
||||||
contact.dispatch_request
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def post(class_name, opts = {})
|
|
||||||
fantasy_resque do
|
|
||||||
p = build_post(class_name, opts)
|
|
||||||
if p.save!
|
|
||||||
raise 'MongoMapper failed to catch a failed save' unless p.id
|
|
||||||
|
|
||||||
self.aspects.reload
|
|
||||||
|
|
||||||
add_to_streams(p, opts[:to])
|
|
||||||
dispatch_post(p, :to => opts[:to])
|
|
||||||
end
|
|
||||||
p
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def comment(text, options = {})
|
|
||||||
fantasy_resque do
|
|
||||||
c = build_comment(text, options)
|
|
||||||
if c.save!
|
|
||||||
raise 'MongoMapper failed to catch a failed save' unless c.id
|
|
||||||
dispatch_comment(c)
|
|
||||||
end
|
|
||||||
c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FakeHttpRequest
|
class FakeHttpRequest
|
||||||
def initialize(callback_wanted)
|
def initialize(callback_wanted)
|
||||||
|
|
|
||||||
9
spec/support/fake_resque.rb
Normal file
9
spec/support/fake_resque.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
module Resque
|
||||||
|
def enqueue(klass, *args)
|
||||||
|
if $process_queue
|
||||||
|
klass.send(:perform, *args)
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
42
spec/support/user_methods.rb
Normal file
42
spec/support/user_methods.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
class User
|
||||||
|
def send_contact_request_to(desired_contact, aspect)
|
||||||
|
fantasy_resque do
|
||||||
|
contact = Contact.new(:person => desired_contact,
|
||||||
|
:user => self,
|
||||||
|
:pending => true)
|
||||||
|
contact.aspects << aspect
|
||||||
|
|
||||||
|
if contact.save!
|
||||||
|
contact.dispatch_request
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def post(class_name, opts = {})
|
||||||
|
fantasy_resque do
|
||||||
|
p = build_post(class_name, opts)
|
||||||
|
if p.save!
|
||||||
|
raise 'MongoMapper failed to catch a failed save' unless p.id
|
||||||
|
|
||||||
|
self.aspects.reload
|
||||||
|
|
||||||
|
add_to_streams(p, opts[:to])
|
||||||
|
dispatch_post(p, :to => opts[:to])
|
||||||
|
end
|
||||||
|
p
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def comment(text, options = {})
|
||||||
|
fantasy_resque do
|
||||||
|
c = build_comment(text, options)
|
||||||
|
if c.save!
|
||||||
|
raise 'MongoMapper failed to catch a failed save' unless c.id
|
||||||
|
dispatch_comment(c)
|
||||||
|
end
|
||||||
|
c
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue