Commit Graph

32 Commits

Author SHA1 Message Date
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
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
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
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
1330274657 Fix assertions 2014-03-16 22:47:35 -03:00
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
Jon Leighton
ff7ab3bc78 Automatically maintain test database schema
* Move check from generated helper to test_help.rb, so that all
  applications can benefit
* Rather than just raising when the test schema has pending migrations,
  try to load in the schema and only raise if there are pending
  migrations afterwards
* Opt out of the check by setting
  config.active_record.maintain_test_schema = false
* Deprecate db:test:* tasks. The test helper is now fully responsible
  for maintaining the test schema, so we don't need rake tasks for this.
  This is also a speed improvement since we're no longer reloading the
  test database on every call to "rake test".
2014-01-02 13:49:00 +00:00
Rafael Mendonça França
02d366842c Adding missing require 2014-01-02 00:52:47 -02:00
schneems
9749e0efbf Move default production database to URL sub key
By using the URL sub key in the `database.yml` by default we are exposing the ability to set other attributes such as `pool` or `reap_frequency` without need of modifying the URL to contain non-connection specific information.
2014-01-01 17:48:24 -05:00
schneems
d0926d3d5e fix 2.1.0 bug :( 2013-12-25 18:27:09 -05:00
schneems
707be603cf ensure environment is run before db:structure:load
Right now `db:drop` depends on `load_config` since so when `db:drop` gets executed `load_config` gets run. `db:structure:load` depends on `[:environment, :load_config]`. So before it runs, it executes `environment` but because `load_config` has already executed it is skipped. Note `db:load_config` is "invoke"-d twice, but only "execute"-d once:

```
** Invoke db:drop (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:drop
** Invoke db:structure:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config
** Execute db:structure:load
```

The fix for this is making sure that the environment is run before any `load_config`:

```
** Invoke environment (first_time)
** Execute environment
** Invoke db:drop (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:drop
** Invoke db:structure:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:structure:load
```
2013-12-25 18:03:55 -05:00
schneems
ba882934bb Partial fix of database url tests
Prior to #13463 when `DATABASE_URL` was set, Rails automagically used that value instead of the database.yml. There are tests in dbs_test that expect this to still be true. After that PR, `RAILS_DATABASE_URL` is expected to be read into the YAML file via ERB, this PR fixes that behavior.

Note: this does not entirely fix the tests. It seems that `ActiveRecord::Tasks::DatabaseTasks.current_config` does not process the url string correctly (convert it into a hash), and ` ActiveRecord::Tasks::DatabaseTasks.structure_load(current_config, filename)` as well as other methods in `DatabaseTasks` expect a hash.

It seems like we should involve the resolver somewhere in this process to correctly convert the database url, I do not know the best place for that /cc @josevalim
2013-12-25 18:03:55 -05:00
Kuldeep Aggarwal
b9d79b1f5f using symbol instead of string in establish_connection 2013-12-25 15:24:25 +05:30
schneems
dd93a5f459 Use Full path to sqlite database in tests 2013-12-22 00:56:59 -05:00
Arun Agrawal
c10a78124c More Warnings removed for ruby trunk
Same as 4d4ff531b8807ee88a3fc46875c7e76f613956fb
2013-11-01 13:47:23 +01:00
José Valim
dd5a80dc3d Remove hard coded references to Active Record in railties 2013-03-02 13:52:32 -07:00
Terence Lee
e3f5d023ff run the load_structure test in the test environment 2013-02-21 01:25:05 +11:00
Terence Lee
44298c39e4 test DATABASE_URL without database.yml around 2013-02-21 01:25:05 +11:00
Carlos Antonio da Silva
cf05e5f6ea Stop shelling out more than necessary 2012-12-07 00:06:08 -02:00
Carlos Antonio da Silva
43c284297b Run rake tasks all at once in rake dbs test for a speed up
Before:

    Finished tests in 56.245787s, 0.2133 tests/s, 0.0000 assertions/s.
    12 tests, 0 assertions, 0 failures, 0 errors, 0 skips

After:
    Finished tests in 42.401416s, 0.2830 tests/s, 0.0000 assertions/s.
    12 tests, 0 assertions, 0 failures, 0 errors, 0 skips
2012-12-06 21:43:14 -02:00
Rafael Mendonça França
9cd831a0b0 Fix syntax error in assert_match 2012-09-15 09:13:48 -03:00
Arun Agrawal
ff04bb84e1 Few more warnings removed.
I found them when I was running
warning mode on with railties

See https://github.com/rails/rails/pull/3782
2012-09-15 14:26:04 +05:30
Grace Liu
148c50b49a fixed support for DATABASE_URL for rake db tasks
- added tests to confirm establish_connection uses DATABASE_URL and
  Rails.env correctly even when no arguments are passed in.
- updated rake db tasks to support DATABASE_URL, and added tests to
  confirm correct behavior for these rake tasks.  (Removed
  establish_connection call from some tasks since in those cases
  the :environment task already made sure the function would be called)
- updated Resolver so that when it resolves the database url, it
  removes hash values with empty strings from the config spec (e.g.
  to support connection to postgresql when no username is specified).
2012-09-11 20:40:13 -07:00