Commit Graph

55820 Commits

Author SHA1 Message Date
Akshay Vishnoi
dafe5f4891 test include?- fix typo 2016-01-09 05:55:56 +05:30
Richard Schneeman
7b065f623f Merge pull request #22984 from akshay-vishnoi/fix-docs
[ci skip] Fix typo Renderering --> Rendering
2016-01-08 18:08:54 -06:00
Akshay Vishnoi
ab40d71ff8 [ci skip] Fix typo Renderering --> Rendering 2016-01-09 05:28:44 +05:30
Sean Griffin
302e92359c Refactor tz aware types, add support for PG ranges
This is an alternate implementation to #22875, that generalizes a lot of
the logic that type decorators are going to need, in order to have them
work with arrays, ranges, etc. The types have the ability to map over a
value, with the default implementation being to just yield that given
value. Array and Range give more appropriate definitions.

This does not automatically make ranges time zone aware, as they need to
be added to the `time_zone_aware` types config, but we could certainly
make that change if we feel it is appropriate. I do think this would be
a breaking change however, and should at least have a deprecation cycle.

Closes #22875.

/cc @matthewd
2016-01-08 14:11:45 -07:00
Sean Griffin
c1a1595740 Merge pull request #22967 from schneems/schneems/generic-metadata
Prevent destructive action on production database
2016-01-08 13:42:48 -07:00
schneems
57155064d1 Get update_attributes working with SchemaMigration
You cannot use `update_attributes` on models that do not have a primary key. Since SchemaMigration versions are guaranteed to be unique (they have a unique index on them) we can safely use them as a primary key.
2016-01-08 14:29:31 -06:00
schneems
d70c68d76a Fixing tests and re-locating error checking. 2016-01-08 14:05:20 -06:00
David Heinemeier Hansson
d0393fccff Merge pull request #22977 from rails/revert-22934-master
Revert "Move async execution from celluloid to concurrent-ruby"
2016-01-08 20:13:20 +01:00
David Heinemeier Hansson
36fe301564 Revert "Move async execution from celluloid to concurrent-ruby" 2016-01-08 20:09:25 +01:00
David Heinemeier Hansson
3b7ccadfc1 Merge pull request #22934 from mperham/master
Move async execution from celluloid to concurrent-ruby
2016-01-08 18:23:41 +01:00
schneems
f6628adc11 Fix kwarg to not have circular dependency 2016-01-08 10:05:38 -06:00
schneems
de2cb20117 Use hash like syntax for InternalMetadata
Discussion: https://github.com/rails/rails/pull/22967#discussion_r49137035
2016-01-08 09:27:25 -06:00
schneems
a76c4233a9 Add EnvironmentMismatchError
Raise an error when a destructive action is made on a database where the current environment is different from the environment stored in the database.
2016-01-08 09:25:50 -06:00
schneems
350ae6cdc1 Use key as primary key in schema. 2016-01-08 09:09:00 -06:00
Akira Matsuda & saya
76c385709c [doc] The capture method isn't always used inside views to create a variable
but rather very often used inside helpers to directly return a String value.
[ci skip]
2016-01-08 18:08:11 +09:00
Rafael França
078d86b655 Merge pull request #22973 from kamipo/fix_select_values_method_signature
Fix `select_values` method signature for consistency
2016-01-08 01:44:05 -02:00
Rafael França
2a1312eb9f Merge pull request #22971 from kamipo/insert_sql_is_almost_same_as_insert
`{update|delete}_sql` are almost the same as `{update|delete}`
2016-01-08 01:34:31 -02:00
Ryuta Kamizono
2827fcd2f9 Fix select_values method signature for consistency 2016-01-08 12:18:32 +09:00
Rafael França
6dbc5e7fb8 Merge pull request #22972 from prathamesh-sonpatki/fix-typo
Fix typo in ActionPack CHANGELOG [ci skip]
2016-01-08 01:02:56 -02:00
Prathamesh Sonpatki
4824971f36 Fix typo in ActionPack CHANGELOG [ci skip] 2016-01-08 08:31:08 +05:30
Ryuta Kamizono
c90f141fb1 {update|delete}_sql are almost the same as {update|delete}
Simply `{update|delete}_sql` aliases to `{update|delete}`.
2016-01-08 11:44:29 +09:00
schneems
9219976752 [ci skip] Add comment to remove silenced code. 2016-01-07 18:01:13 -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
Sean Griffin
7595c59523 Merge pull request #18909 from davidcornu/fix-hash-with-indifferent-access-default
Match HashWithIndifferentAccess#default & Hash#default
2016-01-07 14:16:57 -07:00
David Cornu
38a990237a Match HashWithIndifferentAccess#default's behaviour with Hash#default 2016-01-07 15:39:36 -05:00
Rafael França
b4f28dbb39 Merge pull request #22966 from mastahyeti/add_greg
Fix changelog for per-form CSRF tokens
2016-01-07 17:53:23 -02:00
Ben Toews
77d01e36aa add greg 2016-01-07 12:35:46 -07:00
Sean Griffin
43ccebc1db Ensure config.active_record.time_zone_aware_types is always set
While the option on `ActiveRecord::Base` is always around, we need to
explicitly set it on the config object. Otherwise the recommended
configuration change results in an error.

Fixes #22839
2016-01-07 09:55:44 -07:00
Kasper Timm Hansen
a04cb1e376 Merge pull request #22942 from Edouard-chin/rake-routes-error-message
Better error message when running `rake routes` with CONTROLLER arg:
2016-01-07 15:45:00 +01:00
Edouard CHIN
ce13f79105 Better error message when running rake routes with CONTROLLER arg:
- `CONTROLLER` argument can now be supplied in different ways (Rails::WelcomeController, Rails::Welcome, rails/welcome)
- If `CONTROLLER` argument was supplied but it does not exist, will warn the user that this controller does not exist
- If `CONTROLLER` argument was supplied and no routes could be found matching this filter, will warn the user that no routes were found matching the supplied filter
- If no routes were defined in the config/routes.rb file, will warn the user with the original message
2016-01-07 06:35:40 -05:00
Kasper Timm Hansen
c02b85614c Merge pull request #20109 from prathamesh-sonpatki/keep-only-one-root
Remove original root method from Base module and kept overridden implementation in Resources module.
2016-01-07 12:03:22 +01:00
Kasper Timm Hansen
45da423bf3 Merge pull request #22956 from prathamesh-sonpatki/rm-splat-warning
Remove splat operator warning from ssl_test
2016-01-07 11:58:23 +01:00
David Heinemeier Hansson
071cbb3561 Merge pull request #22949 from schneems/schneems/request-id
Default new apps to tag logs with `request_id`
2016-01-07 11:30:26 +01:00
Prathamesh Sonpatki
ee1534e5ab Kept overridden root method and removed original method
- The root method is defined and documented in Base module and
   decorated in Resources module.
 - The documentation in Base module actually talks about method
   signature of decorated method from Resources module.
 - Argument handling was moved to decorated method in
   977455cc2e
   to handle options such as :as with directly passed path parameter.
 - To avoid the confusion, removed original root method from Base module
   and only kept overridden version in Resources module.

 - References - https://github.com/rails/rails/pull/12208 &
                https://github.com/rails/rails/pull/12208#issuecomment-24350897.
2016-01-07 15:50:24 +05:30
Prathamesh Sonpatki
70e73e4d4c Remove splat operator warning from ssl_test
- Removes following warning -

  `rails/actionpack/test/dispatch/ssl_test.rb:203: warning: `*' interpreted as argument prefix`.
2016-01-07 13:53:10 +05:30
Rafael França
21dd85f1ee Merge pull request #22903 from prathamesh-sonpatki/allow-ac-parameters-hash-as-an-argument-to-routes
Allow AC::Parameters as an argument to url_helpers
2016-01-07 05:13:07 -02:00
Rafael França
2674f8043f Merge pull request #22954 from yui-knk/suppress_warning_on_action_view
Suppress warning (instance variable @persisted not initialized)
2016-01-07 05:05:56 -02:00
Prathamesh Sonpatki
a31078556a Allow AC::Parameters as an argument to url_helpers
- Earlier only Hash was allowed as params argument to url_helpers.
- Now ActionController::Parameters instances will also be allowed.
- If the params are not secured then it will raise an ArgumentError to
  indicate that constructing URLs with non-secure params is not recommended.
- Fixes #22832.
2016-01-07 12:12:34 +05:30
yui-knk
54aaf85e4f Suppress warning (instance variable @persisted not initialized) 2016-01-07 10:24:54 +09:00
Rafael França
3cae35bd6c Merge pull request #22952 from Baron-burton/contributing_documentation
Typo in Contributing.md documentation
2016-01-06 21:39:44 -02:00
Baron-burton
1393bc9b9b Typo in Contributing.md documentation
Just fixed a small typo in the documentation.
2016-01-06 23:34:41 +00:00
Rafael França
e10cb1e881 Merge pull request #22948 from kamipo/remove_delete_sql_in_sqlite3_adapter
Remove `delete_sql` in sqlite3 adapter
2016-01-06 19:27:04 -02:00
schneems
81d3bec460 Default new apps to tag logs with request_id
In high volume applications it can be very difficult to figure out what is happening in logs because each request is not easily identified. For example 3 requests could look something like this:

```
Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:21 +0000
  Rendered welcome/index.html.erb within layouts/application (0.1ms)
Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:22 +0000
Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:23 +0000
  Rendered welcome/index.html.erb within layouts/application (0.1ms)
Processing by WelcomeController#index as HTML
Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
Processing by WelcomeController#index as HTML
  Rendered welcome/index.html.erb within layouts/application (0.1ms)
Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
  Processing by WelcomeController#index as HTML
Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
```

The `:request_id` log tag ensures that each request is tagged with a unique identifier. While they are still interleaved it is possible to figure out which lines belong to which requests. Like:

```
[c6034478-4026-4ded-9e3c-088c76d056f1] Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:21 +0000
[c6034478-4026-4ded-9e3c-088c76d056f1]  Rendered welcome/index.html.erb within layouts/application (0.1ms)
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ] Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:22 +0000
[acfab2a7-f1b7-4e15-8bf6-cdaa008d102c] Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:23 +0000
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ]  Rendered welcome/index.html.erb within layouts/application (0.1ms)
[c6034478-4026-4ded-9e3c-088c76d056f1] Processing by WelcomeController#index as HTML
[c6034478-4026-4ded-9e3c-088c76d056f1] Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ] Processing by WelcomeController#index as HTML
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ]  Rendered welcome/index.html.erb within layouts/application (0.1ms)
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ] Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
[acfab2a7-f1b7-4e15-8bf6-cdaa008d102c]  Processing by WelcomeController#index as HTML
[acfab2a7-f1b7-4e15-8bf6-cdaa008d102c] Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
```

Now if you have the logs and you find this unique ID you can filter to only look at information from that request. So a filtered log output would be very clear:

```
[c6034478-4026-4ded-9e3c-088c76d056f1] Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:21 +0000
[c6034478-4026-4ded-9e3c-088c76d056f1]  Rendered welcome/index.html.erb within layouts/application (0.1ms)
[c6034478-4026-4ded-9e3c-088c76d056f1] Processing by WelcomeController#index as HTML
[c6034478-4026-4ded-9e3c-088c76d056f1] Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
```

In addition to this benefit the `:request_id` can be set via the `X-Request-ID` header so that the same request could be traced between multiple components. For example a request comes in Nginx (or another load balancer) could assign a request id. As the load balancer processes the request I can log using that id, then when the request is passed on to Rails, the same id is used. That way if a problem is determined to be not caused in Rails it could be traced back to other components with the same ID. You can set a value in nginx for example using something like this:

```
  location / {
      proxy_pass http://upstream;
      proxy_set_header X-Request-Id $pid-$msec-$remote_addr-$request_length;
  }
# http://stackoverflow.com/questions/17748735/setting-a-trace-id-in-nginx-load-balancer
```

Heroku sets this header value so problems like timeouts that are logged by like router can be traced back to specific request within the application.

Whether you are using components that are setting request ID or not, all production applications can benefit from the additional debugging information of having a unique identifier for all requests. This change will only affect new applications, anyone can opt out by commenting or removing the line in `config/production.rb`.
2016-01-06 15:26:22 -06:00
Ryuta Kamizono
5a56b5718e Remove delete_sql in sqlite3 adapter
`sql += " WHERE 1=1"` was introduced in 69cb942.
But it is not needed. ref https://www.sqlite.org/lang_delete.html
2016-01-07 06:03:49 +09:00
Rafael França
6a42f0093e Merge pull request #22945 from kamipo/refactor_connection_insert_sql
Refactor `connection.insert_sql`
2016-01-06 18:44:23 -02:00
Ryuta Kamizono
2bce5adf5c Refactor connection.insert_sql
`connection.insert_sql` is almost the same as `connection.insert`.
2016-01-07 05:13:29 +09:00
Richard Schneeman
cc58837f64 Merge pull request #22933 from schneems/schneems/fix-broadcast
[close #22917] Don't output to `STDOUT` twice
2016-01-06 11:03:42 -06:00
schneems
b33a5ed67e Remove unused instance variable 2016-01-06 10:25:12 -06:00
schneems
3d10d9d6c3 [close #22917] Don't output to STDOUT twice
When `rails console` or `rails server` are used along with a logger set to output to `STDOUT` then the contents will show up twice. This happens because the logger is extended with `ActiveSupportLogger.broadcast` with a destination of STDOUT even if it is already outputting to `STDOUT`.

Previously PR #22592 attempted to fix this issue, but it ended up causing NoMethodErrors. A better approach than relying on adding a method and flow control is to inspect the log destination directly. For this `ActiveSupport::Logger.logger_outputs_to?` was introduced

```ruby
logger = Logger.new(STDOUT)
ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
# => true
```

To accomplish this we must look inside of an instance variable of standard lib's Logger `@logdev`. There is a related Ruby proposal to expose this method in a standard way: https://bugs.ruby-lang.org/issues/11955
2016-01-06 09:55:35 -06:00
Matthew Draper
998b85ffe8 Merge pull request #22941 from lsylvester/pg-remove-index-legacy
Fix remove_index for postgresql when running legacy migrations
2016-01-07 01:11:17 +10:30