active-hash / active_hash

A readonly ActiveRecord-esque base class that lets you use a hash, a Yaml file or a custom file as the datasource
MIT License
1.2k stars 179 forks source link

Fix unexpected `RecordNotFound` exception when pass a block to `ActiveFile::Base.find` #243

Closed yujideveloper closed 2 years ago

yujideveloper commented 2 years ago

Problem

I have occurred unexpected ActiveHash::RecordNotFound exception when pass a block to ActiveFile::Base.find.

Minimum reproduction code

class Country < ActiveYaml::Base
  set_filename "sample"
end
- id: 1
  name: US
- id: 2
  name: Canada
- id: 3
  name: Mexico
# Actual
Çountry.find { |c| c.name == "US" } # => ActiveHash::RecordNotFound

# Expected
Çountry.find { |c| c.name == "US" } # => <Country:0x000000010686c7f0 @attributes={:id=>1, :name=>"US"}>

This PR's changes

I fixed to pass a block to super method in ActiveFile::Base.find

kbrock commented 2 years ago

Could you add a spec for this?

yujideveloper commented 2 years ago

@kbrock I added specs. Could you review this?

kbrock commented 2 years ago

ran with test locally, all passed

yujideveloper commented 2 years ago

Thanks!