From 537766d0d70ee26b5fce3a770062f15f66e0f790 Mon Sep 17 00:00:00 2001 From: Ilyaaaaaaaaaaaaa Zhitomirskiy Date: Tue, 19 Jul 2011 18:17:08 -0700 Subject: [PATCH] Started working on repost integration test --- app/models/reshare.rb | 2 +- spec/multi_server/repost_spec.rb | 52 ++++++++++++++++++++++++++++++++ spec/multi_server/server_spec.rb | 2 -- spec/support/server.rb | 22 ++++++++++++-- 4 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 spec/multi_server/repost_spec.rb diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 3ea3f0439..8a9bed4a3 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -59,7 +59,7 @@ class Reshare < Post end def root_must_be_public - if self.root.nil? || !self.root.public + if !self.root.public errors[:base] << "you must reshare public posts" return false end diff --git a/spec/multi_server/repost_spec.rb b/spec/multi_server/repost_spec.rb new file mode 100644 index 000000000..4e4bde01d --- /dev/null +++ b/spec/multi_server/repost_spec.rb @@ -0,0 +1,52 @@ + +require 'spec_helper' + + +unless Server.all.empty? + describe "reposting" do + before(:all) do + WebMock::Config.instance.allow_localhost = true + #Server.all.each{|s| s.kill if s.running?} + #Server.all.each{|s| s.run} + end + + after(:all) do + #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?} + WebMock::Config.instance.allow_localhost = false + end + + it 'fetches the original post from the root server' do + Server.all[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, + :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") + end + + Server.all[0].in_scope do + r = User.find_by_username("resharer") + person = Webfinger.new("recipient@localhost:#{Server.all[1].port}").fetch + r.share_with(person, r.aspects.first) + end + Server.all[1].in_scope do + r = User.find_by_username("recipient") + person = Webfinger.new("resharer@localhost:#{Server.all[0].port}").fetch + r.share_with(person, r.aspects.first) + end + + + end + end +end diff --git a/spec/multi_server/server_spec.rb b/spec/multi_server/server_spec.rb index a600bce2e..e8e01fea3 100644 --- a/spec/multi_server/server_spec.rb +++ b/spec/multi_server/server_spec.rb @@ -1,7 +1,6 @@ #This is a spec for the class that runs the servers used in the other multi-server specs require 'spec_helper' -WebMock::Config.instance.allow_localhost = true unless Server.all.empty? describe Server do before(:all) do @@ -57,4 +56,3 @@ unless Server.all.empty? end end end -WebMock::Config.instance.allow_localhost = false diff --git a/spec/support/server.rb b/spec/support/server.rb index 0a848955a..eb31db5e6 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -62,8 +62,11 @@ class Server def db former_env = Rails.env ActiveRecord::Base.establish_connection(env) - result = yield - ActiveRecord::Base.establish_connection(former_env) + begin + result = yield + ensure + ActiveRecord::Base.establish_connection(former_env) + end result end @@ -72,4 +75,19 @@ class Server DatabaseCleaner.clean_with(:truncation) end end + + def in_scope + pod_url = "http://localhost:#{@port}/" + AppConfig.stub!(:pod_url).and_return(pod_url) + AppConfig.stub!(:pod_uri).and_return(URI.parse(pod_url)) + begin + result = db do + yield + end + ensure + AppConfig.unstub!(:pod_url) + AppConfig.unstub!(:pod_uri) + end + result + end end