Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/active_resource/base.rb
Expand Up @@ -871,8 +871,8 @@ def find(*arguments)

case scope
when :all then find_every(options)
when :first then find_every(options).first
when :last then find_every(options).last
when :first then find_every(options).to_a.first
when :last then find_every(options).to_a.last
when :one then find_one(options)
else find_single(scope, options)
end
Expand Down
7 changes: 7 additions & 0 deletions test/cases/finder_test.rb
Expand Up @@ -123,6 +123,13 @@ def test_find_all_by_symbol_from
assert_equal "David", people.first.name
end

def test_find_first_or_last_not_found
ActiveResource::HttpMock.respond_to { |m| m.get "/people.json", {}, "", 404 }

assert_nothing_raised { Person.find(:first) }
assert_nothing_raised { Person.find(:last) }
end

def test_find_single_by_from
ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/manager.json", {}, @david }

Expand Down