diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 573b63567..e3aea84cb 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -6,7 +6,7 @@ require 'uri' class AppConfig < Settingslogic def self.source_file_name - if Rails.env == 'test' || ENV["CI"] + if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration") File.join(Rails.root, "config", "application.yml.example") else File.join(Rails.root, "config", "application.yml") diff --git a/app/models/retraction.rb b/app/models/retraction.rb index e0f3ce63d..8b95aae7d 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -15,6 +15,8 @@ class Retraction def subscribers(user) unless self.type == 'Person' @subscribers ||= self.object.subscribers(user) + @subscribers -= self.object.resharers + @subscribers else raise 'HAX: you must set the subscribers manaully before unfriending' if @subscribers.nil? @subscribers diff --git a/config/application.yml.example b/config/application.yml.example index 0be3aa125..ea01833be 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -154,3 +154,10 @@ test: open_invitations: false +integration_1: + <<: *defaults + pod_url: "http://localhost:45789" + +integration_2: + <<: *defaults + pod_url: "http://localhost:34658" diff --git a/features/step_definitions/oauth_steps.rb b/features/step_definitions/oauth_steps.rb index c8df986db..a14d83db7 100644 --- a/features/step_definitions/oauth_steps.rb +++ b/features/step_definitions/oauth_steps.rb @@ -59,7 +59,7 @@ class Chubbies def self.run @pid = fork do - Process.exec "cd #{Rails.root}/spec/chubbies/ && bundle exec rackup -p #{PORT} 2> /dev/null 1> /dev/null" + Process.exec "cd #{Rails.root}/spec/chubbies/ && bundle exec #{run_command} #{nullify}" end at_exit do @@ -94,9 +94,13 @@ class Chubbies end end + def self.run_command + "rackup -p #{PORT}" + end + def self.get_pid @pid ||= lambda { - processes = `ps ax -o pid,command | grep "rackup -p #{PORT}"`.split("\n") + processes = `ps ax -o pid,command | grep "#{run_command}"`.split("\n") processes = processes.select{|p| !p.include?("grep") } processes.first.split(" ").first }.call diff --git a/spec/multi_server/server_spec.rb b/spec/multi_server/server_spec.rb index a5b5e364a..a600bce2e 100644 --- a/spec/multi_server/server_spec.rb +++ b/spec/multi_server/server_spec.rb @@ -2,13 +2,18 @@ require 'spec_helper' WebMock::Config.instance.allow_localhost = true -if Server.all && Server.all.first && Server.all.first.running? +unless Server.all.empty? describe Server 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 @@ -25,12 +30,12 @@ if Server.all && Server.all.first && Server.all.first.running? it 'takes an environment' do server = Server.new("integration_1") server.env.should == "integration_1" - server.port.should == ActiveRecord::Base.configurations["integration_1"]["app_server_port"] end end describe "#running?" do it "verifies that the server is running" do - Server.new("integration_1").running?.should be_true + server = Server.new("integration_1") + server.running?.should be_true end end describe '#db' do diff --git a/spec/support/server.rb b/spec/support/server.rb index 0b6d4cd78..0a848955a 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -8,11 +8,48 @@ class Server attr_reader :port, :env def initialize(env) - @config = ActiveRecord::Base.configurations[env] - @port = @config["app_server_port"] + @db_config = ActiveRecord::Base.configurations[env] + @app_config = (YAML.load_file AppConfig.source)[env] + @port = URI::parse(@app_config["pod_url"]).port @env = env + ensure_database_setup end + def ensure_database_setup + `cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec rake db:create` + tables_exist = self.db do + ActiveRecord::Base.connection.tables.include?("users") + end + if tables_exist + truncate_database + else + `cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec rake db:schema:load` + end + end + + def run + @pid = fork do + Process.exec "cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec #{run_command}" + end + end + + def kill + puts "I am trying to kill the server" + `kill -9 #{get_pid}` + end + + def run_command + "rails s thin -p #{@port}" + end + + def get_pid + @pid = lambda { + processes = `ps ax -o pid,command | grep "#{run_command}"`.split("\n") + processes = processes.select{|p| !p.include?("grep") } + processes.first.split(" ").first + }.call + end + def running? begin RestClient.get("localhost:#{@port}/users/sign_in") @@ -25,8 +62,9 @@ class Server def db former_env = Rails.env ActiveRecord::Base.establish_connection(env) - yield + result = yield ActiveRecord::Base.establish_connection(former_env) + result end def truncate_database