Commit Graph

9866 Commits

Author SHA1 Message Date
Eileen M. Uchitelle
6b98fbacf7 Merge pull request #19665 from eileencodes/fix-parse_query-method-signature
Fix method signature of `parse_query` to match rack
2015-04-06 08:34:20 -04:00
eileencodes
0eef12c0b3 Fix method signature of parse_query to match rack
Recently rack was changed to have a second argument on the `parse_query`
method (in rack/rack#781). Rails relies on this and it's `parse_query`
method was complaining about missing the second argument. I changed the
arguments to `*` so we don't have this issue in the future.
2015-04-06 08:30:32 -04:00
Stephen Bussey
0de4a23d1c head no_content when there is no template or action performed 2015-04-05 15:46:50 -04:00
Robin Dupret
9cc41c36f7 Fix a few typos [ci skip] 2015-04-05 15:58:43 +02:00
brainopia
58d75fd811 Freeze static arguments for gsub 2015-04-02 02:15:07 +03:00
brainopia
cdac52e124 Prefer string patterns for gsub
https://github.com/ruby/ruby/pull/579 - there is a new optimization
since ruby 2.2

Previously regexp patterns were faster (since a string was converted to
regexp underneath anyway). But now string patterns are faster and
better reflect the purpose.

  Benchmark.ips do |bm|
    bm.report('regexp') { 'this is ::a random string'.gsub(/::/, '/') }
    bm.report('string') { 'this is ::a random string'.gsub('::', '/') }
    bm.compare!
  end
  # string: 753724.4 i/s
  # regexp: 501443.1 i/s - 1.50x slower
2015-04-02 02:07:45 +03:00
Xavier Noria
8798788c65 Merge pull request #19544 from shuhei/fix-parameters-const-missing
Return super in ActionController::Parameters.const_missing
2015-03-28 10:01:25 +01:00
Shuhei Kagawa
1b0526eaac Return super in ActionController::Parameters.const_missing
The current implementation of ActionController::Parameters.const_missing
returns `ActionController::Parameters.always_permitted_parameters` even
if its `super` returns a constant without raising error. This prevents its
subclass in a autoloading module/class from taking advantage of
autoloading constants.

    class SomeParameters < ActionController::Parameters
      def do_something
        DefinedSomewhere.do_something
      end
    end

In the code above, `DefinedSomewhere` is to be autoloaded with
`Module.const_missing` but `ActionController::Parameters.const_missing`
returns `always_permitted_parameters` instead of the autoloaded
constant.

This pull request fixes the issue respecting `const_missing`'s `super`.
2015-03-28 10:40:58 +09:00
George Claghorn
c64b99ecc9 Add ActiveSupport::ArrayInquirer and Array#inquiry
Wrapping an array in an `ArrayInquirer` gives a friendlier way to check its
string-like contents. For example, `request.variant` returns an `ArrayInquirer`
object. To check a request's variants, you can call:

    request.variant.phone?
    request.variant.any?(:phone, :tablet)

...instead of:

    request.variant.include?(:phone)
    request.variant.any? { |v| v.in?([:phone, :tablet]) }

`Array#inquiry` is a shortcut for wrapping the receiving array in an
`ArrayInquirer`:

    pets = [:cat, :dog]
    pets.cat?    # => true
    pets.ferret? # => false
    pets.any?(:cat, :ferret} # => true
2015-03-24 13:33:01 -05:00
George Claghorn
9d9cc4777b Provide friendlier access to request variants
Closes #18933.
2015-03-24 12:49:27 -05:00
Ryan Tomayko
0b81b3094a Fix ActionDispatch::PublicExceptions returning string rack status
The status returned in the rack [status, headers, body] array was
a string, which can cause problems with middleware that assumes the
status will be a Fixnum. This likely never surfaced because other
middleware to_i the status returned from downstream apps before
passing it on.
2015-03-23 13:15:59 +00:00
adam
b49cac80de Fix handling of empty X_FORWARDED_HOST header.
Previously, an empty X_FORWARDED_HOST header would cause
Actiondispatch::Http:URL.raw_host_with_port to return nil, causing
Actiondispatch::Http:URL.host to raise a NoMethodError.
2015-03-20 20:32:30 +00:00
Boris Peterbarg
4be3997c9f Compare content_type with Mime::XML instead of regexp
Regexp is broken for both content types including charsets and for
integration tests, where the content_type is a Mime::Type and not String
2015-03-16 06:35:00 +02:00
Rafael Mendonça França
cf5ec92a8b Merge pull request #19291 from hired/return-truthy-value-from-head
Return truthy value from head method
2015-03-13 11:06:20 -03:00
Joel Hayhurst
d5efb1f9bd Return true from head method
It was returning false in normal circumstances.
This broke the `head :ok and return if` construct.
Add appropriate test.
2015-03-12 14:39:22 -07:00
Guillermo Iguaran
ccf8678cec Merge pull request #19309 from f1sherman/dont-set-session-options-id
Use request.session.id instead of request.session_options[:id]
2015-03-12 11:30:12 -05:00
Brian John
82402e6583 Use request.session.id instead of request.session_options[:id]
As of the upgrade to Rack 1.5, request.session_options[:id] is no
longer populated. Reflect this change in the tests by using
request.session.id instead.

Related change in Rack:
https://github.com/rack/rack/commit/83a270d6
2015-03-12 09:52:38 -05:00
Kohei Suzuki
b60c1fe97b Also skip Content-Encoding and Vary header if 304 2015-03-12 23:32:07 +09:00
Kohei Suzuki
d4103fc232 304 response should not include Content-Type header
Rack::Lint raises an error saying "Content-Type header found in 304
response, not allowed".
2015-03-10 23:39:08 +09:00
eileencodes
2e4a01b92c Call super last in before_setup
This fixes the reasons 4cf3b8a, 303567e, and fa63448 needed to be
reverted in 7142059. The revert has been reverted and this fixes
the issues caused previously.

If we call `super` first we will end up nuking the session settings in the
application tests that do `setup do` - so any session login or cookie
settings will not be persisted thoughout the test sessions.

Calling `super` last prevents `@integration_session` from getting nuked
and set to nil if it's already set.

Test added to prevent regression of this behavior in the future.
2015-03-09 17:11:15 -04:00
eileencodes
d5e55e960c Revert "Revert integration test refactoring that caused app test regressions"
This reverts commit 714205988315d2f98aa3e749747c44470e18676b.
2015-03-09 17:10:24 -04:00
yuuji.yaginuma
fbb11854c7 update integration test example as is not output deprecation warning [ci skip] 2015-03-07 14:28:47 +09:00
Prathamesh Sonpatki
e049319c77 Fix documentation of url_for module [ci skip]
- The request needs to be instance of ActionDispatch::Request or an
   object that responds to host, optional_port, protocol and
   symbolized_path_parameter.
 - This documentation was correctly added in
   e3b3f416b5
   but was changed to
   e1ceae576e.
 - Fixes #16160.
2015-03-06 19:51:07 +05:30
Aaron Patterson
798a14a638 pass a config to the route set
This way we can get the relative_url_root from the application without
setting another global value
2015-03-05 13:12:06 -08:00
Sean Griffin
f18b5fe9b1 Merge pull request #19215 from gsamokovarov/revert-ruby-2-2-0-kwarg-crash-workarounds
Revert work arounds for upstream Ruby 2.2.0 kwargs bug
2015-03-05 10:58:16 -07:00
Sushruth Sivaramakrishnan
5ea829815e nodoc filtered_location [ci skip] 2015-03-05 22:40:22 +05:30
Genadi Samokovarov
8ed0b89bbd Revert work arounds for upstream Ruby 2.2.0 kwargs bug
The bug caused a segfault and you can find more info about it at:
https://bugs.ruby-lang.org/issues/10685.

We did a couple of work arounds, but 2.2.1 rolled out and those aren't
needed anymore.

Here are the reverted commits:

- Revert "Work around for upstream Ruby bug #10685",
  commit 707a433870e9e06af688f85a4aedc64a90791a64.

- Revert "Fix segmentation fault in ActionPack tests",
  commit 22e0a22d5f98e162290d9820891d8191e720ad3b.

I'm also bumping the Ruby version check to 2.2.1 to prevent future
segfaults.
2015-03-05 17:39:22 +02:00
Sushruth Sivaramakrishnan
7f10d72dd2 Doc fix [ci skip] 2015-03-05 19:30:20 +05:30
Sushruth Sivaramakrishnan
d7c1293c5b Doc fix [ci skip] 2015-03-05 18:31:40 +05:30
Sushruth Sivaramakrishnan
72e5fde811 Doc fix [ci skip] 2015-03-05 16:36:48 +05:30
Aaron Patterson
c2108926a4 Drop request class from RouteSet constructor.
If you would like to use a custom request class, please subclass and implemet
the `request_class` method.
2015-03-04 11:02:24 -08:00
Robin Dupret
8a74190121 Tiny documentation edits [ci skip] 2015-03-03 21:30:20 +01:00
Rafael Mendonça França
44ff0313c1 Merge pull request #18775 from yasyf/issue_5122
Fallback to RAILS_RELATIVE_URL_ROOT in `url_for`
2015-03-03 17:19:42 -03:00
Eileen M. Uchitelle
f32b6e243a Merge pull request #19147 from gsamokovarov/work-around-ruby-10695
Work around for upstream Ruby bug #10685
2015-03-02 18:22:31 -05:00
Aaron Patterson
12f2fc56aa Merge pull request #15806 from tgxworld/partition_routes_during_setup
Partition routes during setup.
2015-03-02 15:02:14 -08:00
Zachary Scott
3d69222ca9 Merge pull request #19181 from davydovanton/update-helper-docs
[ci skip] Add documentation for Helpers#all_helpers_from_path
2015-03-02 14:51:58 -08:00
Anton Davydov
7fd2de464e [ci skip] Add documentation for Helpers#all_helpers_from_path 2015-03-03 01:14:48 +03:00
Aaron Patterson
0814bb62e5 be optimistic about missing route keys
this patch makes errors slightly more expensive when someone is missing
a route key, but in exchange it drops 4 allocations per `url_for` call.
Since missing a route key is an error, optimizing for the non-error path
seems like a good trade off
2015-03-02 11:26:23 -08:00
Aaron Patterson
b1051c5dfa use arg size for parallel iteration
we already know the length of the args, so we can use that length for
parallel iteration and cut down on allocations for `url_for` calls.
2015-03-02 11:16:09 -08:00
Aaron Patterson
37654d12ae ask the routes objects for its Rack env key
this centralizes the logic for determining the script name key and drops
object allocations when calling `engine_script_name` (which is called on
each `url_for`).
2015-03-02 11:01:07 -08:00
Aaron Patterson
4cfa10cda5 refactor handle_model to use private helper methods for generation 2015-03-01 16:16:15 -08:00
Aaron Patterson
95c76a7cf3 drop allocations for string and class polymorphic routes 2015-03-01 16:16:15 -08:00
Aaron Patterson
402331ed2d drop string allocations per model url_for call in views
```ruby
article = Article.new.tap(&:save!)
view.url_for article

result = ObjectSpace::AllocationTracer.trace do
  3000.times { view.url_for article }
end
p ObjectSpace::AllocationTracer.allocated_count_table[:T_STRING] / 3000
```
2015-03-01 16:05:58 -08:00
Aaron Patterson
cad20f720c move _generate_paths_by_default to where it is used
_generate_paths_by_default wasn't used in AD::Routing::UrlFor, so we
should be able to move it where it is used in AV::Routing
2015-03-01 13:35:24 -08:00
Genadi Samokovarov
707a433870 Work around for upstream Ruby bug #10685
In f6e293ec54f02f83cdb37502bea117f66f87bcae we avoided a segfault in the
tests, however I think we should try to avoid the crash, as it may
happen in user code as well.

Here is what I distiled the bug down to:

```ruby
# Rails case - works on 2.0, 2.1; crashes on 2.2
require 'action_dispatch'

ActionDispatch::Response.new(200, "Content-Type" => "text/xml")

# General case - works on 2.0, 2.1; crashes on 2.2
def foo(optional = {}, default_argument: nil)
end

foo('quux' => 'bar')
```
2015-03-01 16:31:20 +02:00
Vijay Dev
dcfd4bf223 Merge branch 'master' of github.com:rails/docrails 2015-03-01 12:45:56 +00:00
Aaron Patterson
92849df732 drop allocations when handling model url generation 2015-02-28 16:00:27 -08:00
Vipul A M
cdaab2c479 Removed non-standard and unused require 'active_support/deprecation' from parts out of active_support. 2015-02-27 23:20:09 +05:30
Iain Beeston
a5eddb534f Explained how to set session expiry through session_store config
Most session stores offer an :expire_after option, but it's largely
undocumented. Cookie store also supports a number of options via
rack (these used to be documented in rails 2.3)
2015-02-27 10:29:44 +00:00
Carlos Antonio da Silva
242632167c Merge pull request #19104 from y-yagi/fix_skip_filter
fix NameError in `skip_filter`. callback doesn't exist.
2015-02-27 07:27:42 -03:00