Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify and align test setup with travis-ci.org

  • Loading branch information...
commit 69936ec63d3199d9c0ebf6c237fa5fdfdc0a8ff5 1 parent 9a7842d
@boosty boosty authored
View
1  .gitignore
@@ -1,5 +1,4 @@
test/debug.log
-test/flag_shih_tzu_plugin.sqlite3.db
coverage
.idea
.idea/*
View
7 .travis.yml
@@ -5,3 +5,10 @@ gemfile:
- gemfiles/Gemfile.activerecord-2.3.x
- gemfiles/Gemfile.activerecord-3.0.x
- gemfiles/Gemfile.activerecord-3.1.x
+env:
+ - DB=sqlite
+ - DB=mysql
+ - DB=postgres
+before_script:
+ - "mysql -e 'create database flag_shih_tzu_test;'"
+ - "psql -c 'create database flag_shih_tzu_test;' -U postgres"
View
20 README.rdoc
@@ -233,10 +233,14 @@ The drawback is that due to the bit operator, this query can not use an index
on the flags column.
-==Running the tests
+==Running the gem tests
+
+First, make sure all required gems are installed:
+
+ $ bundle install
The default rake test task will run the tests against the currently locked
-ActiveRecord version (see Gemfile.lock):
+ActiveRecord version (see +Gemfile.lock+):
$ bundle exec rake test
@@ -244,16 +248,16 @@ If you want to run the tests against all supported ActiveRecord versions:
$ bundle exec rake test:all
-This task will use bundler to load specific ActiveRecord versions before
-executing the tests (see gemfiles/), e.g.:
+This will internally use bundler to load specific ActiveRecord versions
+before executing the tests (see +gemfiles/+), e.g.:
$ BUNDLE_GEMFILE='gemfiles/Gemfile.activerecord-3.1.x' bundle exec rake test
-All tests will use the sqlite3 database adapter by default.
-If you want to use a different database, modify <tt>test/database.yml</tt>
-to fit your environment. Then you can use the DB environment variable
-to specify which config from <tt>test/database.yml</tt> to use, e.g.:
+All tests will use an in-memory sqlite database by default.
+If you want to use a different database, see <tt>test/database.yml</tt>
+and use the DB environment variable to specify which config from
+<tt>test/database.yml</tt> to use, e.g.:
$ DB=mysql bundle exec rake
View
2  lib/flag_shih_tzu.rb
@@ -1,3 +1,5 @@
+require "rubygems"
+require "active_record"
require "active_support/all"
module FlagShihTzu
View
20 test/database.yml
@@ -1,17 +1,13 @@
-sqlite3:
+sqlite:
adapter: sqlite3
- database: test/flag_shih_tzu_plugin.sqlite3.db
-
+ database: ":memory:"
+ timeout: 500
mysql:
adapter: mysql2
- host: localhost
- username: root
- password:
- database: flag_shih_tzu_plugin_test
-
-postgresql:
+ database: flag_shih_tzu_test
+ username:
+ encoding: utf8
+postgres:
adapter: postgresql
+ database: myapp_test
username: postgres
- password:
- database: flag_shih_tzu_plugin_test
- min_messages: ERROR
View
3  test/flag_shih_tzu_test.rb
@@ -1,5 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
-load_schema
class Spaceship < ActiveRecord::Base
set_table_name 'spaceships'
@@ -54,7 +53,7 @@ class Planet < ActiveRecord::Base
end
class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
-
+
def setup
Spaceship.destroy_all
end
View
40 test/test_helper.rb
@@ -1,34 +1,14 @@
-ENV['RAILS_ENV'] = 'test'
-ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
+require "test/unit"
+require "yaml"
+require "logger"
+require "flag_shih_tzu"
-#exend LOAD_PATH for test with- and without Railsframework
-$LOAD_PATH << 'lib/'
-$LOAD_PATH << 'vendor/plugins/flag_shih_tzu/lib/'
+ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
-require 'test/unit'
-require 'yaml'
-require 'logger'
-require 'rubygems'
-require 'active_record'
-require 'flag_shih_tzu'
+configs = YAML.load_file('test/database.yml')
+ActiveRecord::Base.configurations = configs
-def load_schema
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
- db_adapter = ENV['DB'] || 'sqlite3'
+db_name = ENV['DB'] || 'sqlite'
+ActiveRecord::Base.establish_connection(db_name)
- # no DB passed, try sqlite3 by default
- db_adapter ||=
- begin
- require 'sqlite3'
- 'sqlite3'
- rescue MissingSourceFile
- end
-
- if db_adapter.nil?
- raise "No DB Adapter selected. Configure test/database.yml and use DB=mysql|postgresql|sqlite3 to pick one. sqlite3 will be used by default (gem install sqlite3)."
- end
-
- ActiveRecord::Base.establish_connection(config[db_adapter])
- load(File.dirname(__FILE__) + "/schema.rb")
-end
+load(File.dirname(__FILE__) + "/schema.rb")
Please sign in to comment.
Something went wrong with that request. Please try again.