I'm developing an internal API using Rails and I'm thinking to use ActiceResource to access it. I want to make integration test cases (ie. making http requests to the controllers in test environment) using ActiveResource but can't figure out how to set up the test cases.
In normal integration test cases you send requests to your own app with get/post methods. Somehow I should tell ActiceResource to connect to my app instead of making a real http connection.
All ActiveResource test examples I see are using mocks. I would like to avoid this and run my tests against my controller code instead. I'm using Rails 5 and Minitest.
Below is the test code which obviously does not work. If I try to run it, it will give an error:
require 'test_helper'
module MyApp
class User < ActiveResource::Base
self.site = 'http://www.example.com'
end
end
class UserFlowsTest < ActionDispatch::IntegrationTest
test "should get index" do
users = MyApp::User.all
assert_response :success
end
end
▶ rails test test/integration/user_flows_test.rb
NoMethodError: undefined method `response_code' for nil:NilClass
actionpack (5.2.1) lib/action_dispatch/testing/assertions/response.rb:81:in `generate_response_message'
actionpack (5.2.1) lib/action_dispatch/testing/assertions/response.rb:31:in `assert_response'
test/integration/user_flows_test.rb:13:in `block in <class:UserFlowsTest>'