method === :Post || :Put || :Delete returns true for all methods
michaelachrisco opened this issue · comments
Looked over some of the new commits. Found some small issues with the request by method function.
def request_by_method(method, body, request, uri)
if method === :Post || :Put || :Delete
request.content_type = 'application/json'
request.body = body.to_json(:max_nesting => false)
end
build_http_client(uri.host, uri.port)
end
method === :Post || :Put || :Delete
#always true or :Put
Say we chose to make this into a ruby function:
2.2.2 :002 > def compare(method)
2.2.2 :003?> method === :Post || :Put || :Delete
2.2.2 :004?> end
=> :compare
2.2.2 :005 > compare(:Get)
=> :Put
2.2.2 :008 > if compare(:Get)
2.2.2 :009?> true
2.2.2 :010?> else
2.2.2 :011 > false
2.2.2 :012?> end
=> true
If we change the block to:
def request_by_method(method, body, request, uri)
# if [:Post, :Put, :Delete].include?(method) <-alternate way so rubocop will not complain
if method === :Post || method === :Put || method === :Delete
request.content_type = 'application/json'
request.body = body.to_json(:max_nesting => false)
end
build_http_client(uri.host, uri.port)
end
The tests fail
Error: test: earthquakes should be able to access the earthquakes dataset. (SODATest):
WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET https://fakehost.socrata.com/resource/earthquakes.json with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'The Best User Agent of All Time', 'X-App-Token'=>'K6rLY8NBK0Hgm8QQybFmwIUQw'}
You can stub this request with the following snippet:
stub_request(:get, "https://fakehost.socrata.com/resource/earthquakes.json").
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'The Best User Agent of All Time', 'X-App-Token'=>'K6rLY8NBK0Hgm8QQybFmwIUQw'}).
to_return(:status => 200, :body => "", :headers => {})
registered request stubs:
stub_request(:get, "https://fakehost.socrata.com/resource/earthquakes.json").
with(:body => "null",
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'The Best User Agent of All Time', 'X-App-Token'=>'K6rLY8NBK0Hgm8QQybFmwIUQw'})
Fix is here: https://github.com/michaelachrisco/soda-ruby/tree/fix-requests
but will require new request stubs for tests.
Cool, thanks @michaelachrisco! I'll take a look at this on Monday or Tuesday.
No problem, have a good weekend!