mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #13629 from dmathieu/drop_test
Be more explicit about the default of db:drop and db:create
This commit is contained in:
commit
b502e3db95
5 changed files with 40 additions and 5 deletions
|
@ -1,3 +1,13 @@
|
|||
* Don't create/drop the test database if RAILS_ENV is specified explicitely.
|
||||
|
||||
Previously, when the environment was development, we would always
|
||||
create or drop both the test and development databases.
|
||||
|
||||
Now, if RAILS_ENV is explicitely defined as development, we don't create
|
||||
the test database.
|
||||
|
||||
*Damien Mathieu*
|
||||
|
||||
* Initialize version on Migration objects so that it can be used in a migration,
|
||||
and it will be included in the announce message.
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ db_namespace = namespace :db do
|
|||
end
|
||||
end
|
||||
|
||||
desc 'Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all databases in the config)'
|
||||
desc 'Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV it defaults to creating the development and test databases.'
|
||||
task :create => [:load_config] do
|
||||
ActiveRecord::Tasks::DatabaseTasks.create_current
|
||||
end
|
||||
|
@ -23,7 +23,7 @@ db_namespace = namespace :db do
|
|||
end
|
||||
end
|
||||
|
||||
desc 'Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)'
|
||||
desc 'Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV it defaults to dropping the development and test databases.'
|
||||
task :drop => [:load_config] do
|
||||
ActiveRecord::Tasks::DatabaseTasks.drop_current
|
||||
end
|
||||
|
|
|
@ -201,7 +201,8 @@ module ActiveRecord
|
|||
|
||||
def each_current_configuration(environment)
|
||||
environments = [environment]
|
||||
environments << 'test' if environment == 'development'
|
||||
# add test environment only if no RAILS_ENV was specified.
|
||||
environments << 'test' if environment == 'development' && ENV['RAILS_ENV'].nil?
|
||||
|
||||
configurations = ActiveRecord::Base.configurations.values_at(*environments)
|
||||
configurations.compact.each do |configuration|
|
||||
|
|
|
@ -129,11 +129,22 @@ module ActiveRecord
|
|||
)
|
||||
end
|
||||
|
||||
def test_creates_test_database_when_environment_is_database
|
||||
def test_creates_test_and_development_databases_when_env_was_not_specified
|
||||
ActiveRecord::Tasks::DatabaseTasks.expects(:create).
|
||||
with('database' => 'dev-db')
|
||||
ActiveRecord::Tasks::DatabaseTasks.expects(:create).
|
||||
with('database' => 'test-db')
|
||||
ENV.expects(:[]).with('RAILS_ENV').returns(nil)
|
||||
|
||||
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
||||
ActiveSupport::StringInquirer.new('development')
|
||||
)
|
||||
end
|
||||
|
||||
def test_creates_only_development_database_when_rails_env_is_development
|
||||
ActiveRecord::Tasks::DatabaseTasks.expects(:create).
|
||||
with('database' => 'dev-db')
|
||||
ENV.expects(:[]).with('RAILS_ENV').returns('development')
|
||||
|
||||
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
||||
ActiveSupport::StringInquirer.new('development')
|
||||
|
@ -239,11 +250,22 @@ module ActiveRecord
|
|||
)
|
||||
end
|
||||
|
||||
def test_creates_test_database_when_environment_is_database
|
||||
def test_drops_test_and_development_databases_when_env_was_not_specified
|
||||
ActiveRecord::Tasks::DatabaseTasks.expects(:drop).
|
||||
with('database' => 'dev-db')
|
||||
ActiveRecord::Tasks::DatabaseTasks.expects(:drop).
|
||||
with('database' => 'test-db')
|
||||
ENV.expects(:[]).with('RAILS_ENV').returns(nil)
|
||||
|
||||
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
||||
ActiveSupport::StringInquirer.new('development')
|
||||
)
|
||||
end
|
||||
|
||||
def test_drops_only_development_database_when_rails_env_is_development
|
||||
ActiveRecord::Tasks::DatabaseTasks.expects(:drop).
|
||||
with('database' => 'dev-db')
|
||||
ENV.expects(:[]).with('RAILS_ENV').returns('development')
|
||||
|
||||
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
||||
ActiveSupport::StringInquirer.new('development')
|
||||
|
|
|
@ -498,6 +498,8 @@ for detailed changes.
|
|||
object. Helper methods used by multiple fixtures should be defined on modules
|
||||
included in `ActiveRecord::FixtureSet.context_class`. ([Pull Request](https://github.com/rails/rails/pull/13022))
|
||||
|
||||
* Don't create or drop the test database if RAILS_ENV is specified explicitely.
|
||||
|
||||
Active Model
|
||||
------------
|
||||
|
||||
|
|
Loading…
Reference in a new issue