mirror of https://github.com/rails/rails
Add version constraint to database gem in generated application
We are using the same version constraint in the database adapters so when a new version of the adapter that doesn't work with the version of rails is released we don't break new applications.
This commit is contained in:
parent
233091c0ec
commit
d0b60f3cd8
|
@ -160,7 +160,8 @@ module Rails
|
|||
|
||||
def database_gemfile_entry
|
||||
return [] if options[:skip_active_record]
|
||||
GemfileEntry.version gem_for_database, nil,
|
||||
gem_name, gem_version = gem_for_database
|
||||
GemfileEntry.version gem_name, gem_version,
|
||||
"Use #{options[:database]} as the database for Active Record"
|
||||
end
|
||||
|
||||
|
@ -196,6 +197,16 @@ module Rails
|
|||
def padding(max_width)
|
||||
' ' * (max_width - name.length + 2)
|
||||
end
|
||||
|
||||
def version
|
||||
version = super
|
||||
|
||||
if version.is_a?(Array)
|
||||
version.join("', '")
|
||||
else
|
||||
version
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def rails_gemfile_entry
|
||||
|
@ -214,16 +225,16 @@ module Rails
|
|||
def gem_for_database
|
||||
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
|
||||
case options[:database]
|
||||
when "oracle" then "ruby-oci8"
|
||||
when "postgresql" then "pg"
|
||||
when "frontbase" then "ruby-frontbase"
|
||||
when "mysql" then "mysql2"
|
||||
when "sqlserver" then "activerecord-sqlserver-adapter"
|
||||
when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
|
||||
when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
|
||||
when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
|
||||
when "jdbc" then "activerecord-jdbc-adapter"
|
||||
else options[:database]
|
||||
when "oracle" then ["ruby-oci8", nil]
|
||||
when "postgresql" then ["pg", ["~> 0.11"]]
|
||||
when "frontbase" then ["ruby-frontbase", nil]
|
||||
when "mysql" then ["mysql2", ["~> 0.3.13"]]
|
||||
when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
|
||||
when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
|
||||
when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
|
||||
when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
|
||||
when "jdbc" then ["activerecord-jdbc-adapter", nil]
|
||||
else [options[:database], nil]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,6 +22,6 @@ Gem::Specification.new do |s|
|
|||
<%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
|
||||
<% unless options[:skip_active_record] -%>
|
||||
|
||||
s.add_development_dependency "<%= gem_for_database %>"
|
||||
s.add_development_dependency "<%= gem_for_database[0] %>"
|
||||
<% end -%>
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ gemspec
|
|||
|
||||
<% if options[:skip_gemspec] -%>
|
||||
group :development do
|
||||
gem "<%= gem_for_database %>"
|
||||
gem "<%= gem_for_database[0] %>"
|
||||
end
|
||||
<% else -%>
|
||||
# Declare any dependencies that are still in development here instead of in
|
||||
|
|
|
@ -203,7 +203,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
run_generator([destination_root, "-d", "mysql"])
|
||||
assert_file "config/database.yml", /mysql/
|
||||
unless defined?(JRUBY_VERSION)
|
||||
assert_gem "mysql2"
|
||||
assert_gem "mysql2", "'~> 0.3.13'"
|
||||
else
|
||||
assert_gem "activerecord-jdbcmysql-adapter"
|
||||
end
|
||||
|
@ -218,7 +218,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
run_generator([destination_root, "-d", "postgresql"])
|
||||
assert_file "config/database.yml", /postgresql/
|
||||
unless defined?(JRUBY_VERSION)
|
||||
assert_gem "pg"
|
||||
assert_gem "pg", "'~> 0.11'"
|
||||
else
|
||||
assert_gem "activerecord-jdbcpostgresql-adapter"
|
||||
end
|
||||
|
@ -450,7 +450,11 @@ protected
|
|||
silence(:stdout) { generator.send(*args, &block) }
|
||||
end
|
||||
|
||||
def assert_gem(gem)
|
||||
assert_file "Gemfile", /^gem\s+["']#{gem}["']$/
|
||||
def assert_gem(gem, constraint = nil)
|
||||
if constraint
|
||||
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
|
||||
else
|
||||
assert_file "Gemfile", /^gem\s+["']#{gem}["']$/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue