Commit Graph

13727 Commits

Author SHA1 Message Date
Matthew Draper ef763d6933 Merge pull request #28644 from mtsmfm/set-capybara-app-host
Set `Capybara.app_host` through `host!`
2017-05-24 13:53:09 +09:30
eileencodes 845aabbcd3 Remove unused simulate method
This method was only used in the Rails tests and not by other methods in
the Rails simulator. Because it's a no-doc'd class it should be safe to
remove without deprecation.
2017-05-22 13:09:57 -04:00
Robin Dupret 0cbb130cf5 Merge pull request #29072 from dixpac/dixpac/add_documentation_for_validate_and_callback_order_of_execution
Improving docs for callbacks execution order [ci skip]
2017-05-21 21:34:47 +02:00
dixpac 4f39556577 Improving docs for callbacks execution order [ci skip]
When define callbacks latest definition on the same callback/method
overwrites previous ones.
2017-05-21 18:45:59 +02:00
Alex Kitchens c01ea3e549 Merge pull request #29134 from joshaidan/document-action-name
Add documentation to accessors in AbstractController::Base
2017-05-19 08:32:19 -05:00
Brian Jones 73294bc96c Clarified description of formats [ci skip] 2017-05-19 01:48:38 -04:00
Ryuta Kamizono b9b4fa9154 Cleanup CHANGELOGs [ci skip]
* Fix indentation.
* Add backticks.
2017-05-19 08:29:55 +09:00
Brian Jones f63a69e92a Added missing punctuation [ci skip] 2017-05-18 13:57:15 -04:00
David Heinemeier Hansson 75fa8dd309 Use recyclable cache keys (#29092) 2017-05-18 18:12:32 +02:00
Brian Jones 89e079f8fd Specify only the body of the response is returned [ci skip] 2017-05-18 11:46:20 -04:00
Brian Jones 73293053b5 Document accessors response_body, action_name, formats [ci skip] 2017-05-17 19:32:56 -04:00
sepehr500 bfbbb12079 Fixed string being modified in place causing frozen string errors in Ruby 2.3 2017-05-15 20:54:13 -04:00
yuuji.yaginuma e605921614 Fix `TestInvalidUrls` with rack 2.0.3
Currently, raise `BadRequest` if params encoding is invalid.
https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/http/parameters.rb#L64..L74
https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/request/utils.rb#L26..L39

However, env values are ensure encoded in ASCII 8 BIT at rack 2.0.3.
68db9aa99e

Therefore, even if specify an invalid urls, it will not cause an error.
2017-05-16 08:01:11 +09:00
Eileen M. Uchitelle 276bfa7fc6 Merge pull request #29062 from eileencodes/force-encoding-to-original-string-encoding
Maintain original encoding from path
2017-05-12 14:58:46 -04:00
eileencodes 8607c25ba7 Maintain original encoding from path
When the path info is read from the socket it's encoded as ASCII 8BIT.
The unescape method changes the encoding to UTF8 but it should maintain
the encoding of the string that's passed in.

This causes parameters to be force encoded to UTF8 when we don't
actually know what the encoding of the parameter should be.
2017-05-12 14:14:01 -04:00
Eugene Kenny fb0fae9747 Pass block in ActionController::Parameters#delete
In order to fully support the same interface as `Hash#delete`, we need
to pass the block through to the underlying method, not just the key.

This used to work correctly, but it regressed when
`ActionController::Parameters` stopped inheriting from `Hash` in 5.0.
2017-05-10 23:48:46 +01:00
Ryuta Kamizono b201474756 Should escape meta characters in regexp 2017-05-07 04:10:00 +09:00
Ryuta Kamizono 7cb71c5ce3 Remove `:doc:` in `:nodoc:` class [ci skip]
The `:doc:` was added in bc478158 but originally `UriEncoder` is a
`:nodoc:` class.
2017-05-01 01:11:14 +09:00
Jon Moss da70168715 Add period
[ci skip]
2017-04-30 10:43:51 -04:00
dixpac 0d0015c98a Add docs for Router::Utils.unescape_uri method 2017-04-30 15:17:09 +02:00
Ryuta Kamizono 89389428b5 Cleanup CHANGELOGs [ci skip]
* Remove trailing spaces.
* Add backticks around method and command.
* Fix indentation.
2017-04-30 02:41:44 +09:00
Rafael Mendonça França e06f68fdb2
Do not try to encoding the parameters when the controller is not defined
When you have a route that points to an nonexistent controller we raise
an exception.

This exception was being caught by the DebugExceptions middleware in
development, but when trying to render the error page, we are reading
the request format[[1][]]. To determine the request format we are reading
the format parameters[[2][]], and to be able to read the parameters we need
to encode them[[3][]]. This was raising another exception that to encode the
parameter we try to load the controller to determine if we need to
encode the parameters are binary[[4][]]. This new exception inside the
DebugExceptions middleware makes Rails to render a generic error page.

To avoid this new exception now we only encode the parameters when the
controller can be loaded.

Fixes #28892

[1]: f52cdaac63/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb (L80)
[2]: f52cdaac63/actionpack/lib/action_dispatch/http/mime_negotiation.rb (L63)
[3]: f52cdaac63/actionpack/lib/action_dispatch/http/parameters.rb (L58)
[4]: f52cdaac63/actionpack/lib/action_dispatch/http/parameters.rb (L88)
2017-04-26 19:45:55 -07:00
Ryuta Kamizono ca9ac31002 `respond_to_missing?` should be private
Follow up of 03d3f036.

Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036.
But the visibility is still public. It should be private.
2017-04-22 23:11:15 +09:00
Rafael Mendonça França d766e3dc5d
Add test case to make sure we can implicit convert a Parameters to a Hash 2017-04-20 22:34:05 -04:00
Rafael Mendonça França 0871e5e5c1
Fix all style guides violations
Closes #28382
Closes #28651
2017-04-19 20:13:42 -04:00
Rafael Mendonça França 93034ad7fe
Reuse the Parameters#to_h check in the routing helpers
Since this protection is now in Parameters we can use it instead of
reimplementing again.
2017-04-18 18:57:13 -04:00
Rafael Mendonça França 70c6fb1a06
Follow the style guide rules in the documetation 2017-04-18 17:33:25 -04:00
Rafael Mendonça França 3ee56f7b3d
Improve documentation
We are talking about a list of parameters even so we need to use plural.
Even if we were talking about the instance of the Parameters object we
would have to use the capital and monospaced font.
2017-04-18 17:33:25 -04:00
Rafael Mendonça França 29333ddb69
Implement ActionController::Parameters#to_query and #to_param
Previously it was raising an error because it may be unsafe to use those
methods in a unpermitted parameter. Now we delegate to to_h that already
raise an error when the Parameters instance is not permitted.

This also fix a bug when using `#to_query` in a hash that contains a
`ActionController::Parameters` instance and was returning the name of the
class in the string.
2017-04-18 17:33:25 -04:00
Rafael Mendonça França af878151db
Use the right assetions to better error messages 2017-04-18 17:33:24 -04:00
Rafael Mendonça França e13e72cce4
Add test to make sure that to_unsafe_h don't mutate the target 2017-04-18 17:33:24 -04:00
Rafael Mendonça França 9f4c2632ef
Add ActionController::Parameters#to_hash to implict conversion
Now methods that implicit convert objects to a hash will be able to work
without requiring the users to change their implementation.

This method will return a Hash instead of a HashWithIndefirentAccess
to mimic the same implementation of HashWithIndefirentAccess#to_hash.
2017-04-18 17:33:24 -04:00
Rafael Mendonça França fd88ccc905
Raise exception when calling to_h in a unfiltered Parameters
Before we returned either an empty hash or only the always permitted
parameters (:controller and :action by default).

The previous behavior was dangerous because in order to get the
attributes users usually fallback to use to_unsafe_h that could
potentially introduce security issues.

The to_unsafe_h API is also not good since Parameters is a object that
quacks like a Hash but not in all cases since to_h would return an empty
hash and users were forced to check if to_unsafe_h is defined or if the
instance is a ActionController::Parameters in order to work with it.
This end up coupling a lot of libraries and parts of the application
with something that is from the controller layer.
2017-04-18 17:33:23 -04:00
Rafael Mendonça França 1396b05e5a
Test the correct object 2017-04-18 17:33:23 -04:00
Andrew White 8776a71397 Use more specific check for :format in route path
The current check for whether to add an optional format to the path
is very lax and will match things like `:format_id` where there are
nested resources, e.g:

    resources :formats do
      resources :items
    end

Fix this by using a more restrictive regex pattern that looks for
the patterns `(.:format)`, `.:format` or `/` at the end of the path.
Note that we need to allow for multiple closing parenthesis since
the route may be of this form:

    get "/books(/:action(.:format))", controller: "books"

This probably isn't what's intended since it means that the default
index action route doesn't support a format but we have a test for
it so we need to allow it.

Fixes #28517.
2017-04-18 11:02:05 +01:00
Kasper Timm Hansen 6309b85100 Default embed_authenticity_token_in_remote_forms to nil.
Effectively treat nil values as "auto", e.g. whatever a form helper
chooses to interpret it as.

But treat an explicitly assigned false value as disabling.
2017-04-16 16:25:38 +02:00
Jon Moss 2b4583f2a2 Move CHANGELOG.md entry from Active Support to Action Pack
Was looking through #28402, and realized the CHANGELOG.md entry is in the wrong
place. Sorry we didn't catch this during code review 😢

[ci skip]
2017-04-11 18:52:02 -04:00
Julian Nadeau 35fac87123
Add action_controller_api, action_controller_base on_load hook 2017-04-10 19:34:48 -04:00
Jon Leighton a500b4796f Improve logging when Origin header doesn't match
I came up against this while dealing with a misconfigured server. The
browser was setting the Origin header to "https://example.com", but the
Rails app returned "http://example.com" from request.base_url (because
it was failing to detect that HTTPS was used).

This caused verify_authenticity_token to fail, but the message in the
log was "Can't verify CSRF token", which is confusing because the
failure had nothing to do with the CSRF token sent in the request. This
made it very hard to identify the issue, so hopefully this will make it
more obvious for the next person.
2017-04-06 16:03:35 +01:00
Fumiaki MATSUSHIMA 4c94d3e0a0 Set `Capybara.app_host` through `host!`
`visit "/"` will visit always "http://127.0.0.1" even when we call `host!`:

```ruby
class SomeTest < ApplicationSystemTest
  def setup
    host! "http://example.com"
  end

  def test_visit
    visit root_url # => visit "http://example.com/"

    visit "/" # => visit "http://127.0.0.1/"
  end
end
```

Because Capybara assumes that host is same as the server if we don't set `Capybara.app_host`:
866c975076/lib/capybara/session.rb (L239)
2017-04-02 21:11:54 +09:00
Andrew White 93982de132 Merge pull request #28606 from maclover7/jm-fix-25820
Do not include default response headers for AC::Metal
2017-03-30 10:29:33 +01:00
Jon Moss 9d695743de Do not include default response headers for AC::Metal
In Rails 4.2, `ActionController::Metal` controllers did not include the
default headers from `ActionDispatch::Response`. However, through e16afe6, and a
general shift towards having `ActionController::Metal` objects contain
`ActionDispatch::Response` objects (instead of just returning an array
of status, headers, and body), this behavior was lost. This PR helps to
restore the original behavior by having `ActionController::Metal`
controllers generate Response objects without the default headers, while
`ActionController::Base` now overrides the factory method to make sure
its version does have the default headers.
2017-03-29 19:26:39 -04:00
Sean Griffin d5a2e8baa9 Merge pull request #28603 from mikeastock/alias-reverse-merge
Add an alias for reverse_merge to with_defaults
2017-03-29 17:23:47 -04:00
Matt Casper 0117810cda Add aliases for reverse_merge to with_defaults
In the context of controller parameters, reverse_merge is commonly used
to provide defaults for user input. Having an alias to reverse_merge
called with_defaults feels more idiomatic for Rails.
2017-03-29 15:55:09 -05:00
Rafael Mendonça França 862cc0bfbe
Add test to make sure subclasses also get helpers 2017-03-29 12:40:57 -04:00
Fumiaki MATSUSHIMA 24e0fa7c4a Make `driven_by` overridable
Sometimes we want to use rack_test partially instead of selenium for test speed:

```ruby
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: {url: "http://chrome:4444/wd/hub"}
end

class WithJavaScriptTest < ApplicationSystemTestCase
end

class WithoutJavaScriptTest < ApplicationSystemTestCase
  driven_by :rack_test
end
```

In the abobe case, `WithoutJavaScriptTest` uses selenium because
`SystemTestCase` calls superclass' driver on `#initialize` (`self.class.superclass.driver.use`).

Using `class_attribute` can handle inherited `driven_by`.
2017-03-29 09:04:30 +09:00
Andrew White 5307f8d49c Merge pull request #28514 from y-yagi/follow_up_to_28056
Fix store accessors in parameters test
2017-03-28 17:27:10 +01:00
Rafael Mendonça França 84bfb81a62
Make sure that ActionController::Api can include helpers
Closes #28554
2017-03-27 19:51:21 -04:00
Rafael França ccab1b2dbe Merge pull request #28528 from domcleal/parseerror-const-deprecation
Change AD::ParamsParser::ParseError deprecation so it can be rescued
2017-03-22 19:26:44 -04:00
Jon Moss 3dd1de8ba4 Small grammar fix
[ci skip]
2017-03-22 15:44:19 -04:00