Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed test suite to work with RACK_ENV=test

  • Loading branch information...
commit 100f7c6103e9c58612804cb8a11056a5d58bc51e 1 parent c046fea
Assaf Arkin assaf authored
1  .travis.yml
View
@@ -8,6 +8,7 @@ env:
- DB=redis
before_script:
- "mysql -e 'create database vanity_test;' >/dev/null"
+- "psql -c 'create database vanity_test;' -U postgres >/dev/null"
notifications:
recipients:
- assaf@labnotes.org
1  Gemfile
View
@@ -16,6 +16,7 @@ group :test do
gem "bson_ext"
gem "mysql"
gem "passenger", "~>2.0"
+ gem "postgres"
gem "rails", "~>2.3.8"
gem "rack"
gem "shoulda"
19 test/rails_test.rb
View
@@ -207,8 +207,7 @@ def test_mongo_connection_from_yaml
YML
end
- ENV["RAILS_ENV"] = "mongodb"
- assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB)
+ assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB, "mongodb")
initializer.after_initialize
$stdout << Vanity.playground.connection
RB
@@ -229,14 +228,12 @@ def test_mongodb_replica_set_connection
YML
end
- ENV["RAILS_ENV"] = "mongodb"
- assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB)
+ assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB, "mongodb")
initializer.after_initialize
$stdout << Vanity.playground.connection
RB
- ENV["RAILS_ENV"] = "mongodb"
- assert_equal "Mongo::ReplSetConnection", load_rails(<<-RB)
+ assert_equal "Mongo::ReplSetConnection", load_rails(<<-RB, "mongodb")
initializer.after_initialize
$stdout << Vanity.playground.connection.mongo.class
RB
@@ -262,14 +259,13 @@ def test_connection_from_yaml_url
def test_connection_from_yaml_missing
FileUtils.mkpath "tmp/config"
- ENV["RAILS_ENV"] = "development"
File.open("tmp/config/vanity.yml", "w") do |io|
io.write <<-YML
production:
adapter: redis
YML
end
- assert_equal "No configuration for development", load_rails(<<-RB)
+ assert_equal "No configuration for development", load_rails(<<-RB, "development")
initializer.after_initialize
$stdout << (Vanity.playground.connection rescue $!.message)
RB
@@ -298,7 +294,7 @@ def test_connection_from_yaml_with_erb
def test_connection_from_redis_yml
FileUtils.mkpath "tmp/config"
yml = File.open("tmp/config/redis.yml", "w")
- yml << "development: internal.local:6379\n"
+ yml << "production: internal.local:6379\n"
yml.flush
assert_equal "redis://internal.local:6379/0", load_rails(<<-RB)
initializer.after_initialize
@@ -310,10 +306,9 @@ def test_connection_from_redis_yml
def test_collection_from_vanity_yaml
FileUtils.mkpath "tmp/config"
- ENV["RAILS_ENV"] = "development"
File.open("tmp/config/vanity.yml", "w") do |io|
io.write <<-YML
-development:
+production:
collecting: false
YML
end
@@ -369,7 +364,7 @@ def load_rails(code, env = "production")
$:.delete_if { |path| path[/gems\\/vanity-\\d/] }
$:.unshift File.expand_path("../lib")
RAILS_ROOT = File.expand_path(".")
-RAILS_ENV = "#{env}"
+RAILS_ENV = ENV['RACK_ENV'] = "#{env}"
require "initializer"
require "active_support"
Rails.configuration = Rails::Configuration.new
9 test/test_helper.rb
View
@@ -1,5 +1,6 @@
$LOAD_PATH.delete_if { |path| path[/gems\/vanity-\d/] }
$LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
+ENV["RACK_ENV"] = "test"
RAILS_ROOT = File.expand_path("..")
require "test/unit"
@@ -48,9 +49,11 @@ def new_playground
"redis"=>"redis://localhost/15",
"mongodb"=>"mongodb://localhost/vanity",
"mysql"=> { "adapter"=>"active_record", "active_record_adapter"=>"mysql", "database"=>"vanity_test" },
+ "postgres"=> { "adapter"=>"active_record", "active_record_adapter"=>"postgresql", "database"=>"vanity_test", "username"=>"postgres" },
"mock"=>"mock:/"
}[adapter]
raise "No support yet for #{adapter}" unless spec
+
Vanity.playground = Vanity::Playground.new(:logger=>$logger, :load_path=>"tmp/experiments")
Vanity.playground.establish_connection spec
end
@@ -105,6 +108,12 @@ def teardown
ActiveRecord::Base.logger = $logger
ActiveRecord::Base.establish_connection :adapter=>"mysql", :database=>"vanity_test"
+if ENV["DB"] == "mysql" || ENV["DB"] == "postgres"
+ require "generators/templates/vanity_migration"
+ VanityMigration.down rescue nil
+ VanityMigration.up
+end
+
class Array
# Not in Ruby 1.8.6.
Please sign in to comment.
Something went wrong with that request. Please try again.