Commit Graph

322 Commits

Author SHA1 Message Date
Rafael Mendonça França
68a2a67116 Merge pull request #18948 from kaspth/automatic-collection-caching
Merge multi_fetch_fragments.
2015-02-25 11:54:07 -03:00
Thiago Pradi
71b73b01a6 Removing unused template 2015-02-22 23:42:50 -03:00
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
Tu Hoang
8ef51f64e5 Typo: Hello = Guten Tag (in German) 2014-12-05 12:54:15 +07:00
Xavier Noria
8d7cf75684 give a better error message for misspelled helpers
See comment in this patch for the rationale.

References #16468
2014-10-25 14:06:33 +02:00
schneems
0b1a87f73c Refactor out Dir.glob from ActionDispatch::Static
Dir.glob can be a security concern. The original use was to provide logic of fallback files. Example a request to `/` should render the file from `/public/index.html`. We can replace the dir glob with the specific logic it represents. The glob {,index,index.html} will look for the current path, then in the directory of the path with index file and then in the directory of the path with index.html. This PR replaces the glob logic by manually checking each potential match. Best case scenario this results in one less file API request, worst case, this has one more file API request.

Related to #16464

Update: added a test for when a file of a given name (`public/bar.html` and a directory `public/bar` both exist in the same root directory. Changed logic to accommodate this scenario.
2014-08-27 13:03:08 -05:00
schneems
8e31fa3b72 Address comments on Gzip implementation
- don't mutate PATH_INFO in env, test
- test fallback content type matches Rack::File
- change assertion style
- make HTTP_ACCEPT_ENCODING comparison case insensitive
- return gzip path from method instead of true/false so we don't have to assume later
- don't allocate un-needed hash.

Original comments:

https://github.com/rails/rails/commit/
cfaaacd9763642e91761de54c90669a88d772e5a#commitcomment-7468728

cc @jeremy
2014-08-24 15:58:16 -05:00
schneems
cfaaacd976 Enable gzip compression by default
If someone is using ActionDispatch::Static to serve assets and makes it past the `match?` then the file exists on disk and it will be served. This PR adds in logic that checks to see if the file being served is already compressed (via gzip) and on disk, if it is it will be served as long as the client can handle gzip encoding. If not, then a non gzip file will be served.

This additional logic slows down an individual asset request but should speed up the consumer experience as compressed files are served and production applications should be delivered with a CDN. This PR allows a CDN to cache a gzip file by setting the `Vary` header appropriately. In net this should speed up a production application that are using Rails as an origin for a CDN. Non-asset request speed is not affected in this PR.
2014-08-20 22:33:06 -05:00
José Valim
57f5b00ba4 Remove more references to respond_with 2014-08-17 13:20:23 -04:00
Rafael Mendonça França
6947e3a2b5 Remove unused fixtures
These fixtures are not used in actionpack tests.
2014-07-16 14:48:45 -03:00
Piotr Chmolowski
025c691536 Ensure LookupContext in Digestor selects correct variant
Related to: #14242 #14243 14293

Variants passed to LookupContext#find() seem to be ignored, so
I've used the setter instead: `finder.variants = [ variant ]`.

I've also added some more test cases for variants. Hopefully this
time passing tests will mean it actually works.
2014-03-09 08:47:17 +01:00
David Heinemeier Hansson
b5fdeaac55 Merge pull request #13470 from strzalek/variants-all-any
Add any/all support for variants
2013-12-31 09:57:09 -08:00
Andrew White
436ed51711 Fix Encoding::CompatibilityError when public path is UTF-8
In #5337 we forced the path encoding to ASCII-8BIT to prevent static
file handling from blowing up before an application has had chance to
deal with possibly invalid urls. However this has a negative side
effect of making it an incompatible encoding if the application's
public path has UTF-8 characters in it.

To work around the problem we check to see if the path has a valid
encoding once it has been unescaped. If it is not valid then we can
return early since it will not match any file anyway.

Fixes #13518
2013-12-29 18:38:53 +00:00
Łukasz Strzałkowski
a288cc1e01 Add any/all support for variants
Like `format.any`, you can do the same with variants.

It works for both inline:

    respond_to do |format|
      format.html.any   { render text: "any"   }
      format.html.phone { render text: "phone" }
    end

and block syntax:

    respond_to do |format|
      format.html do |variant|
        variant.any(:tablet, :phablet){ render text: "any" }
        variant.phone { render text: "phone" }
      end
    end
2013-12-26 20:36:17 +01:00
Łukasz Strzałkowski
edacdbfaf9 Inline variants syntax
In most cases, when setting variant specific code, you're not sharing any code
within format.

Inline syntax can vastly simplify defining variants in those situations:

  respond_to do |format|
    format.js { render "trash" }
    format.html do |variant|
      variant.phone { redirect_to progress_path }
      variant.none  { render "trash" }
    end
  end

Becomes:

  respond_to do |format|
    format.js         { render "trash" }
    format.html.phone { redirect_to progress_path }
    format.html.none  { render "trash" }
  end
2013-12-10 11:55:43 +01:00
David Heinemeier Hansson
99975e742e Variants can be declared without a block to signify their presence in the controller 2013-12-07 16:32:38 -08:00
Łukasz Strzałkowski
2d3a6a0cb8 Action Pack Variants
By default, variants in the templates will be picked up if a variant is set
and there's a match. The format will be:

  app/views/projects/show.html.erb
  app/views/projects/show.html+tablet.erb
  app/views/projects/show.html+phone.erb

If request.variant = :tablet is set, we'll automatically be rendering the
html+tablet template.

In the controller, we can also tailer to the variants with this syntax:

  class ProjectsController < ActionController::Base
    def show
      respond_to do |format|
        format.html do |html|
          @stars = @project.stars

          html.tablet { @notifications = @project.notifications }
          html.phone  { @chat_heads    = @project.chat_heads }
        end

        format.js
        format.atom
      end
    end
  end

The variant itself is nil by default, but can be set in before filters, like
so:

  class ApplicationController < ActionController::Base
    before_action do
      if request.user_agent =~ /iPad/
        request.variant = :tablet
      end
    end
  end

This is modeled loosely on custom mime types, but it's specifically not
intended to be used together. If you're going to make a custom mime type,
you don't need a variant. Variants are for variations on a single mime
types.
2013-12-04 00:13:16 +01:00
Angelo capilleri
43962d6ec5 Fix header Content-Type: #<Mime::NullType:...> in localized template
This PR fixes #13064 regression bug introduced by the #8085

Now in _process_format when the format is a Mime::NullType nothing is written in self.content_type.
In this way the method Response#assign_default_content_type_and_charset can
write the the default mime_type.
2013-12-03 07:46:39 +01:00
BlueHotDog
8642c2aadc Fixing repond_with working directly on the options hash
This fixes an issue where the respond_with worked directly with the given
options hash, so that if a user relied on it after calling respond_with,
the hash wouldn't be the same.

Fixes #12029
2013-10-09 12:36:26 +03:00
claudiob
6aa641f63e Remove HelperyTestHelper not used in any test
HelperyTestHelper was introduced in 66ef922 by @josevalim
to pair with HelperyTestController. This test controller was
later removed in e10a253 by @strzalek, leaving HelperyTestHelper unused
2013-09-14 10:40:28 -07:00
claudiob
61d2391352 Remove helper fixtures not used in any test
The fixture for module AbcHelper defines three functions bare_a,
bare_b and bare_c, but only bare_a is used in the code that tests
helper functions.
2013-09-09 14:19:09 -07:00
Łukasz Strzałkowski
e10a25310f Move abstract's controller tests to AV
The ones that were actually testing AV functionality and should belong in there
2013-08-25 11:40:11 +02:00
Łukasz Strzałkowski
c9ef9c1442 Move remaining layouts tests to AV 2013-08-25 11:39:14 +02:00
Łukasz Strzałkowski
1538395d4c Remove unused fixtures and models from AP tests 2013-08-25 11:39:14 +02:00
Łukasz Strzałkowski
1b446d06dd Move view_paths from AP to AV 2013-08-25 11:39:07 +02:00
Piotr Niełacny
e0438b1c07 Show real LoadError on helpers require
When helper try to require missing file rails will throw exception about
missing helper.

  # app/helpers/my_helper.rb

  require 'missing'

  module MyHelper
  end

And when we try do load helper

  class ApplicationController
    helper :my
  end

Rails will throw exception. This is wrong because there is a helper
file.

  Missing helper file helpers/my_helper.rb

Now when helper try to require non-existed file rails will throw proper
exception.

  No such file to load -- missing
2013-07-10 11:26:43 +02:00
Łukasz Strzałkowski
3fbc89a86b Remove digestor fixtures from AP
They were moved to actionview/ and are not used in actionpack
2013-06-20 17:23:16 +02:00
Piotr Sarnacki
f12109448b Remove unneeded test fixtures in AV 2013-06-20 17:23:16 +02:00
Piotr Sarnacki
5e5bf31b4a Remove unneeded files 2013-06-20 17:23:16 +02:00
Bryan Ricker
3c516c4b52 Allow numbers in partial name for digesting
Add failing test for template with number at the end

Use \w for RENDER_DEPENDENCY regex

Spacing

Add CHANGELOG entry
2013-05-06 18:30:29 -07:00
Aaron Patterson
fd890f6aea Merge pull request #9857 from yyyc514/bad_params_should_400
failure to parse params should trigger a 400 Bad Request
2013-04-30 17:38:56 -07:00
Carlos Antonio da Silva
f5644b0cd6 Fix typo in view name
Introduced in 2c22376fe04b89e8f34620139720b85a85ce3428
2013-04-03 21:02:26 -03:00
Steve Klabnik
c9a92a247d Getting rid of a few other vestiges of rails.png.
We don't actually need a rails.png in the AP fixtures, the tests
that use it don't actually try to load the file.

We also don't need to get rid of it with the dummy reset either.

Finally, it's not needed in the sample application that's included
with the Rails Guides.
2013-04-02 17:44:46 -07:00
Josh Goebel
ea2336b9e2 failure to parse params should trigger a 400 Bad Request 2013-03-21 14:23:46 -04:00
Teo Hui Ming
b307210d49 UTF-8 encode all keys and values in nested params hash. 2013-03-15 09:17:03 +08:00
grosser
149e3cd376 fix respond_to without blocks not working if one of the blocks is all 2013-02-24 11:47:20 -05:00
Yves Senn
cce94e7232 partials inside directory work with assert_template
previously when a partial was placed inside a directory
(eg. '/dir/_partial'), `assert_template` did not replace
the '_' prefix when looking through rendered tempaltes,
which resulted in an error.

I modified it to replace both, the leading '_' and the last '_'
after a '/'.
2013-02-04 14:46:50 +01:00
virusman
9047ca019a Added AR integration tests for form helpers 2013-01-21 17:09:12 +04:00
Carlos Antonio da Silva
c67005f221 Do not generate local vars for partials without object or collection
Previously rendering a partial without giving :object or :collection
would generate a local variable with the partial name by default.

This was noticed due to warnings in Ruby 2.0 of not used variables,
which turned out to be the generation of not used variables inside
partials that do not contain objects related to them.
2013-01-08 09:15:20 -02:00
Brian Alexander
749a745264 Digestor explicit dependency should not contain trailing whitespace
test for rails/rails#8586
2012-12-21 18:00:51 -07:00
Drew Ulmer
7fb8c67047 Add explicit opt-out for fragment cache digesting
This add support for sending an explicit opt-out of the "Russian-doll"
cache digest feature on a case-by-case basis. This is useful when cache-
expiration needs to be performed manually and it would be otherwise
difficult to know the exact name of a digested cache key.

More information: https://github.com/rails/cache_digests/pull/16
2012-11-25 22:10:44 -06:00
Andy Shipman
2938ef7a65 Allow for deep directory path for view templates. 2012-10-11 17:36:58 +01:00
Yves Senn
ed9567401d recognizes when a partial was rendered twice. Closes #3675 2012-10-11 08:46:49 +02:00
Hugo Roque
19dff78d02 assert_template no more passing with what ever string that matches.
Given Im rendering an template `/layout/hello.html.erb`, assert_template was
passing with any string that matches. This behavior allowed false passing like:

	assert_template "layout"
	assert_template "out/hello"

Now the passing possibilities are:

	assert_template "layout/hello"
	assert_template "hello"

fixing assert_template bug when template matches expected, but not ends with

Cherry Pick Merge: Fixes issue #3849 assert_template false positive

taking redundant test off

prevening incorrect assert_template when rendering with repeated names in path

updating CHANGELOG with bugfix: assert_template false passing
2012-09-29 23:31:49 -03:00
David Heinemeier Hansson
c49d959e9d Merge pull request #7251 from rails/integrate-strong_parameters
Integrate strong_parameters in Rails 4
2012-09-18 12:33:13 -07:00
Guillermo Iguaran
de1060f4e0 Rename .rb template handler to .ruby to avoid conflicts with mustache views classes 2012-09-17 10:07:08 -05:00
Guillermo Iguaran
8c4de0e67f Remove integration between attr_accessible/protected and AC::Metal::ParamsWrapper 2012-09-16 23:58:20 -05:00
Arun Agrawal
84a52c6c7a warning removed.
1. Unused variable
2. possibly useless use of a variable in 
void context
2012-09-12 09:28:14 +05:30
Guillermo Iguaran
ab7ae689e9 Add .rb template handler
This handler simply allows arbitrary Ruby code as a template
2012-09-11 01:17:43 -05:00
Christos Zisopoulos
17f2499f04 Digestor can now parse old style hash syntax for render 2012-08-30 13:13:47 +02:00