diff --git a/app/models/person.rb b/app/models/person.rb index 68d18a011dbbe35549d11047238a133fae559d90..756a00ef74717ecf7b35150e79c9942efe185588 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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] != '/' diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 8a9bed4a344df2db7f470dc3c4b0cfd36dadffd1..80bbeb47f9345b5dd3c91d98e890ad889cf7013f 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -1,4 +1,4 @@ -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 diff --git a/config/application.yml.example b/config/application.yml.example index ea01833bee6424553f6f0d9b532ba9d02c7df75a..6577ffd9db3ec66683842b2caa9a16f6627bb50c 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -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 diff --git a/config/environments/integration_1.rb b/config/environments/integration_1.rb index 1279e645a142226ac1fbaa68d428710a7fe2b39b..86f1c30438f18fa0bcf39dfd4fdacc29bb1cb1c0 100644 --- a/config/environments/integration_1.rb +++ b/config/environments/integration_1.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index dbd6da864a1d58e393924f174c58ffa3bd2eaf94..b637cc97deff2414166699872652f719bae5305f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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) diff --git a/spec/multi_server/repost_spec.rb b/spec/multi_server/repost_spec.rb index 4e4bde01d15f6da7e463fe86c9c89713299ccd21..48577eb4cc79c7628131eff51cc55d3466c1c882 100644 --- a/spec/multi_server/repost_spec.rb +++ b/spec/multi_server/repost_spec.rb @@ -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 diff --git a/spec/support/server.rb b/spec/support/server.rb index 27df791f7ea290446044412d3b0b614bc9ec872d..898a7614ab321d891d4fb121bca06bb8345e6c05 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,5 +1,10 @@ #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 diff --git a/spec/support/user_methods.rb b/spec/support/user_methods.rb index ff9925b41da7e34129a9bcb8429b5454f41e8227..63063be5fd9cd3a81ed1697495bb3a9571453c6e 100644 --- a/spec/support/user_methods.rb +++ b/spec/support/user_methods.rb @@ -1,4 +1,8 @@ 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