This project is archived and is in readonly mode.

#3795 ✓stale
Damien MATHIEU

Add global parameters in functional tests

Reported by Damien MATHIEU | January 27th, 2010 @ 01:17 PM

Whenever we use deep nested routes, we might end up with a lot of recurrent parameters.
Currently, it seems we have no other choice but to repeat them all when making the request to test the action.

The patch I've written and I suggest allows to define some "global parameters".
These global parameters are defined before to call the process method and so allows us to avoid defining them for every request.

So we can have the following :

class PostsControllerTest < ActionController::TestCase
    def setup
        @request.global_parameters[:test] = 'foo'
    end

    test "it should make a request" do
        get :index
    end
end

Our get request will have the parameter "test" provided with the value "foo".

My patch does a merge of the global parameters with the request's parameters. So if you provide parameters directly in the get method, they'll override the global ones.

In the class, if we add a test

test "it should make a second request" do
    get :index, :test => 'bar'
end

The test parameter will have the 'bar' value.

The global parameters are reseted after every request. So you can't put them in the initialize method. But they're not spread across controllers.

My patch is currently only for Rails 3. And I'd like some comments about this before to also do it for rails 2.3.
But if this works, I'll make a second patch.

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar October 9th, 2010 @ 03:14 AM

    • State changed from “new” to “stale”
    • Importance changed from “” to “Low”

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

  • Ryan Bigg

    Ryan Bigg October 9th, 2010 @ 10:05 PM

    • Tag cleared.

    Automatic cleanup of spam.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages