Commit Graph

15110 Commits

Author SHA1 Message Date
Guillermo Iguaran e43d0ddb03
Merge pull request #42790 from YusukeIwaki/replace_poltergeist_with_cuprite
Deprecate `poltergeist` and `webkit` driver registration. Add `cuprite`.
2021-07-20 18:14:58 -07:00
Ryuta Kamizono e50b0e3ab3 Fixup CHANGELOGs [ci skip] 2021-07-21 10:08:08 +09:00
YusukeIwaki e489b2467b Deprecate :poltergeist, :webkit instead of removing. 2021-07-21 09:52:34 +09:00
YusukeIwaki 5372459aa4 Remove `poltergeist` and `webkit` driver registration logics in system testing. Add `cuprite` instead.
Poltergeist and capybara-webkit are already not maintained.

* https://github.com/teampoltergeist/poltergeist
* https://github.com/thoughtbot/capybara-webkit

Most users actually use Selenium with Headless Chrome in these years, and it is not encouraged to use poltergeist or capybara-webkit at this moment.

Cuprite is a good alternative driver to Poltergeist: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing
Not only removing deprecated Capybara drivers, also introducing Cuprite.
2021-07-21 09:52:29 +09:00
Ryuta Kamizono a206aecedf chore: Use `e.g.` which is the more used spelling
```
% git grep -i '\be\.g\.' | wc -l
290
```
2021-07-21 09:17:54 +09:00
Petrik 688ed7084a Add `Middleware#remove` to delete middleware or raise if not found.
`Middleware#remove` works just like `Middleware#delete` but will
raise an error if the middleware isn't found.

This partly reverts 07558ff57c, where
`delete` would raise an error.
It might be expected that `delete` fails silently for some environments.
Or maybe you want to make sure a middleware isn't present.

Co-authored-by: Alex Ghiculescu <alexghiculescu@gmail.com>
2021-07-20 18:29:42 +02:00
Eugene Kenny a39098dc85 Don't eager load ActionController::Live
This module must be included into a controller before it can be used,
which means it will be eager loaded along with the application.
2021-07-19 00:58:02 +01:00
Eugene Kenny 9a6ab5e89e Fix "warning: instance variable @browser not initialized"
Followup to 000969928d.
2021-07-19 00:32:00 +01:00
Bodacious 39ab10164b
Exclude added flash types from action_methods 2021-07-14 08:35:27 +02:00
Eileen M. Uchitelle d364cfb34e
Merge pull request #42672 from jonathanhefner/system-testing-browser-iff-selenium
Configure browser only when using Selenium
2021-07-12 10:05:05 -04:00
Rafael França 2d1e6aea58
Merge pull request #42655 from ghiculescu/middleware-delete-raise
Deleting an item from the Middleware stack should raise if the item is not found
2021-07-07 13:22:01 -04:00
Ryuta Kamizono e9e8ea2b20 :nodoc: `FakeRuntime` [ci skip]
People should not reference the fake class in their apps.
2021-07-05 18:12:19 +09:00
Ryuta Kamizono 5f45aeaaae :nodoc: for corrections
Like all others for corrections already does.
2021-07-05 17:59:22 +09:00
Petrik 0409ed57ac Clean up checks to see if DidYouMean is defined
As of Ruby 2.7 DidYouMean is included as a default gem, so there is no
need to check if DidYouMean is defined in the test suite. We still need
to check if the DidYouMean modules are defined in the actual code, as
someone might run Rails with DidYouMean disabled by using the
`--disable-did_you_mean` flag. This is ussually done for performance
reasons.

This commit also includes some of the changes made by Yuki in:
https://github.com/rails/rails/pull/39555
These changes include replacing Jaro with the more accurate
SpellChecker, and using DidYouMean::Correctable for simplere
corrections.

The DidYouMean::SpellChecker does have a treshold for corrections.
If there is not enough similarity it might not return a suggestion.
To stop the tests from failing some test data had to be changed.

For example, `non_existent` does not meet the treshold for `hello`, but
`ello` does:

DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('non_existent')
=> []
DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('ello')
=> ["hello"]

The treshold makes sense for spelling errors. But maybe we should add a
different SpellChecker that helps to get a suggestion even if there is
little overlap. For example for when a model only has 2 attributes
(title and body), it's helpful to get a suggestion for `name`

Co-Authored-By: Yuki Nishijima <yk.nishijima@gmail.com>
2021-07-04 13:43:50 +02:00
Jonathan Hefner 0552220c46 Fix "wrong number of arguments" error
Follow-up to #41467.

`Capybara::RackTest::Driver#initialize` uses keyword arguments, just
like `Capybara::Selenium::Driver#initialize`.
2021-07-01 16:19:15 -05:00
Jonathan Hefner 000969928d Configure browser only when using Selenium
Since #39179, `selenium/webdriver` is required only when using the
`:selenium` driver.  However, `ActionDispatch::SystemTesting::Browser`
references `::Selenium` as soon as it is instantiated, and thus raises
an error when using a non-`:selenium` driver.

This commit ensures that `ActionDispatch::SystemTesting::Browser` is
instantiated only when using the `:selenium` driver.
2021-07-01 15:39:53 -05:00
Alex Ghiculescu 07558ff57c Deleting an item from the Middleware stack should raise if the item is not found
Currently if you call any `move` operation on the middleware stack with a middleware item that doesn't exist, [it will raise](53d54694e9/actionpack/test/dispatch/middleware_stack_test.rb (L102)). But the same doesn't happen if you call `delete` with a non-existant item. This makes it hard to debug issues like https://github.com/rails/rails/pull/42652 as the `delete` call fails silently.

I think `delete` should raise same as `move` does, and this PR implements that.

This would be a breaking change if someone has code calling `delete` on a non-existant middleware item, the fix would be to just remove that code since it's not doing anything.
2021-07-01 09:04:34 -05:00
Jean Boussier ef747e9f7e
Merge pull request #42652 from ghiculescu/remove-local-cache-middleware
Allow removing LocalCache middleware in application.rb
2021-07-01 15:20:53 +02:00
Alex Ghiculescu ff66477182 Allow removing LocalCache middleware in application.rb
All other middlewares can be removed from the stack in `config/application.rb`. `ActiveSupport::Cache::Strategy::LocalCache::Middleware` cannot, because it is added to the stack as an instance rather than a class, here: https://github.com/rails/rails/blob/main/railties/lib/rails/application/bootstrap.rb#L62. As a result, [this check](https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/middleware/stack.rb#L133) fails unless you also pass the same instance. The instance is not available in `config/appliaction.rb` because `Rails.cache` has not been initialized yet (it's initialized when the middleware is set).

This means that if you want to remove the local cache middleware you have to make an initiailzer just for that. Unlike all other middlewares which can be dealt with as classes in `config/application.rb`.

The fix is to check the middleware's `name`, not `klass`, for delete operations. The name is [provided explicitly](https://github.com/rails/rails/blob/main/activesupport/lib/active_support/cache/strategy/local_cache.rb#L162) presumably for this reason.
2021-06-30 12:28:51 -05:00
Dirkjan Bussink 0523532a3c
Always use OpenSSL constants for Digest operations
As also previously discussed in
https://github.com/rails/rails/pull/40770#issuecomment-748347066, this
moves the usage of Digest constants to always use the OpenSSL version of
those Digest implementations.
2021-06-30 13:57:54 +02:00
Zachary Scott 3a2205c60d 💅 Adjust the wording for AC::DataStreaming Cache-Control
hack [ci skip]
2021-06-27 07:07:18 +09:00
Guillermo Iguaran 6f1ff6fc65
Merge pull request #42609 from tadas-s/remove-ie6-7-8-specific-hack
Remove IE6-7-8 file download related hack/fix
2021-06-25 16:08:38 -07:00
Tadas Sasnauskas d08035b0f2 Remove IE6-7-8 file download related hack/fix
IE 6-7-8 has bug when 'Cache-Control: no-cache' head would break file download.
It's been fixed in IE9 (which is also ancient and barely used version).

Some extra details [here][1] and [here][2].

The way this fix is implemented clashes with what's been done in PR #40324. By
adding ':public' key to cache control header set it wipes default headers.

Since IE 6-7-8 are ancient browsers - let's just get rid of this hack.

[1]: https://stackoverflow.com/q/9766639/843067
[2]: https://stackoverflow.com/q/3415370/843067
2021-06-25 19:15:19 +01:00
Jean Boussier fcc3cd3265 Consider AC::Parameters as Hash in url_for
Ref: https://github.com/rails/rails/pull/42020

It's not uncommon to want to forward request parameters,
as such the `:params` paramter of `url_for` often receive
an AC::Parameters instance.
2021-06-25 18:07:48 +02:00
Alexander Azarov dc2d948930
Skip logging backtrace when exception is in `rescue_responses`
Closes #9343

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
2021-06-24 23:04:12 -04:00
Kevin Sjöberg f0f067af78 Ignore file fixtures on `db:fixtures:load` 2021-06-23 20:42:28 +02:00
Rafael Mendonça França 3a98e7da62
Merge pull request #41609 2021-06-23 18:29:49 +00:00
Rafael França cb52350f38
Merge pull request #40324 from tadas-s/cache-control-no-store
Implement 'no_store' HTTP cache directive
2021-06-23 14:27:58 -04:00
Rafael França ec6935606e
Merge pull request #42437 from HParker/digest-find-parent-controller-template
Use the lookup_context to find the correct template path
2021-06-23 13:59:09 -04:00
Ben Sheldon cc79283518 Documentation for ActionController::API use neutral language [ci skip] 2021-06-22 10:21:39 -07:00
Aaron Patterson 2f012f74cc
Merge pull request #42020 from chaymaeBZ/merge-params-when-it-is-a-hash
Only merge params option if params is a Hash in url_for helper
2021-06-21 13:04:21 -07:00
Aditya Bhutani 32af6add67 [ci skip] Fixing all <x> based occurances to <x>-based 2021-06-16 19:15:12 +05:30
Emma e518999142
Update http_authentication.rb
Words such as "dead simple" are at best redundant, and at worst distracting.
2021-06-13 13:24:51 +01:00
Tadas Sasnauskas 07da73429a Implement 'no_store' HTTP cache directive method
Summary
=======

Currently there is no way to set "Cache-Control: no-store" header using
built-in cache control methods ("expires_now"/"expires_in"/etc..). One of
the [top StackOverflow][1] answers currently suggests putting it directly
into header set.

Unfortunately, it cannot later be overridden in specific/individual actions by
calling say 'expires_in 5.minutes'. Resulting header in that case is
stays the same, i.e. 'Cache-Control: no-store'.

This:
 1. Adds the 'no_store' method to set "Cache-Control: no-store" header.
 2. Changes cache control "merge and normalize" code so default "no-store"
    directive can be overridden using built in cache control methods mentioned
    above.

What's the use of it
--------------------

Couple examples:

* To [prevent rendering stale content][3] if browser return button is used
('expires_now' does not help).
* To prevent browser disk cache being used. In some situations it's considered
a [privacy/security risk][4].

Other Information
=================

Mozilla developer docs for [Cache-Control][2] header.

[1]: https://stackoverflow.com/questions/10744169/rails-set-no-cache-method-cannot-disable-browser-caching-in-safari-and-opera
[2]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
[3]: https://engineering.mixmax.com/blog/chrome-back-button-cache-no-store/
[4]: https://portswigger.net/kb/issues/00700100_cacheable-https-response
2021-06-12 08:58:14 +01:00
Nate Berkopec 5a2cea265d
Fix hot-path raising in ActionDispatch::Static
Using File.stat where a file does not exist raises an exception.

Since ActionDispatch::Static does this:

def call(env)
  @file_handler.attempt(env) || @app.call(env)
end

... this means that around 8 exceptions are raised and rescued on each
request which is passed to the application.

This change improves latency by ~.14 milliseconds on all applications.

Partial revert of #37265
2021-06-11 07:56:38 -06:00
Rafael França b0d8d82760
Merge pull request #42244 from hahmed/fix-invalid-statement-compile-error
Fix invalid statement template compile error
2021-06-09 22:24:30 -04:00
HParker 26259b0660 Use the lookup_context to find the correct template path
This replaces the controller/action method of finding a path with the lookup_context which should always find the same thing as the render method finds.
2021-06-09 15:56:45 -07:00
Haroon Ahmed 1be3277a7b Fix invalid statement template compile error 2021-06-09 22:31:59 +01:00
Brian P O'Rourke 4f32e2e0fa
Fix outdated explanation of take_failed_screenshot usage 2021-06-08 21:51:28 -07:00
Adam Hess e8156a2788 Return "test" as the controller_name in ActionView tests
before https://github.com/rails/rails/pull/40125 test names would be
set to "test" after this change controller_name was nil when using
ActionView::TestCase.

This returns ActionView::TestCase to previous behavior returning "test"
2021-06-07 15:52:08 -07:00
Dylan Thacker-Smith f6fb700f4c actionpack: Use an infinite sized queue in testing ActionController::Live
To avoid a deadlock from the buffer filling up during testing due to the
ActionController::Live test monkey patch that processes the request in
the same thread, which means there is no consumer of the queue until
the request is processed.
2021-06-03 14:13:59 -04:00
Ricardo Díaz 093a4cde26 Drop support for the `SERVER_ADDR` header
Following up https://github.com/rails/rails/pull/42349 and
https://github.com/rack/rack/pull/1573 the `SERVER_ADDR` header can be
dropped, considering that it's not required by the CGI spec.
2021-06-02 12:34:15 -05:00
Gannon McGibbon b9f48d5d58
Merge pull request #42216 from gmcgibbon/set_options_in_default_session
Set session options when initializing a basic session
2021-06-02 12:30:21 -04:00
John Hawthorn cb8fc821ae
Merge pull request #42349 from jhawthorn/bump_rack_dependency
Bump rack to remove ssl? override
2021-06-01 13:41:14 -07:00
Eileen M. Uchitelle 0d18b43f6e
Merge pull request #42283 from HParker/named-routes-identifies-false
cause rails to correctly place optional path parameter booleans
2021-06-01 15:47:28 -04:00
John Hawthorn 14688b5578 Bump rack to remove ssl? override
Rack 2.2+ already understands "wss" as being "ssl", so bumping the
requirement lets us remove this override and call to super.
2021-06-01 11:15:14 -07:00
Gannon McGibbon 5f4bb201bc Set session options when initializing a basic session 2021-06-01 12:27:42 -04:00
Jacopo 32db1486fb Allow to overwrite Cache-Control header in `fresh_when` and `stale?`
Add a `cache_control: {}` option to `fresh_when` and `stale?`,
when given works as a shortcut to set `response.cache_control` manually.

Closes #41644
2021-05-28 12:32:30 +02:00
Adam Hess 98ed2406f7 cause rails to correctly place optional path parameters
previously, if you specify a url parameter that is part of the path as false it would include that part of the path as parameter at the end of the url instead of in the path for example:
`get "(/optional/:optional_id)/things" => "foo#foo", as: :things`
`things_path(optional_id: false)  # => /things?optional_id=false`

this is not the case for empty string,
`things_path(optional_id: '')  # => "/things"

this is due to a quark in how path parameters get removed from the parameters.

we where doing `(paramter || recall).nil?` which returns nil if both values are nil however it also return nil if one value is false and the other value is nil. i.e. `(false || nil).nil # => nil` which is confusing.

After this change, `true` and `false` will be treated the same when used as optional path parameters. meaning now,

```
get '(this/:my_bool)/that' as: :that

that_path(my_bool: true) # => `/this/true/that`
that_path(my_bool: false) # => `/this/false/that`
```
fixes: https://github.com/rails/rails/issues/42280

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2021-05-27 18:21:01 -07:00
Haroon Ahmed 7982e004bf [ci skip] Improve sentence around setting xhr:true for process method in
testing/integration.rb
2021-05-21 17:09:41 +01:00