Commit Graph

84 Commits

Author SHA1 Message Date
Ł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
Ł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
8e3413d410 Create AbstractController::Rendering interface
This interface should be use when implementing renderers.
2013-08-25 11:39:09 +02:00
Łukasz Strzałkowski
8c2c95e5d2 Fix AP test suite after moving stuff to AV 2013-08-25 11:39:08 +02:00
Yves Senn
3af7b16c11 add test-case to verify error.path when a helper was not found.
This verifies the code added with:
99c9d18601
2013-07-12 15:40:47 +02:00
Yves Senn
5bee14f3a4 move MissingHelperError out of the ClassMethods module. 2013-07-12 15:34:29 +02:00
Marc Schütz
90e420e406 Remove accidentally committed vi .swp file. 2013-07-10 16:06:40 +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
printercu
14c196e5a3 Avoid leak into controller's action_methods 2013-04-18 20:03:31 +04:00
Anupam Choudhury
d18e8b1a38 Refactored to remove unused variable 2013-03-28 15:58:03 +05:30
Rafael Mendonça França
e7438501d6 Merge pull request #8458 from lucisferre/improve-layout-override-fallback-behavior
Provides standard layout lookup behavior for method and proc cases

Conflicts:
	actionpack/CHANGELOG.md
2013-03-27 16:09:12 -03:00
Chris Nicola
ef27bba63d Provides standard layout lookup behavior for method and proc cases
When setting the layout either by referencing a method or supplying a
Proc there is no way to fall back to the default lookup behavior if
desired. This patch allows fallback to the layout lookup behavior when
returning nil from the proc or method.
2013-03-27 10:59:50 -07:00
Prathamesh Sonpatki
ba7c9d76af Changed 'args' to 'arguments' in test description 2013-03-24 02:27:43 +05:30
Carlos Antonio da Silva
57b65ef416 Fix setting expected value in translation tests
It was being set to nil instead due to the wrong assignment.
2013-01-21 09:29:03 -02:00
Jens Bissinger
4685d75736 Removed ActionController::Base dependency from abstract controller translation tests. 2013-01-20 15:53:43 +01:00
Jens Bissinger
1de60c54d3 Test abstract controller's localize method. 2013-01-20 15:44:03 +01:00
Akira Matsuda
70ae89c321 Remove unnecessary begin..rescue..end, use only rescue 2013-01-06 15:41:14 +09:00
Francesco Rodriguez
1b97d41e52 add tests to aliased _filter callbacks 2012-12-07 15:29:51 -05:00
Francesco Rodriguez
5fb94ec044 use _action instead of _filter callbacks 2012-12-07 15:24:56 -05:00
David Heinemeier Hansson
9d62e04838 Rename all action callbacks from *_filter to *_action 2012-12-07 18:54:44 +01:00
Sergey Pchelincev
1b5298e805 add lazy look up in abstract controller's translate method 2012-07-18 10:33:14 +03:00
Aaron Patterson
cd4a0a3332 we raise a subclass of LoadError, so rescue that 2012-06-14 10:40:23 -07:00
José Valim
dd0275e463 Add a test case for layout nil. 2012-03-28 23:06:52 +04:00
Luke Gruber
08c4d8eac3 use consistent explicit module inclusion
aid ease of understanding and readability for tests
2012-03-16 21:54:25 -04:00
Luke Gruber
aca6937760 allow zero-arity proc for AbstrController::layout
proc without parameters can now be given to
AbstractController::layout
2012-03-15 16:40:23 -04:00
Santiago Pastorino
687db9f86d Add missing require 2012-03-10 19:15:29 -02:00
Santiago Pastorino
4751a699c9 AbstractController.action_methods should return a Set 2012-03-10 18:37:30 -02:00
Alexey Vakhov
b27c29ef4a Fix layout lookup for anonymous controller 2012-02-28 14:42:57 +04:00
Aaron Patterson
fd918fe5ed AP tests should inherit from AS::TestCase 2012-01-05 17:05:44 -08:00
José Valim
cae1768c6a Remove deprecated layout lookup. 2011-12-20 14:44:48 +01:00
José Valim
5ad5215211 Deprecate implicit layout lookup in favor of inheriting the _layout config. 2011-12-09 07:20:55 +01:00
Prem Sichanugrist
18ceed201b Allow layout fallback when using layout method
Rails will now use your default layout (such as "layouts/application") when you specify a layout with `:only` and `:except` condition, and those conditions fail.

For example, consider this snippet:

    class CarsController
      layout 'single_car', :only => :show
    end

Rails will use 'layouts/single_car' when a request comes in `:show` action, and use 'layouts/application' (or 'layouts/cars', if exists) when a request comes in for any other actions.
2011-12-06 21:16:29 -05:00
José Valim
43d27e9105 Deprecate passing the template handler in the template name.
For example, calling hello.erb is now deprecated. Since Rails 3.0
passing the handler had no effect whatsover. This commit simply
deprecates such cases so we can clean up the code in later releases.
2011-09-22 15:37:38 +02:00
Santiago Pastorino
adef9764ae Merge pull request #1644 from smartinez87/warns
Remove unused variable causing warning in 1.9.3
2011-06-10 18:35:14 -07:00
Sebastian Martinez
c4ddc6f693 Remove unused variable causing warning in 1.9.3 2011-06-10 21:10:06 -03:00
Neeraj Singh
277eb05733 class WithSymbolReturningString is not used anywhere in the test.
Secondly it seemed from the method that the intent was to test a case
where layout was declared in a symbol and the method named mention in
layout returns nil.

That case is already covered with class     class WithSymbolReturningNil .

Also the case of SymbolReturningString is covered with the class
WithSymbol.
2011-06-08 20:22:13 -04:00
Neeraj Singh
7fff2f9fe3 Make test meaningful
If before_filter list was being called mistakenly then
the test should fail. However test will not fail because
second filter is assigning new values to @list. To truly
test that first before_filter is not called when it should
not be called then @list should not assigned value unconditionally.

This patch will make the test fail if first filter is called.
2011-06-08 10:51:10 -04:00
José Valim
47ac896936 Merge pull request #1549 from neerajdotname/rename_to_method_for_action
test name should reflect the name of the method
2011-06-08 00:41:55 -07:00
Neeraj Singh
8f3c9e87d9 test name should reflect the name of the method
that is actually being called
2011-06-08 03:17:27 -04:00
Neeraj Singh
cbfdd0df33 remove unused class from test 2011-06-08 02:54:19 -04:00
Aaron Patterson
36d6678690 removing usesless variable assignments 2011-01-18 15:52:56 -08:00
Nick Sutterer
db24701abe process_action accepts multiple args, even with Callbacks. 2010-12-29 16:37:10 -08:00
artemave
ddd85ef9c6 #948 template_inheritance 2010-12-26 22:32:15 -08:00
José Valim
14f9904e0f Avoid (@_var ||= nil) pattern by using initialize methods and ensuring everyone calls super as expected. 2010-09-29 11:18:31 +02:00
Emilio Tagua
0c08d8bd75 Fix more warnings by defining variables and using instance_variable_defined? instead instance_variable_get. 2010-09-28 18:25:52 -03:00
José Valim
66ef92272c Add clear_helpers as a way to clean up all helpers added to this controller, maintaing just the helper with the same name as the controller. 2010-08-26 16:07:54 -03:00
Santiago Pastorino
b451de0d6d Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:12:33 -03:00
Piotr Sarnacki
84f0a0bc30 Reload action_methods in AbstractController after defining new method.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-04 14:44:34 -03:00
Jeremy Kemper
81f398b804 Fix setting helpers_path to a string or pathname 2010-07-07 12:03:08 -07:00
José Valim
02399a1184 Ensure overwritten callbacks conditions in controllers work [#4761 state:resolved] [#3913 state:resolved] 2010-06-22 07:57:45 +02:00