Commit Graph

5825 Commits

Author SHA1 Message Date
eileencodes
ec14aad419 Fix route creation when format is a blank string
Commit bff61ba, while reducing allocations, caused a regression when an empty
format is passed to a route.

This can happen in cases where you're using an anchor tag, for example:
`https://example.com/parent/575256966.#child_1032289285`.

Because of this change `format` was getting sent in
`parameterized_parts` when previously it was not included. This resulted
in blank `format`'s being returned as `.` when if there was an extension
included it would be `.extension`. Since there was no extension this
caused incorrect URL's.

The test shows this would result in `/posts/show/1.` instead of
`/posts/show/1` which causes bad urls since the format is not present.
2015-09-02 09:18:46 -04:00
eileencodes
75a121a2c5 Fix bug where cookies mutated by request were not persisted
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.
2015-09-01 08:42:30 -04:00
Rafael Mendonça França
c47c1d206e Merge pull request #19788 from cmdrclueless/actionpack_http_url_ipv6
Fix broken IPv6 addresses handling
2015-09-01 01:32:54 -03:00
akihiro17
2de60a926b Set the content-type to text/html if the options[:html] is true
In this commit, we set the content-type to `text/html` in AbstractController if the `options[:html]` is true so that we don't include ActionView::Rendering into ActionController::Metal to set it properly.

I removed the if `options[:plain]` statement because `AbstractController#rendered_format` returns `Mime::TEXT` by default.
2015-08-29 01:02:43 +09:00
Xavier Noria
cbe7899f9d revises 877e42e
* 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.
2015-08-28 17:15:20 +02:00
Gaurish Sharma
877e42e232 [Feature] params.require requires array of params
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
2015-08-28 18:02:13 +05:30
Yves Senn
6236cc46b9 Merge pull request #21384 from jeremyf/updating-ActionController-TestSession-to-behave-as-a-hash-with-indifferent
Updating TestSession to access with indifference
2015-08-27 14:16:30 +02:00
Aaron Patterson
d47438745e remove RackDelegation module
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)
2015-08-26 11:53:15 -07:00
Aaron Patterson
3cc35bed7a include ActionView::Rendering in the minimal controller
without this module, the content type is not set correctly
2015-08-26 11:53:15 -07:00
Ronak Jangir
8d7bf97798 Removed duplicate requiring minitest/mock as it is already required in method_call_assertions 2015-08-26 19:43:54 +05:30
Jeremy Friesen
0258ef33a5 Updating TestSession to access with indifference
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
2015-08-26 09:08:18 -04:00
Aaron Patterson
51c7ac142d provide a request and response to all controllers
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:

  * 85a78d9358/actionpack/lib/action_controller/metal.rb (L221-L223)
2015-08-25 18:35:44 -07:00
Aaron Patterson
27902c7e96 Fix another rack SPEC violation 2015-08-25 17:22:52 -07:00
Aaron Patterson
7401c4a1e9 rack SPEC doesn't allow first on the body
collect the body and make assert against the collected body
2015-08-25 17:02:07 -07:00
Aaron Patterson
67b2841fbe adding a direct dispatch method to controller classes
This saves a lambda and request allocation on each request.
2015-08-25 16:25:52 -07:00
Kasper Timm Hansen
7ee60d4c5b Merge pull request #21368 from rodzyn/remove_mocha
Get rid of mocha tests in actionpack - part 2
2015-08-25 21:46:30 +02:00
Rafael Mendonça França
578618d8e6 Merge pull request #21366 from amitsuroliya/remove_unused_variable
Remove more unused block arguments
2015-08-25 14:08:17 -03:00
amitkumarsuroliya
8f0073bba1 Remove more unused block arguments 2015-08-25 22:23:23 +05:30
Rafael Mendonça França
e84cc9afe4 Merge pull request #21345 from aditya-kapoor/trim-ap
Trim out least needed controllers from AP test suite
2015-08-25 12:44:34 -03:00
Marcin Olichwirowicz
00234f5619 Get rid of mocha tests - part 2 2015-08-25 09:28:06 +02:00
Rafael Mendonça França
f3e68ec16a Merge pull request #21094 from aditya-kapoor/add-missing-ap-tests
add missing test for action regexp for routing
2015-08-25 03:10:23 -03:00
Anshul Sharma
7b1c783630 Remove unused block arguments 2015-08-25 09:31:12 +05:30
Aaron Patterson
c82248ea86 remove more direct env mutations 2015-08-24 17:07:48 -07:00
Aaron Patterson
7a62cc7d22 remove dead code 💣 2015-08-24 14:11:37 -07:00
Aaron Patterson
74020eb255 use make_set helper method to generate route sets
We should keep the route set generation logic in one place
2015-08-24 13:59:40 -07:00
Aaron Patterson
2237ee0596 subclass and delegate rather than mutating existing objects
If we subclass and augment the superclass, then we don't need to have
setters for particular things on the superclass.
2015-08-24 13:49:52 -07:00
Gaurav Sharma
a50872d51d temp files are no more require
`💅`
2015-08-25 01:36:05 +05:30
Aaron Patterson
337684fa28 use a custom request class to determine the controller class
controller class resolution has been moved to the request object, so we
should override that method instead of relying on the RouteSet to
generate the controller class.
2015-08-24 12:06:41 -07:00
Rafael Mendonça França
9e5ba3c86b Merge pull request #21355 from akihiro17/remove-variables
Remove unused variables
2015-08-24 13:36:10 -03:00
Kasper Timm Hansen
b9825801e2 Merge pull request #21321 from rodzyn/removing_mocha
Get rid of mocha tests in actionpack - part 1
2015-08-24 12:44:01 +02:00
Marcin Olichwirowicz
3a161e65e7 Get rid of mocha tests - part 1 2015-08-24 12:24:07 +02:00
akihiro17
7adef79e14 Remove unused variables 2015-08-24 17:33:19 +09:00
Aditya Kapoor
b393c6af92 Trim out unneeded controllers from AP test suite 2015-08-24 01:02:14 +05:30
Aaron Patterson
5fe141638f use a request object in the session middleware
This commit allows us to use one request object rather than allocating
multiple request objects to deal with the session.
2015-08-22 17:57:45 -07:00
eileencodes
4276b214f8 Refactor to remove controller class from route to request
This refactoring moves the controller class name that was on the route
set to the request. The purpose of this refactoring is for changes we
need to move controller tests to integration tests, mainly being able to
access the controller on the request instead of having to go through
the router.

[Eileen M. Uchitelle & Aaron Patterson]
2015-08-22 09:44:24 -04:00
Aaron Patterson
34fa6658dd pass a request object to the headers object 2015-08-21 11:21:10 -07:00
Aaron Patterson
c6cfcc6124 move header allocation to a helper method
I'm going to change the constructor, so it's easier to do it in one
place.
2015-08-21 11:21:10 -07:00
Andrew White
95cb2e3a8a Merge pull request #21106 from amitsuroliya/fix_routing_test
Remove duplicity in tests
2015-08-21 11:25:38 +01:00
Marcin Olichwirowicz
36e53fca78 Add test for parsing application/vnd.api+json 2015-08-21 09:31:18 +02:00
Aaron Patterson
51211a94bd point at rack master 2015-08-20 13:45:11 -07:00
Aaron Patterson
7187339854 make the routes reader private
nobody should be touching the routes hash without going through the
NamedRouteCollection object.
2015-08-18 16:33:18 -07:00
Aaron Patterson
4d9475bef9 symbols will always be constructed with strings. 💣 2015-08-18 15:20:19 -07:00
Aaron Patterson
23cfdd4b71 test the verb method on the route, specifically 2015-08-17 16:36:31 -07:00
Aaron Patterson
c42db41f54 routes are always constructed with a hash for the conditions 2015-08-17 16:30:53 -07:00
Aaron Patterson
1ce74b009f introduce an alternate constructor for Route objects
I want to change the real constructor to take a particular parameter for
matching the request method
2015-08-17 16:08:39 -07:00
Aaron Patterson
e9777ef62e default pattern to use a joined string
The string we create is almost always the same, so rather than joining
all the time, lets join once, then reuse that string everywhere.
2015-08-17 13:51:38 -07:00
Aaron Patterson
703275ba70 use the mapper to build the routing table
We should build the routes using the user facing API which is `Mapper`.
This frees up the library internals to change as we see fit. IOW we
shouldn't be testing internals.
2015-08-15 14:32:04 -07:00
Aaron Patterson
a293812bff only keep one hash of named routes
The outer router object already keeps a hash of named routes, so we
should just use that.
2015-08-14 18:06:48 -07:00
Aaron Patterson
4bdd92d9fd rm add_route2
refactor the tests with a backwards compatible method call so we can rm
add_route2 from the journey router
2015-08-14 16:25:03 -07:00
Aaron Patterson
6c48d9392f pass pass the mapping object down the add_route stack
then we can let the mapping object derive stuff that the Route object
needs.
2015-08-14 16:13:26 -07:00
Aaron Patterson
5ba6966766 pass the mapping object to build_route
now that we aren't doing options manipulations, we can just pass the
mapping object down and read values from it.
2015-08-14 14:41:48 -07:00
Aaron Patterson
b10b279b97 deprecate passing a string for both the beginning path and :path option 2015-08-14 11:55:50 -07:00
Aaron Patterson
b592c5b607 pass the path ast down
now we don't need to add it to a hash and delete it from the hash later
just to pass it around
2015-08-14 10:44:49 -07:00
Aaron Patterson
aaaa67902e pull up path parsing
`add_route` needs the AST, so rather than shove it in a hash and delete
later, lets move parsing up the stack so we can pass down later
2015-08-14 10:39:33 -07:00
Aaron Patterson
7fa6600b52 use predicate methods instead of hard coding verb strings
also change the feeler to subclass AD::Request so that it has all the
methods that Request has
2015-08-14 10:39:33 -07:00
Aaron Patterson
c3284e2a36 implement requirements in terms of routes 2015-08-14 10:39:33 -07:00
Aaron Patterson
60adf118a6 implement the asts method in terms of paths / patterns
Eventually I want to eliminate the FakeSet test class
2015-08-14 10:39:32 -07:00
Aaron Patterson
61437232a9 extract ast finding to a method
I'm going to reimplement this using route objects, so it will be easier
if we just change ast access to go through a method rather than hashes
2015-08-14 10:39:32 -07:00
Aaron Patterson
715abbbb33 stop adding path_info to the conditions hash
we don't need to keep adding it and deleting if from hashes.
2015-08-14 10:39:32 -07:00
Aaron Patterson
947ebe9a6d remove Strexp
This was a useless object.  We can just directly construct a
Path::Pattern object without a Strexp object.
2015-08-13 15:42:46 -07:00
Aaron Patterson
4868692687 pass anchor directly to Pattern
the caller already has it, there is no reason to pack it in to an object
and just throw that object away.
2015-08-13 15:16:25 -07:00
Aaron Patterson
45d594fa53 pull up options_constrants extraction 2015-08-13 14:15:04 -07:00
Aaron Patterson
b778f6348b remove as
the caller already has access to `as`, so we can stop passing it around.
2015-08-13 14:04:02 -07:00
Aaron Patterson
e38a456faf remove anchor from mapping
the same value that is extracted from the options hash earlier is
returned, so we don't need to pass it in in the first place.  The caller
already has the data, so stop passing it around.
2015-08-13 13:58:16 -07:00
Aaron Patterson
aef421ed9d pull anchor extraction up
this way we don't have to mutate the options hash so far away from where
the user passed it in
2015-08-13 13:55:03 -07:00
Aaron Patterson
33dc653466 raise if anchor is passed to scope
The `anchor` parameter [is overridden](b4b4a611d0/actionpack/lib/action_dispatch/routing/mapper.rb (L1528)) unless it
is directly passed to `match`, so setting it in a scope must be a
mistake.
2015-08-13 13:41:03 -07:00
Aaron Patterson
ec895189e4 pull formatted up the stack
this reduces the number of times we have to mutate the options hash.
2015-08-12 16:54:35 -07:00
Aaron Patterson
d61e3c79dc add a regression test for scoped format params
This just ensures that `format` is applied to things inside the scope
2015-08-12 16:54:35 -07:00
Aaron Patterson
e2735b2b32 add a regression test for adding arbitrary keys to scope 2015-08-12 15:17:21 -07:00
Aaron Patterson
1c94317539 add a method to Scope for getting mapping options
Eventually we don't want to expose the "options" hash from scope, only
read values from it.  Lets start by adding a reader method.
2015-08-12 14:30:54 -07:00
Aaron Patterson
b46c67fb47 pull via all the way out of add_route 2015-08-12 14:30:53 -07:00
Aaron Patterson
4c641c6e36 add a test for adding "via" using scope 2015-08-12 14:30:53 -07:00
Aaron Patterson
b59ff24207 pull via extraction up
We're going to try pulling this up further, and check `via` validity
sooner.  This way we don't have to do a bunch of processing on `options`
hashes only to find out that the route is incorrect
2015-08-12 14:30:53 -07:00
Sean Griffin
e69364bc2d Merge pull request #21203 from denniss/issue-21199
Authorization scheme should be case insensitive. Fixes #21199
2015-08-11 17:25:00 -06:00
Aaron Patterson
97d7dc48d6 pull to up
this way we don't have to insert / delete it from the options hash so
many times.
2015-08-11 16:16:09 -07:00
Dennis Suratna
dec2f52fa4 Authorization scheme should be case insensitive. Fixes #21199 2015-08-11 15:59:44 -07:00
Aaron Patterson
5935e4c882 push option decomposition up a bit more
I think we can find the original place where `action` is added to the
options hash now.
2015-08-11 14:49:19 -07:00
Aaron Patterson
97bbde7600 pull up the "options.delete(:controller)" logic
we want to try to pull this logic up to where the user actually passed
in "controller" so that it's close to the related call.  That way when
we're down the stack, we don't need to wonder "why are we doing this?"
2015-08-11 14:49:18 -07:00
eileencodes
286cb890de Refactor route assertion methods in resources test
The tests and methods were hard to read with `options[:options]` all
over the place. This refactoring makes the code easier to understand.

The change came out of work for moving the underlying code of controller
tests to integraiton tests.
2015-08-08 11:53:05 -04:00
Rafael Mendonça França
d919fd88ec Merge pull request #11352 from xaviershay/dispatcher-api
Allow a custom dispatcher to be provided to routing.
2015-08-08 12:22:21 -03:00
eileencodes
12f08acbac Fix deprecation warning in tests
Using the string version of the class reference is now deprecated when
referencing middleware. This should be written as a class not as a string.

Deprecation warning that this change fixes:
```
DEPRECATION WARNING: Passing strings or symbols to the middleware
builder is deprecated, please change
them to actual class references.  For example:
  "ActionDispatch::ShowExceptions" => ActionDispatch::ShowExceptions
```
2015-08-08 10:38:09 -04:00
eileencodes
c8b8295583 Refactor to remove DrawOnce module
We were doing extra work that could be pushed off to Integration test
and SharedRoutes. Creating an extra module isn't necessary when those
are created by their respective classes.
2015-08-08 10:15:35 -04:00
Xavier Shay
2992b1c04c Allow a custom dispatcher to be provided to routing. 2015-08-07 20:06:24 -07:00
Aaron Patterson
1f80f3a373 remove vestigial code
Looks like this was left over from converting Rails to Rack.  I think
it's safe to remove now.
2015-08-07 16:17:22 -07:00
Aaron Patterson
2a3c47ff5d finish deprecating handling strings and symbols
since we only work with instances of classes, it greatly simplifies the
`Middleware` implementation.
2015-08-07 15:37:31 -07:00
Aaron Patterson
83b767cef9 Using strings or symbols for middleware class names is deprecated.
Convert things like this:

  middleware.use "Foo::Bar"

to this:

  middleware.use Foo::Bar
2015-08-07 15:37:31 -07:00
Aaron Patterson
27eddbb332 simplify the Middleware constructor
We should do the hard work outside the constructor.  Also fix the tests
to not directly construct middleware objects, but to go through the
stack object.
2015-08-07 15:37:31 -07:00
Michael Grosser
a278630f5f do not add common ports to HTTP_HOST
- webservers do not do it
 - it makes redirect urls ugly when request.host is used for redirection
2015-08-06 17:33:32 -07:00
Aaron Patterson
6d85804bc6 ExceptionWrapper doesn't need to know about env
ExceptionWrapper only cares about the backtrace cleaner, so lets just
pass the cleaner to the wrapper.  It does not need to know that env
exists or what key the backtrace cleaner is stored in
2015-08-06 15:59:44 -07:00
Aaron Patterson
8f27d6036a use a request object to reduce string allocations and not know about ENV keys 2015-08-06 15:12:19 -07:00
Rafael Mendonça França
19d46e849e Merge pull request #21131 from eagletmt/percent-filename
Fix Encoding::UndefinedConversionError with multibyte UTF-8 filename containing "%" character
2015-08-06 17:20:59 -03:00
Matthew Gerrior
3004cc8177 Adds missing argument handling for ActionController::TestSession to
allow testing controllers that use session#fetch with a default value.
2015-08-06 15:29:45 -04:00
Kohei Suzuki
b5ae1be2cd Add failing spec on utf8 filename with percent character 2015-08-04 21:27:22 +09:00
Aditya Kapoor
7481039225 Add missing assertion for test_route_with_colon_first 2015-08-03 13:48:15 +05:30
amitkumarsuroliya
eb55bd3430 Remove duplicity in tests 2015-08-03 12:31:19 +05:30
Aditya Kapoor
854ab2e1e6 add missing tests for action regexp 2015-08-02 13:39:40 +05:30
Rafael Mendonça França
32b0db266c Merge pull request #20590 from vngrs/set_default_charset
Document, refactor and create test case for ActionDispatch::Response
2015-07-27 17:31:24 -03:00
Roque Pinel
12b0b26df7 Fix state being carried over from previous transaction
This clears the transaction record state when the transaction finishes
with a `:committed` status.

Considering the following example where `name` is a required attribute.
Before we had `new_record?` returning `true` for a persisted record:

```ruby
  author = Author.create! name: 'foo'
  author.name = nil
  author.save        # => false
  author.new_record? # => true
```
2015-07-20 09:12:01 -06:00
Roque Pinel
780af27bf9 Fix exception overwritten for parameters fetch method
When executing an `ActionController::Parameters#fetch` with a block
that raises a `KeyError` the raised `KeyError` will be rescued and
converted to an `ActionController::ParameterMissing` exception,
covering up the original exception.

[Jonas Schubert Erlandsson & Roque Pinel]
2015-07-18 18:48:41 -04:00
Prem Sichanugrist
8cb8ce98d9 Stop using deprecated render :text in test
This will silence deprecation warnings.

Most of the test can be changed from `render :text` to render `:plain`
or `render :body` right away. However, there are some tests that needed
to be fixed by hand as they actually assert the default Content-Type
returned from `render :body`.
2015-07-17 22:27:33 -04:00
Prem Sichanugrist
6790228b39 Add deprecation warning for render :text
We've started on discouraging the usage of `render :text` in #12374.
This is a follow-up commit to make sure that we print out the
deprecation warning.
2015-07-17 21:12:47 -04:00
Robin Dupret
ae1b96cfcd Skip a few failing tests on JRuby with the attached tickets 2015-07-17 15:00:00 +02:00
Prem Sichanugrist
14a3bd520d Make AC::Parameters not inherited from Hash
This is another take at #14384 as we decided to wait until `master` is
targeting Rails 5.0. This commit is implementation-complete, as it
guarantees that all the public methods on the hash-inherited Parameters
are still working (based on test case). We can decide to follow-up later
if we want to remove some methods out from Parameters.
2015-07-15 11:11:36 -04:00
Aaron Patterson
468a55b741 Merge pull request #20866 from jdantonio/countdown-latch
Replace `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch` from concurrent-ruby.
2015-07-14 11:06:20 -07:00
Rafael Mendonça França
7645a5f85d Merge pull request #20877 from sikachu/rename-ac-test_response
Change AC::TestResponse to AD::TestResponse
2015-07-14 12:26:30 -03:00
Aaron Patterson
9cff248469 only call methods that are on the superclass
We want to treat the response object as if it's a real response object
(not a test object), so we should only call methods that are on the
superclass.
2015-07-14 07:46:17 -07:00
Prem Sichanugrist
e26d11c876 Change AC::TestResponse to AD::TestResponse
ActionController::TestResponse was removed in d9fe10c and caused a test
failure on Action View as its test case still refers to it.
2015-07-14 09:27:42 -04:00
Aaron Patterson
908bc79729 use a lookup table for assert_response
We shouldn't depend on specific methods imlemented in the TestResponse
subclass because the response could actually be a real response object.

In the future, we should either push the aliased predicate methods in
TestResponse up to the real response object, or remove them
2015-07-13 18:10:36 -07:00
Aaron Patterson
d9fe10cb8a only have one TestResponse class 2015-07-13 17:52:02 -07:00
Jerry D'Antonio
284a9ba8ec Replaced ActiveSupport::Concurrency::Latch with concurrent-ruby.
The concurrent-ruby gem is a toolset containing many concurrency
utilities. Many of these utilities include runtime-specific
optimizations when possible. Rather than clutter the Rails codebase with
concurrency utilities separate from the core task, such tools can be
superseded by similar tools in the more specialized gem. This commit
replaces `ActiveSupport::Concurrency::Latch` with
`Concurrent::CountDownLatch`, which is functionally equivalent.
2015-07-13 15:44:21 -04:00
Aaron Patterson
140d5a3b2f use Rack::Test::UploadedFile when uploading files
We should use rack-test's upload file objects on the test side so that
we will be able to correctly generate mime blob posts in the future
2015-07-09 11:51:45 -07:00
Aaron Patterson
394b7be036 set parameters as a query string
We should convert request parameters to a query string, then let the
request object parse that query string.  This should give us results
that are more similar to the real-world
2015-07-09 10:12:19 -07:00
Aaron Patterson
40ed4eefe4 use JSON to communicate between the controller and the tests 2015-07-09 07:50:41 -07:00
Aaron Patterson
5ea8efecd0 build and assign parameters rather than rely on mutations
We should assign parameters to the request object rather than mutate the
hash that is returned by `query_parameters` or `request_parameters`
2015-07-08 16:43:58 -07:00
Aaron Patterson
f65fd25f04 request objects are no longer recycled
Instead of trying to manually clear out a request object, lets just
allocate a new one.  The rack ENV is reused and cleaned (still), but the
request object is not.
2015-07-08 16:23:32 -07:00
Aaron Patterson
b5a9525932 pass the variant as a parameter to more reflect real world apps 2015-07-08 16:15:50 -07:00
Aaron Patterson
78a5124bf0 add a new constructor for allocating test requests 2015-07-08 16:09:49 -07:00
Aaron Patterson
db41f33d7c make env a required parameter 2015-07-08 15:59:30 -07:00
Aaron Patterson
4b1a0adf54 remove call to build_request 2015-07-08 15:14:41 -07:00
Aaron Patterson
460079a771 let the superclass build the request and response
We should leverage the request / response objects that the superclass
has already allocated for us.
2015-07-08 14:15:53 -07:00
Aaron Patterson
59a9068c3f pass variants in rather than mutating the request.
Variants are typically set in the controller based on some attribute of
the request that the browser sent.  We should make our tests more in
line with reality by doing the same and not mutating the request object.
2015-07-07 15:51:01 -07:00
eileencodes
8363b879fe pass cookies from the jar in the HTTP_COOKIE header
we should be pushing the cookies in via headers rather than maintaining
some object and "recycling" it.
2015-07-07 14:31:34 -07:00
Arthur Nogueira Neves
e598967548 Merge pull request #13897 from gmalette/nested-parameter-filtering-2
Allow filtering params based on parent keys
2015-07-06 16:33:01 +02:00
Kasper Timm Hansen
90ebba6836 Fix the random caching test failure. 2015-07-05 13:53:20 +02:00
eileencodes
4d7b507073 Improve error messages in cookies_test
Using `assert_predicate` and `assert_match` instead of just `assert` is
preferrable because better error messages are output.

In the case of `assert response.cookies.empty?` the error message was
`Failed assertion, no message given.` but now with `assert_predicate` it
will be `Expected {"user_name"=>"david"} to be empty?.`

For `assert_match(/user_name=david/,
response.headers["Set-Cookie"])` as well, the message returned was
unhelpful - `Failed assertion, no message given.` but now will tell what
was expected and what was returned with `Expected /user_name=david/ to
match "user_name=nope; path=/".`
2015-06-27 16:48:20 -04:00
Kasper Timm Hansen
991e98f564 Merge pull request #20276 from davetron5000/revert-head-on-no-template
Allow default_render to take a block to customize behavior when there's no template
2015-06-27 22:18:17 +02:00
Rafael Mendonça França
75b63de5ed Merge pull request #19431 from hmarr/head-routing
Respect routing precedence for HEAD requests
2015-06-22 19:34:37 -03:00
Guillaume Malette
33b93174f0 Allow filtering params based on parent keys
Add the possibility to only filter parameters based on
their full path instead of relying on the immediate key.

    config.filter_parameters += ['credit_card.code']

    { 'credit_card' => { 'code' => '[FILTERED]' },
      'source' => { 'code' => '<%= puts 5 %>' } }
2015-06-22 10:04:11 -04:00
Dave Copeland
6fda6c3778 Override default_render's behavior with a block
In 0de4a23 the behavior when there is a missing template was changed to
not raise an error, but instead head :no_content.  This is a breaking
change and some gems rely on this happening.

To allow gems and other code to work around this, allow
`default_render` to take a block which, if provided, will
execute the contents of that block instead of doing the `head :no_content`.
2015-06-20 12:00:07 -04:00
Arthur Neves
ffba8f79a2
Revert "Merge pull request #20584 from arthurnn/fix_url"
This reverts commit 0b3397872582f2cf1bc6960960a6393f477c55e6, reversing
changes made to 56d52e3749180e6c1dcf7166adbad967470aa78b.

As pointed out on the PR, this will hide development mistakes too, which
is not ideal.
2015-06-17 20:17:44 +02:00
Mehmet Emin İNAÇ
422292dc98 Document, refactor and create test case for ActionDispatch::Response#charset= method 2015-06-17 00:58:50 +03:00
Arthur Neves
e23b314945
Catch InvalidURIError on bad paths on redirect.
Handle URI::InvalidURIError errors on the redirect route method, so it
wont raise a 500 if a bad path is given.
2015-06-16 23:27:49 +02:00
Aaron Patterson
50176b59fa remove header= on the response object.
People should be free to mutate the header object, but not to set a new
header object.  That header object may be specific to the webserver, and
we need to hide it's internals.
2015-06-15 17:54:08 -07:00
Mehmet Emin İNAÇ
cf81a3bae0 Deprecate passing hash as first parameter into ActionController::Head 2015-06-15 23:53:45 +03:00
Kasper Timm Hansen
374b163999 Fix flakyness.
Brought on by my own stupidity :)
2015-06-15 22:04:43 +02:00
Fumiaki MATSUSHIMA
bb0186cf55 ActionDispatch::SSL should keep original header's behavior
`ActionDispatch::SSL` changes headers to `Hash`.
So some headers will be broken if there are some middlewares
on ActionDispatch::SSL and if it uses `Rack::Utils::HeaderHash`.
2015-06-14 23:20:04 +09:00
Yuki Nishijima
5226058163 Add the ability of returning arbitrary headers to ActionDispatch::Static
Now ActionDispatch::Static can accept HTTP headers so that developers
will have control of returning arbitrary headers like
'Access-Control-Allow-Origin' when a response is delivered. They can
be configured through `#config.public_file_server.headers`:

  config.public_file_server.headers = {
    "Cache-Control"               => "public, max-age=60",
    "Access-Control-Allow-Origin" => "http://rubyonrails.org"
  }

Also deprecate `config.static_cache_control` in favor of
`config.public_file_server.headers`.
2015-06-13 09:30:23 -07:00
Jorge Bejar
6c16577311 Return 204 if render is not called in API controllers 2015-06-11 16:54:17 -03:00
Jorge Bejar
8d3e6e5f4d Add test coverage for implicit render in empty actions 2015-06-11 16:54:16 -03:00
Jorge Bejar
a2c9a73084 Include ParamsWrapper in AC::API
ParamsWrapper was initially removed from API controllers according to
the following discusision:
https://github.com/rails-api/rails-api/issues/33

However, we're including it again so Rails API devs can decide
whether to enable or disable it.
2015-06-11 16:54:16 -03:00
Jorge Bejar
08cfe34174 Rename test methods in api conditional get controller tests 2015-06-11 16:54:14 -03:00
Jorge Bejar
674dab30bc Routes resources avoid :new and :edit endpoints if api_only is enabled 2015-06-11 16:54:14 -03:00
Santiago Pastorino
099055de66 Remove extra whitespaces 2015-06-11 16:54:13 -03:00
Santiago Pastorino
440b334cbb Use new hash syntax 2015-06-11 16:54:13 -03:00
Santiago Pastorino
e7b89f1081 Remove Unneeded ApiPublicExceptions middleware, PublicExceptions already does the work 2015-06-11 16:54:13 -03:00
Santiago Pastorino
4c1b437ed7 Use nex hash syntax on tests 2015-06-11 16:54:13 -03:00
Santiago Pastorino
3adb5eac3b Add ApiPublicException middleware 2015-06-11 16:54:10 -03:00
Santiago Pastorino
2d86b6d9ae Move Model test class inside RenderersApiController namespace 2015-06-11 16:54:09 -03:00
Santiago Pastorino
032778eefb Add ActionController API functionality 2015-06-11 16:54:09 -03:00
Yuki Nishijima
a888c3cdc9 Change the index arg of ActionDispatch::Static#new to a kwarg 2015-06-11 04:34:11 -07:00