Commit Graph

35 Commits

Author SHA1 Message Date
Rafael Mendonça França
93559da482 Remove debugger support
bebugger doesn't work with Ruby 2.2 so we don't need to support it
anymore
2015-01-04 15:54:22 -03:00
Akira Matsuda
4ded131181 Expectations first 2014-08-28 14:41:00 +09:00
Akira Matsuda
0c885d6818 Reset RACK_ENV after modified in a test case 2014-08-28 14:41:00 +09:00
Rafael Mendonça França
b17330cf39 Remove mocha usage 2014-07-23 19:01:44 -03:00
Rafael Mendonça França
fcc2231a04 Stop using mocha on dbconsole_test 2014-07-15 23:36:45 -03:00
Rafael Mendonça França
a83efa4a1f Stop using mocha on console_test 2014-07-07 23:39:18 -03:00
David Rodríguez de Dios
6fae9ac581 Isolate debugger related code 2014-04-10 16:02:13 +02:00
David Rodríguez de Dios
7901ae13a1 Keep debugger support only for rubies < 2.0.0 2014-04-08 20:55:23 +02:00
schneems
6cc03675d3 Ensure Active Record connection consistency
Currently Active Record can be configured via the environment variable `DATABASE_URL` or by manually injecting a hash of values which is what Rails does, reading in `database.yml` and setting Active Record appropriately. Active Record expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot rip out this functionality without deprecating. This presents a problem though when both config is set, and a `DATABASE_URL` is present. Currently the `DATABASE_URL` should "win" and none of the values in `database.yml` are used. This is somewhat unexpected to me if I were to set values such as `pool` in the `production:` group of `database.yml` they are ignored.

There are many ways that active record initiates a connection today:

- Stand Alone (without rails)
  - `rake db:<tasks>`
  - ActiveRecord.establish_connection
 
- With Rails
  - `rake db:<tasks>`
  - `rails <server> | <console>`
  - `rails dbconsole`


We should make all of these behave exactly the same way. The best way to do this is to put all of this logic in one place so it is guaranteed to be used.

Here is my prosed matrix of how this behavior should work:

```
No database.yml
No DATABASE_URL
=> Error
```

```
database.yml present
No DATABASE_URL
=> Use database.yml configuration
```

```
No database.yml
DATABASE_URL present
=> use DATABASE_URL configuration
```

```
database.yml present
DATABASE_URL present
=> Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url`
   sub key "wins". If other paramaters `adapter` or `database` are specified in YAML,
   they are discarded as the `url` sub key "wins".
```

### Implementation

Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge all connection information before returning. This is achieved through a utility class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`.

To understand the exact behavior of this class, it is best to review the behavior in activerecord/test/cases/connection_adapters/connection_handler_test.rb though it should match the above proposal.
2014-01-09 16:35:37 -06:00
schneems
a1f9ae5eb8 Fix DB Console tests
The build is broken: https://travis-ci.org/rails/rails/builds/15824530

This commit fixes it.

The problem: Sqlite expects the `database` part to be an absolute path. That prompted this change to be committed to master: fbb79b517f

This change provides correct behavior. Unfortunately tests were introduced in 971d5107cd that were relying on the incorrect behavior. We can avoid the fix by changing to another database url such as `mysql` or `postgresql`

In addition to fixing the failure, the assertions are changed so that the "expected" value comes before "actual" value.
2013-12-21 23:09:01 -05:00
Huiming Teo
971d5107cd fixed rails dbconsole to support ENV['DATABASE_URL']. 2013-12-16 18:31:49 +08:00
Marc Schütz
16c0023a9a Make logging to stdout work again with implicit development env 2013-10-13 19:21:18 +02:00
schneems
5f98bb402b Only output Server logs in Development
Right now when you start a server via `rails s`, the logger gets extended so that it logs to the file system and also to stdout. This extension behavior is not "intelligent" and if the default logger is already set to output to stdout, then the contents will be received twice.

To capture logs in accordance with http://www.12factor.net/logs some platforms require the logs to be sent to standard out. If a logger is set to stdout, and the server is started using `rails server` instead of another method (i.e. `thin start` etc.) then the app will produce double logs.

This PR fixes the issue by only extending the logger to standard out in the development environment. So that in production you don't get double logs like this:

```
ActionView::Template::Error (wrong number of arguments (5 for 4)):
    1: <% lang_index = 0 %>
    2: <div class="row">
    3:   <ul class="nav nav-tabs nav-stacked span2" data-tabs="tabs" id="repo-tabs">
    4:     <% repos.group_by(&:language).each do |lang, repos| %>
    5:       <% unless lang == nil %>
    6:         <li><a href="#<%= "#{lang.parameterize}#{lang.hash}" %>" data-toggle="tab"><%= lang %></a></li>
    7:       <% end -%>
  app/views/shared/_repos.html.erb:4:in `_app_views_shared__repos_html_erb___1685450633638247395_70300668607000'
  app/views/pages/index.html.erb:13:in `_app_views_pages_index_html_erb__2084723628308867770_70300687584880'

ActionView::Template::Error (wrong number of arguments (5 for 4)):
    1: <% lang_index = 0 %>
    2: <div class="row">
    3:   <ul class="nav nav-tabs nav-stacked span2" data-tabs="tabs" id="repo-tabs">
    4:     <% repos.group_by(&:language).each do |lang, repos| %>
    5:       <% unless lang == nil %>
    6:         <li><a href="#<%= "#{lang.parameterize}#{lang.hash}" %>" data-toggle="tab"><%= lang %></a></li>
    7:       <% end -%>
  app/views/shared/_repos.html.erb:4:in `_app_views_shared__repos_html_erb___1685450633638247395_70300668607000'
  app/views/pages/index.html.erb:13:in `_app_views_pages_index_html_erb__2084723628308867770_70300687584880'
```

ATP Railties. Opened against master in favor of #10999
2013-09-22 20:56:31 -05:00
Vipul A M
113e39625b fix private attribute warning 2013-04-04 23:23:46 +05:30
Carlos Antonio da Silva
11dd15a5c2 Fix failing test regarding console change to fix sandboxing
Introduced in be3e10cd26bc8ec29c6474d03a08a8e733108e7d.
2013-03-08 21:48:28 -03:00
Mykola Kyryk
4fa6088b42 This commit fixes issue #8628
Allow environment name to start with a substring of the default
environment names.
For example: tes, pro, prod, dev, devel, etc.

Fixing identation.

Adding test for Rails::Console.parse_arguments method.

Fix issue 8628 for Rails::DBConsole.
2013-01-04 17:05:49 +02:00
Carlos Antonio da Silva
5a8f25f003 Refactor tests that switch RAILS_ENV and RACK_ENV
This cleanup aims to fix a build failure:
https://travis-ci.org/rails/rails/jobs/3515951/#L482

Since travis always have both ENV vars set to "test", a test is failing
where it's expected to output the default env "development", but "test"
is the result due to RACK_ENV being set when we expect it to not be.

By cleaning this duplication we ensure that changing any of these env
variables will pick the right expected value.
2012-12-06 10:47:14 -02:00
kennyj
a7695579a5 Add ENV['RACK_ENV'] support to rake runner/console/server. 2012-12-06 02:05:33 +09:00
Carlos Antonio da Silva
53aefdec91 Fix rails db command with sqlite3 database
When using sqlite3 it was attempting to find the database file based on
Rails.root, the problem is that Rails.root is not always present because
we try to first manually load "config/database.yml" instead of loading
the entire app, to make "rails db" faster.

This means that when we're in the root path of the app, calling "rails db"
won't allow us to use Rails.root, making the command fail for sqlite3
with the error:

    ./rails/commands/dbconsole.rb:62:in `start':
      undefined method `root' for Rails:Module (NoMethodError)

The fix is to simply not pass any dir string to File.expand_path, which
will make it use the current directory of the process as base, or the
root path of the app, which is what we want.

When we are in any other subdirectory, calling "rails db" should work
just fine, because "config/database.yml" won't be found, thus "rails db"
will fallback to loading the app, making Rails.root available.

Closes #8257.
2012-11-18 23:52:39 -02:00
Arun Agrawal
c33c991eab Removing warning : assigned but unused variable 2012-11-10 17:34:39 +05:30
Robin Dupret
5ad7f8ab41 Use Ruby 1.9 Hash syntax in railties 2012-10-14 18:26:58 +02:00
Arun Agrawal
3121ac06a9 warning fixed: ambiguous first argument; put parentheses or even spaces 2012-10-10 10:40:14 +05:30
Rafael Mendonça França
9a30d82d45 Set RACK_ENV to nil in the dbconsole test
This will fix the travis-ci build
2012-05-30 23:29:47 -03:00
Sam Oliver
dce0afd47f Remove support for rails server RAILS_ENV=env-name 2012-05-30 22:28:07 +01:00
Sam Oliver
cdd6d9b53a Fix various bugs with console arguments.
Allow hyphens in environment names again.
2012-05-30 22:23:04 +01:00
Arun Agrawal
05f88024de More assert_match warnings fixed. 2012-05-30 14:46:08 +05:30
Alexey Vakhov
1fed1f14fc Fix rails db -h and cosmetic fixes in usage banners
Ruby tries to use '-h' as short version of '--header' by default
https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1372-1381.
To force `rails db -h` prints an usage message we should add the `-h`
options explicitly.
2012-05-22 08:59:30 +04:00
Alexey Vakhov
a060c41ef7 Use relative path to sqlite3 db in rails db command
Rails uses sqlit3 db file with a path relative to the rails root. It
allows to execute server not from rails root only. For example you
can fire `./spec/dummy/script/rails s` to start dummy application
server if you develop some engine gem.

Now the `rails db` command uses relative paths also and you can explore
your dummy db via `./spec/dummy/script/rails db` command.
2012-05-22 08:59:25 +04:00
Piotr Sarnacki
d98bbdee14 Fix build 2012-05-06 21:38:34 -07:00
Dmitry Vorotilin
346bb01849 More faster rails dbconsole 2012-05-06 22:53:53 +04:00
Alexey Vakhov
5d685f9db7 Add Rails::DBConsole tests 2012-05-02 08:48:06 +04:00
schneems
7529283732 match rails console environment support, to server
rails server takes `-e` as an argument to specify RAILS_ENV, rails console currently does not have the same interface. This commit fixes this disparity so developers can manually specify `RAILS_ENV` or can pass in an environment with a `-e`.
2012-03-22 13:13:12 -04:00
schneems
0a555dd421 fix rails server support of RAILS_ENV variable
When launching rails server from the command line with a rails environment specified such as `rails server RAILS_ENV=production` an error would occur since rails will try to use `RAILS_ENV=production` as it's server. 

When launching rails with a specified server such as thin `rails server thin RAILS_ENV=production` no error will be thrown, but rails will not start up in the specified environment.

This fixes both of those cases
2012-03-20 20:58:50 -04:00
Piotr Sarnacki
c84e4b5d4b Fix tests, Rails.env may be different on CI 2012-02-16 21:26:01 +01:00
Piotr Sarnacki
dd655d88d6 Refactor Rails::Console to make it easier to test and add tests for it 2012-02-16 20:41:35 +01:00