Commit Graph

12916 Commits

Author SHA1 Message Date
Rafael França
921ce291d4 Merge pull request #22277 from jwworth/pull-request/fix-typo-1447344392
Fix typo [ci skip]
2015-11-12 14:38:50 -02:00
Yves Senn
0e04ae3d2a Merge pull request #22259 from daisuko/remove_compiled_root_from_static_rb
remove unnecessary @compiled_root from static.rb
2015-11-12 17:18:11 +01:00
Jake Worth
432c7a5b76 Fix typo [ci skip] 2015-11-12 10:06:44 -06:00
claudiob
6c75bcbbb7 Show middleware classes on /rails/info/properties
Closes #21230 by following the indication of @rafaelfranca:

> I think the output change would be simpler.
> What is really important to show is the class of the middleware, so we should change the output to show that.
2015-11-11 09:46:23 -08:00
daisuko
3c217faa86 remove unnecessary @compiled_root from static.rb 2015-11-11 21:13:33 +09:00
Jerry D'Antonio
23b6f65fd1 Require only necessary concurrent-ruby classes. 2015-11-04 21:12:28 -05:00
Yves Senn
23bb31b158 tests, test should not care wether 9ms or 11ms have passed.
This solves:

```
Expected /Completed 200 OK in [\d]ms/ to match "Completed 200 OK in 943ms".
```
2015-11-04 16:42:27 -05:00
Kasper Timm Hansen
a3e05f7c81 Move static_cache_contorl deprecation changelog entry to Railties.
The configuration for `config.static_cache_control`, and its replacement
`config.public_file_server.headers` are implemented in Railties.

People would configure this in environment files, which is Railties domain too.
2015-11-04 22:07:45 +01:00
Tijmen Brommet
08689a2d1f Add text template for source code
When a request is made with AJAX and an error occurs, Rails will render
a text-template for the exception instead of the HTML error page
(#11960).

The `.text.erb` variant of the `_source` template is currently missing,
causing HTML to be rendered in the response. This commit adds the text
template.

To keep the page scannable we only only show the first three source
extracts.

Related to #14745.

Before:

```
~/testing-exceptions  ᐅ curl 'http://localhost:3000/' -H
'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

    <div class="source " id="frame-source-0">
      <div class="info">
        Extracted source (around line <strong>#3</strong>):
      </div>
      <div class="data">
        <table cellpadding="0" cellspacing="0" class="lines">
          <tr>
```

After:

```
~/testing-exceptions  ᐅ curl 'http://localhost:3000/' -H
'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

Extracted source (around line #3):

*3     raise
```
2015-11-03 22:13:10 +00:00
Yuki Nishijima
266455cf25 Deprecate exception#original_exception in favor of exception#cause 2015-11-03 06:54:34 -08:00
Aaron Patterson
d5890bdf66 remove present? call; we do not need it 2015-11-02 15:20:13 -08:00
Jake Worth
1f47adcc29 Fix double word 'string' [ci skip] 2015-11-01 11:20:59 -06:00
Vijay Dev
b217354dbb Merge branch 'master' of github.com:rails/docrails 2015-10-31 17:01:41 +00:00
Sean Griffin
eb6cdcab39 Merge pull request #21251 from rodzyn/more_param_parser_tests
Add test for parsing application/vnd.api+json
2015-10-30 13:44:04 -06:00
Paul Grayson
e6e056c2c1 In url_for, never append ? when the query string is empty anyway.
It used to behave like this:

    url_for(controller: 'x', action: 'y', q: {})
    # -> "/x/y?"

We previously avoided empty query strings in most cases by removing
nil values, then checking whether params was empty.  But as you can
see above, even non-empty params can yield an empty query string.  So
I changed the code to just directly check whether the query string
ended up empty.

(To make everything more consistent, the "removing nil values"
functionality should probably move to ActionPack's Hash#to_query, the
place where empty hashes and arrays get removed.  However, this would
change a lot more behavior.)
2015-10-29 17:02:13 -07:00
Aaron Patterson
8941831733 Revert "ActionController::Base#process() now only takes an action name"
This reverts commit 9f93a5efbba3e1cbf0bfa700a17ec8d1ef60d7c6.
2015-10-29 16:18:27 -07:00
Aaron Patterson
9f93a5efbb ActionController::Base#process() now only takes an action name
rather than an action name and *args.  The *args were not being used in regular
applications outside tests.  This causes a backwards compatibility
issue, but reduces array allocations for most users.
2015-10-29 15:40:18 -07:00
Aaron Patterson
82328a563f switch to JSON.dump to avoid infinite recursion 2015-10-29 14:42:52 -07:00
eileencodes
42eb37ab51 use dispatch instead of process to run requests though
`dispatch` sets the request and response on the controller for us
automatically, so the test harness doesn't need to know the internals of
how request / response is set.

Conflicts:
	actionpack/lib/action_controller/test_case.rb
2015-10-29 14:24:25 -07:00
eileencodes
b329fbb5f2 Remove unnecessary method 2015-10-29 14:12:19 -07:00
Gaurav Sharma
4ff9a824bf specify deprecated waring, follow the standard conventions
`skip_filter`, `skip_action_callback` may both are deprecated in Rails 5.1 so waring msg should be specific.
2015-10-28 13:09:18 +05:30
Rafael Mendonça França
a05f410029 Write the cookie jar it was not committed in TestCase
For ActionController::Base we write the cookies in a middleware if it
was not yet committed no matter if the response was committed or not. [1]

For ActionController::Live we write the cookies before the response is
committed. [2]

We already mimic ActionController::Live in
ActionController::TestCase but we don't mimic the ActionController::Base
behavior because we were checking if the response was committed before
writing the cookies.

Now we are matching the behavior of the middleware and writing the
cookies if it was not written before.

[1]: 80c6b901d4/actionpack/lib/action_dispatch/middleware/cookies.rb (L599-L604)
[2]: 80c6b901d4/actionpack/lib/action_controller/metal/live.rb (L218-L223)
2015-10-28 02:45:29 -02:00
Rafael Mendonça França
80c6b901d4 Remove dead code
This is leftover from when `render nothing: true` rendered blank string.
2015-10-28 01:39:23 -02:00
Guo Xiang Tan
190c69ece3 Remove skipped JRuby tests that are passing on 9.0.3.0. 2015-10-27 01:13:28 -02:00
Claudio B
504e5e102b Merge pull request #22060 from sebmck/tweak-wording
Tweaked wording used in some tests.
2015-10-25 08:04:40 -07:00
yuuji.yaginuma
8e7998cd5a fix rdoc markup [ci skip] 2015-10-25 21:25:16 +09:00
Sebastian McKenzie
a97dcde689 Tweaked wording used in some tests. 2015-10-25 08:57:50 +00:00
Guo Xiang Tan
682d624a85 Remove skip on tests that have been fixed. 2015-10-24 08:08:26 +08:00
Grey Baker
59ab2d1ee5 Catch invalid UTF-8 querystring values and respond with BadRequest 2015-10-23 14:56:47 +01:00
Guo Xiang Tan
c285bbec17 FIX: Randomly failing test when running without GIL. 2015-10-23 21:15:51 +08:00
Rafael Mendonça França
2828cfd137 Merge pull request #22029 from yui-knk/fixup_content_type_regexp
Use sufficient a regexp anchor to check `@response.content_type.to_s`
2015-10-22 13:51:54 -02:00
Sean Griffin
b1e40cff80 Merge pull request #19327 from rousisk/master
Change Integer#year to return a Fixnum instead of a Float to improve consistency
2015-10-22 07:07:27 -06:00
yui-knk
36005af64a Use sufficient a regexp anchor to check @response.content_type.to_s
This commit follows up of ea9bc06c9a47b839d5e2db94ba6bf7e29c8f0ae9.
To check `@response.content_type.to_s` is ended with `"xml"`,
to use `\z` is sufficient.
2015-10-22 20:33:32 +09:00
yui-knk
ad1f056016 Suppress warnings (warnings about AD::IntegrationTest HTTP request)
These warings have been appeared from
ea9bc06c9a47b839d5e2db94ba6bf7e29c8f0ae9.
2015-10-22 20:21:25 +09:00
Konstantinos Rousis
0d2ce9d723 Change Integer#year to return a Fixnum instead of a Float to improve consistency 2015-10-22 12:44:03 +02:00
Timo Schilling
db7eab78bd remove unnecessary forwardable require
`Forwardable` has been used in the past
2015-10-21 18:44:17 +02:00
Sean Griffin
ea9bc06c9a Merge pull request #20715 from simsalabim/feature/parse-rss-atom-as-xml
parse RSS/ATOM responses as XML, not HTML
2015-10-20 16:11:36 -06:00
Yves Senn
8572634450 Merge pull request #22003 from yui-knk/remove_needless_require_as
Delete needless `require 'active_support/deprecation'`
2015-10-20 13:46:50 +02:00
yui-knk
1099329be0 Delete needless require 'active_support/deprecation'
When `require 'active_support/rails'`, 'active_support/deprecation'
is automatically loaded.
2015-10-20 20:02:59 +09:00
Agis Anastasopoulos
3f81b3753f Show helpful messages on invalid param. encodings
Prior to this change, given a route:

    # config/routes.rb
    get ':a' => "foo#bar"

If one pointed to http://example.com/%BE (param `a` has invalid encoding),
a `BadRequest` would be raised with the following non-informative message:

    ActionController::BadRequest

From now on the message displayed is:

    Invalid parameter encoding: hi => "\xBE"

Fixes #21923.
2015-10-19 17:36:22 +03:00
Jeremy Daer
9d05430c95 Merge pull request #19135 from yuki24/access-control-support
Add basic support for access control headers to ActionDispatch::Static
2015-10-13 11:16:50 -07:00
Andrew White
f39ab9f343 Merge pull request #21849 from yui-knk/refactor_regexp_to_string
Change `Journey::Route#verb` to return string instead of regexp.
2015-10-12 13:28:03 +01:00
Rafael Sales
4db921a8e7 Allow multiple root routes in same scope level
When an application has multiple root entries with different
constraints, the current solution is to use `get '/'`. Example:

**Currently I have to do:**
```ruby
get '/', to: 'portfolio#show', constraints: ->(req) { Hostname.portfolio_site?(req.host) }
get '/', to: 'blog#show',      constraints: ->(req) { Hostname.blog_site?(req.host) }
root 'landing#show'
```

**But I would like to do:**
```ruby
root 'portfolio#show', constraints: ->(req) { Hostname.portfolio_site?(req.host) }
root 'blog#show',      constraints: ->(req) { Hostname.blog_site?(req.host) }
root 'landing#show'
```

Other URL matchers such as `get`, `post`, etc, already allows this, so I
think it's fair that `root` also allow it since it's just a shortcut for
a `get` internally.
2015-10-10 08:22:31 -03:00
Ronak Jangir
ee47e34d82 used predicate methods to avoid is_a? checks 2015-10-10 00:05:36 +05:30
amitkumarsuroliya
517613c39e Improved readability of Assertion docs, replaced ‘Assert’ -> ‘Asserts’ at all places [ci skip]
Following commit 495722a956
2015-10-09 00:40:15 +05:30
Matthew Erhard
bcfbd8ba21 Fix mounted engine named routes regression
When generating the url for a mounted engine through its proxy, the path should be the sum of three parts:

1. Any `SCRIPT_NAME` request header or the value of `ActionDispatch::Routing::RouteSet#relative_url_root`.
2. A prefix (the engine's mounted path).
3. The path of the named route inside the engine.

Since commit 44ff0313c1, this has been broken. Step 2 has been changed to:

2. A prefix (the value of `ActionDispatch::Routing::RouteSet#relative_url_root` + the engine's mounted path).

The value of `ActionDispatch::Routing::RouteSet#relative_url_root` is taken into account in step 1 of the route generation and should be ignored when generating the mounted engine's prefix in step 2.

This commit fixes the regression by having `ActionDispatch::Routing::RouteSet#url_for` check `options[:relative_url_root]` before falling back to `ActionDispatch::Routing::RouteSet#relative_url_root`. The prefix generating code then sets `options[:relative_url_root]` to an empty string. This empty string is used instead of `ActionDispatch::Routing::RouteSet#relative_url_root` and avoids the duplicate `relative_url_root` value in the final result.

This resolves #20920 and resolves #21459
2015-10-07 12:45:01 -04:00
Ronak Jangir
495722a956 Fixed wording in Assertion docs, changed ‘Assert’ -> ‘Asserts’ 2015-10-07 21:07:46 +05:30
Aaron Patterson
895c359182 use methods for accessing the cache control headers
Use the methods rack provides so we don't have to worry about the exact
header key.
2015-10-06 13:39:03 -07:00
Aaron Patterson
cddb700cc2 etag header is in Rack, so use it's response methods
Rack implements the Etag header manipulation methods, so we can use
those instead of ours.
2015-10-06 13:39:03 -07:00
Jeremy Daer
565094a8b5 Use Mime[:foo] instead of Mime::Type[:FOO] for back compat
Rails 4.x and earlier didn't support `Mime::Type[:FOO]`, so libraries
that support multiple Rails versions would've had to feature-detect
whether to use `Mime::Type[:FOO]` or `Mime::FOO`.

`Mime[:foo]` has been around for ages to look up registered MIME types
by symbol / extension, though, so libraries and plugins can safely
switch to that without breaking backward- or forward-compatibility.

Note: `Mime::ALL` isn't a real MIME type and isn't registered for lookup
by type or extension, so it's not available as `Mime[:all]`. We use it
internally as a wildcard for `respond_to` negotiation. If you use this
internal constant, continue to reference it with `Mime::ALL`.

Ref. efc6dd550ee49e7e443f9d72785caa0f240def53
2015-10-06 11:29:30 -07:00
Kasper Timm Hansen
5b69e30622 Merge pull request #21887 from abhishekjain16/doc_fix
Fix usage of word alternatively in docs [ci skip]
2015-10-06 20:21:00 +02:00
tanmay3011
148d1217a1 [ci skip] Change 'an URL' to 'a URL' as URL doesn't have a vowel sound 2015-10-06 23:34:05 +05:30
Abhishek Jain
fe33c15d4d Fix usage of word alternatively in docs [ci skip] 2015-10-06 23:20:27 +05:30
Aaron Patterson
69009f4473 move file sending to the response object
Just a slight refactor that delegates file sending to the response
object.  This gives us the advantage that if a webserver (in the future)
provides a response object that knows how to do accelerated file
serving, it can implement this method.
2015-10-05 16:50:50 -07:00
Sean Griffin
0e27ad3525 Merge pull request #21848 from yui-knk/test_suppress_warnings
Suppress warnings of `assigned but unused variable`
2015-10-04 07:39:46 -06:00
Vijay Dev
7976b6d306 Merge branch 'master' of github.com:rails/docrails 2015-10-04 12:33:14 +00:00
Jeremy Daer
2356403330 Introduce Headers#add. Move Response#add_header upstream.
* Introduce `ActionDispatch::Http::Headers#add` to add a value to
  a multivalued header.
* Move `Response#add_header` upstream: https://github.com/rack/rack/pull/957
* Match upstream `Response#have_header?` -> `#has_header?` name change.
2015-10-03 21:59:18 -07:00
yui-knk
218336fa54 Change Journey::Route#verb to return string instead of regexp.
By [this commit](0b476de445)
`Journey::Route#verb` need not to return verb as regexp.
The returned value is used by inspector, so change it to be a string.

Add inspect_with_multiple_verbs test case to keep the behavior of
inspector correctly.
2015-10-03 18:28:29 +09:00
yui-knk
2ded9c657a Suppress warnings of assigned but unused variable 2015-10-03 15:50:52 +09:00
Jeremy Daer
28a1a39967 Response#add_header for adding to multi-valued headers like Vary 2015-10-01 21:52:57 -07:00
Jeremy Daer
be5e6cea73 Don't set a nil Set-Cookie header when there aren't any cookies. Omit the header. 2015-10-01 18:47:13 -07:00
Gaurav Sharma
d87427c6c7 adding test for content type with default charset
* first test is for `default_charset` i.e `ActionDispatch::Response.default_charset = “utf-8”`

* In below test we are passing `ActionDispatch::Response.default_charset = 'utf-16’` so name of the test is irrelevant — “read content type without charset”
2015-10-02 01:27:23 +05:30
akihiro17
388124e411 Remove TestRouter#add_routes
Now, we use the mapper to build the routing table

related to 703275ba70
2015-09-29 13:43:11 +09:00
Aaron Patterson
64df657026 remove useless method
the caller of `handle_conditional_get!` checks the committed state of
the response, so we don't need to in the subclass.
2015-09-28 13:51:00 -07:00
Rafael Mendonça França
b0ce1415fb Revert "proper raise ArgumentError, divided large text new line"
This reverts commit 4147ab730e807f622e5260a5f876749ff41fef26.
2015-09-28 17:45:53 -03:00
Gaurav Sharma
4147ab730e proper raise ArgumentError, divided large text new line 2015-09-29 01:16:12 +05:30
Ronak Jangir
dd5b083f5d Renamed ‘Return’ to ‘Returns’ [ci skip] 2015-09-28 20:15:53 +05:30
yui-knk
2dcd79a161 [ci skip] Fix document of ActionController::RequestForgeryProtection
* add `end` to end of class definition
* add a blank line between explanation and example code
2015-09-28 21:15:54 +09:00
Ronak Jangir
4b4249fa7e Added test case for deprecation of Mime.const_defined? and removed use of it. 2015-09-27 14:15:17 +05:30
Rafael Mendonça França
854a454a91 Merge pull request #21768 from Gaurav2728/gaurav-doc_fix_for_mime
fix Mime type in doc since mime types via constants is deprecated [ci…
2015-09-25 22:37:13 -03:00
Aaron Patterson
80c468c2ad inherit from our AbstractStore 2015-09-25 17:12:46 -07:00
Aaron Patterson
add46482a5 pull the flash methods in to their own module
We only want to activate flash when the user has enabled it.  Api
servers don't use flash, so add an empty implementation to the base
Request object.
2015-09-25 16:09:58 -07:00
Aaron Patterson
ca324a0d90 commit the flash after the controller finishes being serviced
Committing the flash needs to happen in order for the session to be
written correctly, so lets guarantee that it actually does happen.
2015-09-25 15:35:34 -07:00
Aaron Patterson
d14caa300c move flash committing to the request object.
I'm doing this so that we can commit the flash to the session object Out
of Band of the flash middleware
2015-09-25 15:31:02 -07:00
Gaurav Sharma
2b8a862365 fix Mime type in doc since mime types via constants is deprecated [ci skip] 2015-09-26 00:20:41 +05:30
amitkumarsuroliya
832c95c315 Fix deprecated mime types via constants
Accessing mime types via constants is deprecated. Now, we are using `Mime::Type[:JSON]` instead of `Mime::JSON`
2015-09-25 07:01:45 +05:30
Aaron Patterson
9a1ca78d34 build the Set-Cookie header functionally
Use the Rack utility methods for functional header manipulation.  This
helps to eliminate coupling on the header hash
2015-09-24 13:54:42 -07:00
Aaron Patterson
fcf5e178dd move the Header hash to the super class
I want to move the header hash to the super request object in order to
consolidate behavior.  We should be switching out buffering strategies
rather than header strategies since things like "mutating headers after
send" is an error in both cases (buffering vs streaming).
2015-09-24 13:54:42 -07:00
Aaron Patterson
a2448e74b9 mutate headers before committing the response
We should not mutate headers after the response has been committed.
2015-09-24 13:54:42 -07:00
Aaron Patterson
10762e9e55 call get instead of controller.process
we want the request to go through the test harness, not directly call
the methods on the controller
2015-09-23 16:44:00 -07:00
Aaron Patterson
208956c0d0 remove controller construction
also remove req / res references
2015-09-23 16:42:15 -07:00
Aaron Patterson
85ab2e7328 stop directly referencing the request and response objects 2015-09-23 16:40:56 -07:00
Aaron Patterson
f150edb640 test framework allocates the controller for us 2015-09-23 16:01:11 -07:00
Aaron Patterson
53549a7585 type of response should not matter 2015-09-23 16:00:38 -07:00
Aaron Patterson
b5e36dd00a don't touch the response object until after we call get 2015-09-23 15:59:32 -07:00
Aaron Patterson
d175ab2bd6 stop directly setting headers on the controller
again, since we are going through the test harness, all this is done
for us.
2015-09-23 15:48:02 -07:00
Aaron Patterson
f679397634 stop constructing a request object in this setter
Since we just go through the normal test harness that sets up a request
for us, we don't need to do this anymore.
2015-09-23 15:48:01 -07:00
Aaron Patterson
4f7dbf50d9 test against controller responses
rather than calling methods on the controller.  We should test the
values returned by the controller rather than assuming that the
internals are implemented in a certain way.
2015-09-23 15:48:01 -07:00
Aaron Patterson
e16afe61ab stop applying default headers in ActionDispatch::Response
I'm making this change so that I can construct response objects that
*don't* have the default headers applied.  For example, I would like to
construct a response object from the return value of a controller.

If you need to construct a response object with the default headers,
then please use the alternate constructor:
`ActionDispatch::Response.create`
2015-09-23 15:48:01 -07:00
Kasper Timm Hansen
262f92364b Merge pull request #21736 from eliotsykes/document-bearer-prefix
Document Bearer prefix for Authorization header [ci skip]
2015-09-23 22:14:43 +02:00
Aaron Patterson
db1d4d31c9 don't access the response object before a request was made
It doesn't make sense to access the response object before a request is
made (how was a response object created without making a request?)  This
commit splits testing default headers and default header mutation tests
and removes access to the pre-request response object.
2015-09-23 12:08:32 -07:00
Aaron Patterson
39df51e171 split cookie tests
these should really be multiple tests.
2015-09-23 11:25:33 -07:00
Aaron Patterson
4cf449df91 don't mutate a response object after to_a
When the response object is `to_a`'d, that means it's been written to
the socket.  It doesn't make sense to mutate the response object after
it's been written (and this may raise an exception in the future).
2015-09-23 11:23:22 -07:00
Eliot Sykes
619481559d Document Bearer prefix for Authorization header [ci skip] 2015-09-23 18:00:41 +01:00
amitkumarsuroliya
96eece6cb4 Updated Mime Negotiations docs [ci skip]
As we all know that Accessing mime types via constants is deprecated. Now, we are using `Mime::Type[:JSON]` instead of `Mime::JSON`
2015-09-23 14:52:27 +05:30
Aaron Patterson
9f23ee0fdc ask the request object for the session
The flash middleware shouldn't know how to look up the session object.
Just ask the request for that information.
2015-09-22 17:43:15 -07:00
Aaron Patterson
a9f28600e9 don't deal with nil values
We can know whether or not there is a content type object, and just exit
early.  There is no need to `try` so hard.
2015-09-22 16:20:27 -07:00
Juanito Fatas
2510784e78 Fix a typo: Mime::Types should be Mime::Type [ci skip] 2015-09-22 10:04:27 +08:00
Jeremy Daer
b694796da0 Merge pull request #21703 from ronakjangir47/redirect_error_messages
Added assertion for error messages for redirection to nil and params
2015-09-21 17:44:19 -07:00
Aaron Patterson
6486c7ac94 drop array allocations on Mime::Type#=~
Synonyms are always a list of strings, and we have access to the
internal string representation, so we can avoid allocating new arrays.
2015-09-21 15:30:02 -07:00
Aaron Patterson
e35225e938 remove another blank? call 2015-09-21 15:06:52 -07:00
Aaron Patterson
1fe0a1b5eb remove html_types set
Now that `all` has it's own object, we don't need the html_types Set.
2015-09-21 15:05:00 -07:00
Aaron Patterson
f8ba48c150 introduce an All mime type
This class gives us the `all?` predicate method that returns true
without hitting method missing
2015-09-21 14:10:17 -07:00
Aaron Patterson
7cdb2ec963 remove blank? calls on ==
Since Mime::Type implements `method_missing`, and `blank?` triggers it's
positive branch:

  f9dda1567e/actionpack/lib/action_dispatch/http/mime_type.rb (L342)

We should stop calling `blank?`.
2015-09-21 14:00:52 -07:00
Aaron Patterson
f9dda1567e change inheritance to composition
Changes `Mimes` to compose a set rather than inherit from array.  With
this change we don't need to define as many methods, so ISEQ memory is
saved.  Also it is clear which methods break the set cache.
2015-09-21 13:45:27 -07:00
Aaron Patterson
8325d4c473 update changelog for mime changes 2015-09-21 12:13:13 -07:00
Aaron Patterson
fb9a39f4fa swap upcase and to_sym 2015-09-21 12:11:27 -07:00
Aaron Patterson
e4ba720c17 stop calling deprecated methods
We should be asking the mime type method for the mime objects rather
than via const lookup
2015-09-21 12:04:12 -07:00
Aaron Patterson
efc6dd550e deprecate accessing mime types via constants
We don't want to manage a list of constants on `Mime::`.  Managing
constants is strange because it will break method caches, not to mention
looking up by a constant could cause troubles.  For example suppose
there is a top level constant `HTML`, but nobody registers the HTML mime
type and someone accesses `Mime::HTML`.  Instead of getting an error
about how the mime type doesn't exist, instead you'll get the top level
constant.

So, instead of directly accessing the constants, change this:

  Mime::HTML

To this:

  Mime::Type[:HTML]
2015-09-21 12:04:12 -07:00
Aaron Patterson
ad1d0b8408 cache the new type object on the stack
Now we don't have to look it up with a `const_get`.
2015-09-21 12:04:12 -07:00
Ronak Jangir
58ec903cd4 Added assertion for error messages for redirection to nil and params
As both `redirect_to_nil` and `redirect_to_params` are raising same `ActionController::ActionControllerError` so it’s good to assert error messages as well
2015-09-21 22:02:03 +05:30
Harry V. Kiselev
ab0f846e20 Update routing.rb
forgotten end of the block
2015-09-20 22:54:24 +03:00
Akira Matsuda
4a4f8500a0 Typppo 2015-09-21 01:32:54 +09:00
Ronak Jangir
efa019b49c Added test for send_file_headers called with nil content type 2015-09-19 18:35:41 +05:30
Aaron Patterson
38d2bf5fd1 mostly remove the ParamsParser middleware
This can still be added to the middleware stack, but is really not
necessary.  I'll follow up with a commit that deprecates the constant
2015-09-18 15:36:55 -07:00
Aaron Patterson
58dba19a0b remove outdated comment
all parameter parsing is done on the request object now, so we don't
need to worry about at ParamParser middleware
2015-09-18 14:34:42 -07:00
Aaron Patterson
d14d41282e all parameter parsing is done through the request object now. 2015-09-18 14:34:09 -07:00
Aaron Patterson
b8b7664415 let the request object handle parsing XML posts
The test request object will handle parsing XML posts now, so we don't
need to eagerly parse them in the test harness
2015-09-18 14:32:20 -07:00
Aaron Patterson
05b08f2952 remove setting request parameters for JSON requests
The request object will automatically parse these in the
`parse_formatted_parameters` method, so we don't have to worry about it.
2015-09-18 13:52:30 -07:00
Aaron Patterson
8db2e67c0a remove the request parameter from parse_formatted_parameters
This is an instance method on the request object now so we don't need it
anymore
2015-09-18 13:05:01 -07:00
Aaron Patterson
a1ced8b52c do not instantiate a param parser middleware
we don't actually need a param parser middleware instance since the
request object will take care of parsing parameters for us.  For now,
we'll just configure the parameter parsers on the request in this class.
2015-09-18 13:03:07 -07:00
Aaron Patterson
b93c226d19 push the parameter parsers on to the class
The middleware stack is a singleton in the application (one instance is
shared for the entire application) which means that there was only one
opportunity to set the parameter parsers.  Since there is only one set
of parameter parsers in an app, lets just configure them on the request
class (since that is where they are used).
2015-09-18 11:46:51 -07:00
Aaron Patterson
91d05082e4 stop eagerly parsing parameters
Parameters will not be parsed until they are specifically requested via
the `request_parameters` method.
2015-09-18 11:37:02 -07:00
Aaron Patterson
1555ae9be1 only wrap the strategy with exception handling
we need to be more specific about exception handling when dealing with
the parse strategies.  The calls to `return yield` can also raise an
exception, but we don't want to handle that in *this* code.
2015-09-18 11:34:54 -07:00
Aaron Patterson
73396238e7 pull normalize_encode_params up
`normalize_encode_params` is common to all parser code paths, so we can
pull that up and always apply it before assigning the request parameters
2015-09-18 11:26:15 -07:00
Aaron Patterson
93a391e786 remove the default parameter from the parser method
since there is only one "default" strategy now, we can just use the
block parameter for that.
2015-09-18 11:24:13 -07:00
Aaron Patterson
3efb0bcdaf move parameter parsing to the request object
All parameter parsing should be on the request object because the
request object is the object that we ask for parameters.
2015-09-18 11:19:04 -07:00
Akira Matsuda
dcecbb4234 File encoding is defaulted to utf-8 in Ruby >= 2.1 2015-09-18 17:05:05 +09:00
Juanito Fatas
1fd99224dc Use rack.session_options instead of directly change env 2015-09-16 01:01:53 +08:00
Aaron Patterson
49316d8a63 fewer direct env manipulations
this commit removes some direct access to `env`.
2015-09-15 07:43:04 -07:00
Aaron Patterson
ec6638a237 allocate request objects with the env hash, set routes on the request
This commit is to abstract the code away from the env hash.  It no
longer needs to have the routes key hard coded.
2015-09-15 07:38:39 -07:00
Aaron Patterson
2f0bc1f789 only "normalize" once 2015-09-14 16:25:48 -07:00
Aaron Patterson
2db7304c2c create a new renderer instance on calls to for
This changes the renderer class to store the controller and defaults as
an instance variable rather than allocating a new class.  You can create
a new renderer with an new env by calling `Renderer#new` or use new
defaults by calling `Renderer#with_defaults` and saving the return value
somewhere.

Also I want to keep the `env` private since I would like to change the
keys in the future.  This commit only translates particular keys that
the user requested.
2015-09-14 15:58:12 -07:00
Aaron Patterson
8e489db9de eagerly allocate the renderer object
this means the reader doesn't need to lock, but does have the added cost
of a new object created for every controller
2015-09-14 15:29:19 -07:00
Aaron Patterson
9808cdfa03 initialize @renderer to avoid ivar warnings 2015-09-14 15:23:25 -07:00
Aaron Patterson
167db914ed add a lock when allocating the renderer
The controller class is shared among threads, so we need to lock when
allocating the Renderer.
2015-09-14 14:54:33 -07:00
Aaron Patterson
c33f51a894 rack_response should use the status it's given 2015-09-14 09:19:30 -07:00
Pedro Nascimento
7c4716008d Fix HSTS default expire in ActionDispatch::SSL docs. 2015-09-14 00:04:51 -03:00
Claudio B.
9f4f08cdc1 Merge pull request #21584 from claudiob/remove-hawd-doc
Remove wrong doc line about AC::Parameters
2015-09-10 14:51:54 -07:00
claudiob
82239a995d Remove wrong doc line about AC::Parameters
AC::Parameters does not inherit from HashWithIndifferentAccess
since #20868 by @sikachu
2015-09-10 14:48:23 -07:00
eileencodes
b3ab44f6cb Update documentation to reflect Rack::Session::Abstract changes
`Rack::Session::Abstract::ID` is now deprecated and
`Rack::Session::Abstract::Persisted` should be used instead.
2015-09-09 09:04:55 -04:00
eileencodes
43d7a03aef Handle Content-Types that are not :json, :xml, or :url_encoded_form
In c546a2b this was changed to mimic how the browser behaves in a real
situation but left out types that were registered.

When this was changed it didn't take `text/plain` or `text/html` content
types into account. This is a problem if you're manipulating the
`Content-Type` headers in your controller tests, and expect a certain
result.

The reason I changed this to use `to_sym` is because if the
`Content-Type` is not registered then the symbol will not exist. If it's
one of the special types we handle that specifically (:json, :xml, or
:url_encoded_form). If it's any registered type we handle it by setting
the `path_parameters` and then the `request_parameters`. If the `to_sym`
returns nil an error will be thrown.

If the controller test sets a `Content-Type` on the request that `Content-Type`
should remain in the header and pass along the filename.

For example:
If a test sets a content type on a post
```
@request.headers['CONTENT_TYPE'] = 'text/plain'
post :create, params: { name: 'foo.txt' }
```

Then `foo.txt` should be in the `request_parameters` and params related
to the path should be in the `path_parameters` and the `Content-Type`
header should match the one set in the `@request`. When c546a2b was
committed `text/plain` and `text/html` types were throwing a "Unknown
Content-Type" error which is misleading and incorrect.

Note: this does not affect how this is handled in the browser, just how
the controller tests handle setting `Content-Type`.
2015-09-09 09:04:44 -04:00
Aaron Patterson
fecf9d729a ensure that mutating headers will impact the content_type method 2015-09-08 16:14:47 -07:00
Aaron Patterson
a27bb77482 mime_type will always return a string 2015-09-08 16:14:47 -07:00
Aaron Patterson
c10efc8386 remove parse_content_type parameter
This method is specifically about the content type so lets remove the
parameter.
2015-09-08 16:14:47 -07:00
Aaron Patterson
376cccbdc1 avoid allocations when there is no content type set
create a singleton content type that just has nils, so that we don't
have to allocate a content type object all the time.
2015-09-08 16:14:47 -07:00
Aaron Patterson
8301969df9 handle implicit rendering correctly
If someone sets just a charset, but depends on the implicit type from
rendering, this will store a strange content type header that looks like
this:  `; charset=blah`.  This is so that when the content type header
is parsed again, it will return nil for the actual type.
2015-09-08 16:14:47 -07:00
Aaron Patterson
bf8b22b392 remove mime type lookups when parsing the content type
It turns out that the response object never really cares what the mime
type object is, so just use the string.
2015-09-08 16:14:47 -07:00
Aaron Patterson
31b3294d49 refactor content type setting
pull content-type setting to a private method to dry it up.
2015-09-08 16:14:47 -07:00
Aaron Patterson
1cc315c83c make Content-Type header the canonical location for content-type info
Instead of storing content type information in an ivar and a header,
lets move to just store the content type info in just the header.
2015-09-08 16:14:47 -07:00