Skip to content
Extraits de code Groupes Projets
Valider 7382dfb7 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Multi-server spec now successfully passes along a reshare

parent e19fb6d0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -235,7 +235,6 @@ class Person < ActiveRecord::Base
protected
def clean_url
self.url ||= "http://localhost:3000/" if self.class == User
if self.url
self.url = 'http://' + self.url unless self.url.match(/https?:\/\//)
self.url = self.url + '/' if self.url[-1, 1] != '/'
......
class Reshare < Post
class Reshare < Post
belongs_to :root, :class_name => 'Post'
validate :root_must_be_public
......@@ -7,12 +7,12 @@ class Reshare < Post
xml_attr :root_diaspora_id
xml_attr :root_guid
before_validation do
before_validation do
self.public = true
end
def root_guid
self.root.guid
self.root.guid
end
def root_diaspora_id
......@@ -21,9 +21,9 @@ class Reshare < Post
def receive(user, person)
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
if user.contact_for(person)
local_reshare.receive(user, person)
end
......@@ -42,7 +42,9 @@ class Reshare < Post
local_post = Post.where(:guid => @root_guid).select('id').first
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
post = received_post
......
......@@ -157,7 +157,9 @@ test:
integration_1:
<<: *defaults
pod_url: "http://localhost:45789"
enable_splunk_logging: false
integration_2:
<<: *defaults
pod_url: "http://localhost:34658"
enable_splunk_logging: false
......@@ -15,13 +15,12 @@ Diaspora::Application.configure do
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
#config.threadsafe!
config.threadsafe!
# 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
......
......@@ -19,7 +19,7 @@ end
Factory.define :person do |p|
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.after_build do |person|
person.profile ||= Factory.build(:profile, :person => person)
......
......@@ -6,11 +6,13 @@ unless Server.all.empty?
describe "reposting" do
before(:all) do
WebMock::Config.instance.allow_localhost = true
enable_typhoeus
#Server.all.each{|s| s.kill if s.running?}
#Server.all.each{|s| s.run}
end
after(:all) do
disable_typhoeus
#Server.all.each{|s| s.kill if s.running?}
#sleep(1)
#Server.all.each{|s| puts "Server at port #{s.port} still running." if s.running?}
......@@ -18,34 +20,43 @@ unless Server.all.empty?
end
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")
resharer = Factory.create(:user_with_aspect, :username => "resharer")
connect_users_with_aspects(original_poster, resharer)
original_post = original_poster.post(:status_message,
original_post = original_poster.post(:status_message,
:public => true,
:text => "Awesome Sauce!",
:to => 'all')
resharer.post(:reshare, :root_id => original_post.id, :to => 'all')
end
Server.all[1].in_scope do
recipient = Factory.create(:user_with_aspect, :username => "resharer")
Server[1].in_scope do
recipient = Factory.create(:user_with_aspect, :username => "recipient")
end
Server.all[0].in_scope do
Server[0].in_scope do
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)
end
Server.all[1].in_scope do
Server[1].in_scope do
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)
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
......
#This class is for running servers in the background during integration testing. This will not run on Windows.
class Server
def self.[] index
self.all[index]
end
def self.all
@servers ||= ActiveRecord::Base.configurations.keys.select{
|k| k.include?("integration")
......@@ -29,7 +34,7 @@ class Server
def run
@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
......@@ -39,7 +44,7 @@ class Server
end
def run_command
"rails s thin -p #{@port}"
"rails s -p #{@port}"
end
def get_pid
......@@ -78,15 +83,14 @@ class Server
def in_scope
pod_url = "http://localhost:#{@port}/"
AppConfig.stub!(:pod_url).and_return(pod_url)
AppConfig.stub!(:pod_uri).and_return(Addressable::URI.parse(pod_url))
old_pod_url = AppConfig[:pod_url]
AppConfig[:pod_url] = pod_url
begin
result = db do
yield
end
ensure
AppConfig.unstub!(:pod_url)
AppConfig.unstub!(:pod_uri)
AppConfig[:pod_url] = old_pod_url
end
result
end
......
class User
include Rails.application.routes.url_helpers
def default_url_options
{:host => AppConfig[:pod_url]}
end
alias_method :share_with_original, :share_with
......@@ -16,7 +20,9 @@ class User
aspects = self.aspects_from_ids(opts[:to])
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
unless opts[:created_at]
p.created_at = Time.now - 1
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter