Commit Graph

5472 Commits

Author SHA1 Message Date
Kasper Timm Hansen
11644fd0ce Collections automatically cache and fetch partials.
Collections can take advantage of `multi_read` if they render one template
and their partials begin with a cache call.

The cache call must correspond to either what the collections elements are
rendered as, or match the inferred name of the partial.

So with a notifications/_notification.html.erb template like:

```ruby
<% cache notification %>
  <%# ... %>
<% end %>
```

A collection would be able to use `multi_read` if rendered like:

```ruby
<%= render @notifications %>
<%= render partial: 'notifications/notification', collection: @notifications, as: :notification %>
```
2015-02-21 16:06:57 +01:00
Aaron Patterson
303567e554 lazily create the integration session
now we don't have to call reset! everywhere
2015-02-12 12:04:23 -08:00
Rafael Mendonça França
76f6524538 Merge pull request #11790 from printercu/patch-3
ActionController#translate supports symbols
2015-02-12 15:39:17 -02:00
claudiob
050fda0206 Accept a collection in fresh_when and stale?
The methods `fresh_when` and `stale?` from ActionController::ConditionalGet
accept a single record as a short form for a hash. For instance

```ruby
  def show
    @article = Article.find(params[:id])
    fresh_when(@article)
  end
```

is just a short form for:

```ruby
  def show
    @article = Article.find(params[:id])
    fresh_when(etag: @article, last_modified: @article.created_at)
  end
```

This commit extends `fresh_when` and `stale?` to also accept a collection
of records, so that a short form similar to the one above can be used in
an `index` action. After this commit, the following code:

```ruby
def index
  @article = Article.all
  fresh_when(etag: @articles, last_modified: @articles.maximum(:created_at))
end
```

can be simply written as:

```ruby
def index
  @article = Article.all
  fresh_when(@articles)
end
```
2015-02-10 17:08:44 -08:00
claudiob
c7331e057b Fix wrong kwarg "record" from #18872
PR #18772 changed the parameters of `stale?` to use `kwargs`.
[As for this comment](https://github.com/rails/rails/pull/18872/files#r24456288)
the default value for the `etag` parameter should be `record`, not `nil`.

This commit fixes the code and introduces a test that:

- passed before #18872
- fails on the current master (after #18772)
- passes again after setting the default value of `etag` to `record`.
2015-02-10 17:02:24 -08:00
Terence Sun
b9c63b0aae Explicitly ignored wildcard verbs from head_routes
In match_head_routes, deleted the routes in which request.request_method was empty (matches all HTTP verbs) when responding to a HEAD request. This prevents catch-all routes (such as Racks) from intercepting the HEAD request.

Fixes #18698
2015-02-08 12:03:56 -05:00
Rafael Mendonça França
35e2255b7a Merge pull request #18771 from kirs/deprecate-xhr
Migrating xhr methods to keyword arguments syntax
2015-02-05 18:27:47 -02:00
Vipul A M
6eced6a1fe Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 onwards. 2015-02-03 20:51:40 +05:30
Aaron Patterson
e6d8f435a9 Merge pull request #18721 from sj26/pre-discard-flash
Pre-discard flash messages
2015-02-01 08:58:11 -08:00
Andrew White
bf1716bc61 Merge pull request #18769 from gsamokovarov/exception-wrapper-windows-paths
Show proper traces on Windows for the error pages
2015-02-01 16:56:40 +00:00
Kir Shatrov
b19999f3a7 Migrating xhr methods to keyword arguments syntax
in `ActionController::TestCase` and
`ActionDispatch::Integration`

Old syntax:

    `xhr :get, :create, params: { id: 1 }`

New syntax example:

    `get :create, params: { id: 1 }, xhr: true`
2015-02-01 16:07:42 +03:00
Yves Senn
e374db2371 Merge pull request #18759 from yuki24/remove-warning
✂️ warning from controller renderer test
2015-02-01 11:44:12 +01:00
Genadi Samokovarov
872e22c603 Show proper traces on Windows for the error pages
This is an issue brought up by @daniel-rikowski in rails/web-console#91.

Citing his PR proposal here:

> Prior to this, backtrace lines were simply split by a single colon.
>
> Unfortunately that is also the drive letter delimiter in Windows paths
> which resulted in a lot of empty source fragments of "C:0". ("C" from
> the drive letter and 0 from "/path/to/rails/file.rb:16".to_i)
>
> Now the trace line is split by the first colon followed by some digits,
> which works for both Windows and Unix path styles.

Now, the PR was sent against web-console, because of the templates copy
issue we used to had. Instead of bothering the contributor to reopen the
issue against upstream Rails itself, I will make sure he gets the credit
by putting his name in [rails-contributors/hard_coded_authors.rb][].

  [rails-contributors/hard_coded_authors.rb]: (https://github.com/fxn/rails-contributors/blob/master/app/models/names_manager/hard_coded_authors.rb).
2015-02-01 12:00:18 +02:00
robertomiranda
ce8efcf296 Use public Module#include, in favor of https://bugs.ruby-lang.org/issues/8846
ref: https://github.com/rails/rails/pull/18763#issuecomment-72349769
2015-01-31 23:12:41 -05:00
Yuki Nishijima
1bb1b9e8cb ✂️ warning from controller renderer test
rails/actionpack/test/controller/renderer_test.rb:89: warning: possible reference to past scope - defaults
2015-01-31 17:48:55 -08:00
Samuel Cochran
3f528e371c Migrate old flash behaviour 2015-01-30 09:47:03 +11:00
Rafael Mendonça França
50318f5d7e Remove duplicated tests 2015-01-29 19:25:57 -02:00
Rafael Mendonça França
bb6fe7e73a Consistent usage of spaces in hashes across our codebase 2015-01-29 12:19:41 -02:00
Kir Shatrov
baf14ae513 Switch to kwargs in ActionController::TestCase and ActionDispatch::Integration
Non-kwargs requests are deprecated now.
Guides are updated as well.

`post url, nil, nil, { a: 'b' }` doesn't make sense.
`post url, params: { y: x }, session: { a: 'b' }` would be an explicit way to do the same
2015-01-29 14:44:46 +02:00
Samuel Cochran
f7adb34999 Discard from flash before persisting in session 2015-01-29 23:18:55 +11:00
Samuel Cochran
3a102d0528 Fix flash remaining after last flash deleted
Inside a controller functional test after the last flash is deleted it
still persists the flash because to_session_value is nil. We should
delete it from the session when the serialized version is nil, same as
the flash middleware.
2015-01-29 23:00:44 +11:00
Tekin Suleyman
db870f222e Preserve default url options when generating URLs
Fixes an issue that would cause default_url_options to be lost when generating
URLs with fewer positional arguments than parameters in the route definition.
2015-01-28 21:15:52 +00:00
Rafael Mendonça França
39bcbaece6 Just assert the deprecation of one method 2015-01-28 18:50:11 -02:00
Rafael Mendonça França
643f08beeb Merge pull request #18693 from aditya-kapoor/deprecate_via_redirect
Deprecate *_via_redirect integration test methods
2015-01-28 18:34:39 -02:00
Aditya Kapoor
751f752b43 Deprecate *_via_redirect integration test methods 2015-01-28 17:23:30 +05:30
Zhang Kai Yu
3e02cdc872 Add test for HTTP basic authentication when no credential is given. 2015-01-24 07:17:11 +08:00
Rafael Mendonça França
e36ecf4d77 Merge pull request #18546 from brainopia/action_view_render
A shortcut to setup controller environment
2015-01-22 12:09:32 -02:00
brainopia
656628961c Add ActionController::Base.render 2015-01-22 01:02:13 +03:00
brainopia
801e399e42 Add ActionController::Renderer
Render arbitrary templates outside of controller actions
2015-01-22 01:02:11 +03:00
brainopia
ee6e13f3da Add ActionController::Metal#set_request!
Add `ActionController::Metal#set_request!` to set a request
on controller instance without calling dispatch.
2015-01-21 23:53:38 +03:00
rono23
8a8dac80bb Fix name_for_action in routing 2015-01-19 10:32:27 +09:00
claudiob
7d493a6020 Remove unused AV fixtures from AP tests
When `render` was moved from ActionPack to ActionView in acc8e259,
some fixtures required by the tests were duplicated, but they are
actually only required by ActionView tests.

To give one example, `double_render` is already defined [in the AV tests](72139d8d31/actionview/test/actionpack/controller/render_test.rb (L407))
and is never used in the ActionPack tests.
2015-01-11 13:01:13 -08:00
Kuldeep Aggarwal
90aef23e38 No need of requiring rbconfig, it is by-default loaded 2015-01-10 20:27:18 +05:30
Jonas Baumann
0739480f45 Default headers, removed in controller actions, will not be reapplied to the test response. 2015-01-09 16:55:02 +01:00
Abdelkader Boudih
7644a99d90 Deprecate all *_filter callbacks in favor of *_action callbacks 2015-01-08 20:52:36 +00:00
Rafael Mendonça França
b8e83ce1c5 Merge pull request #18404 from claudiob/rebase-14549
Add test case and documentation for skip_before_filter.
2015-01-08 18:08:02 -02:00
Josef Šimánek
0074bbb07b Add prepend option to protect_from_forgery. 2015-01-08 19:47:19 +01:00
claudiob
9a25603d0a Add test/doc for :if/:except in skip_before_action
The new test/docs further explain the conflicts that can happen when
mixing `:if`/`:unless` options with `:only`/`:except` options in
`skip_before_action`.

The gist is that "positive" filters always have priority over negative
ones.

The previous commit already showed that `:only` has priority over `:if`.

This commit shows that `:if` has priority over `:except`.

For instance, the following snippets are equivalent:

```ruby
skip_before_action :some_callback, if: -> { condition }, except: action
```

```ruby
skip_before_action :some_callback, if: -> { condition }
```
2015-01-08 09:30:31 -08:00
Lauro Caetano
ae9f803c5d Add test case and documentation for skip_before_filter.
Test case for using skip_before_filter with the options :only and :if
both present. In this case, the :if option will be ignored and :only
will be executed.

Closes #14549 (the commit was cherry-picked from there).
2015-01-08 09:13:45 -08:00
brainopia
08d3f0e3b3 Remove ActionController::HideActions (closes #18336) 2015-01-06 23:40:45 +03:00
Carlos Antonio da Silva
afd5e9a7ff Remove respond_to/respond_with placeholder methods
This functionality has been extracted to the responders gem.
2015-01-04 18:22:09 -02:00
Rafael Mendonça França
34e380764e Remove deprecated usage of string keys in URL helpers 2015-01-04 11:58:42 -03:00
Rafael Mendonça França
e4e1fd7ade Remove deprecated only_path option on *_path helpers 2015-01-04 11:58:42 -03:00
Rafael Mendonça França
d282125a18 Remove deprecate *_path helpers in email views 2015-01-04 11:58:42 -03:00
Rafael Mendonça França
1f3b0a8609 Remove deprecated support to define routes with :to option that
doesn't contain `#`
2015-01-04 11:58:41 -03:00
Rafael Mendonça França
4b19d5b7bc Remove deprecated ActionDispatch::Response#to_ary 2015-01-04 11:58:41 -03:00
Rafael Mendonça França
e4cfd353a4 Remove deprecated option use_route in controller tests 2015-01-04 11:58:41 -03:00
Rafael Mendonça França
3456d543eb Merge pull request #10380 from JonRowe/test_all_domain_2_letter_tld
Assert that 2 letter tlds with 3 letter domain names work when option specified.
2015-01-02 21:27:38 -03:00
Rafael Mendonça França
2d743b528c Merge pull request #17978 from kommen/fixed-pr-14903
Ensure append_info_to_payload is called even if an exception is raised.

Conflicts:
	actionpack/CHANGELOG.md
2015-01-02 14:16:15 -03:00
brainopia
95333e1317 Integration requests should work in contexts without setup and teardown 2015-01-02 16:52:32 +03:00