This project is archived and is in readonly mode.

#3368 ✓stale
Steffen Bartsch

Allow ActiveResource to use IntegrationTests for requests

Reported by Steffen Bartsch | October 12th, 2009 @ 02:52 PM

HttpMock is great to test the client side of a REST API. But if you're responsible for client and server side, it makes sense to do full end-to-end tests from your application's controllers to the client app. Up to now, you'd need to set up a local server to end-to-end-test the ActiveResource requests from the client app against. The supplied patch allows to use the integration test infrastructure to route the ActiveResource requests to the app's controllers.

Here is how you would use it

  require 'active_resource/integration_test_support'

  class APIIntegrationTest < ActionController::IntegrationTest
    test "API requests work end-to-end" do
      ActiveResource::Connection.with_integration_test_session(open_session) do
        result = APIClient.some_method_that_requires_api_access
        assert result

The patch is only a few lines and against 2-3-stable atm.

Comments and changes to this ticket

  • Taryn

    Taryn October 13th, 2009 @ 03:27 PM

    This looks pretty promising and would be extremely useful not to have to rely on HttpMock (which is limited).

    But I'm not sure what the abilities/limitations of the above approach are.

    Can you give some realistic examples of use?

    Cheers and thanks,
    [who eventually figured out how to signup*]

    • Hint: don't click 'sign-up' at top-right...
  • Steffen Bartsch

    Steffen Bartsch October 13th, 2009 @ 03:53 PM

    Taryn, I suppose that you are asking for limitations compared to full stack tests with ActiveResource querying a server instance. I haven't stumbled over any, yet, so I can only think areas where issues might come from. All that is abstracted away is Net::HTTP, so you won't test any HTTP-specific stuff, e.g. doing SSL-related requests. Everything else depends on the IntegrationTest implementation of Rails: if a specific HTTP feature was missing there, you won't be able to use it in this approach.

    For me it helped a lot in testing a synchronization client and server. I'm not sure, how more relevant usage examples would look like. My tests aren't doing more then the above example: setting up the environment on the server, calling client APIs inside the with_integration_test_session block and asserting the results. What kind of example were you thinking of?

  • Rohit Arondekar

    Rohit Arondekar October 6th, 2010 @ 06:40 AM

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

    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.

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=""></a>