aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-10-29 22:07:13 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-10-29 22:09:23 -0200
commit67417f18215349cad990b1230ecf591b5509d557 (patch)
treeee103f76c6d5ea0c380986ab666d295346164828 /railties
parent8941831733fc56e2b1872f41c85cc48d782bb984 (diff)
downloadrails-67417f18215349cad990b1230ecf591b5509d557.tar.gz
rails-67417f18215349cad990b1230ecf591b5509d557.tar.bz2
rails-67417f18215349cad990b1230ecf591b5509d557.zip
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.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/app_base.rb33
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/Gemfile2
-rw-r--r--railties/test/generators/app_generator_test.rb12
4 files changed, 32 insertions, 17 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 0f44f4694e..56c9d3e354 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -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
diff --git a/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec
index f8ece4fe73..ff242adbab 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec
+++ b/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec
@@ -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
diff --git a/railties/lib/rails/generators/rails/plugin/templates/Gemfile b/railties/lib/rails/generators/rails/plugin/templates/Gemfile
index 2c91c6a0ea..f085a2577a 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/plugin/templates/Gemfile
@@ -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
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index e5f10a89d3..446fef562b 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -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