Exception on 404 with .find(:first), .find(:last) #88

Merged
merged 1 commit into from Nov 30, 2015

Projects

None yet

4 participants

@rfletcher
Contributor

If a collection API returns a 404 when calling .find(:first) or .find(:last), it causes an exception. Here's my original test script:

require "active_resource"
require "webmock"

include WebMock::API

stub_request( :any, "api.example.com/people.json" ).to_return( :status => 404 )

class Person < ActiveResource::Base
  self.site = "http://api.example.com"
end

Person.find( :one )

And the result:

activeresource-4.0.0/lib/active_resource/base.rb:874:in `find': undefined method `first' for nil:NilClass (NoMethodError)
@ryana
ryana commented Sep 27, 2013

+1

@rafaelfranca rafaelfranca merged commit be02a77 into rails:master Nov 30, 2015

1 check passed

default The Travis CI build passed
Details
@apepper
apepper commented Jun 16, 2016

This PR introduced a bug: Base.first is no longer lazy but instead fetched all items from the server first, before returning the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment