mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
8941831733
commit
67417f1821
4 changed files with 32 additions and 17 deletions
|
@ -162,7 +162,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
|
||||
|
||||
|
@ -202,6 +203,16 @@ module Rails
|
|||
def self.path(name, path, comment = nil)
|
||||
new(name, nil, comment, path: path)
|
||||
end
|
||||
|
||||
def version
|
||||
version = super
|
||||
|
||||
if version.is_a?(Array)
|
||||
version.join("', '")
|
||||
else
|
||||
version
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def rails_gemfile_entry
|
||||
|
@ -230,16 +241,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.18"]]
|
||||
when "frontbase" then ["ruby-frontbase", nil]
|
||||
when "mysql" then ["mysql2", [">= 0.3.18", "< 0.5"]]
|
||||
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
|
||||
|
|
|
@ -264,7 +264,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
if defined?(JRUBY_VERSION)
|
||||
assert_gem "activerecord-jdbcmysql-adapter"
|
||||
else
|
||||
assert_gem "mysql2"
|
||||
assert_gem "mysql2", "'>= 0.3.18', '< 0.5'"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -279,7 +279,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
if defined?(JRUBY_VERSION)
|
||||
assert_gem "activerecord-jdbcpostgresql-adapter"
|
||||
else
|
||||
assert_gem "pg"
|
||||
assert_gem "pg", "'~> 0.18'"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -686,7 +686,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
capture(:stdout) { generator.send(*args, &block) }
|
||||
end
|
||||
|
||||
def assert_gem(gem)
|
||||
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
|
||||
def assert_gem(gem, constraint = nil)
|
||||
if constraint
|
||||
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
|
||||
else
|
||||
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue