Commit Graph

95 Commits

Author SHA1 Message Date
Yasuo Honda
a374af8b57 Shorten ActiveRecord::InternalMetadata.table_name to ar_internal_metadata
to support Oracle database which only supports 30 byte identifier length
2016-02-01 15:41:37 +00:00
Vipul A M
e3b04447f4 Be consistent in testing outputs from railties test and use /bin/rails everywhere(the default behaviour now) instead of mix of /bin/rake /bin/rails everywhere
[Ryo Hashimoto & Vipul A M]
2016-01-24 20:01:02 +05:30
schneems
d70c68d76a Fixing tests and re-locating error checking. 2016-01-08 14:05:20 -06:00
schneems
900bfd94a9 Prevent destructive action on production database
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`.
2016-01-07 18:01:05 -06:00
Matthew Draper
a6d4e5e532 Internal test migrations use the private 'Current' version
Apart from specific versioning support, our tests should focus on the
behaviour of whatever version they're accompanying, regardless of when
they were written.

Application code should *not* do this.
2015-12-15 17:18:09 +10:30
Chuck Callebs
2ddb599710 Add Rails command infrastructure and encapsulate development caching 2015-12-04 13:15:43 -05:00
Rafael Mendonça França
640a300d17 Remove warnings 2015-12-04 00:00:10 -02:00
yui-knk
a7beeb7faa Make db:migrate:status to render 1_some.rb format migrate files.
`1_valid_people_have_last_names.rb` and
`20150823202140_create_users.rb` are valid migration file name.
But `1_valid_people_have_last_names.rb` is rendered as
`********** NO FILE **********` when `rake db:migrate:status`.

Fix to this bug, this commit includes

* define some API private methdos and a Constant
  `match_to_migration_filename?`, `parse_migration_filename`, and
  `MigrationFilenameRegexp`
* use these methods in `db:migrate:status` task

Example:

These files are in `db/migrate`

* 1_valid_people_have_last_names.rb
* 20150819202140_irreversible_migration.rb
* 20150823202140_add_admin_flag_to_users.rb
* 20150823202141_migration_tests.rb
* 2_we_need_reminders.rb
* 3_innocent_jointable.rb

we can migrate all of them.

Before

```shell
$ bundle exec rake db:migrate:status

...

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     001             ********** NO FILE **********
   up     002             ********** NO FILE **********
   up     003             ********** NO FILE **********
   up     20150819202140  Irreversible migration
   up     20150823202140  Add admin flag to users
   up     20150823202141  Migration tests
```

After

```shell
$ bundle exec rake db:migrate:status

...

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     001             Valid people have last names
   up     002             We need reminders
   up     003             Innocent jointable
   up     20150819202140  Irreversible migration
   up     20150823202140  Add admin flag to users
   up     20150823202141  Migration tests
```
2015-11-02 23:06:57 +09:00
Jay Hayes
c2e597a736 Exit with non-zero status when db:drop fails
* 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`.
* ⚠️ 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.
2015-10-20 19:17:58 -05:00
Jay Hayes
2893e6c0a4 Exit with non-zero status when db:create fails
* 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`.
* ⚠️ 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.
2015-10-20 19:17:58 -05:00
Jay Hayes
1cd35be3eb Fix test of drop failure
* 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.
2015-10-20 19:17:58 -05:00
Jay Hayes
213ff7ca0c Add tests to verify exit status for create/drop failures
* 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.
2015-10-20 19:17:58 -05:00
Chuck Callebs
a01e58afd9 Add rake dev:cache task to enable dev mode caching.
Taken from @Sonopa's commits on PR #19091.

Add support for dev caching via "rails s" flags.

Implement suggestions from @kaspth.

Remove temporary cache file if server does not have flags.

Break at 80 characters in railties/CHANGELOG.md

Remove ability to disable cache based on server options.

Add more comprehensive options: --dev-caching / --no-dev-caching
2015-08-04 23:41:23 -04:00
schneems
9b18ba75b1 Fix rake/notes_test
Presumably due to https://github.com/rails/sprockets-rails/pull/265 sprockets was trying to load the "scss" gem but it isn't in the gemfile:

```
ApplicationTests::RakeTests::RakeNotesTest#test_register_a_new_extension:
LoadError: cannot load such file -- sass
```

If we use an empty precompile list, it won't try to load sass.
2015-07-29 20:12:56 -05:00
Yves Senn
2183caa24a dump_schema_after_migration applies migration tasks other than db:migrate
Closes #20743.

The task `db:_dump` now only dumps the schema if
`ActiveRecord::Base.dump_schema_after_migration` is true. This has
effects:

- `db:migrate:up`
- `db:migrate:down`
- `db:forward`
- `db:rollback`
2015-06-30 16:36:03 +02:00
Yves Senn
a8f250a22c tests, railties tests should use bin/ executables when possible.
We recommend using the `bin/` executables in our docs and guides.
Let's make sure that our tests execute the same code path.
2015-06-30 11:19:01 +02:00
Yoong Kang Lim
6fc83f8efe rake restart should work without a tmp folder
In restart.rake, the creation of tmp/restart.txt
would fail if the tmp folder does not exist in the
app. This is a problem because apps cloned using
git would not have the tmp folder, as the folder is
in .gitignore. This commit creates the tmp folder
if it does not exist.

Fixes #20299

[Yoong Kang Lim, Sunny Juneja]
2015-05-30 00:44:05 -07:00
Rafael Mendonça França
a75f6cfb1b Merge pull request #20326 from hderms/dh/fix_task_bug
Fix rake method definition leaking onto Object
2015-05-27 22:19:57 -03:00
Dermot Haughey
ae5c3c3514 add fixed file
add framework_test

add another test
2015-05-27 19:24:47 -05:00
Yves Senn
557c46a41e Revert "Merge pull request #17920 from 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.
2015-04-27 11:45:21 +02:00
Jeremy Kemper
5154089c18 Revert "Merge pull request #19404 from dmathieu/remove_rack_env"
Preserving RACK_ENV behavior.

This reverts commit 7bdc7635b885e473f6a577264fd8efad1c02174f, reversing
changes made to 45786be516e13d55a1fca9a4abaddd5781209103.
2015-03-20 08:14:11 -07:00
Damien Mathieu
d578cbfb5c don't fallback to RACK_ENV when RAILS_ENV is not present 2015-03-19 10:06:28 +01:00
Hyonjee Joo
b181297ad7 Created rake restart task.
Fixes #18876. Rake restart touches `tmp/restart.txt` to restart
application on next request. Updated tests and documentation
accordingly.
2015-02-26 15:26:59 -05:00
Yves Senn
36ce0c2c82 db:structure:load and db:schema:load no longer purge the database.
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
2014-12-18 10:08:17 +01:00
Yves Senn
5c4495538b bring back db:test:prepare.
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.
2014-11-25 18:17:01 +01:00
yuuji.yaginuma
1b958e0a79 Revert "Replace String index juggling with Pathname goodness in db:fixtures:load"
This reverts commit 482fdad5ef8a73688b50bba3991dd4ef6f286edd.

Fixes #17237.
2014-11-02 23:58:30 +00:00
Yves Senn
316962d092 build fix, we have to reset the RACK_ENV as well.
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.
2014-09-04 07:54:30 +02:00
Yves Senn
ded17a498a schema loading rake tasks maintain database connection for current env.
[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.
2014-09-03 18:02:44 +02:00
Viktar Basharymau
0813607c70 Add a test for db:migrate:status to check missing file scenario 2014-06-27 18:28:12 +03:00
Paul B
d1fa1fc35a Return a non zero code when db has never been setup on status 2014-05-07 18:33:18 -03:00
Matthew Draper
f846828dae Revise 'sqlite3:' URL handling for smoother upgrades
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.
2014-04-03 01:30:27 +10:30
Yves Senn
582cbff616 test for structure:dump without schema information table. refs eafec46
This is a test case for the fix provided in eafec4694c5b37eff9d83b1188b8e331fa6027fa
2014-03-20 18:40:51 +01:00
Carlos Antonio da Silva
97229c69ea Remove some indirection in rake dbs test
Just pass in the expected database as argument rather than "caching"
it in a hash and using the hash in the helper methods.
2014-03-20 08:27:23 -03:00
Carlos Antonio da Silva
66dc576217 Check if the output is empty rather than asserting for equality
Also fix indent of test block.
2014-03-20 08:19:33 -03:00
Carlos Antonio da Silva
e0235c3721 Refactor assertion of line numbers matching 4 spaces 2014-03-19 21:47:38 -03:00
Carlos Antonio da Silva
29aff93dc4 Move booting/loading tasks setup to the rake notes helper method 2014-03-19 21:47:38 -03:00
Carlos Antonio da Silva
9c5c0bcfa6 Extract rake notes command and lines scan boilerplate
Refactor to a reusable method.
2014-03-19 21:47:38 -03:00
Carlos Antonio da Silva
3a3a386d4f Remove extra space assertion
No need to check that each line contains an extra space, just matching
the space in the regexp is enough to ensure that.
2014-03-19 21:47:38 -03:00
Carlos Antonio da Silva
dcf7a166f2 Extract common setup for loading tasks in rake notes tests 2014-03-19 21:47:38 -03:00
Guillermo Iguaran
4a69c933cf Merge pull request #14379 from robertomiranda/rake-notes.config
Add Public Api for Register New Extensions for Rake Notes
2014-03-17 17:47:24 -05:00
robertomiranda
3b073ac195 Rake notes should picked up new Extensions registered in the config/application.rb file 2014-03-17 17:03:52 -05:00
Carlos Antonio da Silva
1330274657 Fix assertions 2014-03-16 22:47:35 -03:00
robertomiranda
ce38a6b8b6 Fix Shadowing extensions variable in Register Annotation Exentsions 2014-03-16 14:32:08 -05:00
robertomiranda
f43421cb65 Supporting .ruby, .yml and .yaml Extension in Rake Notes 2014-03-14 17:51:14 -05:00
robertomiranda
810af6f6ee Remove .scss, .sass, .less, .haml, .slim, coffee from Rake Notes. Now we have an API for register it in the corresponding gems 2014-03-14 17:39:04 -05:00
robertomiranda
a2fb164a4f Add Public Api for register new extensions for Rake Notes 2014-03-14 15:22:02 -05:00
Aaron Patterson
22a1a5ac8c remove railties changes. fixes #14054
Squashed commit of the following:

commit 96991e8e919edfb20cc4120bca4e36ed51175d57
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:29:24 2014 -0800

    Revert "gems can be added or skipped from the template"

    This reverts commit 8beb42cfbc41753ae4dbb91e16abcd1fb7d00356.

    Conflicts:
    	railties/lib/rails/generators/rails/app/app_generator.rb
    	railties/test/generators/app_generator_test.rb

commit 35599c0e657245ef14ac0f28c9189ad16acf40e6
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:26:53 2014 -0800

    Revert "oops, template replay needs to happen after bundle. :orz:"

    This reverts commit 9104702be61253f9448ca070a22fc86bb4299555.

    Conflicts:
    	railties/lib/rails/generators/rails/app/app_generator.rb

commit f519c3902c313db8e906a49251c91643b8e6499e
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:51 2014 -0800

    Revert "only ask for these ivars if the target responds to them"

    This reverts commit 656d412546cd97d5660c634c2a41c799d3f9e211.

commit aa524a9428e3e4c45fe221f10a66a08efb827ab5
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:39 2014 -0800

    Revert "refactor generator tests to use block form of Tempfile"

    This reverts commit 65251820ef0ab7f3cffb38130de3dd41af8d72be.

commit 7d3740549fa4dfa62e3761f8d4bc6d6d441256e7
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:25 2014 -0800

    Revert "add a more restricted codepath for templates fixes #13390"

    This reverts commit 2875b4a66e38e4333da887a4afbed33358999298.

commit 525df0af1001918986cdfce59539fd2d52c4f32c
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:11 2014 -0800

    Revert "add a send so `apply` can be called.  Fixes #13510"

    This reverts commit c5034d60dba0cd31a6a8c612ee35d63b8127793a.
2014-02-14 11:38:26 -08:00
Aaron Patterson
c5034d60db add a send so apply can be called. Fixes #13510
THIS IS A HUGE HACK.  Thor does not allow us to define public methods
without turning them in to "thor tasks".  That means we cannot subclass
the `apply` method and make it public, so we have to make the method
private and call `send` on it.
2014-02-11 14:08:12 -08:00
Emil Soman
8806768e9f Add config to disable schema dump after migration
* Add a config on Active Record named `dump_schema_after_migration`
* Schema dump doesn't happen if the config is set to false
* Set default value of the config to true
* Set config in generated production environment file to false
* Update configuration guide
* Update CHANGELOG
2014-02-06 17:38:31 +05:30
schneems
f642b18c0e Use DATABASE_URL by default
See https://github.com/rails/rails/pull/13463#issuecomment-31480799 for full conversation.
2014-01-02 15:00:30 -06:00