Skip to content

Commit

Permalink
Merge pull request active-hash#288 from active-hash/285-pretty-print-…
Browse files Browse the repository at this point in the history
…relations

feat: improve pp output for ActiveHash::Relation
  • Loading branch information
kbrock authored Aug 11, 2023
2 parents 0774392 + d23246d commit 57092b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/active_hash/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions spec/active_hash/relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 57092b4

Please sign in to comment.