Commit Graph

79 Commits

Author SHA1 Message Date
Joel Hawksley
136b814144 Include layout when rendering objects from controllers
In https://github.com/rails/rails/pull/37919, support
for rendering objects that respond_to render_in in
controllers was added. However, the implementation
did not support layouts.

This change updates the implementation from #37919
to more closely match the rest of the
ActionView::Template classes, enabling the use of layouts.

Co-authored-by: Felipe Sateler <fsateler@gmail.com>
2020-10-14 11:49:45 -06:00
Joel Hawksley
c82a9193df
Document view components support (#38656) 2020-03-13 23:52:49 +01:00
Joel Hawksley
05a2a939f0 Remove validations from example components
We're moving away from using validations in our
component framework, and feel that it's better
to avoid prescribing their usage in these
example classes, which exist to serve as example
objects that are compatible with the render_in
API.
2020-02-20 09:48:25 -07:00
Joel Hawksley
20a83f52d7
Render objects that respond_to render_in in controllers
In https://github.com/rails/rails/pull/36388,
we supported passing objects that `respond_to` `render_in`
to `render`, but _only_ in views.

This change does the same for controllers, as Rails
generally gives the expectation that `render` behaves
the same in both contexts.

Co-authored-by: Aaron Patterson <tenderlove@github.com>
2019-12-09 16:43:18 -07:00
Joel Hawksley
4fbb1e9f5b
Add test case 2019-12-09 15:37:27 -07:00
Kir Shatrov
dfcc766163 Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
David Heinemeier Hansson
75fa8dd309 Use recyclable cache keys (#29092) 2017-05-18 18:12:32 +02:00
Akira Matsuda
9360b6be63 class Foo < Struct.new(:x) creates an extra unneeded anonymous class
because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
2017-01-13 15:13:47 +09:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Thiago Pradi
90c06717bc Removing unused fake models 2014-09-07 22:51:14 -03:00
Godfrey Chan
ff1192fea4 Eliminate JSON.{parse,load,generate,dump} and def to_json
JSON.{dump,generate} offered by the JSON gem is not compatiable with
Rails at the moment and can cause a lot of subtle bugs when passed
certain data structures. This changed all direct usage of the JSON gem
in internal Rails code to always go through AS::JSON.{decode,encode}.

We also shouldn't be implementing `to_json` most of the time, and
these occurances are replaced with an equivilent `as_json`
implementation to avoid problems down the road.

See [1] for all the juicy details.

[1]: intridea/multi_json#138 (comment)
2013-11-05 22:26:45 -08:00
Thiago Pradi
25b0076eba Removing unused fake models from actionpack tests 2013-10-16 00:51:57 -03:00
Łukasz Strzałkowski
1538395d4c Remove unused fixtures and models from AP tests 2013-08-25 11:39:14 +02:00
Carlos Galdino
1ce4b5b33d Add HTML5 input[type="color"] helper 2012-05-21 17:23:48 -03:00
Thiago Pradi
c6e6598d96 Removing old Controller test 2012-02-12 21:05:30 -02:00
Thiago Pradi
c0a1a86693 Cleaning Route generation tests 2012-02-12 03:09:03 -02:00
Prem Sichanugrist
3def1c8edb Fix override API response bug in respond_with
Default responder was only using the given respond block when user
requested for HTML format, or JSON/XML format with valid resource. This
fix the responder so that it will use the given block regardless of the
validity of the resource. Note that in this case you'll have to check
for object's validity by yourself in the controller.

Fixes #4796
2012-02-03 14:15:51 -05:00
Arun Agrawal
7276fc63be 'with_kcode' removed.
Testing Sandbox removed.
2011-12-21 15:39:50 +05:30
José Valim
fd86a1b6b0 Rely on a public contract between railties instead of accessing railtie methods directly. 2011-11-23 19:06:45 +00:00
Mike Gehard
6c43532cb6 Silence Ruby warnings about uninitialized instance variable. 2011-09-09 15:48:43 -06:00
Sam Pohlenz
237f87089c Use real hash model in nested fields_for with hash model test 2011-06-22 10:54:45 +09:30
José Valim
31906eecdf Fix tests on 1.9.2. 2010-11-28 12:48:50 +01:00
Neeraj Singh
fa2a5ae033 If a user wants json output then try best to render json output. In such cases prefer kind_of(String) over respond_to?(to_str)
[#5841 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-24 22:08:36 +01:00
Neeraj Singh
fbaf3a23d9 fields_for should treat ActiveRecord::Relation as an array
[#5795 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-11 17:14:47 +01:00
Aaron Patterson
5769636663 fixing a few test warnings 2010-10-04 19:32:49 -07:00
Aaron Patterson
18a7b767e8 moving fake model to the correct file 2010-10-03 14:40:06 -07:00
Carlos Antonio da Silva
8a16485a96 Review most of the form_for deprecated tests, missing tests with index like [] 2010-09-26 02:13:45 +08:00
Piotr Sarnacki
6f3119d3c2 Remove namespace for isolated namespaced models in forms 2010-09-03 22:59:15 +02:00
Piotr Sarnacki
0c1cd15470 to_param shoul return a string 2010-09-03 22:59:08 +02:00
David Chelimsky
91125f9927 move FixtureResolver to a file that is accessible outside Rails' own tests
[#4522 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-02 22:45:54 +02:00
José Valim
f28d856cec Improve performance of the rendering stack by freezing formats as a sign that they shouldn't be further modified. 2010-03-19 17:20:20 +01:00
José Valim
191a2f78b1 Sending the partial as info is no longer required. 2010-03-18 12:12:07 +01:00
José Valim
8dd731bc50 Move more normalization up to the lookup context, so it does not have to repeat in every resolver. 2010-03-16 02:09:16 +01:00
José Valim
839362fa07 Make all AP tests pass for Ruby 1.9.1. 2010-03-12 11:50:45 +01:00
José Valim
6c027443b0 Add tests for lookup context. 2010-03-11 13:23:14 +01:00
José Valim
00d6271d2b Clean up the API required from ActionView::Template. 2010-03-09 13:12:11 +01:00
José Valim
6e0443fd43 First take on ViewPaths clean up. 2010-03-07 12:49:27 +01:00
José Valim
250c809246 Require persisted? in ActiveModel::Lint and remove new_record? and destroyed? methods. ActionPack does not care if the resource is new or if it was destroyed, it cares only if it's persisted somewhere or not. 2010-02-21 11:12:14 +01:00
snusnu
f81c6bc040 AMo #key is now #to_key and CI is probably happy
Obviously #key is a too common name to be included
in the AMo interface, #to_key fits better and also
relates nicely to #to_param. Thx wycats, koz and
josevalim for the suggestion.

AR's #to_key implementation now takes customized
primary keys into account and there's a testcase
for that too.

The #to_param AMo lint makes no assumptions on how
the method behaves in the presence of composite
primary keys. It leaves the decision wether to
provide a default, or to raise and thus signal to
the user that implementing this method will need
his special attention, up to the implementers. All
AMo cares about is that #to_param is implemented
and returns nil in case of a new_record?.

The default CompliantObject used in lint_test
provides a naive default implementation that just
joins all key attributes with '-'.

The #to_key default implementation in lint_test's
CompliantObject now returns [id] instead of [1].
This was previously causing the (wrong) tests I
added for AR's #to_key implementation to pass. The
#to_key tests added with this patch should be
better.

The CI failure was caused by my lack of knowledge
about the test:isolated task. The tests for the
record_identifier code in action_controller are
using fake non AR models and I forgot to stub the
#to_key method over there. This issue didn't come
up when running the test task, only test:isolated
revealed it. This patch fixes that.

All tests pass isolated or not, well, apart from
one previously unpended test in action_controller
that is unrelated to my patch.
2010-02-20 20:17:29 -08:00
snusnu
9acd686753 Adds #key and #to_param to the AMo interface
This commit introduces two new methods that every
AMo compliant object must implement. Below are the
default implementations along with the implied
interface contract.

  # Returns an Enumerable of all (primary) key
  # attributes or nil if new_record? is true
  def key
    new_record? ? nil : [1]
  end

  # Returns a string representing the object's key
  # suitable for use in URLs, or nil if new_record?
  # is true
  def to_param
    key ? key.first.to_s : nil
  end

1) The #key method

Previously rails' record_identifier code, which is
used in the #dom_id helper, relied on calling #id
on the record to provide a reasonable DOM id. Now
with rails3 being all ORM agnostic, it's not safe
anymore to assume that every record ever will have
an #id as its primary key attribute.

Having a #key method available on every AMo object
means that #dom_id can be implemented using

  record.to_model.key # instead of
  record.id

Using this we're able to take composite primary
keys into account (e.g. available in datamapper)
by implementing #dom_id using a newly added

  record_key_for_dom_id(record)

method. The user can overwrite this method to
provide customized versions of the object's key
used in #dom_id.

Also, dealing with more complex keys that can
contain arbitrary strings, means that we need to
make sure that we only provide DOM ids that are
valid according to the spec. For this reason, this
patch sends the key provided through a newly added

  sanitize_dom_id(candidate_id)

method, that makes sure we only produce valid HTML

The reason to not just add #dom_id to the AMo
interface was that it feels like providing a DOM
id should not be a model concern. Adding #dom_id
to the AMo interface would force these concern on
the model, while it's better left to be implemented
in a helper.

Now one could say the same is true for #to_param,
and actually I think that it doesn't really fit
into the model either, but it's used in AR and it's
a main part of integrating into the rails router.

This is different from #dom_id which is only used
in view helpers and can be implemented on top of a
semantically more meaningful method like #key.

2) The #to_param method

Since the rails router relies on #to_param to be
present, AR::Base implements it and returns the
id by default, allowing the user to overwrite the
method if desired.

Now with different ORMs integrating into rails,
every ORM railtie needs to implement it's own
#to_param implementation while already providing
code to be AMo compliant. Since the whole point of
AMo compliance seems to be to integrate any ORM
seamlessly into rails, it seems fair that all we
really need to do as another ORM, is to be AMo
compliant. By including #to_param into the official
interface, we can make sure that this code can be
centralized in the various AMo compliance layers,
and not be added separately by every ORM railtie.

3) All specs pass
2010-02-19 23:31:25 -08:00
José Valim
b1edd09662 Ensure render :text => resource first tries to invoke :to_text on it 2010-02-16 23:26:29 +01:00
José Valim
214b548485 Make check boxes accept :multiple as option so they can handle collections (such as HABTM). 2010-01-14 01:07:03 +01:00
Carsten Gehling
bef968d379 I18n label helper [#745 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-01-02 22:27:02 +01:00
Joshua Peek
7fe19d415a Make recognize try to constantize controller to see if it exists 2009-12-01 22:22:48 -06:00
Joshua Peek
3895e2ccb3 Donate tests I wrote for rackmount rails integration 2009-10-20 09:52:59 -05:00
Joshua Peek
673f73b538 Add define another "stuff" controller to support routing tests 2009-10-10 21:30:50 -05:00
Joshua Peek
7bc5e3bd02 Add define a "stuff" controller in fixtures to support routing tests 2009-10-10 21:30:50 -05:00
Joshua Peek
61411f2aeb Redraw default routes on all internal integration tests. We don't need SimpleRouteCase anymore 2009-10-03 23:18:32 -05:00