aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
Commit message (Collapse)AuthorAgeFilesLines
* Support testing of non-ActionDispatch-routed apps.Darren Cheng2019-02-051-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The [Grape API framework](https://github.com/ruby-grape/grape) regularly writes tests like [spec/grape/api_spec.rb](https://github.com/ruby-grape/grape/blob/master/spec/grape/api_spec.rb). When attempting to write a test in a Rails environment similar to the following: ``` describe Grape::Api, type: :request do let(:app) { Class.new(Grape::API) do get 'test' do { foo: 'bar' } end end } it '200s' do get 'test' end end ``` The following exception is thrown: ``` NoMethodError: undefined method `url_helpers' for #<Array:0x00007fb4e4bc4c88> -- 0: .../lib/action_dispatch/testing/integration.rb:330:in `block in create_session' 1: .../lib/action_dispatch/testing/integration.rb:326:in `initialize' 2: .../lib/action_dispatch/testing/integration.rb:326:in `new' 3: .../lib/action_dispatch/testing/integration.rb:326:in `create_session' 4: .../lib/action_dispatch/testing/integration.rb:316:in `integration_session' 5: .../lib/action_dispatch/testing/integration.rb:348:in `block (2 levels) in <module:Runner>' ``` This change explicitly ensures that `app.routes` is an `ActionDispatch::Routing::RouteSet` instance.
* Merge pull request #35162 from silppuri/fix-incorrectly-matching-unachored-pathsAaron Patterson2019-02-052-11/+17
|\ | | | | Fix incorrectly matching unanchored paths
| * Restrict matching with word boundary or end of stringPetri Avikainen2019-02-051-11/+11
| |
| * Define word boundary for unanchored path regexpPetri Avikainen2019-02-052-11/+17
| |
* | Respect ENV variables when finding DBs etc for the test suiteMatthew Draper2019-02-061-3/+6
| | | | | | | | | | If they're not set we'll still fall back to localhost, but this makes it possible to run the tests against a remote Postgres / Redis / whatever.
* | Merge pull request #35134 from Edouard-chin/ec-cookie-expiry-regressionRafael França2019-02-041-9/+2
|\ \ | | | | | | Cookie doesn't expire anymore unless a flag is set:
| * | Cookie doesn't expire anymore unless a flag is set:Edouard CHIN2019-02-041-9/+2
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - There is a regression in 6.0 introduced by #32937 where cookie doesn't expire anymore unless the new `use_cookies_with_metadata` configuration is set to `true`. This causes issue for app migration from 5.2 to 6.0 because the `use_cookies_with_metadata` flag can't be set to true until all servers are running on 6.0. Here is a small reproduction script that you can run in the console ```ruby ActionDispatch::Cookies request = ActionDispatch::Request.empty request.env["action_dispatch.key_generator"] = ActiveSupport::KeyGenerator.new('1234567890') request.env["action_dispatch.signed_cookie_salt"] = 'signed cookie' request.env["action_dispatch.cookies_rotations"] = ActiveSupport::Messages::RotationConfiguration.new request.env["action_dispatch.use_authenticated_cookie_encryption"] = true signed_cookie = request.cookie_jar.signed signed_cookie[:foobar] = { value: '123', expires: 1.day.ago } p signed_cookie[:foobar] ```
* | Merge pull request #35086 from gsamokovarov/cleanup-whitelisting-refsGannon McGibbon2019-02-041-3/+3
|\ \ | |/ |/| Cleanup the whitelisting references after #33145
| * Cleanup the whitelisting references after #33145Genadi Samokovarov2019-02-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | During the development of #33145, I have named a few concepts in the code as `whitelisted`. We decided to stay away from the term and I adjusted most of the code afterwards, but here are the cases I forgot to change. I also found a case in the API guide that we could have cleaned up as well. [ci skip]
* | Add `require "selenium/webdriver"` to all using `DrivenBySeleniumWith*` classesRyuta Kamizono2019-01-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://travis-ci.org/rails/rails/jobs/486285170#L1349-L1366 ``` % git grep -n DrivenBySeleniumWith test/abstract_unit.rb:374:class DrivenBySeleniumWithChrome < ActionDispatch::SystemTestCase test/abstract_unit.rb:378:class DrivenBySeleniumWithHeadlessChrome < ActionDispatch::SystemTestCase test/abstract_unit.rb:382:class DrivenBySeleniumWithHeadlessFirefox < ActionDispatch::SystemTestCase test/dispatch/system_testing/screenshot_helper_test.rb:10: new_test = DrivenBySeleniumWithChrome.new("x") test/dispatch/system_testing/screenshot_helper_test.rb:18: new_test = DrivenBySeleniumWithChrome.new("x") test/dispatch/system_testing/screenshot_helper_test.rb:28: new_test = DrivenBySeleniumWithChrome.new("x") test/dispatch/system_testing/screenshot_helper_test.rb:40: new_test = DrivenBySeleniumWithChrome.new("x") test/dispatch/system_testing/screenshot_helper_test.rb:48: new_test = DrivenBySeleniumWithChrome.new("x") test/dispatch/system_testing/screenshot_helper_test.rb:62: new_test = DrivenBySeleniumWithChrome.new("x") test/dispatch/system_testing/screenshot_helper_test.rb:76:class SeleniumScreenshotsTest < DrivenBySeleniumWithChrome test/dispatch/system_testing/system_test_case_test.rb:11:class OverrideSeleniumSubclassToRackTestTest < DrivenBySeleniumWithChrome test/dispatch/system_testing/system_test_case_test.rb:19:class SetDriverToSeleniumTest < DrivenBySeleniumWithChrome test/dispatch/system_testing/system_test_case_test.rb:25:class SetDriverToSeleniumHeadlessChromeTest < DrivenBySeleniumWithHeadlessChrome test/dispatch/system_testing/system_test_case_test.rb:31:class SetDriverToSeleniumHeadlessFirefoxTest < DrivenBySeleniumWithHeadlessFirefox test/dispatch/system_testing/system_test_case_test.rb:49:class UndefMethodsTest < DrivenBySeleniumWithChrome ```
* | selenium-webdriver is not always required for system testingRyuta Kamizono2019-01-301-0/+1
| | | | | | | | | | | | But `NameError: uninitialized constant ActionDispatch::SystemTesting::Browser::Selenium` is pretty confused. I've little improved missing constant error to `NameError: uninitialized constant Selenium`.
* | Fix system testing failureRyuta Kamizono2019-01-301-0/+2
| | | | | | | | https://travis-ci.org/rails/rails/jobs/486155626#L1317-L1335
* | Implement a way to add browser capabilities:Edouard CHIN2019-01-291-0/+67
|/ | | | | | | | | | | | | | | | | | * There is currently no way to define specific browser capabilities since our SystemTest driver override the `option` key [Ref](https://github.com/rails/rails/blob/a07d0680787ced3c04b362fa7a238c918211ac70/actionpack/lib/action_dispatch/system_testing/driver.rb#L35) This option key is used internally by selenium to add custom capabilities on the browser. Depending on the Browser, some option are allowed to be passed inside a hash, the driver takes care of setting whatever you passed on the driver option. An example [here](https://github.com/rails/rails/blob/a07d0680787ced3c04b362fa7a238c918211ac70/actionpack/lib/action_dispatch/system_testing/driver.rb#L35) where you are allowed to pass args such as `--no-sandbox` etc However this behavior was only meant for backward compatibility and as you can see it's deprecated. The non-deprecated behavior is to create a `<Driver>::Option` object containing all the capabilities we want. This is what we [currently do](https://github.com/rails/rails/blob/a07d0680787ced3c04b362fa7a238c918211ac70/actionpack/lib/action_dispatch/system_testing/browser.rb#L34-L36) when chrome or firefox are in headless mode. This PR allows to pass a block when calling `driven_by`, the block will be pased a `<Driver>::Option` instance. You can modify this object the way you want by adding any capabilities. The option object will be then passed to selenium. ```ruby driven_by :selenium, using: :chrome do |driver_option| driver_option.add_argument('--no-sandbox') driver_option.add_emulation(device: 'iphone 4') end ```
* Merge pull request #35054 from bogdanvlviv/exercise-redirect_backRyuta Kamizono2019-01-261-0/+29
|\ | | | | Ensure that `redirect_back` with `fallback_location` to another host is allowed
| * Ensure that `redirect_back` with `fallback_location` to another host is allowedbogdanvlviv2019-01-251-0/+29
| | | | | | | | I would like to add those tests to prevent regression.
* | Loosen check of error cause fileyuuji.yaginuma2019-01-261-2/+2
| | | | | | | | | | Since "actionpack" is not included in isolation test. Ref: https://travis-ci.org/rails/rails/jobs/484514392#L2715
* | Fixed a bug where the debug view does not show the error page properlyYuki Nishijima2019-01-241-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two cases where the debug view does not show the error details properly: * When the cause is mapped to an HTTP status code the last exception is unexpectedly uwrapped * When the last error is thrown from a view template the debug view is not using the `rescues/template_error.html.erb` to generate the view Both the cases could be fixed by not unwrapping the exception. The only case where the exception should be unwrapped is when the last error is an `ActionView::Template::Error` object. In this case the HTTP status code is determined based on the cause. There are actually more wrapper exceptions that are intentionally thrown. However, there is a consistent pattern of setting the original message and original backtrace to the wrapper exception implemented, so the debug view will not lose the information about what went wrong eariler.
* | Prefer strings over regex expressionsYuki Nishijima2019-01-241-22/+20
|/ | | | | | | | | | | | | | | | | | In this case statement, there are two patterns that start with the same line: when %r{/not_found} ... when %r{/not_found_original_exception} ... Because the string "/not_found_original_exception" does match the first one, it is never routed to what it is supposed to be routed, causing one of the tests for DebugExceptions to happen to be passing. After changing the regex expressions back to strings, I noticed that the test setup is not complete (the template object needs to be a proper template object). Once I fixed it all the tests started padding.
* Merge pull request #35018 from gmcgibbon/revert_redirect_to_allow_other_hostRafael França2019-01-223-42/+12
|\ | | | | Revert ensure external redirects are explicitly allowed
| * Revert ensure external redirects are explicitly allowedGannon McGibbon2019-01-223-42/+12
| |
* | Merge pull request #35020 from alkesh26/ationpack-typo-fixesRafael França2019-01-222-4/+4
|\ \ | | | | | | Actionpack typo fixes.
| * | 1. Replaced unused variables by `_`.alkesh262019-01-222-4/+4
| |/ | | | | | | 2. Typo fixes.
* | Merge pull request #34952 from rails/template-stuffAaron Patterson2019-01-221-55/+0
|\ \ | |/ |/| Template Handler Refactoring
| * Templates should be eval'd in the context of an AV::Base objectAaron Patterson2019-01-171-55/+0
| |
* | Changed webserver to web server.alkesh262019-01-221-1/+1
| |
* | Remove secret_token rack env and cookie upgrade codeRafael Mendonça França2019-01-174-190/+18
| | | | | | | | Now that secret_token was removed all this code is now dead.
* | Remove deprecated `#acronym_regex` method from `Inflections`Rafael Mendonça França2019-01-171-1/+0
| |
* | Remove deprecated `fragment_cache_key` helper in favor of ↵Rafael Mendonça França2019-01-171-8/+0
| | | | | | | | `combined_fragment_cache_key`
* | Remove deprecated methods in ActionDispatch::TestResponseRafael Mendonça França2019-01-171-7/+0
| | | | | | | | | | `#success?`, `missing?` and `error?` were deprecated in Rails 5.2 in favor of `#successful?`, `not_found?` and `server_error?`.
* | Ensure external redirects are explicitly allowedGannon McGibbon2019-01-173-12/+42
| | | | | | | | Add `fallback_location` and `allow_other_host` options to `redirect_to`.
* | Revert "Don't handle params option in a special way in url_for helper"Rafael Mendonça França2019-01-162-1/+9
|/ | | | | | | | | | | This reverts commit e385e4678fc64be6e176c3bdac6641db9fe48d85. While this option was undocumented it exists to make possible to pass parameters to the route helpers that are reserved like `:domain`. While `url_for(domain: 'foo.com')` would generate a URL in the `foo.com` domain `url_for(params: { domain: 'foo.com' })` would generate a URL with `?domain=foo.com`.
* Enable `Lint/UselessAssignment` cop to avoid unused variable warnings (#34904)Ryuta Kamizono2019-01-092-4/+4
| | | | | | | | | | | | | | * Enable `Lint/UselessAssignment` cop to avoid unused variable warnings Since we've addressed the warning "assigned but unused variable" frequently. 370537de05092aeea552146b42042833212a1acc 3040446cece8e7a6d9e29219e636e13f180a1e03 5ed618e192e9788094bd92c51255dda1c4fd0eae 76ebafe594fc23abc3764acc7a3758ca473799e5 And also, I've found the unused args in c1b14ad which raises no warnings by the cop, it shows the value of the cop.
* Allow using combine the Cache-Control `public` and `no-cache` headersyuuji.yaginuma2019-01-071-0/+10
| | | | | | | | | | | | | | | | | Since #30367, if `no-cache` includes Cache-Control headers, special keys like `public`, `must-revalidate` are ignored. But in my understanding, `public` still need in case of want to cache authenticated pages. The authenticated pages to be cacheable, but still authenticated for every user, need to specify the `Cache-Control: public, no-cache`. For keys other than `public`, I did not know the case where it was necessary to use it in combination with `no-cache`, so I fixed that can be used only for `public`. Ref: https://www.mnot.net/cache_docs/#CACHE-CONTROL Fixes #34780.
* Make Rails Facebook-freeSasha Koss2018-12-241-2/+2
| | | If Basecamp is a Facebook-free business, then Rails should be Facebook-free framework.
* Add missing require for `IPAddr`yuuji.yaginuma2018-12-241-0/+1
| | | | Ref: https://travis-ci.org/rails/rails/jobs/469956825#L1694
* Remove unused methodsyuuji.yaginuma2018-12-231-26/+0
| | | | These were unused since 11af089cee0a0e744e267d32becfe2c66a586d31 and e35b98e6f5c54330245645f2ed40d56c74538902.
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-217-147/+113
| | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-213-3/+3
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* Pass the correct value as JSONyuuji.yaginuma2018-12-191-1/+1
| | | | | | | | | | | | This takes away the following log. ``` Error occurred while parsing request parameters. Contents: {:foo=>"heyo"} ``` Pass the correct value as JSON
* Merge pull request #34737 from r7kamura/feature/test-case-params-nilKasper Timm Hansen2018-12-181-0/+12
|\ | | | | Allow nil params on controller HTTP test methods
| * Allow nil params on controller HTTP test methodsr7kamura2018-12-181-0/+12
| |
* | More exercise `test_running_prepended_before_and_after_action`Ryuta Kamizono2018-12-191-1/+3
|/ | | | | Just testing that `after_action` is invoked before `prepend_after_action`.
* Merge branch 'master' into host-authorizationEileen M. Uchitelle2018-12-171-0/+14
|\
| * Allow using parsed_body in ActionController::TestCaseTobias Bühlmann2018-12-161-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | … by switching the initialzation of an appropriate response parser in `ActionDispatch::TestResponse` from eagerly to lazily. By doing so, the response parser can be correctly set for `ActionController::TestCase`, which doesn't include the content type header in the constructor but only sets it at a later time. Fixes #34676.
* | Introduce a guard against DNS rebinding attacksGenadi Samokovarov2018-12-151-0/+160
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ActionDispatch::HostAuthorization is a new middleware that prevent against DNS rebinding and other Host header attacks. By default it is included only in the development environment with the following configuration: Rails.application.config.hosts = [ IPAddr.new("0.0.0.0/0"), # All IPv4 addresses. IPAddr.new("::/0"), # All IPv6 addresses. "localhost" # The localhost reserved domain. ] In other environments, `Rails.application.config.hosts` is empty and no Host header checks will be done. If you want to guard against header attacks on production, you have to manually permit the allowed hosts with: Rails.application.config.hosts << "product.com" The host of a request is checked against the hosts entries with the case operator (#===), which lets hosts support entries of type RegExp, Proc and IPAddr to name a few. Here is an example with a regexp. # Allow requests from subdomains like `www.product.com` and # `beta1.product.com`. Rails.application.config.hosts << /.*\.product\.com/ A special case is supported that allows you to permit all sub-domains: # Allow requests from subdomains like `www.product.com` and # `beta1.product.com`. Rails.application.config.hosts << ".product.com"
* Use `Testing::Parallelization` in Action Packs's testyuuji.yaginuma2018-11-281-77/+1
| | | | | | Parallel execution of `ForkingExecutor` is the same approach as `Testing::Parallelization`. So do not need to have own code inside Action Pack. Let's use an already existing feature.
* Use env instead of headers on those testsRafael Mendonça França2018-11-261-14/+14
| | | | | We are dealing with the rack env so it is better to specify it in the tests.
* Raise an error on root route naming conflicts.Gannon McGibbon2018-11-201-3/+13
| | | | | Raises an ArgumentError when multiple root routes are defined in the same context instead of assigning nil names to subsequent roots.
* Merge pull request #20865 from colavitam/only-except-behaviorRafael Mendonça França2018-11-191-0/+22
|\ | | | | | | :only and :except are now chained for routing resource(s)
| * :only and :except are now chained for routing resource(s)Michael Colavita2015-07-131-0/+22
| | | | | | | | | | | | | | | | | | | | | | Allow chaining the :only and :except options for routing resource(s). Previously, the following yielded routes for both show and destroy: resource :account, :only => [:show, :destroy], :except => :destroy This now yields only the show action. This chaining can be useful for passing optional :except options to code that makes use of the :only option (e.g. for a gem with its own routing methods).