Commit Graph

13727 Commits

Author SHA1 Message Date
Jon Moss f1a2a94f54 Small grammar fix
Tried to make the sentence read more clearly.

[ci skip]
2017-03-22 15:36:17 -04:00
Dominic Cleal d5ea4bde59
Use DeprecatedConstantAccessor for AD::ParamsParser::ParseError
Fixes #28525
2017-03-22 16:21:40 +00:00
Xavier Noria 34fe2a4fc7 Merge pull request #28394 from shime/docs-action-dispatch
[docs] fix ActionDispatch documentation
2017-03-22 00:51:29 -07:00
Matthew Draper 6c08d480f1 Start Rails 5.2 development 2017-03-22 10:11:39 +10:30
yuuji.yaginuma edcbb2e5b7 Fix store accessors in parameters test
* The method name must be `stored_attributes`, not `stores_attributes`.
* `attribute_names` must return a non-empty value. Because
  `stored_attributes` is not checked if `attribute_names` is empty.

Follow up to #28056
2017-03-22 08:20:18 +09:00
Rafael França 88b16843f6 Merge pull request #28056 from sngeth/wrap_store_accessors_in_params
Wrap stored accessors in parameters
2017-03-21 16:52:47 -04:00
Rafael Mendonça França b7bd4e2848
Fix test assertion 2017-03-21 16:51:56 -04:00
Rafael Mendonça França 681277e53b
Fix test that was asserting the wrong thing 2017-03-21 16:50:35 -04:00
Sid Ngeth ea5aa2525b Wrap store accessors in parameters
Modified params wrapper to account for model's stored_attributes
2017-03-21 15:47:29 -04:00
Rafael Mendonça França 843345cae5
Revert "Merge pull request #27775 from domcleal/27774-format-reset"
This reverts commit c6f9f8c28a, reversing
changes made to c309073c74.

Reason: This is fixing the behavior in the wrong place. Now the request
path after the request is nil and there is no way to assert that.
Also the test that was added in that PR also fails in 4.2 where the
reporter says it was passing. The reason the bahavior changed between
Rails 4.2 and Rails 5 is that the format in the path is now respected.
The correct way to fix the problem is not doign two requests in the same
controller test and use integrations tests. This change caused a
regression between Rails 5.0.1 and 5.0.2.
2017-03-21 13:40:41 -04:00
Andrew White fd16e1a92f Always use original url_for when generating direct routes
Action View overrides `url_for` in the view context to render paths by
default when using `url_for` and this means that direct route helpers
don't get the full url when called with the url suffix. To fix this
always call the original `url_for`.
2017-03-17 21:30:29 +00:00
Andrew White 35afd2c53b Add support for calling nested direct routes (#28462)
Not all requirements can be expressed in terms of polymorphic url
options so add a `route_for` method that allows calling another
direct route (or regular named route) which a set of arguments, e.g:

    resources :buckets

    direct :recordable do |recording|
      route_for(:bucket, recording.bucket)
    end

    direct :threadable do |threadable|
      route_for(:recordable, threadable.parent)
    end

This maintains the context of the original caller, e.g.

    threadable_path(threadable) # => /buckets/1
    threadable_url(threadable)  # => http://example.com/buckets/1
2017-03-17 18:07:09 +01:00
Rafael França 7413be0d31 Merge pull request #28341 from mtsmfm/pass-options-to-driven-by
Pass options to `driven_by`
2017-03-17 11:39:13 -04:00
eileencodes eadbc82c47 Bump Capybara and include Minitest::Assertions
Capybara was updated in teamcapybara/capybara#1841 to use Minitest style
assertions so that system test output shows x number of assertions, x
numbe of failures, etc.

Before:

```
6 runs, 0 assertions, 0 failures, 0 errors, 0 skips
```

After:

```
6 runs, 7 assertions, 1 failures, 0 errors, 0 skips
```

This change bumps Capybara from 2.7.0 to 2.13.0 and includes the
required minitest assertion file in the test case. 🎉
2017-03-17 08:22:22 -04:00
Vipul A M 0a4d1c3cde Cleanup documentation fixes (#28460) 2017-03-17 17:33:35 +05:30
Dmitriy Budnik 20a0f5e839 Updates incorrect documentation [ci skip]
Looking on code for this method it's clear that it's just returns `response.status` instead of full `response` object.
It's better to correct docs as probably lots of specs are relying on this behavior.
2017-03-16 13:29:31 +02:00
Andrew White 886085d643 Remove unnecessary params munging
In 9b654d4 some params munging was added to ensure that they were
set whenever `recognize_path` would call either a proc or callable
constraint. Since we no longer mutate the environment hash within
the method it's now unnecessary and actually causes params to leak
between route matches before checking constraints.

Fixes #28398.
2017-03-15 16:51:51 +00:00
Jon Moss 783aa528b8 Small grammar change
Reads easier, and removes extra tick marks.

[ci skip]
2017-03-13 19:37:27 -04:00
Olivier 67e1d022e1 Fix Typo [ci skip]
Arcticle --> Article
2017-03-13 18:38:03 -04:00
Jon Moss db98b05113 Fix HTTPS grammar
[ci skip]
2017-03-13 15:52:46 -04:00
Vipul A M e0397b0c25 Merge pull request #28381 from shime/docs-action-controller-base
[docs] fix ActionController docs
2017-03-13 23:00:52 +05:30
Hrvoje Šimić 1c6747999a
[docs] fix ActionDispatch documentation 2017-03-13 17:05:12 +01:00
Eileen M. Uchitelle 5a053052ad Merge pull request #28185 from renchap/system-testing-screenshot-output
Dont always display inline screenshots in system testing (#28133)
2017-03-13 08:01:03 -04:00
Fumiaki MATSUSHIMA ec99107a29 Pass options to `driven_by`
Capybara drivers can handle some options such like `url`.

### before

```
# test/test_helper.rb
Capybara.register_driver :remote_chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome, url: "http://example.com/wd/hub")
end

# test/application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :remote_chrome
end
```

### after

```
# test/application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: {url: "http://chrome:4444/wd/hub"}
end
```
2017-03-13 19:59:01 +09:00
Hrvoje Šimić b383b34660
[docs] fix ActionController documentation
[ci skip]
2017-03-12 15:59:40 +01:00
alpaca-tc c5f8fe9379 Fixes ActionController::Rendering#with_defaults
`env` is undefined.
2017-03-12 22:38:20 +09:00
Renaud Chaput 79435c0e64 Dont always display inline screenshots in system testing (#28133)
3 output types are supported:
- simple: only display the screenshot path
- artifact: display the screenshot in the terminal, using the artifact protocol (supported by some CI)
- inline (default): display the screenshot in the terminal, inline (supported by some terminals)

You can force the output type by setting the `RAILS_SYSTEM_TESTING_SCREENSHOT` environment variable
2017-03-11 23:17:20 +01:00
Eileen M. Uchitelle c186bf6b44 Merge pull request #28378 from y-yagi/use_correct_variable_in_reverse_merge_test
Use correct value in `reverse_merge` test
2017-03-11 16:33:10 -05:00
Hrvoje Šimić 95c847a1ff
[docs] remove unnecessary sentence
[ci skip]
2017-03-11 13:09:12 +01:00
Ryuta Kamizono 2e752d18b3 Fix indentation and formatting in CHANGELOGs [ci skip] 2017-03-11 17:31:25 +09:00
yuuji.yaginuma 6568da325d Use correct value in `reverse_merge` test 2017-03-11 14:07:01 +09:00
Rafael Mendonça França 744d388a90 Add @takkanm credits in the changelog [ci skip] 2017-03-10 18:11:12 -05:00
Rafael Mendonça França c76190ed76 Merge pull request #28355 from Edouard-chin/reversemerge-for-strongparameters
Added `reverse_merge`/`reverse_merge!` to AC::Parameters:

[Rafael Mendonça França + Mitsutaka Mimura]
2017-03-10 18:10:11 -05:00
Edouard CHIN 4d79862836 Added `reverse_merge`/`reverse_merge!` to AC::Parameters:
- This PR adds the `reverse_merge` and `reverse_merge!` method to `ActionController::Parameters`
- Fixes #28353
2017-03-09 13:48:13 -05:00
eileencodes 7c9af60e5c Call system test driver per-instance rather than globally
Previously the system test subclasses would call `driven_by` when the
app booted and not again when the test was initialized which resulted in
the driver from whichever class was called last to be used in tests.

In rails/rails#28144 the `driven_by` method was changed to run `use` on
setup and `reset` on teardown. While this was a viable fix this really
pointed to the problem that system test `driven_by` was a global
setting, rather than a per-class setting.

To alieviate this problem calling the driver should be done on an
instance level, rather than on the global level. I added an `initialize`
method to `SystemTestCase` which will call `use` on the superclass
driver. Running the server has been moved to `start_application` so that
it only needs to be called once on boot and no options from `driven_by`
were being passed to it.

This required a largish rewrite of the tests. Each test needs to utilize
the subclass so that it can properly test the drivers.
`ActionDispatch::SystemTestCase` shouldn't be called directly anymore.
2017-03-09 10:52:05 -05:00
eileencodes 4dbebe487d Refactor system test driver/browser
Since using a browser is only for selenium it doesn't really make sense
to have a separate class for handling it there. This brings a lot of the
if/else out of the main SystemTestCase class and into the Driver class
so we can abstract away all that extra work.
2017-03-09 07:27:40 -05:00
T.J. Schuck 26dcd7f7ee Tests for delegated public methods on AC::Parameters 2017-03-07 19:30:17 -05:00
Jon Moss b85b92176b params --> parameters
[ci skip]
2017-03-07 18:58:01 -05:00
T.J. Schuck 830ed5a536 Document delegated public methods on AC::Parameters
[ci skip]
2017-03-07 18:09:59 -05:00
Andrew White fde46f43bd Add CHANGELOG entry for #28250 2017-03-06 12:22:21 +00:00
Giorgos Vrettos 32046deced Fix malformed asset_url when rendering template with ActionController::Renderer 2017-03-06 13:12:14 +02:00
Jon Moss 99e4ed78b9 Merge pull request #28301 from y-yagi/fix_direct_with_params_example
Fix `direct` with params example [ci skip]
2017-03-05 21:32:18 -05:00
yuuji.yaginuma 0c1ff4243e Fix `direct` with params example [ci skip]
Since `ActionController:Parameters` does not inherit `Hash`, need to
explicitly convert it to `Hash`.
Also, `Parameters#to_h` returns `Hash` whose key is `String`. Therefore,
if merge as it is, the value will not be overwritten as expected.
2017-03-06 08:33:39 +09:00
Ryuta Kamizono 660e189c35 Fix CI failure due to contain <U+2028>
```diff
diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb
index a3159c29dd..1836a07d4e 100644
--- a/actionpack/lib/action_controller/metal/redirecting.rb
+++ b/actionpack/lib/action_controller/metal/redirecting.rb
@@ -50,8 +50,8 @@ module Redirecting
     #   redirect_to post_url(@post), status: 301, flash: { updated_post_id: @post.id }
     #   redirect_to({ action: 'atom' }, alert: "Something serious happened")
     #
-    # Statements after redirect_to in our controller get executed, so redirect_to doesn't stop the execution of the function.
-    <U+2028># To terminate the execution of the function immediately after the redirect_to, use return.
+    # Statements after +redirect_to+ in our controller get executed, so +redirect_to+ doesn't stop the execution of the function.
+    # To terminate the execution of the function immediately after the +redirect_to+, use return.
     #   redirect_to post_url(@post) and return
     def redirect_to(options = {}, response_status = {})
       raise ActionControllerError.new("Cannot redirect to nil!") unless options
```

https://travis-ci.org/rails/rails/jobs/207908041#L549
2017-03-06 00:24:30 +09:00
Vipul A M 6ef074a3b2 Merge pull request #28259 from ChakreshwarSharma/redirect_to_doc
[ci skip]  Use return with redirect_to
2017-03-05 19:53:31 +05:30
Eileen M. Uchitelle c21f71c7ef Merge pull request #28264 from y-yagi/do_not_take_screenshot_if_driver_does_not_support_it
Do not take screenshot if driver does not support screenshot
2017-03-05 09:17:08 -05:00
eileencodes 0a7e91abbc Revert "Add a changelog entry for #28284 [ci skip]"
This reverts commit 84c1b107b9.

Reverted #28283 so reverted it's changelog update as well.
2017-03-05 09:08:17 -05:00
eileencodes fea0c35107 Revert "Merge pull request #28283 from y-yagi/silence_puma_startup_messages_in_system_test"
This reverts commit 0d73f9116c, reversing
changes made to 21ff8a4932.

We don't want to silence Puma because it's start up messages can be
useful (to see threads, port etc). #28109 was instead fixed by not
running system tests by defaul with `bin/rails test` in #28286.
2017-03-05 09:00:32 -05:00
Tejas Bubane 609bf1ac8f
[ci skip] Fix ParameterMissing exception name in docs
Should be `ActionController::ParameterMissing` and not
`ActionController::MissingParameter`.

Corresponding change was done in guides in
https://github.com/rails/rails/pull/9816.
2017-03-04 21:30:18 +05:30
Robin Dupret 145adda581 Fix a wrong pull request reference [ci skip] 2017-03-04 15:15:20 +01:00
Robin Dupret 84c1b107b9 Add a changelog entry for #28284 [ci skip] 2017-03-04 14:39:56 +01:00
yuuji.yaginuma 5752ff8dec Silence puma startup messages in system test
Fixes #28109
2017-03-04 18:26:28 +09:00
yuuji.yaginuma 2ee4058cc5 Do not take screenshot if driver does not support screenshot
`Capybara::RackTest::Driver` does not support taking screenshots. If call
`#save_screenshot` on `Capybara::RackTest::Driver` will raise the error.

```ruby
Error:
UsersTest#test_visiting_the_index:
Capybara::NotSupportedByDriverError: Capybara::Driver::Base#save_screenshot
```

To prevent errors, if driver does not support screenshot, do not call it.
2017-03-04 17:40:51 +09:00
ChakreshwarSharma 51068a71fc [ci skip] Use return with redirect_to 2017-03-04 13:34:22 +05:30
Fumiaki MATSUSHIMA 5edbdca5c0 Fix random failure on system test with ajax
If application has ajax, browser may begin request after rollback.
`teardown_fixtures` will be called after `super` on `after_teardown`
so we must call `Capybara.reset_sessions!` before `super`

b61a56541a/activerecord/lib/active_record/fixtures.rb (L857)
2017-03-03 19:36:56 +09:00
yuuji.yaginuma 3da239a2cd Take failed screenshot before reset driver
Now reset the driver before take failed screenshot since #28144.
However, I think that failed screenshot should be take with the driver
actually used in the test.
So, fixed to take screenshot before reset driver.
2017-02-28 10:06:21 +09:00
Jerry Tao 6ddd65c9f3 Remove unused params. 2017-02-26 12:22:06 +00:00
Andrew White 558336ee2a Commit flash changes when using a redirect route.
In ca324a0 the flash middleware was effectively removed by its
constructor returning the app it was passed and the `commit_flash`
call was moved to the `ActionController::Metal#dispatch` method.
This broke any redirect routes that modified the flash because the
redirect happens before `dispatch` gets called.

To fix it, this commit adds a `commit_flash` call in the `serve`
method of `ActionDispatch::Routing::Redirect`.

Fixes #27992.
2017-02-25 17:07:07 +00:00
Andrew White 71152576cb [ci ckip] Fix example of resolve in CHANGELOG.md 2017-02-25 14:22:29 +00:00
Dylan Thacker-Smith 29c02709cd Add missing gzip footer check in ActiveSupport::Gzip.decompress
A gzip file has a checksum and length for the decompressed data in its
footer which isn't checked by just calling Zlib::GzipReader#read.
Calling Zlib::GzipReader#close must be called after reading to the end
of the file causes this check to be done, which is done by
Zlib::GzipReader.wrap after its block is called.
2017-02-24 17:33:36 -05:00
Lucas Mazza 704853b58b
Change `SystemTestCase.driven_by` to use `setup`/`teardown` hooks
Previously, `driven_by` would change the Capybara configuration when
the test case is loaded, and having multiple test classes with different
`driven_by` configs would fail as the last loaded would be effective.
2017-02-24 13:22:22 -03:00
Rafael Mendonça França f4acdd83ff
Preparing for 5.1.0.beta1 release 2017-02-23 14:53:21 -05:00
eileencodes e23464bc9e Move documentation to the correct place
The documentation needs to be above the method to correctly document the
method.
2017-02-23 14:47:09 -05:00
yuuji.yaginuma ebaf1e709f Do not take screenshot when test skipped 2017-02-23 22:40:35 +09:00
Andrew White fd85bec261 [ci skip] Fix more quotes in direct/resolve docs
Also correct use of `direct class:` to `resolve` in example.
2017-02-23 12:00:51 +00:00
Andrew White 630e709ea6 Clarify use of params in `direct`
Since a `direct` url helper block is evaluated using `instance_exec`
then methods that are available in the instance context can be
accessed, e.g. the params object in a controller action or view.

This wasn't clear from the example so expand on that point and add
a test case for this situation.
2017-02-22 21:22:22 +00:00
Andrew White a92bd65e37 Add more missing requires
Further missing requires for Timeout exposed due to Bundler 1.14.5
2017-02-22 14:05:37 +00:00
Andrew White 923d98bd77 Bump removal of `/:controller/:action` to Rails 5.2 2017-02-22 13:37:42 +00:00
Kasper Timm Hansen ecca24e2d7 [ci skip] Fix direct/resolve documentation.
Use double quoted strings, come down hard on some typos.
2017-02-21 21:17:16 +01:00
Kasper Timm Hansen e31e992ad8 [ci skip] Fix typos in direct/resolve changelog. 2017-02-21 21:11:39 +01:00
Andrew White f3d729f753 Merge pull request #23138 from rails/custom-url-helpers-and-polymorphic-urls
Implement custom url helpers and polymorphic mapping
2017-02-21 20:00:31 +00:00
Jon Moss e2c0d7aea8 Add backticks around command
[ci skip]
2017-02-21 11:59:37 -05:00
Andrew White d7c1e62c2c Split direct method into two
Use a separate method called `resolve` for the custom polymorphic
mapping to clarify the API.
2017-02-21 15:30:48 +00:00
Andrew White fbda6b9837 Push option extract into call method 2017-02-21 15:30:47 +00:00
Andrew White ef862c04e5 Fix typo in exception message 2017-02-21 15:30:47 +00:00
Andrew White 050d7b1b92 Removed `model_name` method to prevent warning 2017-02-21 15:30:47 +00:00
Andrew White c116eaf221 Prefer remove_method over undef_method
Using `undef_method` means that when a route is removed any other
implementations of that method in the ancestor chain are inaccessible
so instead use `remove_method` which restores access to the ancestor.
2017-02-21 15:30:47 +00:00
Andrew White 81a6761af2 Support mapping of non-model classes 2017-02-21 15:30:47 +00:00
Andrew White 80dcfd014b Raise an error if `direct` is inside a scope block 2017-02-21 15:30:47 +00:00
Andrew White 960e73a96d Add CHANGELOG entry for `direct` method 2017-02-21 15:30:47 +00:00
Andrew White 3bf47b018b Add custom polymorphic mapping
Allow the use of `direct` to specify custom mappings for polymorphic_url, e.g:

  resource :basket
  direct(class: "Basket") { [:basket] }

This will then generate the following:

  >> link_to "Basket", @basket
  => <a href="/basket">Basket</a>

More importantly it will generate the correct url when used with `form_for`.

Fixes #1769.
2017-02-21 15:30:47 +00:00
Andrew White d67e252028 Add test for calling a url helper in Mapper#direct 2017-02-21 15:30:47 +00:00
Andrew White 7d1e738057 Don't allocate a hash unnecessarily 2017-02-21 15:30:46 +00:00
Andrew White e96da0a7be Only accept symbols and strings for Mapper#direct 2017-02-21 15:30:46 +00:00
Andrew White 47a27e8950 Rename url_helper to direct 2017-02-21 15:30:46 +00:00
Andrew White ce7d5fb2e6 Add support for defining custom url helpers in routes.rb
Allow the definition of custom url helpers that will be available
automatically wherever standard url helpers are available. The
current solution is to create helper methods in ApplicationHelper
or some other helper module and this isn't a great solution since
the url helper module can be called directly or included in another
class which doesn't include the normal helper modules.

Reference #22512.
2017-02-21 15:30:46 +00:00
Andrew White 31dc46cb9c Wrap routes.url_helpers.url_for via a proxy
The singleton url_for on Rails.application.routes.url_helpers isn't the
same as the url_for you get when you include the module in your class as
the latter has support for polymorphic style routes, etc. whereas the
former accepts only a hash and is the underlying implementation defined
on ActionDispatch::Routing::RouteSet.

This commit changes the singleton method to call through a proxy instance
so that it gets the full range of features specified in the documentation
for url_for.
2017-02-21 15:30:46 +00:00
Robin Dupret 658b524435 Tiny documentation edits [ci skip] 2017-02-21 16:23:49 +01:00
kenta-s 5d3abc06c3 Fix some grammar in docs [ci skip] 2017-02-21 13:48:41 +09:00
Guillermo Iguaran 6df558f2ab Merge pull request #28081 from meinac/fix_redirect_method
Use `response#location` instead of `#location` in redirect.
2017-02-21 11:28:54 +09:00
Jon Moss ab0146075a Add missing space
[ci skip]
2017-02-20 17:08:33 -05:00
eileencodes 13151d511e Add changelog for system tests 2017-02-20 16:40:07 -05:00
eileencodes 42a6dbdf84 Clean up documentation
There were some grammar issues and incorrect information in the system
tests documentation.
2017-02-20 16:08:20 -05:00
eileencodes 2d61c5d846 Rename system_test_helper -> application_system_test_case
This renames the system test helper file to be application system test
case to match what the rest of Rails does. In the future we should
consider changing the test_helper to match.
2017-02-20 15:07:35 -05:00
eileencodes 161cf89e13 Fix default host in setup, move teardown to helper file
* Override integration test default host

Integration tests automatically set the default host to
'http://example.com'. This works fine for integration tests because they
are not real browser sessions, but doesn't work fine for system tests
because they are real browser sessions.

We can override this by setting the `host!` in `before_setup. The
`Capybara.always_include_port` will allow the test to look at
`127.0.0.1:port capybara picks` and properly redirect the test.

Any application can override this by setting the `host!` in
their system test helper. Generally though, applications are going to be
using localhost.

In this commit I also moved the setup and teardown into their own module
for tidiness.

* Move teardown settings into system test case

These configuration options can be put into the system test case file
instead of the generated system tests helper file. This is an
implementation detail and therefore shouldn't be generated with the
template.
2017-02-20 15:07:35 -05:00
eileencodes 983275eb7c Fix screenshot helper to provide correct file name
We only want the file name to include the word `failures` if it failed,
not any time the user wants to take a screenshot during a test run.
2017-02-20 15:07:35 -05:00
eileencodes 1a0ca84a06 Move and rename system tests
* Move system tests back into Action Pack
* Rename `ActionSystemTest` to `ActionDispatch::SystemTestCase`
* Remove private base module and only make file for public
`SystemTestCase` class, name private module `SystemTesting`
* Rename `ActionSystemTestCase` to `ApplicationSystemTestCase`
* Update corresponding documentation and guides
* Delete old `ActionSystemTest` files
2017-02-20 15:07:35 -05:00
eileencodes 5bf0aa6745 Turn system testing into it's own gem and rename
Renames `Rails::SystemTestCase` to `ActionSystemTest` and moves it to a
gem under the Rails name.

We need to name the class `ActionSystemTestCase` because the gem expects
a module but tests themselves expect a class.

Adds MIT-LICENSE, CHANGELOG, and README for the future.
2017-02-20 15:07:33 -05:00
eileencodes a21e18d508 Appease Rubocop
Rubocop / code climate don't like single quotes and prefer doubles.
2017-02-20 15:07:33 -05:00
eileencodes c83e6d36dd Refactor so all drivers use Puma by default
Puma is the default webserver of Rails. Because of this it doesn't make
sense to run tests in Webkit if the default server is Puma.

Here I've refactored the webserver to be it's own standalone module so
it can be shared between Rails' selenium default driver and Capybara's
defaut drivers.
2017-02-20 15:07:33 -05:00