Web mock disable_net_connect!(allow_localhost: true) not working
vikramjadon921995 opened this issue · comments
I have this code in my spec_helper.rb
WebMock.disable_net_connect!(allow_localhost: true)
When in rails console in test environment, i create a user (a model in my project), it shows following error while calling callbacks to create elasticsearch indexes of that user. My Elasticsearch server is running on localhost:9200.
============================================================ ({:host=>"localhost", :port=>9200, :protocol=>"http"})
(0.6ms) ROLLBACK
WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: PUT http://localhost:9200/user_test/user/9 with body '{"company_watchlists":[{"id":17,"name":"Saved Companies","created_at":"2016-10-01T20:18:38.923Z","updated_at":"2016-10-01T20:18:38.923Z","is_smart":false,"is_favourite":true,"total_companies":0}]}' with headers {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'Date'=>'Sat, 01 Oct 2016 20:18:38 GMT', 'User-Agent'=>'Faraday v0.9.0'}
You can stub this request with the following snippet:
stub_request(:put, "http://localhost:9200/user_test/user/9").
with(:body => {"{\"company_watchlists\":{\"id\":17,\"name\":\"Saved Companies\",\"created_at\":\"2016-10-01T20:18:38.923Z\",\"updated_at\":\"2016-10-01T20:18:38.923Z\",\"is_smart\":false,\"is_favourite\":true,\"total_companies\":0}}"=>true},
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'Date'=>'Sat, 01 Oct 2016 20:18:38 GMT', 'User-Agent'=>'Faraday v0.9.0'}).
to_return(:status => 200, :body => "", :headers => {})
============================================================
I don't want to stub requests to localhost:9200.
sorry, my bad, submitted issue at the wrong place.