Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Allow ActiveResource to use IntegrationTests for requests

#3368

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
      end
    end
  end

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

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Taryn
    Taryn

    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,
    Taryn
    [who eventually figured out how to signup*]

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

    October 13th, 2009 @ 03:27 PM

  2. Steffen Bartsch
    Steffen Bartsch

    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?

    October 13th, 2009 @ 03:53 PM

  3. Rohit Arondekar
    Rohit Arondekar
    • 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.

    October 6th, 2010 @ 06:40 AM