Started working on repost integration test

This commit is contained in:
Ilyaaaaaaaaaaaaa Zhitomirskiy 2011-07-19 18:17:08 -07:00 committed by Raphael Sofaer
parent 70be713b15
commit 537766d0d7
4 changed files with 73 additions and 5 deletions

View file

@ -59,7 +59,7 @@ class Reshare < Post
end end
def root_must_be_public def root_must_be_public
if self.root.nil? || !self.root.public if !self.root.public
errors[:base] << "you must reshare public posts" errors[:base] << "you must reshare public posts"
return false return false
end end

View file

@ -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

View file

@ -1,7 +1,6 @@
#This is a spec for the class that runs the servers used in the other multi-server specs #This is a spec for the class that runs the servers used in the other multi-server specs
require 'spec_helper' require 'spec_helper'
WebMock::Config.instance.allow_localhost = true
unless Server.all.empty? unless Server.all.empty?
describe Server do describe Server do
before(:all) do before(:all) do
@ -57,4 +56,3 @@ unless Server.all.empty?
end end
end end
end end
WebMock::Config.instance.allow_localhost = false

View file

@ -62,8 +62,11 @@ class Server
def db def db
former_env = Rails.env former_env = Rails.env
ActiveRecord::Base.establish_connection(env) ActiveRecord::Base.establish_connection(env)
result = yield begin
ActiveRecord::Base.establish_connection(former_env) result = yield
ensure
ActiveRecord::Base.establish_connection(former_env)
end
result result
end end
@ -72,4 +75,19 @@ class Server
DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.clean_with(:truncation)
end end
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 end