diff --git a/lib/active_hash/relation.rb b/lib/active_hash/relation.rb index 6e513e29..30d5e783 100644 --- a/lib/active_hash/relation.rb +++ b/lib/active_hash/relation.rb @@ -22,6 +22,10 @@ def where(conditions_hash = :chain) spawn.where!(conditions_hash) end + def pretty_print(pp) + pp.pp(entries.to_ary) + end + class WhereChain attr_reader :relation diff --git a/spec/active_hash/relation_spec.rb b/spec/active_hash/relation_spec.rb index 432286d1..e40c7d0f 100644 --- a/spec/active_hash/relation_spec.rb +++ b/spec/active_hash/relation_spec.rb @@ -71,4 +71,16 @@ expect(klass.where(display: true).length).to eq(1) end end + + describe "#pretty_print" do + it "prints the records" do + out = StringIO.new + PP.pp(subject, out) + + expect(out.string.scan(/\bid\b/).length).to eq(2) + expect(out.string).to match(/\bCanada\b/) + expect(out.string).to match(/\bUS\b/) + expect(out.string).to_not match(/ActiveHash::Relation/) + end + end end