Multi-server spec now successfully passes along a reshare
This commit is contained in:
parent
e19fb6d0f8
commit
7382dfb7be
8 changed files with 50 additions and 27 deletions
|
|
@ -235,7 +235,6 @@ class Person < ActiveRecord::Base
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def clean_url
|
def clean_url
|
||||||
self.url ||= "http://localhost:3000/" if self.class == User
|
|
||||||
if self.url
|
if self.url
|
||||||
self.url = 'http://' + self.url unless self.url.match(/https?:\/\//)
|
self.url = 'http://' + self.url unless self.url.match(/https?:\/\//)
|
||||||
self.url = self.url + '/' if self.url[-1, 1] != '/'
|
self.url = self.url + '/' if self.url[-1, 1] != '/'
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
class Reshare < Post
|
class Reshare < Post
|
||||||
|
|
||||||
belongs_to :root, :class_name => 'Post'
|
belongs_to :root, :class_name => 'Post'
|
||||||
validate :root_must_be_public
|
validate :root_must_be_public
|
||||||
|
|
@ -7,12 +7,12 @@ class Reshare < Post
|
||||||
xml_attr :root_diaspora_id
|
xml_attr :root_diaspora_id
|
||||||
xml_attr :root_guid
|
xml_attr :root_guid
|
||||||
|
|
||||||
before_validation do
|
before_validation do
|
||||||
self.public = true
|
self.public = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def root_guid
|
def root_guid
|
||||||
self.root.guid
|
self.root.guid
|
||||||
end
|
end
|
||||||
|
|
||||||
def root_diaspora_id
|
def root_diaspora_id
|
||||||
|
|
@ -21,9 +21,9 @@ class Reshare < Post
|
||||||
|
|
||||||
def receive(user, person)
|
def receive(user, person)
|
||||||
local_reshare = Reshare.where(:guid => self.guid).first
|
local_reshare = Reshare.where(:guid => self.guid).first
|
||||||
if local_reshare.root.author_id == user.person.id
|
if local_reshare && local_reshare.root.author_id == user.person.id
|
||||||
local_reshare.root.reshares << local_reshare
|
local_reshare.root.reshares << local_reshare
|
||||||
|
|
||||||
if user.contact_for(person)
|
if user.contact_for(person)
|
||||||
local_reshare.receive(user, person)
|
local_reshare.receive(user, person)
|
||||||
end
|
end
|
||||||
|
|
@ -42,7 +42,9 @@ class Reshare < Post
|
||||||
local_post = Post.where(:guid => @root_guid).select('id').first
|
local_post = Post.where(:guid => @root_guid).select('id').first
|
||||||
|
|
||||||
unless local_post && self.root_id = local_post.id
|
unless local_post && self.root_id = local_post.id
|
||||||
received_post = Diaspora::Parser.from_xml(Faraday.get(root_author.url + "/p/#{@root_guid}.xml").body)
|
response = Faraday.get(root_author.url + "/p/#{@root_guid}.xml")
|
||||||
|
received_post = Diaspora::Parser.from_xml(response.body)
|
||||||
|
|
||||||
unless post = received_post.class.where(:guid => received_post.guid).first
|
unless post = received_post.class.where(:guid => received_post.guid).first
|
||||||
post = received_post
|
post = received_post
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,9 @@ test:
|
||||||
integration_1:
|
integration_1:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
pod_url: "http://localhost:45789"
|
pod_url: "http://localhost:45789"
|
||||||
|
enable_splunk_logging: false
|
||||||
|
|
||||||
integration_2:
|
integration_2:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
pod_url: "http://localhost:34658"
|
pod_url: "http://localhost:34658"
|
||||||
|
enable_splunk_logging: false
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,12 @@ Diaspora::Application.configure do
|
||||||
|
|
||||||
# Show full error reports and disable caching
|
# Show full error reports and disable caching
|
||||||
config.consider_all_requests_local = true
|
config.consider_all_requests_local = true
|
||||||
config.action_view.debug_rjs = true
|
|
||||||
config.action_controller.perform_caching = false
|
config.action_controller.perform_caching = false
|
||||||
|
|
||||||
# Don't care if the mailer can't send
|
# Don't care if the mailer can't send
|
||||||
config.action_mailer.raise_delivery_errors = false
|
config.action_mailer.raise_delivery_errors = false
|
||||||
config.active_support.deprecation = :log
|
config.active_support.deprecation = :log
|
||||||
#config.threadsafe!
|
config.threadsafe!
|
||||||
|
|
||||||
# Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars
|
# Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars
|
||||||
# This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why
|
# This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ end
|
||||||
|
|
||||||
Factory.define :person do |p|
|
Factory.define :person do |p|
|
||||||
p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@aol.com" }
|
p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@aol.com" }
|
||||||
p.sequence(:url) { |n| "http://google-#{n}#{r_str}.com/" }
|
p.sequence(:url) { |n| AppConfig[:pod_url] }
|
||||||
p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export
|
p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export
|
||||||
p.after_build do |person|
|
p.after_build do |person|
|
||||||
person.profile ||= Factory.build(:profile, :person => person)
|
person.profile ||= Factory.build(:profile, :person => person)
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,13 @@ unless Server.all.empty?
|
||||||
describe "reposting" do
|
describe "reposting" do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
WebMock::Config.instance.allow_localhost = true
|
WebMock::Config.instance.allow_localhost = true
|
||||||
|
enable_typhoeus
|
||||||
#Server.all.each{|s| s.kill if s.running?}
|
#Server.all.each{|s| s.kill if s.running?}
|
||||||
#Server.all.each{|s| s.run}
|
#Server.all.each{|s| s.run}
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:all) do
|
after(:all) do
|
||||||
|
disable_typhoeus
|
||||||
#Server.all.each{|s| s.kill if s.running?}
|
#Server.all.each{|s| s.kill if s.running?}
|
||||||
#sleep(1)
|
#sleep(1)
|
||||||
#Server.all.each{|s| puts "Server at port #{s.port} still running." if s.running?}
|
#Server.all.each{|s| puts "Server at port #{s.port} still running." if s.running?}
|
||||||
|
|
@ -18,34 +20,43 @@ unless Server.all.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fetches the original post from the root server' do
|
it 'fetches the original post from the root server' do
|
||||||
Server.all[0].in_scope do
|
original_post = nil
|
||||||
|
Server[0].in_scope do
|
||||||
original_poster = Factory.create(:user_with_aspect, :username => "original_poster")
|
original_poster = Factory.create(:user_with_aspect, :username => "original_poster")
|
||||||
resharer = Factory.create(:user_with_aspect, :username => "resharer")
|
resharer = Factory.create(:user_with_aspect, :username => "resharer")
|
||||||
|
|
||||||
connect_users_with_aspects(original_poster, resharer)
|
connect_users_with_aspects(original_poster, resharer)
|
||||||
|
|
||||||
original_post = original_poster.post(:status_message,
|
original_post = original_poster.post(:status_message,
|
||||||
:public => true,
|
:public => true,
|
||||||
:text => "Awesome Sauce!",
|
:text => "Awesome Sauce!",
|
||||||
:to => 'all')
|
:to => 'all')
|
||||||
resharer.post(:reshare, :root_id => original_post.id, :to => 'all')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Server.all[1].in_scope do
|
Server[1].in_scope do
|
||||||
recipient = Factory.create(:user_with_aspect, :username => "resharer")
|
recipient = Factory.create(:user_with_aspect, :username => "recipient")
|
||||||
end
|
end
|
||||||
|
|
||||||
Server.all[0].in_scope do
|
Server[0].in_scope do
|
||||||
r = User.find_by_username("resharer")
|
r = User.find_by_username("resharer")
|
||||||
person = Webfinger.new("recipient@localhost:#{Server.all[1].port}").fetch
|
person = Webfinger.new("recipient@localhost:#{Server[1].port}").fetch
|
||||||
r.share_with(person, r.aspects.first)
|
r.share_with(person, r.aspects.first)
|
||||||
end
|
end
|
||||||
Server.all[1].in_scope do
|
Server[1].in_scope do
|
||||||
r = User.find_by_username("recipient")
|
r = User.find_by_username("recipient")
|
||||||
person = Webfinger.new("resharer@localhost:#{Server.all[0].port}").fetch
|
person = Webfinger.new("resharer@localhost:#{Server[0].port}").fetch
|
||||||
r.share_with(person, r.aspects.first)
|
r.share_with(person, r.aspects.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Server[0].in_scope do
|
||||||
|
r = User.find_by_username("resharer")
|
||||||
|
r.post(:reshare, :root_id => original_post.id, :to => 'all')
|
||||||
|
debugger
|
||||||
|
end
|
||||||
|
|
||||||
|
Server[1].in_scope do
|
||||||
|
Post.exists?(:guid => original_post.guid).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
#This class is for running servers in the background during integration testing. This will not run on Windows.
|
#This class is for running servers in the background during integration testing. This will not run on Windows.
|
||||||
class Server
|
class Server
|
||||||
|
|
||||||
|
def self.[] index
|
||||||
|
self.all[index]
|
||||||
|
end
|
||||||
|
|
||||||
def self.all
|
def self.all
|
||||||
@servers ||= ActiveRecord::Base.configurations.keys.select{
|
@servers ||= ActiveRecord::Base.configurations.keys.select{
|
||||||
|k| k.include?("integration")
|
|k| k.include?("integration")
|
||||||
|
|
@ -29,7 +34,7 @@ class Server
|
||||||
|
|
||||||
def run
|
def run
|
||||||
@pid = fork do
|
@pid = fork do
|
||||||
Process.exec "cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec #{run_command}"
|
Process.exec "cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec #{run_command} 2> /dev/null"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -39,7 +44,7 @@ class Server
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_command
|
def run_command
|
||||||
"rails s thin -p #{@port}"
|
"rails s -p #{@port}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_pid
|
def get_pid
|
||||||
|
|
@ -78,15 +83,14 @@ class Server
|
||||||
|
|
||||||
def in_scope
|
def in_scope
|
||||||
pod_url = "http://localhost:#{@port}/"
|
pod_url = "http://localhost:#{@port}/"
|
||||||
AppConfig.stub!(:pod_url).and_return(pod_url)
|
old_pod_url = AppConfig[:pod_url]
|
||||||
AppConfig.stub!(:pod_uri).and_return(Addressable::URI.parse(pod_url))
|
AppConfig[:pod_url] = pod_url
|
||||||
begin
|
begin
|
||||||
result = db do
|
result = db do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
AppConfig.unstub!(:pod_url)
|
AppConfig[:pod_url] = old_pod_url
|
||||||
AppConfig.unstub!(:pod_uri)
|
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
class User
|
class User
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
def default_url_options
|
||||||
|
{:host => AppConfig[:pod_url]}
|
||||||
|
end
|
||||||
|
|
||||||
alias_method :share_with_original, :share_with
|
alias_method :share_with_original, :share_with
|
||||||
|
|
||||||
|
|
@ -16,7 +20,9 @@ class User
|
||||||
|
|
||||||
aspects = self.aspects_from_ids(opts[:to])
|
aspects = self.aspects_from_ids(opts[:to])
|
||||||
add_to_streams(p, aspects)
|
add_to_streams(p, aspects)
|
||||||
dispatch_post(p, :to => opts[:to])
|
dispatch_opts = {:url => post_url(p), :to => opts[:to]}
|
||||||
|
dispatch_opts.merge!(:additional_subscribers => p.root.author) if class_name == :reshare
|
||||||
|
dispatch_post(p, dispatch_opts)
|
||||||
end
|
end
|
||||||
unless opts[:created_at]
|
unless opts[:created_at]
|
||||||
p.created_at = Time.now - 1
|
p.created_at = Time.now - 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue