Commit Graph

13221 Commits

Author SHA1 Message Date
Aaron Patterson
d5c6babd9e AC::Request#format always returns a value, so we do not need to try 2016-02-09 12:12:15 -08:00
Aaron Patterson
02c3867882 speed up string xor operation and reduce object allocations
```
[aaron@TC rails (master)]$ cat xor.rb
a = "\x14b\"\xB4P8\x05\x8D\xC74\xC3\xEC}\xFDf\x8E!h\xCF^\xBF\xA5%\xC6\xF0\xA9\xF9x\x04\xFA\xF1\x82"
b = "O.\xF7\x01\xA9D\xA3\xE1D\x7FU\x85\xFC\x8Ak\e\x04\x8A\x97\x91\xD01\x02\xA4G\x1EIf:Y\x0F@"

def xor_byte_strings(s1, s2)
  s1.bytes.zip(s2.bytes).map { |(c1,c2)| c1 ^ c2 }.pack('c*')
end

def xor_byte_strings2(s1, s2)
  s2_bytes = s2.bytes
  s1.bytes.map.with_index { |c1, i| c1 ^ s2_bytes[i] }.pack('c*')
end

require 'benchmark/ips'
require 'allocation_tracer'

Benchmark.ips do |x|
  x.report 'xor_byte_strings' do
    xor_byte_strings a, b
  end

  x.report 'xor_byte_strings2' do
    xor_byte_strings2 a, b
  end
end

ObjectSpace::AllocationTracer.setup(%i{type})
result = ObjectSpace::AllocationTracer.trace do
  xor_byte_strings a, b
end
p :xor_byte_strings => result
ObjectSpace::AllocationTracer.clear
result = ObjectSpace::AllocationTracer.trace do
  xor_byte_strings2 a, b
end
p :xor_byte_strings2 => result
[aaron@TC rails (master)]$ ruby -I~/git/allocation_tracer/lib xor.rb
Calculating -------------------------------------
    xor_byte_strings    10.087k i/100ms
   xor_byte_strings2    11.339k i/100ms
-------------------------------------------------
    xor_byte_strings    108.386k (± 5.8%) i/s -    544.698k
   xor_byte_strings2    122.239k (± 3.0%) i/s -    612.306k
{:xor_byte_strings=>{[:T_ARRAY]=>[38, 0, 0, 0, 0, 0], [:T_STRING]=>[2, 0, 0, 0, 0, 0]}}
{:xor_byte_strings2=>{[:T_ARRAY]=>[3, 0, 0, 0, 0, 0], [:T_DATA]=>[1, 0, 0, 0, 0, 0], [:T_IMEMO]=>[2, 0, 0, 0, 0, 0], [:T_STRING]=>[2, 0, 0, 0, 0, 0]}}
```
2016-02-08 15:40:25 -08:00
Arthur Nogueira Neves
98ed722039 Merge pull request #23534 from bronson/fix-redefined-warning
fix 'method redefined' warnings
2016-02-08 17:19:15 -05:00
Rafael Mendonça França
9b5ae716db Revert "Merge pull request #23562 from Azzurrio/patch-1"
This reverts commit 8c3cca5e113213958469b1cec8aa9a664535251a, reversing
changes made to 9dcf67c4da35b165301865d9721da1d552f7e03f.

Reason: https://github.com/rails/rails/pull/23562#issuecomment-181442569
2016-02-08 14:09:29 -02:00
Karim El-Husseiny
ec82c13dd4 Update rails-html-sanitizer version to v1.0.3
rails-html-sanitizer 1.0.2 is vulnerable: https://groups.google.com/d/msg/rubyonrails-security/uh--W4TDwmI/m_CVZtdbFQAJ
2016-02-08 17:04:31 +02:00
Matthew Draper
15f6ad3adc Merge pull request #23532 from matthewd/live-interlock
Hand off the interlock to the new thread in AC::Live
2016-02-08 06:42:49 +10:30
David Heinemeier Hansson
7e35cb2987 Add SVG as a default mime type 2016-02-07 15:34:13 +01:00
Scott Bronson
73d1975810 fix 'method redefined' warnings 2016-02-06 18:24:10 -08:00
Matthew Draper
3e4a69e52d Hand off the interlock to the new thread in AC::Live
Most importantly, the original request thread must yield its share lock
while waiting for the live thread to commit -- otherwise a request's
base and live threads can deadlock against each other.
2016-02-07 08:32:27 +10:30
Kasper Timm Hansen
4e4bcae084 Avoid coupling Action Pack to Railties.
Referencing Rails.env without checking if it's defined couples
us to Railties.

Fix by avoiding the line breaks if we don't have an env check
to rely on.
2016-02-06 22:28:59 +01:00
Aaron Patterson
38b5af6595 add missing require 2016-02-05 13:44:08 -08:00
Aaron Patterson
a640da454f disable controller / view thread spawning in tests
Tests can (and do) access the database from the main thread.  In this
case they were starting a transaction, then making a request.  The
request would create a new thread, which would allocate a new database
connection.  Since the main thread started a transaction that contains
data that the new thread wants to see, the new thread would not see it
due to data visibility from transactions.  Spawning the new thread in
production is fine because middleware should not be doing database
manipulation similar to the test harness.  Before 603fe20c it was
possible to set the database connection id based on a thread local, but
603fe20c changes the connection lookup code to never look at the
"connection id" but only at the thread object itself.  Without that
indirection, we can't force threads to use the same connection pool as
another thread.

Fixes #23483
2016-02-05 11:42:15 -08:00
Prathamesh Sonpatki
7ca7c0ef28 Put some space for non-assets requests in development mode
- Fixes #23428.
2016-02-03 15:48:38 +05:30
Sean Griffin
522099a13f Sleep well, sweet prince
Prototype, you have served us well. But you are no longer how we make an
XMLHttpRequest. RIP
2016-02-02 18:55:33 -07:00
Rafael França
dd041934dd Merge pull request #23396 from pschambacher/pschambacher/fix_assert_generates
Duplicate assert_generates options before modifying it
2016-02-02 01:49:55 -02:00
Kang-Kyu Lee
c4ac23bfa6 Update CHANGELOG.md
fix indentation to show it as code
2016-02-01 14:21:34 -08:00
Rafael Mendonça França
60b040e362 Add some Action Cable CHANGELOG entries
And improve changelongs.

[ci skip]
2016-02-01 19:57:50 -02:00
Sean Griffin
49f6ce63f3 Preparing for Rails 5.0.0.beta2 2016-02-01 14:37:52 -07:00
Kasper Timm Hansen
84c3738c14 Converge on filter.
Some places were saying filter, while others said filter_options, spare the ambiguity
and use filter throughout.

This inlines a needless local variable and clarifies a route filter consists of defaults
and values to match against.
2016-02-01 22:15:21 +01:00
Kasper Timm Hansen
5966b801ce Simplify filter normalization.
Assume the filter is a string, if it wasn't a hash and isn't nil. Remove needless else
and rely on Ruby's default nil return.

Add spaces within hash braces.
2016-02-01 22:11:52 +01:00
Kasper Timm Hansen
baae952588 Merge pull request #23225 from vipulnsward/20420-rake-routes-options
Add options for rake routes task
2016-02-01 22:09:22 +01:00
Vipul A M
8a436fdd98 Add options for rake routes task
Add two options: `-c` and `-g`.
`-g` option returns the urls name, verb and path fields that match the pattern.
`-c` option returns the urls for specific controller.

Fixes #18902, and Fixes #20420

[Anton Davydov & Vipul A M]
2016-02-02 00:27:30 +05:30
Jon Moss
b3427c662e Add documentation for #17573
Fixes some parts of #23148.

[ci skip]
2016-02-01 13:28:30 -05:00
Pierre Schambacher
c3639458af Duplicate assert_generates options before modifying it 2016-02-01 11:51:45 +00:00
Matthew Draper
d6f2000a67 Wrangle the asset build into something that sounds more general 2016-02-01 05:03:03 +10:30
Tom Prats
45a75a3fcc Update Session to utilize indiffernt access 2016-01-30 19:30:32 -05:00
Rafael França
8d30ef7cdd Merge pull request #23342 from y-yagi/remove_unused_variable
remove unused variable from render test
2016-01-30 12:11:02 -05:00
Rafael França
dfde688496 Merge pull request #23343 from y-yagi/remove_unused_require
remove unused require
2016-01-30 12:10:47 -05:00
eileencodes
c4d85dfbc7 Handle response_body= when body is nil
There are some cases when the `body` in `response_body=` can be set to
nil. One of those cases is in `actionpack-action_caching` which I found
while upgrading it for Rails 5.

It's not possible to run `body.each` on a `nil` body so we have to
return after we run `response.reset_body!`.
2016-01-30 09:42:59 -05:00
yuuji.yaginuma
a027a750d0 remove unused require
`with_indifferent_access` had been used in `assigns` method, but has been removed in ca83436.
2016-01-30 13:50:22 +09:00
yuuji.yaginuma
647a04cdbc remove unused variable from render test
This removes the following warning.

```
rails/actionpack/test/controller/render_test.rb:278: warning: assigned but unused variable - response
```
2016-01-30 13:40:12 +09:00
Tom Prats
82dc8266dd Update session to have indifferent access 2016-01-29 17:22:05 -05:00
Tawan Sierek
349f187f58 Add additional documentation on Headers#[] [ci skip]
Issue #16519 covers confusion potentially caused by how HTTP
headers, that contain underscores in their names, are retrieved
through `ActionDispatch::Http::Headers#[]`.

This confusion has its origin in how a CGI maps HTTP header names
to variable names. Even though underscores in header names
are rarely encountered, they are valid according to RFC822 [1].
Nonetheless CGI like variable names, as requested by the Rack
specfication, will only contain underscores and therefore the
original header name cannot be recovered after the Rack server passed
on the environemnt hash. Please, see also the disscussion on
StackOverflow [2], which also links to an explaination in the
nginx documentation [3].

[1] http://www.ietf.org/rfc/rfc822.txt
[2] http://stackoverflow.com/questions/22856136/why-underscores-are-forbidden-in-http-header-names
[3] https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#missing-disappearing-http-headers
2016-01-29 22:11:16 +01:00
Rafael Mendonça França
f16709231d Merge pull request #22800 from dgynn/pr_cache_helper_options
Restore ability to pass extra options to cache stores
2016-01-29 00:15:19 -05:00
Aaron Patterson
c082a7aae4 speed up accept header parsing a bit.
Accept header is taken from what Safari on El Capitan sends:

```ruby
require 'benchmark/ips'
require 'action_dispatch/http/mime_type'
require 'active_support/all'

accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'

Benchmark.ips do |x|
  x.report "omg" do
    Mime::Type.parse(accept)
  end
end
```

Before:

```
[aaron@TC actionpack (master)]$ be ruby ../x.rb
Calculating -------------------------------------
                 omg     3.181k i/100ms
-------------------------------------------------
                 omg     35.062k (±12.8%) i/s -    174.955k
[aaron@TC actionpack (master)]$ be ruby ../x.rb
Calculating -------------------------------------
                 omg     3.153k i/100ms
-------------------------------------------------
                 omg     33.724k (±12.4%) i/s -    167.109k
[aaron@TC actionpack (master)]$ be ruby ../x.rb
Calculating -------------------------------------
                 omg     3.575k i/100ms
-------------------------------------------------
                 omg     37.251k (±10.4%) i/s -    185.900k
```

After:

```
[aaron@TC actionpack (master)]$ be ruby ../x.rb
Calculating -------------------------------------
                 omg     3.365k i/100ms
-------------------------------------------------
                 omg     40.069k (±16.1%) i/s -    198.535k
[aaron@TC actionpack (master)]$ be ruby ../x.rb
Calculating -------------------------------------
                 omg     4.168k i/100ms
-------------------------------------------------
                 omg     47.596k (± 7.7%) i/s -    237.576k
[aaron@TC actionpack (master)]$ be ruby ../x.rb
Calculating -------------------------------------
                 omg     4.282k i/100ms
-------------------------------------------------
                 omg     43.626k (±17.7%) i/s -    209.818k
```
2016-01-28 16:08:15 -08:00
Aaron Patterson
f8c9ef8401 convert AcceptList to a regular class
we never use this custom array outside the mime type `parse` method.  We
can reduce the interaction to just a regular array, so we should use
that instead (IOW, there was nothing special about AcceptList so we
should remove it).
2016-01-28 14:14:32 -08:00
eileencodes
5181d5c283 Run file.close before unlinking for travis
This works on OSX but for some reason travis is throwing a
```
  1) Error:
ExpiresInRenderTest#test_dynamic_render_with_absolute_path:
NoMethodError: undefined method `unlink' for nil:NilClass
```
Looking at other tests in Railties the file has a name and we close
it before unlinking, so I'm going to try that.
2016-01-28 15:23:55 -05:00
eileencodes
020d6fda29 Regression test for rendering file from absolute path
Test that we are not allowing you to grab a file with an absolute path
outside of your application directory. This is dangerous because it
could be used to retrieve files from the server like `/etc/passwd`.
2016-01-28 14:25:57 -05:00
Aaron Patterson
a447252ac4 remove == from AcceptItem
Remove nonsense definition of == from `AcceptItem`.  The definition only
compared names and not `q` values or even object identity.  The only use
was in the `assort!` method that really just wanted the index of the
item given the item's name.  Instead we just change the caller to use
`index` with the block form.
2016-01-27 18:28:05 -08:00
Aaron Patterson
7fc79bc790 remove useless private methods
This commit refactors the private methods that were just aliases to []
to just directly use [] and cache the return values on the stack.
2016-01-27 18:28:05 -08:00
Aaron Patterson
f7f59c2eb7 change @app_xml_idx to an lvar and cache it on the stack
same strategy as `@text_xml_idx`: cache it on the stack to avoid ivar
lookups and the `||=` call.
2016-01-27 18:28:05 -08:00
Aaron Patterson
542b2e9c9b change @text_xml_idx to an lvar and cache it on the stack
this eliminates the ivar lookup and also eliminates the `||=`
conditional that happens every time we called the `text_xml_idx` method.
2016-01-27 18:28:04 -08:00
Marek
385e0a3311 Fix typo in strong params hash deprecation message
and remove unecessary spaces in string interpolation.
2016-01-27 18:41:48 +00:00
Akira Matsuda
5262bf544a doc typo
[ci skip]
2016-01-27 18:19:53 +09:00
Aaron Patterson
3844854af1 add a skip for failing test 2016-01-26 18:01:24 -08:00
Aaron Patterson
00285e7cf7 fix permitted? conditional for render calls 2016-01-26 18:00:49 -08:00
Aaron Patterson
9777a97ffa Merge pull request #23242 from maclover7/fix-error-sec
Fix undefined error for `ActionController::Parameters`
2016-01-26 17:24:37 -08:00
Jon Moss
534b12afb5 Fix undefined error for ActionController::Parameters 2016-01-26 20:16:40 -05:00
Aaron Patterson
0361d8449f clear view path cache between tests
The cache for `render file:` seems to also be used in the case of
`render(string)`.  If one is supposed to be a hit and the other is
supposed to be a miss, and they both reference the same file, then the
cache could return incorrect values.  This commit clears the cache
between runs so that we get non-cached behavior.
2016-01-26 17:06:31 -08:00
Aaron Patterson
6dfab475ca Merge branch '5-0-beta-sec'
* 5-0-beta-sec:
  bumping version
  fix version update task to deal with .beta1.1
  Eliminate instance level writers for class accessors
  allow :file to be outside rails root, but anything else must be inside the rails view directory
  Don't short-circuit reject_if proc
  stop caching mime types globally
  use secure string comparisons for basic auth username / password
2016-01-25 11:25:11 -08:00
Aaron Patterson
908c011395 bumping version 2016-01-25 10:22:15 -08:00
Vipul A M
c7281b37ac Fix nodoc to internal class error document some of them
[ci skip]
Fixes #20808

[Vipul A M & Julio Lopez]
2016-01-25 23:04:40 +05:30
Aaron Patterson
b7758b40fc allow :file to be outside rails root, but anything else must be inside the rails view directory
CVE-2016-0752
2016-01-22 15:02:27 -08:00
Aaron Patterson
51313c21a6 stop caching mime types globally
Unknown mime types should not be cached globally.  This global cache
leads to a memory leak and a denial of service vulnerability.

CVE-2016-0751
2016-01-22 15:00:31 -08:00
Aaron Patterson
17e6f1507b use secure string comparisons for basic auth username / password
this will avoid timing attacks against applications that use basic auth.

CVE-2015-7576
2016-01-22 14:55:14 -08:00
Vipul A M
48c03c59c3 rm changelog for unreleased changes fixes
Based on https://github.com/rails/rails/pull/23167/files#r50507317

[ci skip]
2016-01-22 12:43:03 +05:30
Rafael França
6fcc3c47eb Merge pull request #23167 from maclover7/fix-21032
Fix `ActionController::Parameters#==` bug
2016-01-21 17:34:55 -05:00
Jon Moss
627f736cc0 Fix ActionController::Parameters#== bug
See bug #21032.
2016-01-21 17:28:18 -05:00
Vipul A M
9b3dc9d850 - Fix warning introduced in 77acc004ef when fixing API responses.
- render :text is deprecated, so added an assertion for it.
2016-01-22 00:38:12 +05:30
sealocal
27a4e9345f remove doc reference to ActionController::MimeResponds#respond_to 2016-01-20 23:41:07 -08:00
sealocal
36b359f816 document simple example of ActionController::MimeResponds#respond_to 2016-01-20 23:39:46 -08:00
Jon Moss
77acc004ef Re-add ActionController::ApiRendering
- Fixes bug #23142.
- Bug was occurring only with ActionController::API, because `_process_options` wasn't being run for API requests, even though it was being run for normal app requests.
2016-01-20 19:16:23 -05:00
Aaron Patterson
06397336b2 Merge pull request #23140 from rails/fix-search-for-custom-routes
Fix marking of custom routes for Journey
2016-01-20 15:14:13 -08:00
Godfrey Chan
24e39ffb53 Merge pull request #17573 from zerothabhishek/master
Response etags to always be weak: Prefixed 'W/' to value returned by Act...
2016-01-20 14:27:52 -08:00
Andrew White
1eace9402b Fix marking of custom routes for Journey
The Mapper build_path method marks routes where path parameters are part
of a path segment as custom routes by altering the regular expression, e.g:

    get '/foo-:bar', to: 'foo#bar'

There were some edge cases where certain constructs weren't being picked
up and this commit fixes those.

Fixes #23069.
2016-01-20 17:59:13 +00:00
eileencodes
4b507dff1e Revert "Remove literal? check to fix issue with prefixed optionals"
This reverts commit 5d1b7c3b441654e8008dcd303f5367883ec660a6.

The change here didn't actually fix the issue it was trying to fix, and
this isn't the correct way to fix either issue. The problem is switching
from the builder to grouping with find_all/regex is now very dependent
on how you structure your path pattern.
2016-01-20 10:24:33 -05:00
abhishek
e362c31b34 Response etags to always be weak: Prefixed W/ to value returned by ActionDispatch::Http::Cache::Response#etag= such that etags set in fresh_when and stale? are weak. For #17556. 2016-01-20 07:57:30 +05:30
schneems
fe55163f11 Revert "Its ideal to set Vary: Accept-Encoding, irrespective of whether gzipped version exists or not. This is helpful for CDN's to later distinguish assets, based on previous, current copies and introduced gzip version if any."
This reverts commit 067c52f608568e35181830a5c1016e382650e655.

Conversation: https://github.com/rails/rails/pull/23120#issuecomment-173007011
2016-01-19 16:22:40 -06:00
Richard Schneeman
a4c82d8e64 Merge pull request #23120 from vipulnsward/always-set-vary-for-static-assets
Its ideal to set Vary: Accept-Encoding, irrespective of whether gzipped or not
2016-01-19 13:33:51 -06:00
schneems
875a0b6e4f Link to docs instead of listing methods 2016-01-19 12:32:55 -06:00
Vipul A M
067c52f608 Its ideal to set Vary: Accept-Encoding, irrespective of whether gzipped version exists or not. This is helpful for CDN's to later distinguish assets, based on previous, current copies and introduced gzip version if any.
For ref: https://www.fastly.com/blog/best-practices-for-using-the-vary-header

This change sets `Vary` header always, to be on safer side
2016-01-19 23:48:59 +05:30
schneems
3f2ac413b7 Add methods to StrongParameters
It's reasonable to expose different value readers.
2016-01-19 12:06:29 -06:00
schneems
66d705b3e7 [close #23084] Deprecated StrongParameters
We can provide a more flexible upgrade experience by warning users they are using unsafe methods instead of forcing the safe API by deprecating before removal. This PR provides this functionality.
2016-01-19 12:05:44 -06:00
Vipul A M
ee14fbe4ee Pass through AP CHANGELOG [ci skip] 2016-01-18 12:05:23 +05:30
eileencodes
5d1b7c3b44 Remove literal? check to fix issue with prefixed optionals
In commit d993cb3 `build_path` was changed from using `grep` to
`find_all` to save array allocations.

This change was a little too aggressive in that when the dash comes
before the symbol like `/omg-:song` the symbol is skipped.

Removing the check for `n.right.left.literal?` fixes this issue, but
does add back some allocations. The number of allocations are still well
less than before.

I've added a regression test to test this behavior for the future.

Fixes #23069.

Array allocations as of d993cb3:

```
{:T_SYMBOL=>11}
{:T_REGEXP=>17}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_OBJECT=>91009}
{:T_DATA=>100088}
{:T_HASH=>114013}
{:T_STRING=>159637}
{:T_ARRAY=>321056}
{:T_IMEMO=>351133}
```

Array allocations after this change:

```
{:T_SYMBOL=>11}
{:T_REGEXP=>1017}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_DATA=>84092}
{:T_OBJECT=>87009}
{:T_HASH=>110015}
{:T_STRING=>166152}
{:T_ARRAY=>322056}
{:T_NODE=>343558}
```
2016-01-16 15:00:18 -05:00
Rafael França
cff9cd9fe7 Merge pull request #22985 from akshay-vishnoi/fix-typo
test `include?`- fix typo
2016-01-16 03:59:29 -02:00
Rebecca Skinner
99e9630ef8 Fix typo in docs [ci skip] 2016-01-14 11:04:08 +08:00
Akira Matsuda
d9bdb61158 Space Oddity
Converting nbsp(\u{00A0}) to the normal ASCII space(\u{0020})
[ci skip]
2016-01-14 10:36:54 +09:00
Yves Senn
f5ab4055b9 docs, formatting pass over changelogs. [ci skip] 2016-01-13 10:19:55 +01:00
Aaron Patterson
7b7b12f598 do not run in parallel on travis 2016-01-12 15:55:47 -08:00
Aaron Patterson
dd73144658 remove present? calls
Empty strings / data structures should be treated differently than nils.
We don't really need these calls here (don't pass in blank strings).
2016-01-12 14:22:02 -08:00
Aaron Patterson
04d61612f9 monkey patch recycle! on to controllers once
Instead of checking whether the class has recycle! or not, we can just
always add the method to all controller classes when the test harness is
loaded.  Technically this means that the controller test harness will
not work with controllers that do not inherit from AC::Metal, but then,
I'm not sure that is supported anyway.

Mixing in the module one will ensure that we don't break method caches,
and eliminates a runtime check so it should speed up tests (slightly).
2016-01-12 14:09:56 -08:00
Rafael França
12f4976200 Merge pull request #22935 from cllns/add-status-name-to-output
Add HTTP status name to output of tests
2016-01-12 19:47:40 -02:00
Rafael França
89f70938d7 Merge pull request #23035 from jkowens/fix-null-byte
Prevent static middleware from attempting to serve a request with a null byte
2016-01-12 19:46:42 -02:00
Sean Collins
a4032ca072 Add both HTTP Response Code and Type to assertion messages
Also, refactor logic to convert between symbol and response code,
via the AssertionResponse class
2016-01-12 13:09:00 -07:00
Jordan Owens
918f0eea97 Prevent attempt to serve a request with a null byte
File paths cannot contain null byte characters and methods that do path
operations such as Rack::Utils#clean_path_info will raise unwanted
errors.
2016-01-12 14:05:54 -05:00
claudiob
2228860364 AC::Parameters#at_json: restore Rails 4.2’s value
Fixes #23026

See discussion at #23026
2016-01-12 10:27:29 -08:00
Matthew Draper
272c5838df Commit before freezing the headers
This shouldn't generally come up: under a standard flow, we don't start
sending until after the commit. But application code always finds a way.
2016-01-12 11:37:42 +10:30
Akira Matsuda
dbf67b3a6f Unneeded &block parameters 2016-01-12 05:15:56 +09:00
Kasper Timm Hansen
56c93bba2f Merge pull request #21181 from denisenkom/mypatch
Test basic auth with symbols in password
2016-01-10 17:44:43 +01:00
Akshay Vishnoi
dafe5f4891 test include?- fix typo 2016-01-09 05:55:56 +05:30
Akshay Vishnoi
ab40d71ff8 [ci skip] Fix typo Renderering --> Rendering 2016-01-09 05:28:44 +05:30
Prathamesh Sonpatki
4824971f36 Fix typo in ActionPack CHANGELOG [ci skip] 2016-01-08 08:31:08 +05:30
Ben Toews
77d01e36aa add greg 2016-01-07 12:35:46 -07: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
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
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
Rafael França
ced9612b59 Merge pull request #22275 from mastahyeti/per-form-csrf
Per-form CSRF tokens
2016-01-06 02:55:10 -02:00
Rafael França
8788c7ce84 Merge pull request #22906 from bf4/rendering_exceptions
Add ActionController:Renderers test
2016-01-04 21:12:11 -02:00
Kasper Timm Hansen
52bb2d36d3 Add as to encode a request as a specific mime type.
Turns

```
post articles_path(format: :json), params: { article: { name: 'Ahoy!' } }.to_json,
  headers: { 'Content-Type' => 'application/json' }
```

into

```
post articles_path, params: { article: { name: 'Ahoy!' } }, as: :json
```
2016-01-04 23:07:34 +01:00
Ben Toews
3e98819e20 add option for per-form CSRF tokens 2016-01-04 12:26:38 -07:00
Benjamin Fleischer
f2b3b4019a Group related methods together 2016-01-03 22:54:42 -06:00
Benjamin Fleischer
f27360af04 Add ActionController:Renderers test
To complement actionpack/test/controller/metal/renderers_test.rb
2016-01-03 22:51:45 -06:00
Santiago Pastorino
3d590add45 Merge pull request #22890 from DNNX/times-map
Replace x.times.map{} with Array.new(x){} in AD::Journey::Path::Pattern
2016-01-03 20:23:50 -03:00
Anton Davydov
7d74b73a06 Fix typo in test desctiption [skip ci] 2016-01-04 00:11:03 +03:00
Viktar Basharymau
20aef99f7b Replace x.times.map{} with Array.new(x){}
The former is slightly more readable, performant and has fewer method calls.

```ruby
Benchmark.ips do |x|
  x.report('times.map') { 5.times.map{} }
  x.report('Array.new') { Array.new(5){} }
  x.compare!
end
__END__
Calculating -------------------------------------
           times.map    21.188k i/100ms
           Array.new    30.449k i/100ms
-------------------------------------------------
           times.map    311.613k (± 3.5%) i/s -      1.568M
           Array.new    590.374k (± 1.2%) i/s -      2.954M

Comparison:
           Array.new:   590373.6 i/s
           times.map:   311612.8 i/s - 1.89x slower
```
2016-01-02 19:34:40 +03:00
Rafael França
8167fa4562 Merge pull request #22519 from bf4/test_use_renderers
Add tests for ActionController::Renderers::use_renderers
2015-12-31 20:17:00 -02:00
Benjamin Fleischer
1c361ea356 Test ActionController::Renderers::use_renderers 2015-12-31 13:07:58 -06:00
Rashmi Yadav
1b608a695c Update copyright notices to 2016 [ci skip] 2015-12-31 18:27:19 +02:00
Kasper Timm Hansen
4ff5f6a15b Merge pull request #22850 from prathamesh-sonpatki/fix_ac_params_unsafe_h_2
Fix AC::Parameters#to_unsafe_h to return all unfiltered values
2015-12-31 09:04:42 +01:00
Prathamesh Sonpatki
28f648dbc7 Fix AC::Parameters#to_unsafe_h to return all unfiltered values
- AC::Parameters#convert_parameters_to_hashes should return filtered or
  unfiltered values based on whether it is called from `to_h` or `to_unsafe_h`
  instead of always defaulting to `to_h`.
- Fixes #22841
2015-12-31 12:32:29 +05:30
Rafael França
1f85e1c9f3 Merge pull request #22826 from timrogers/actiondispatch-ssl-config
Configurable redirect and secure cookies for ActionDispatch::SSL
2015-12-31 03:25:47 -02:00
Rafaël Blais Masson
040ed26656 Avoid Time.parse for static date
Benchmark.ips do |x|
    x.report('Time.parse') { Time.parse('2011-01-01') }
    x.report('Time.new')   { Time.new(2011, 1, 1) }
  end

  Calculating -------------------------------------
            Time.parse     6.640k i/100ms
              Time.new    15.082k i/100ms
  -------------------------------------------------
            Time.parse     71.915k (± 3.1%) i/s -    365.200k
              Time.new    167.645k (± 3.3%) i/s -    844.592k
2015-12-30 14:36:32 -05:00
Prathamesh Sonpatki
07af4dfd00 Fix test for AC::Parameters#to_unsafe_h
- Test should call `to_unsafe_h` instead of `to_h`
2015-12-30 20:54:46 +05:30
Richard Schneeman
cc5ae3e6df Merge pull request #22830 from jcoyne/parameters_include
Add AC::Parameters#include?
2015-12-29 14:14:51 -06:00
Jorge Bejar
44ca804229 Format from Accept headers have higher precedence than path extension format 2015-12-29 13:43:14 -03:00
Jorge Bejar
9a85da9367 Rely on default Mime format when MimeNegotiation#format_from_path_extension is not a valid type
Closes #22747
2015-12-29 13:42:57 -03:00
Justin Coyne
ff8a62d1d0 Add AC::Parameters#include?
Fixes #22818
2015-12-29 10:11:26 -06:00
Takayuki Matsubara
65e36d3181 Escape cookie's key and value in ActionController::TestCase
Get an incorrect cookie value in controller action method
if cookie value contains an escapable string.
2015-12-30 00:24:56 +09:00
Tim Rogers
32b1c90837 Flexible configuration for ActionDispatch::SSL 2015-12-29 13:07:51 +00:00
Dave Gynn
837e40dcac restore ability to pass extra options to cache stores
The `cache` helper methods should pass any extra options
to the cache store. For example :expires_in would be a
valid option if memcache was the cache store. The change
in commit da16745 broke the ability to pass any options
other than :skip_digest and :virtual_path. This PR
restores that functionality and adds a test for it.
2015-12-26 22:37:31 -08:00
Tim Rogers
9e0fa4cddd Improve RDoc documentation of ActionDispatch::SSL 2015-12-24 14:11:51 +00:00
Rafael Mendonça França
d182c22e91 Currectly test the Middleware#== 2015-12-22 17:09:26 -02:00
Rafael Mendonça França
d9f4a2839f Merge pull request #22743 from maclover7/fix-22738
Add #== back to ActionDispatch::MiddlewareStack::Middleware
2015-12-22 15:04:53 -02:00
Yves Senn
099082690d release notes, extract notable changes from Action Pack CHANGELOG.
[ci skip]
2015-12-22 12:19:37 +01:00
Jon Moss
0c5287a668 Add #== back to ActionDispatch::MiddlewareStack::Middleware
This was causing bug #22738 to occur. Also added extra tests to make
sure everything is A-OK.
2015-12-21 19:55:10 -05:00
Matthew Draper
b7ac079068 Remember the parameter hash we return
Callers expect to be able to manipulate it.
2015-12-22 05:48:38 +10:30
Genadi Samokovarov
c5b6ec7b0f No more no changes entries in the CHANGELOGs
During the `5.0.0.beta1` release, the CHANGELOGs got an entry like the
following:

```
* No changes.
```

It is kinda confusing as there are indeed changes after it. Not a
biggie, just a small pass over the CHANGELOGs.

[ci skip]
2015-12-21 11:46:38 +02:00
Vijay Dev
b691d62be9 Merge branch 'master' of github.com:rails/docrails 2015-12-20 12:33:46 +00:00
eileencodes
099ddfdefd Add CHANGELOG headers for Rails 5.0.0.beta1 2015-12-18 15:58:25 -05:00
eileencodes
7eae0bb88e Change alpha to beta1 to prep for release of Rails 5
🎉 🍻
2015-12-18 12:14:09 -05:00
Rafael França
027d964d89 Merge pull request #22650 from derekprior/dp-actionpack-warnings
Fix "instance variable not initialized" in tests
2015-12-18 12:49:36 -02:00
Rafael França
b5c13fcdaa Merge pull request #20797 from byroot/prevent-url-for-ac-parameters
Prevent ActionController::Parameters in url_for
2015-12-18 12:47:38 -02:00
David Heinemeier Hansson
ea4f0e2bab Refer to rails command instead of rake in a bunch of places
Still more to do. Please assist!
2015-12-18 13:01:10 +01:00
Derek Prior
31ef17a5eb
Fix "instance variable not initialized" in tests
The ActionPack test suite had a handful of these warnings when run. This
was due to `assert_response` being tested outside the context of a
controller instance where those instance variables would already have
been initialized.
2015-12-17 21:20:25 -05:00
Derek Prior
91e3aa1942
Document when fallback_location is used [ci-skip]
If you're not familiar with how the `Referer` header works, you likely
won't understand why you need to provide a fallback or under what
circumstances it would be used.

Hopefully this clarifies things a bit.
2015-12-17 20:57:42 -05:00
Kasper Timm Hansen
4b46c5ce83 Only dup Ruby's Hash and Array.
When calling `to_h` on an `ActionController::Parameters` instance it would
`deep_dup` its internal parameters.

This inadvertently called `dup` on a passed Active Record model which would
create new models. Fix by only dupping Ruby's Arrays and Hashes.
2015-12-17 21:55:03 +01:00
Derek Prior
dc4429ca3b
Deprecate redirect_to :back
Applications that use `redirect_to :back` can be forced to 500 by
clients that do not send the HTTP `Referer` (sic) header.
`redirect_back` requires the user to consider this possibility up front
and avoids this trivially-caused application error.
2015-12-16 11:42:25 -05:00
Derek Prior
13fd5586ce
Add redirect_back for safer referrer redirects
`redirect_to :back` is a somewhat common pattern in Rails apps, but it
is not completely safe. There are a number of circumstances where HTTP
referrer information is not available on the request. This happens often
with bot traffic and occasionally to user traffic depending on browser
security settings.

When there is no referrer available on the request, `redirect_to :back`
will raise `ActionController::RedirectBackError`, usually resulting in
an application error.

`redirect_back` takes a required `fallback_location` keyword argument
that specifies the redirect when the referrer information is not
available.  This prevents 500 errors caused by
`ActionController::RedirectBackError`.
2015-12-16 11:42:05 -05:00
Rafael França
d953512360 Merge pull request #22605 from tonyta/delete-dead-comments
Delete dead code comments
2015-12-16 14:23:31 -02:00
Rafael França
b7a7e82207 Merge pull request #22598 from yui-knk/deprecate_string_callback
Deprecate passing string to define callback.
2015-12-16 13:54:02 -02:00
yui-knk
21f4017fd9 Deprecate passing string to define callback. 2015-12-16 19:56:20 +09:00
Tony Ta
2eda1a98e0 deletes code commented out in 72160d9f 2015-12-15 22:28:50 -08:00
Sean Griffin
1ad94e760d Merge pull request #14212 from tylerhunt/fix-token-regex
Handle tab in token authentication header.
2015-12-15 10:59:54 -07:00
Rafael Mendonça França
dc3d3fb0b9 Remove warning of shadowing variable 2015-12-15 15:52:57 -02:00
Jean Boussier
4752e7d837 Prevent ActionController::Parameters from being passed to url_for directly 2015-12-15 13:16:54 +01:00
Sam Stephenson
99caf9ae7e Add fragment_cache_key macro for controller-wide fragment cache key prefixes 2015-12-14 19:53:43 -06:00
Sam Stephenson
1a404abc03 Remove ActionView::Helpers::CacheHelper#fragment_cache_key
Introduced in e56c63542780fe2fb804636a875f95cae08ab3f4, `CacheHelper#fragment_cache_key` is a duplicate of `ActionController::Caching::Fragments#fragment_cache_key`.

We now require the view to provide this method on its own (as with `view_cache_dependencies`); `ActionController::Caching::Fragments` exports its version as a `helper_method`.
2015-12-14 17:57:39 -06:00
Sean Griffin
1dc1c8e40b Merge pull request #22564 from maximeg/legit_name_errors
Don't catch all NameError to reraise as ActionController::RoutingError
2015-12-14 10:17:42 -07:00
Prem Sichanugrist
6d4aef984c Make Parameters#to_h and #to_unsafe_h return HWIA
This makes these two methods to be more inline with the previous
behavior of Parameters as Parameters used to be inherited from HWIA.

Fixes #21391
2015-12-14 10:28:54 -05:00
eileencodes
cd355a8eeb Fix spacing on CHANGELOG name
So that it appears correctly in the CHANGELOG on github.
2015-12-12 14:44:59 -05:00
eileencodes
4414c5d179 Remove ActionController::TestCase from documentation
In Rails 5.1 `ActionController::TestCase` will be moved out of Rails
into it's own gem.

Please use `ActionDispatch::IntegrationTest` going foward.

Because this will be moved to a gem I used `# :stopdoc:` instead of
deleting the documentation. This will remove it from the Rails
documentation but still leave the method documented for when we move it
to a gem.

Guides have been updated to use the routing structure used in Integration
and all test examples have been updated to inherit from
`ActionDispatch::IntegrationTest` instead of `ActionController::TestCase.

Fixes #22496
2015-12-12 14:44:50 -05:00
Maxime Garcia
d3dd3847bc Don't catch all NameError to reraise as ActionController::RoutingError #22368 2015-12-12 11:22:08 +01:00
Jon Atack
c6fe614e45 Show redirect response code in assert_response messages
Follow-up to PR #19977, which helpfully added the redirection path to the error message of assert_response if response is a redirection, but which removed the response code, obscuring the type of redirect.

This PR:

- brings back the response code in the error message,

- updates the tests so the new messages can be tested,

- and adds test cases for the change.
2015-12-11 18:18:08 +01:00
Rafael França
b0e5fc2737 Merge pull request #22514 from prathamesh-sonpatki/use-assert-over-assert-predicate
Use assert over assert_predicate in assert_response
2015-12-11 14:11:15 -02:00
Santiago Pastorino
b11bca98bf Merge pull request #20831 from jmbejar/rails-api-json-error-response
Rails API: Ability to return error responses in json format also in development
2015-12-09 15:26:46 -03:00
Jorge Bejar
cdb7a8477f Avoid calling AD::MimeNegotiation#format_from_path_extension method twice 2015-12-09 14:18:13 -03:00
Jorge Bejar
da5acae032 Avoid warning because of the mime type 2015-12-09 10:53:46 -03:00
Jorge Bejar
84e8accd6f Do not add format key to request_params
I did this change but it is affecting how the request params end up
after being processed by the router.

To be in the safe side, I just take the format from the extension in the
URL when is not present in those params and it's being used only for the
`Request#formats` method
2015-12-09 10:53:46 -03:00
Jorge Bejar
290a536d28 Update Changelog with the added response_format option in AD::DebugExceptions 2015-12-09 10:53:46 -03:00
Jorge Bejar
6fa2023c81 DebugException initialize with a response_format value 2015-12-09 10:53:45 -03:00
Jorge Bejar
6fb2afed52 Better name for method in DebugExceptions middleware 2015-12-09 10:53:45 -03:00
Jorge Bejar
02c5c0d156 Improve regexp in AC::Http::Parameters 2015-12-09 10:53:45 -03:00
Jorge Bejar
d879c0ec5a Minor cleanup in AD::DebugExceptions 2015-12-09 10:53:45 -03:00
Jorge Bejar
b75f5c278a Remove unneeded args in AD::DebugExceptions 2015-12-09 10:53:45 -03:00
Jorge Bejar
a16ab35d34 New hash syntax in AD::DebugExceptions 2015-12-09 10:53:44 -03:00
Jorge Bejar
05d89410bf Fix some edge cases in AD::DebugExceptions in rails api apps 2015-12-09 10:53:44 -03:00
Jorge Bejar
83b4e9073f Response when error should be formatted properly in Rails API if local request 2015-12-09 10:53:41 -03:00
eileencodes
b05801754f Fix make_response! when called by serve in RouteSet
All of our tests were testing the `ActionController::Live` behavior in a
standalone environment, without going through the router or behaving
like a real application.

This resulted in `ActionController::Live` throwing the exception
`undefined method 'request' for #<ActionDispatch::Request:0x00000003ad1148>`
because `make_response!` was expecting a response instead of a request.

The expectation of a response came from `set_response!` in non-router
tests setting the response and passing it to `make_response!`. In the
case of an application we would hit `serve` in `RouteSet` first which
would send us to `make_response!` with a request sent instead of a
response.

The changes here remove `set_response!` so `make_response!` always
receives a request.

Thanks to KalabiYau for help with the investigation and solution.

Fixes #22524

[Eileen M. Uchitelle & KalabiYau]
2015-12-09 08:19:07 -05:00
Jorge Bejar
b79bfaadaf Use URL path extension as format in bad params exception handling 2015-12-08 21:23:47 -03:00
eileencodes
3979403781 Change the protect_from_forgery prepend default to false
Per this comment
https://github.com/rails/rails/pull/18334#issuecomment-69234050 we want
`protect_from_forgery` to default to `prepend: false`.

`protect_from_forgery` will now be insterted into the callback chain at the
point it is called in your application. This is useful for cases where you
want to `protect_from_forgery` after you perform required authentication
callbacks or other callbacks that are required to run after forgery protection.

If you want `protect_from_forgery` callbacks to always run first, regardless of
position they are called in your application, then you can add `prepend: true`
to your `protect_from_forgery` call.

Example:

```ruby
protect_from_forgery prepend: true
```
2015-12-07 10:38:26 -05:00
Matthew Draper
8b2eb4aa7a Merge pull request #22475 from claudiob/missing-require
Add missing require to strong_parameters.rb
2015-12-08 01:52:57 +10:30
Rafael França
bf9facb31c Merge pull request #22517 from Elektron1c97/master
[ci skip] Add a dollar sign to each command in the READMEs
2015-12-07 01:07:09 -02:00
eileencodes
ff891616ac Only commit the cookie jar if it hasn't been committed
We don't want to commit the cookie jar more than once because then we
will be attempting to modify a frozen hash.

Fixes Railties test failure caused by 492b134.
2015-12-06 16:28:45 -05:00
eileencodes
8350925bec Stop violating law of demeter in response cookie_jar
This adds a new method to request and response so we don't need to
violate the law of demeter.

We are changing `Request` and `Response` so that they always have a
`cookie_jar`

This is a continuation on work to combine integration and controller
test code bases in Rails.
2015-12-06 15:32:47 -05:00
eileencodes
492b134433 Push before_sending to super class
We want to get rid of the `Live::Response` so we are consolidating methods
from `Live::Response` and `Response` by merging them together.

This adds an `#empty` method to the request so we don't need to
hard-code the empty array each time we call an empty
`ActionDispatch::Request`.

The work here is a continuation on combining controller and integration
test code bases into one.
2015-12-06 15:32:40 -05:00
Eileen M. Uchitelle
67688aa739 Merge pull request #22453 from wjessop/use_action_dispatch_default_tld_length
Test against the real value of tld_length unless explicitly set
2015-12-06 13:21:38 -05:00
Elektron1c97
6bd417df50 [ci skip] Add a dollar sign to each command in the READMEs
According to pr #22443 in the guides there's always a dollar sign before every command, so why is in the main README a `$` and in every submodule a `%`?

Just eye candy..
2015-12-06 19:18:52 +01:00
Prathamesh Sonpatki
b247116210 Use assert over assert_predicate in assert_response
- `assert_predicate` appends its own error message at the end of message
  generated by `assert_response` and because of that the error message
  displays the whole `response` object.
- For eg.

  Expected response to be a <success>, but was a redirect to <http://test.host/posts>.
  Expected #<ActionDispatch::TestResponse:0x007fb1cc1cf6f8....(lambda)>}>> to be successful?.

- Complete message can be found here -
  https://gist.github.com/prathamesh-sonpatki/055afb74b66108e71ded#file-gistfile1-txt-L19.

- After this change the message from `assert_predicate` won't be
  displayed and only message generated by `assert_response` will be shown
  as follows:

  Expected response to be a <success>, but was a redirect to <http://test.host/posts>
2015-12-06 21:39:59 +05:30
Arthur Nogueira Neves
65443ceb0d Merge pull request #19977 from prathamesh-sonpatki/mention-redirect-path-in-assert-response
Add redirection path in the error message of assert_response if response is :redirect
2015-12-05 16:52:04 -05:00
Matthew Draper
0d8b3c2e7f Shrink a couple of deprecation warnings to one-liners
The previous spelling seemed a bit too generous with the whitespace, and
looked out of place when amongst others.
2015-12-06 05:10:49 +10:30
claudiob
8a410043be Add missing require to strong_parameters.rb
The file [references Rack::Test here](https://github.com/rails/rails/blame/master/actionpack/lib/action_controller/metal/strong_parameters.rb#L671)
so it's better off requiring 'rack/test' in the first place.
2015-12-04 14:31:32 -08:00
Will Jessop
e8bfaa58bd Test against the real value of tld_length unless explicitly set
There were two places where the tld_length default
was hard-coded to 1, both overriding the real default
value of ActionDispatch::Http::URL.tld_length in this
set of tests.

This commit removes both of those, relying on the
actual value of ActionDispatch::Http::URL.tld_length,
unless it's specifically overridden.
2015-12-04 16:40:08 +00:00
Prathamesh Sonpatki
1ee87e42ca Add redirection path in the error message of assert_response if response is :redirect
- If the assert_response is checking for any non-redirect response like
  :success and actual response is :redirect then, the error message displayed
  was -

     Expected response to be a <success>, but was <302>

- This commit adds the redirect path to the error message of
  assert_response if the response is :redirect.
  So above message is changed to -

     Expected response to be a <success>, but was a redirect to <http://test.host/posts/lol>
2015-12-04 13:13:25 +05:30
Yves Senn
391567d457 Merge pull request #22373 from yui-knk/ad_constraints
Add `Routing` namespace to point appropriate constant
2015-11-30 09:12:06 +01:00
Arthur Nogueira Neves
3513f80e53 Merge pull request #22371 from yui-knk/better_mount_error
Brush up errors of `ActionDispatch::Routing::Mapper#mount`
2015-11-28 11:29:46 -05:00
yui-knk
f9e8d2c9a2 [ci skip] Add author's name to CHANGELOG 2015-11-28 17:39:38 +09:00
yui-knk
f8f7e66f5f Brush up errors of ActionDispatch::Routing::Mapper#mount
* Integrate to raise `ArgumentError`
* Detailed error message when `path` is not defined
* Add a test case, invalid rack app is passed
2015-11-28 10:50:11 +09:00
Arthur Nogueira Neves
9afb0b9c43 Merge pull request #21241 from pdg137/master
In url_for, never append ? when the query string is empty anyway.
2015-11-26 16:10:46 -05:00
Rafael França
e1e6499ede Merge pull request #22263 from mastahyeti/csrf-origin-check
Add option to verify Origin header in CSRF checks

[Jeremy Daer + Rafael Mendonça França]
2015-11-26 14:23:50 -02:00
Ben Toews
85783534fc Add option to verify Origin header in CSRF checks 2015-11-25 15:06:12 -07:00
Rafael França
40acdcfb7c Merge pull request #22172 from tijmenb/fix-source-in-show-exception
Add text template for source code
2015-11-24 02:11:09 -02:00
Sean Griffin
8404ed6408 Merge pull request #17928 from sergey-alekseev/remove-unused-form-data-method 2015-11-23 14:33:11 -07:00
Grey Baker
1715f113da Clearer comment and variable name on IP spoofing 2015-11-22 14:45:05 +00:00
yui-knk
e39650b7ec Add Routing namespace to point appropriate constant
Make it clear we use `ActionDispatch::Routing::Endpoint`
2015-11-22 23:23:44 +09:00
Claudio B
bf7ab2f92b Merge pull request #22353 from Bounga/doc_for_cookies_encrypted
Add missing example for cookies.encrypted [ci skip]
2015-11-20 11:25:09 -08:00
yui-knk
8d23f37b15 Remove arity check for RouteSet#draw
This code was added for migration from Rails 3.1 to upper,
now we are developing Rails 5.
2015-11-21 01:12:45 +09:00
Nicolas Cavigneaux
e56d3aff24 Add missing example for cookies.encrypted [ci skip] 2015-11-20 11:19:16 +01:00
Gaurav Sharma
762f7daf55 Add missing punctuation mark [ci skip] 2015-11-18 08:22:16 +05:30
Vijay Dev
153d7ca630 Merge branch 'master' of github.com:rails/docrails 2015-11-15 19:16:58 +00:00
claudiob
010667ba08 [ci skip] Fix <tt> in doc 2015-11-15 02:41:01 -08:00
Gaurav Sharma
899b6bbef3 adding missing . 2015-11-15 00:10:02 +05:30
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
Mikhail Denisenko
2ae757d76b Test basic auth with symbols in login and password 2015-10-24 10:43:30 -04: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