aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
Commit message (Collapse)AuthorAgeFilesLines
* Use rack.session_options instead of directly change envJuanito Fatas2015-09-161-1/+1
|
* fewer direct env manipulationsAaron Patterson2015-09-151-1/+1
| | | | this commit removes some direct access to `env`.
* allocate request objects with the env hash, set routes on the requestAaron Patterson2015-09-152-9/+6
| | | | | This commit is to abstract the code away from the env hash. It no longer needs to have the routes key hard coded.
* only "normalize" onceAaron Patterson2015-09-141-1/+1
|
* create a new renderer instance on calls to `for`Aaron Patterson2015-09-141-39/+46
| | | | | | | | | | | | This changes the renderer class to store the controller and defaults as an instance variable rather than allocating a new class. You can create a new renderer with an new env by calling `Renderer#new` or use new defaults by calling `Renderer#with_defaults` and saving the return value somewhere. Also I want to keep the `env` private since I would like to change the keys in the future. This commit only translates particular keys that the user requested.
* eagerly allocate the renderer objectAaron Patterson2015-09-142-9/+6
| | | | | this means the reader doesn't need to lock, but does have the added cost of a new object created for every controller
* initialize `@renderer` to avoid ivar warningsAaron Patterson2015-09-141-1/+8
|
* add a lock when allocating the rendererAaron Patterson2015-09-141-1/+5
| | | | | The controller class is shared among threads, so we need to lock when allocating the Renderer.
* Merge pull request #21584 from claudiob/remove-hawd-docClaudio B.2015-09-101-3/+2
|\ | | | | Remove wrong doc line about AC::Parameters
| * Remove wrong doc line about AC::Parametersclaudiob2015-09-101-3/+2
| | | | | | | | | | AC::Parameters does not inherit from HashWithIndifferentAccess since #20868 by @sikachu
* | Handle Content-Types that are not :json, :xml, or :url_encoded_formeileencodes2015-09-091-2/+5
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In c546a2b this was changed to mimic how the browser behaves in a real situation but left out types that were registered. When this was changed it didn't take `text/plain` or `text/html` content types into account. This is a problem if you're manipulating the `Content-Type` headers in your controller tests, and expect a certain result. The reason I changed this to use `to_sym` is because if the `Content-Type` is not registered then the symbol will not exist. If it's one of the special types we handle that specifically (:json, :xml, or :url_encoded_form). If it's any registered type we handle it by setting the `path_parameters` and then the `request_parameters`. If the `to_sym` returns nil an error will be thrown. If the controller test sets a `Content-Type` on the request that `Content-Type` should remain in the header and pass along the filename. For example: If a test sets a content type on a post ``` @request.headers['CONTENT_TYPE'] = 'text/plain' post :create, params: { name: 'foo.txt' } ``` Then `foo.txt` should be in the `request_parameters` and params related to the path should be in the `path_parameters` and the `Content-Type` header should match the one set in the `@request`. When c546a2b was committed `text/plain` and `text/html` types were throwing a "Unknown Content-Type" error which is misleading and incorrect. Note: this does not affect how this is handled in the browser, just how the controller tests handle setting `Content-Type`.
* push content_type assigment in to metalAaron Patterson2015-09-082-5/+7
| | | | | everything above metal really doesn't care about setting the content type, so lets rearrange these methods to be in metal.
* avoid useless string allocationsAaron Patterson2015-09-081-1/+1
| | | | | | | _set_content_type only does something when there is a request object, otherwise the return value of _get_content_type is always ignored. This commit moves everything to the module that has access to the request object so we'll never to_s unless there is a reason
* use accessors instead of manipulating the hashAaron Patterson2015-09-081-2/+2
| | | | | in the future I would like to make the header hash read only (or at least remove guarantees that mutations will do anything).
* stop using deprecated Abstract::ID classAaron Patterson2015-09-041-1/+1
|
* stop inheriting from Rack::RequestAaron Patterson2015-09-041-4/+4
| | | | | | Just include the modules necessary in the Request object to implement the things we need. This should make it easier to build delegate request objects because the API is smaller
* typo "description not clear corrected with proper description and ↵kishore-mohan2015-09-021-2/+2
| | | | action_controller_overview file Rails' -> Rails" [ci skip]
* Fix bug where cookies mutated by request were not persistedeileencodes2015-09-011-0/+1
| | | | | | | | | | | | | | | With changes made in 8363b8 and ae29142 cookies that are mutated on the request like `cookies.signed = x` were not retained in subsequent tests, breaking cookie authentiation in controller tests. The test added demonstrates the issue. The reason we need to select from non-deleted cookies is because without checking the `@delete_cookies` the `cookie_jar` `@cookies` will send the wrong cookies to be updated. The code must check for `@deleted_cookies` before sending an `#update` with the requests cookie_jar cookies. This follows how the cookie_jar cookies from the request were updated before these changes.
* Merge pull request #21298 from rodzyn/remove_dead_codeRafael Mendonça França2015-09-011-4/+0
|\ | | | | Remove dead code
| * Remove dead codeMarcin Olichwirowicz2015-08-191-4/+0
| |
* | add a method for getting the http auth saltAaron Patterson2015-08-291-2/+2
| |
* | env to get_header conversionAaron Patterson2015-08-291-1/+1
| |
* | fixes example for consistency [ci skip]Xavier Noria2015-08-291-3/+3
| |
* | swaps words [ci skip]Xavier Noria2015-08-291-1/+1
| |
* | revamps the docs of strong params require [ci skip]Xavier Noria2015-08-291-9/+40
| | | | | | | | References #19565.
* | revises 877e42eXavier Noria2015-08-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * A string in the example lacked quotes. * The tests asserted stuff about :last_name, whereas test params do not have that key. * But, the first one passed, why? After hitting my head against the wall and doing some obscure rituals realized the new #require had an important typo, wanted to iterate over the array argument (key), but it ran over its own hash keys (method #keys). * Modified the test to prevent the same typo to happen again. * The second test assigned to an unused variable safe_params that has been therefore removed. * Grammar of the second test description. * Since I was on it, reworded both test descriptions.
* | [Feature] params.require requires array of paramsGaurish Sharma2015-08-281-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR adds ability to accept arrays which allows you to require multiple values in one method. so instead of this: ```ruby params.require(:person).require(:first_name) params.require(:person).require(:last_name) ``` Here it will be one line for each params, so say if I require 10params, it will be 10lines of repeated code which is not dry. So I have added new method which does this in one line: ```ruby params.require(:person).require([:first_name, :last_name]) ``` Comments welcome
* | Revert "this always sets :public to false, so just do that"Aaron Patterson2015-08-271-1/+1
| | | | | | | | | | | | This reverts commit cae2b5bb59212961c4a35c939381ebece48d1177. I am an idiot.
* | this always sets :public to false, so just do thatAaron Patterson2015-08-271-1/+1
| |
* | Merge pull request #21384 from ↵Yves Senn2015-08-271-2/+2
|\ \ | | | | | | | | | | | | jeremyf/updating-ActionController-TestSession-to-behave-as-a-hash-with-indifferent Updating TestSession to access with indifference
| * | Updating TestSession to access with indifferenceJeremy Friesen2015-08-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following Rails code failed (with a `KeyError` exception) under test: ```ruby class ApplicationController < ActionController::Base def user_strategy # At this point: # ```ruby # session == { # "user_strategy"=>"email", # "user_identifying_value"=>"hello@world.com" # } # ``` if session.key?(:user_strategy) session.fetch(:user_strategy) end end end ``` When I checked the session's keys (`session.keys`), I got an array of strings. If I accessed `session[:user_strategy]` I got the expected `'email'` value. However if I used `session.fetch(:user_strategy)` I got a `KeyError` exception. This appears to be a Rails 4.2.4 regression (as the code works under Rails 4.2.3). Closes #21383
* | | only call self.content_type= when there is a responseAaron Patterson2015-08-262-3/+6
| | | | | | | | | | | | | | | Apparently the AbstractController (whatever "abstract" means) is expected to work without a request and response.
* | | Pull `plain` content type handling up to `render`Aaron Patterson2015-08-261-6/+2
| | | | | | | | | | | | | | | `render` is the only possible source for the `plain` option. Pulling the conditional up to the `render` method removes far away conditionals
* | | stop passing the options hash to `_process_format`Aaron Patterson2015-08-261-2/+2
| | | | | | | | | | | | | | | | | | We don't need to pass the full hash just to pull one value out. It's better to just pass the value that the method needs to know about so that we can abstract it away from "options"
* | | remove RackDelegation moduleAaron Patterson2015-08-2610-66/+16
| | | | | | | | | | | | | | | | | | Since all controller instances are required to have a request and response object, RackDelegation is no longer needed (we always have to delegate to the response)
* | | remove useless methodAaron Patterson2015-08-261-5/+0
| | | | | | | | | | | | | | | the subclass sets the body on the response object, so we don't need the superclass doing it too
* | | include ActionView::Rendering in the minimal controllerAaron Patterson2015-08-261-1/+1
| | | | | | | | | | | | without this module, the content type is not set correctly
* | | `headers` should delegate to the response objectAaron Patterson2015-08-261-1/+2
| | |
* | | remove useless status setAaron Patterson2015-08-261-2/+0
| | | | | | | | | | | | | | | | | | Now that `Controller#status=` just delegates to the response object, we don't need to set the response on the controller and the response. We can just set it in one place.
* | | remove useless conditionalAaron Patterson2015-08-261-1/+1
| | | | | | | | | | | | we always have a response object, so there is no reason to test it
* | | remove ivars from the "protected" listAaron Patterson2015-08-261-1/+1
| | | | | | | | | | | | these ivars don't exist anymore, so we can remove them from the list
* | | use the content_type method on the request objectAaron Patterson2015-08-261-1/+1
| | | | | | | | | | | | | | | since the controller always has a request on it, we can just ask the request for the content type.
* | | ask the response for the statusAaron Patterson2015-08-261-3/+2
| | | | | | | | | | | | | | | | | | The controller instance always has an instance of a response object. We should store the status code on the response object so that it's only store in one place.
* | | remove useless conditionalAaron Patterson2015-08-261-1/+1
| | | | | | | | | | | | | | | We always have a response object in controller instances, so we can remove this conditional
* | | remove useless conditionalAaron Patterson2015-08-261-1/+1
|/ / | | | | | | | | controller instances always have a response object, so we don't need to test to see if there is one, just always call to_a on the response.
* | provide a request and response to all controllersAaron Patterson2015-08-253-30/+29
| | | | | | | | | | | | | | | | | | | | Controllers should always have a request and response when responding. Since we make this The Rule(tm), then controllers don't need to be somewhere in limbo between "asking a response object for a rack response" or "I, myself contain a rack response". This duality leads to conditionals spread through the codebase that we can delete: * https://github.com/rails/rails/blob/85a78d9358aa728298cd020cdc842b55c16f9549/actionpack/lib/action_controller/metal.rb#L221-L223
* | :snip: whitespaceAaron Patterson2015-08-251-2/+2
| |
* | move response allocation to the class levelAaron Patterson2015-08-252-8/+22
| | | | | | | | | | | | we don't need an instance to figure out what type of response to allocate. Later we'll pull this up the stack and pass the response object down
* | adding a direct dispatch method to controller classesAaron Patterson2015-08-251-0/+10
| | | | | | | | This saves a lambda and request allocation on each request.
* | always dispatch to controllers the same wayAaron Patterson2015-08-251-0/+1
| | | | | | | | | | controllers should always go through the `action` class method so that their middleware is respected.