Closed mjc closed 10 years ago
Hi mjc and thanks. The problem is that offspring should never return nil. Query methods returning a randomly sized list of individuals like offspring or siblings are always expected to return an array, empty if is the case. So taking advantage of what you said I've made a little refactoring deleting useless #to_a calls. Can you tell me or write an rspec example where #offspring return nil?
Steps to reproduce nil offspring (Rails 4.1.4):
Create blank model with the requisite fields
Migrate database
Insert some records without setting any father_ids or mother_ids
call ModelName.first.offspring
here is a sample rails app that uses sqlite that can trigger it: https://github.com/mjc/blankrails/tree/genealogy-nil-demo
Person.create! name: 'Person One', sex: 1 # => #<Person id: 1, name: "Person One", sex: 1, father_id: nil, mother_id: nil, current_spouse_id: nil, created_at: "2014-08-04 18:27:22", updated_at: "2014-08-04 18:27:22">
Person.first.offspring # => nil
It was because of weak checks about sex values should be ok in version 1.3.0. Can I have a feedback please?
With 3 items and no genealogy set up, trying to call .add_father or .add_parents bails because:
evaluates to true.
this patch fixes this.