diff --git a/lib/active_hash/relation.rb b/lib/active_hash/relation.rb index e24d1ac..59d57b9 100644 --- a/lib/active_hash/relation.rb +++ b/lib/active_hash/relation.rb @@ -135,6 +135,7 @@ def find_by_id(id) end def count + return super if block_given? length end diff --git a/spec/active_hash/relation_spec.rb b/spec/active_hash/relation_spec.rb index e40c7d0..bf89269 100644 --- a/spec/active_hash/relation_spec.rb +++ b/spec/active_hash/relation_spec.rb @@ -39,6 +39,16 @@ end end + describe '#count' do + it 'supports a block arg' do + expect(subject.count { |s| s.name == "US" }).to eq(1) + end + + it 'returns the correct number of items of the relation' do + expect(subject.count).to eq(2) + end + end + describe '#size' do it 'returns an Integer' do expect(subject.size).to be_an(Integer)