Start Adding jdbcmysql support to new rails template.

More will come for jruby app.
This commit is contained in:
Arun Agrawal 2011-04-22 23:07:46 +05:30
parent eb599295db
commit 6cea2436d7
3 changed files with 39 additions and 2 deletions

View File

@ -9,7 +9,7 @@ require 'uri'
module Rails
module Generators
class AppBase < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db jdbcmysql )
JAVASCRIPTS = %w( jquery prototype )
attr_accessor :rails_template
@ -156,12 +156,13 @@ module Rails
end
def gem_for_database
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db jdbcmysql)
case options[:database]
when "oracle" then "ruby-oci8"
when "postgresql" then "pg"
when "frontbase" then "ruby-frontbase"
when "mysql" then "mysql2"
when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
else options[:database]
end
end

View File

@ -0,0 +1,30 @@
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install activerecord-jdbcmysql-adapter
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: jdbcmysql
database: <%= app_name %>_development
username: root
password:
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: jdbcmysql
database: <%= app_name %>_test
username: root
password:
host: localhost
production:
adapter: jdbcmysql
database: <%= app_name %>_production
username: root
password:
host: localhost

View File

@ -131,6 +131,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_file "Gemfile", /^gem\s+["']mysql2["']$/
end
def test_config_jdbcmysql_database
run_generator([destination_root, "-d", "jdbcmysql"])
assert_file "config/database.yml", /jdbcmysql/
assert_file "Gemfile", /^gem\s+["']activerecord-jdbcmysql-adapter["']$/
end
def test_generator_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"]
assert_no_file "config/database.yml"