aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/rake/dbs_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Make sure this test check the issue solved in #31135Rafael Mendonça França2018-09-221-6/+12
| | | | | | | | | | | | | | | Before this change this test was passing even if we revert #31135. The reason for that is that `app 'development'` will load the environment in the test process and it is happening before db_create_and_drop is called. This was not asserting that the environment was loaded in the db:create task itself. To test it we enhance the db:create task with a block that writes to a tmp file the value of the config. If the environment is loaded before that task enhancement runs the content of the file will have "true" insteand of "false".
* Merge pull request #33744 from bogdanvlviv/fixes-27852Ryuta Kamizono2018-08-301-1/+1
|\ | | | | Prevent leaking of user's DB credentials on `rails db:create` failure
| * Prevent leaking of user's DB credentials on `rails db:create` failurebogdanvlviv2018-08-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #27852 reports that when `rails db:create` fails, it causes leaking of user's DB credentials to $stderr. We print a DB's configuration hash in order to help users more quickly to figure out what could be wrong with his configuration. This commit changes message from "Couldn't create database for #{configuration.inspect}" to "Couldn't create '#{configuration['database']}' database. Please check your configuration.". There are two PRs that fixing it #27878, #27879, but they need a bit more work. I decided help to finish this and added Author of those PRs credit in this commit. Since it is a security issue, I think we should backport it to `5-2-stable`, and `5-1-stable`. Guided by https://edgeguides.rubyonrails.org/maintenance_policy.html#security-issues Fixes #27852 Closes #27879 Related to #27878 [Alexander Marrs & bogdanvlviv]
* | Remove this conditionalEileen Uchitelle2018-08-291-1/+1
| | | | | | | | I removed the argument so I should remove the conditional too.
* | Remove unused argumentEileen Uchitelle2018-08-291-1/+1
| | | | | | | | The test that used this was updated and it's no longer needed.
* | Drop load_database_yaml and fix testEileen Uchitelle2018-08-291-3/+7
|/ | | | | | | | | | | | | | | | | | | | | | | | | | We originally did the whole `load_database_yaml` thing because this test wasn't cooperating and we needed to finish the namespaced rake tasks for multiple databases. However, it turns out that YAML can't eval ERB if you don't tell it it's ERB so you get Pysch parse errors if you're using multi-line ERB or ERB with conditionals. It's a hot mess. After trying a few things and thinking it over we decided that it wasn't worth bandaiding over, the test needed to be improved. The test was added in #31135 to test that the env is loaded in these tasks. But it was blowing up because we were trying to read a database name out of the configuration - however that's not the purpose of this change. We want to read environment files in the rake tasks, but not in the config file. In this PR we changed the test to test what the PR was actually fixing. We've also deleted the `load_database_yaml` because it caused more problems than it was worth. This should fix the issues described in https://github.com/rails/rails/pull/32274#issuecomment-384161057. We also had these problems at GitHub. Co-authored-by: alimi <aibrahim2k2@gmail.com>
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-1/+1
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the futureRyuta Kamizono2017-12-141-2/+2
| | | | Follow up of #31432.
* Make `Migrator.current_version` work without a current databaseyuuji.yaginuma2017-12-031-0/+14
| | | | | | | This is necessary in order to make the processing dependent on `Migrator.current_version` work even without database. Context: https://github.com/rails/rails/pull/31135#issuecomment-348404326
* Add `environment` as dependency of `load_config` (#31135)Yuji Yaginuma2017-11-141-2/+18
| | | | | | | | | | | | Currently the environment is not loaded in some db tasks. Therefore, if use encrypted secrets values in `database.yml`, `read_encrypted_secrets` will not be true, so the value can not be used correctly. To fix this, added `environment` as dependency of `load_config`. It also removes explicit `environment` dependencies that are no longer needed. Fixes #30717
* Remove unnecessary migration deletionyuuji.yaginuma2017-11-081-4/+0
| | | | | Since isolation application is generated with the `--skip-gemfile` option, so `active_storage:install` is not executed.
* `rails new` runs `rails active_storage:install`bogdanvlviv2017-11-061-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Omit `rails activestorage:install` for jdbcmysql, jdbc and shebang tests AppGeneratorTest#test_config_jdbcmysql_database rails aborted! LoadError: Could not load 'active_record/connection_adapters/mysql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (compressed) bin/rails:4:in `<main>' Tasks: TOP => activestorage:install => environment (See full trace by running task with --trace) AppGeneratorTest#test_config_jdbc_database rails aborted! LoadError: Could not load 'active_record/connection_adapters/jdbc_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (compressed) bin/rails:4:in `<main>' Tasks: TOP => activestorage:install => environment (See full trace by running task with --trace) AppGeneratorTest#test_shebang_is_added_to_rails_file /home/ubuntu/.rbenv/versions/2.4.1/bin/ruby: no Ruby script found in input (LoadError) Prevent PendingMigrationError in tests * Run `bin/rails db:migrate RAILS_ENV=test` in test_cases before start tests to prevent PendingMigrationError * FileUtils.rm_r("db/migrate") * --skip-active-storage Fix failed tests in `railties/test/railties/engine_test.rb` Related to #30111 Imporve `SharedGeneratorTests#test_default_frameworks_are_required_when_others_are_removed` - Explicitly skip active_storage - Ensure that skipped frameworks are commented - Ensure that default frameworks are not commented Fix error `Errno::ENOSPC: No space left on device - sendfile` Since `rails new` runs `rails active_storage:install` that boots an app. Since adding Bootsnap 0312a5c67e35b960e33677b5358c539f1047e4e1 during booting an app, it creates the cache: 264K tmp/cache/bootsnap-load-path-cache 27M tmp/cache/bootsnap-compile-cache * teardown_app must remove app
* `ActiveRecord::Tasks::DatabaseTasks.load_schema` has always to establish ↵bogdanvlviv2017-10-151-0/+8
| | | | | | | | | | | | database connection When load schema from `structure.sql`, database connection isn't established. `ActiveRecord::Tasks::DatabaseTasks.load_schema` has to establish database connection since it executes ``` ActiveRecord::InternalMetadata.create_table ActiveRecord::InternalMetadata[:environment] = environment ```
* Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong ↵bogdanvlviv2017-10-151-0/+39
| | | | | | | | | | | | | | | | | | | | | | ar_internal_metadata's data for a test database. Before: ``` $ RAILS_ENV=test rails dbconsole > SELECT * FROM ar_internal_metadata; key|value|created_at|updated_at environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679 ``` After: ``` $ RAILS_ENV=test rails dbconsole > SELECT * FROM ar_internal_metadata; key|value|created_at|updated_at environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679 ``` Fixes #26731.
* Remove redundant execution of `Dir.chdir(app_path) { }` in railties' testsbogdanvlviv2017-10-081-59/+48
|
* Run in-app rails commands via fork+load where possibleMatthew Draper2017-09-041-44/+38
| | | | | While this avoids shell argument parsing, we still pass through everything in our stack.
* Adding frozen_string_literal pragma to Railties.Pat Allan2017-08-141-0/+2
|
* Fix `warning: ambiguous first argument`yuuji.yaginuma2017-07-251-1/+1
| | | | | | | | This fixes the following warning: ``` railties/test/application/rake/dbs_test.rb:265: warning: ambiguous first argument; put parentheses or a space even after `/' operator ```
* Avoid modifying frozen string in check_schema_fileEugene Kenny2017-07-231-0/+7
| | | | | | This was missed when the frozen string literal pragma was added to this file because the string is only modified when running in the context of a full Rails app, which wasn't covered by the test suite.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Remove unused requireRyuta Kamizono2017-02-121-1/+0
| | | | | | These files are not using `strip_heredoc`. Closes #27976
* update CREATE TABLE statements generated by `sqlite3` commandyuuji.yaginuma2017-01-191-2/+2
| | | | | | | From SQLite 3.16.0, `IF NOT EXISTS` set to CREATE TABLE statements. Ref: https://www.sqlite.org/src/info/c7021960f5c070fb Fixes #27635.
* applies new string literal convention in railties/testXavier Noria2016-08-061-32/+32
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Remove unused boot_rails method and it's usagePrathamesh Sonpatki2016-07-041-1/+0
| | | | | - The `boot_rails` method from abstract_unit.rb is empty after 2abcdfd978fdcd491576a237e8c6b. - So let's remove it and its usage.
* Fixed assertions with regex used in dbs testsVipul A M2016-04-191-2/+2
|
* Added notice when a database is successfully created or dropped.bogdanvlviv2016-04-171-2/+2
|
* Shorten ActiveRecord::InternalMetadata.table_name to ar_internal_metadataYasuo Honda2016-02-011-2/+2
| | | | to support Oracle database which only supports 30 byte identifier length
* Be consistent in testing outputs from railties test and use /bin/rails ↵Vipul A M2016-01-241-21/+21
| | | | | | everywhere(the default behaviour now) instead of mix of /bin/rake /bin/rails everywhere [Ryo Hashimoto & Vipul A M]
* Fixing tests and re-locating error checking.schneems2016-01-081-2/+2
|
* Prevent destructive action on production databaseschneems2016-01-071-3/+3
| | | | | | | This PR introduces a key/value type store to Active Record that can be used for storing internal values. It is an alternative implementation to #21237 cc @sgrif @matthewd. It is possible to run your tests against your production database by accident right now. While infrequently, but as an anecdotal data point, Heroku receives a non-trivial number of requests for a database restore due to this happening. In these cases the loss can be large. To prevent against running tests against production we can store the "environment" version that was used when migrating the database in a new internal table. Before executing tests we can see if the database is a listed in `protected_environments` and abort. There is a manual escape valve to force this check from happening with environment variable `DISABLE_DATABASE_ENVIRONMENT_CHECK=1`.
* Remove warningsRafael Mendonça França2015-12-041-4/+4
|
* Exit with non-zero status when db:drop failsJay Hayes2015-10-201-0/+10
| | | | | | | | | | | * If the drop task fails for a reason other than the database not existing, processing should end. This is indicated by a non-zero exit status. * Since the backtrace is already printed to screen, we forgo printing it again by using an explicit call to `exit`. * :warning: This modifies the behavior of the db:create task slightly in that the stack trace is no longer printed by default. If the `--trace` option is used, it will print the trace _after_ the error message.
* Exit with non-zero status when db:create failsJay Hayes2015-10-201-0/+17
| | | | | | | | | | | * If the create task fails for a reason other than the database already existing, processing should end. This is indicated by a non-zero exit status. * Since the backtrace is already printed to screen, we forgo printing it again by using an explicit call to `exit`. * :warning: This modifies the behavior of the db:create task slightly in that the stack trace is no longer printed by default. If the `--trace` option is used, it will print the trace _after_ the error message.
* Fix test of drop failureJay Hayes2015-10-201-4/+1
| | | | | | | * Previously the sqlite3 adapter could not "fail" on drop. Now an error is raised when no file exists. * Also updates purge to be resilient of drop failures. This is how purge is expected to behave.
* Add tests to verify exit status for create/drop failuresJay Hayes2015-10-201-0/+28
| | | | | | | | | | * Running the db:create task when the database already exists isn't really an error case. That is processing may proceed in this case because the database exists as requested. So let's validate that behavior with a test. * Likewise, if the database doesn't exist when running the db:drop task processing may continue as the requested condition is already met. Thus a test.
* tests, railties tests should use `bin/` executables when possible.Yves Senn2015-06-301-19/+19
| | | | | We recommend using the `bin/` executables in our docs and guides. Let's make sure that our tests execute the same code path.
* Revert "Merge pull request #17920 from ↵Yves Senn2015-04-271-0/+28
| | | | | | | | | | | | | | | calebthompson/dont-rely-on-environment-task-for-schema-load" This reverts commit 08ff4ccbbb3fb143a02e6752efb974a4bcfcd3bb, reversing changes made to 6c9ed6dbc62450cdb87559afd15798305e069146. Caused by #17920. Closes #19545. This patch introduced regressions because initializers were no longer loaded. Specifically missing inflections result in broken restores of the database.
* Revert "Merge pull request #19404 from dmathieu/remove_rack_env"Jeremy Kemper2015-03-201-0/+3
| | | | | | | Preserving RACK_ENV behavior. This reverts commit 7bdc7635b885e473f6a577264fd8efad1c02174f, reversing changes made to 45786be516e13d55a1fca9a4abaddd5781209103.
* don't fallback to RACK_ENV when RAILS_ENV is not presentDamien Mathieu2015-03-191-3/+0
|
* `db:structure:load` and `db:schema:load` no longer purge the database.Yves Senn2014-12-181-0/+25
| | | | | | | | | | | | | | | | | Closes #17945 `db:test:prepare` still purges the database to always keep the test database in a consistent state. This patch introduces new problems with `db:schema:load`. Prior to the introduction of foreign-keys, we could run this file against a non-empty database. Since every `create_table` containted the `force: true` option, this would recreate tables when loading the schema. However with foreign-keys in place, `force: true` wont work anymore and the task will crash. /cc @schneems
* bring back `db:test:prepare`.Yves Senn2014-11-251-9/+0
| | | | | | | | | | | | | | | This reverts deprecations added in #13528. The task is brought back for two reasons: 1. Give plugins a way to hook into the test database initialization process 2. Give the user a way to force a test database synchronization While `test:prepare` is still a dependency of every test task, `db:test:prepare` no longer hooks into it. This means that `test:prepare` runs before the schema is synchronized. Plugins, which insert data can now hook into `db:test:prepare`. The automatic schema maintenance can't detect when a migration is rolled-back, modified and reapplied. In this case the user has to fall back to `db:test:prepare` to force the synchronization to happen.
* Revert "Replace String index juggling with Pathname goodness in ↵yuuji.yaginuma2014-11-021-0/+10
| | | | | | | | db:fixtures:load" This reverts commit 482fdad5ef8a73688b50bba3991dd4ef6f286edd. Fixes #17237.
* build fix, we have to reset the RACK_ENV as well.Yves Senn2014-09-041-2/+5
| | | | | This is a follow-up to ded17a4 to get the build passing on Travis. As Travis has `ENV["RACK_ENV"]` set to `test` we need to reset that as well.
* schema loading rake tasks maintain database connection for current env.Yves Senn2014-09-031-0/+26
| | | | | | | | | | [Joshua Cody & Yves Senn] Closes #16757. Prior to this patch schema loading rake tasks had the potential to leak a connection to a different database. This had side-effects when rake tasks operating on the current connection (like `db:seed`) were chained.
* Revise 'sqlite3:' URL handling for smoother upgradesMatthew Draper2014-04-031-2/+2
| | | | | | | | | | | | | | | | Restore the 4.0 behaviour for 'sqlite3:///', but deprecate it. We'll change to the absolute-path interpretation in 4.2. The current "correct" spellings for in-memory, relative, and absolute URLs, respectively, are: sqlite3::memory: sqlite3:relative/path sqlite3:/full/path Substantially reverses/defers fbb79b517f3127ba620fedd01849f9628b78d6ce. Uncovered by @guilleiguaran while investigating #14495, though that sounds like a different issue.
* test for structure:dump without schema information table. refs eafec46Yves Senn2014-03-201-0/+12
| | | | This is a test case for the fix provided in eafec4694c5b37eff9d83b1188b8e331fa6027fa
* Remove some indirection in rake dbs testCarlos Antonio da Silva2014-03-201-34/+20
| | | | | Just pass in the expected database as argument rather than "caching" it in a hash and using the hash in the helper methods.
* Check if the output is empty rather than asserting for equalityCarlos Antonio da Silva2014-03-201-5/+4
| | | | Also fix indent of test block.
* Fix assertionsCarlos Antonio da Silva2014-03-161-2/+2
|