From 3b052a4f5e1f226c3e5c66d491167cb1afec72f5 Mon Sep 17 00:00:00 2001 From: Chad Heinen Date: Sat, 3 Feb 2018 18:11:08 -0600 Subject: [PATCH] ArrayFormatter now returns arrays for has_many :through associations The array_formatter was always returning an empty array when associated objects were called via a `has_many through:` relationship because they are loaded as a collection, and the collection is always considered empty. resolves: https://github.com/awesome-print/awesome_print/issues/331 --- CHANGELOG.md | 2 +- lib/awesome_print/formatters/array_formatter.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3a9e8..d339ba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## master (unreleased) - - new things! + - ArrayFormatter now returns arrays for has_many :through associations [@chadh13] - [#332] ## 1.8.0 - stat("$HOME/.aprc") once [@kstephens] - [#304] diff --git a/lib/awesome_print/formatters/array_formatter.rb b/lib/awesome_print/formatters/array_formatter.rb index 32973d3..3340a77 100644 --- a/lib/awesome_print/formatters/array_formatter.rb +++ b/lib/awesome_print/formatters/array_formatter.rb @@ -12,7 +12,7 @@ module AwesomePrint end def format - if array.empty? + if array.length.zero? '[]' elsif methods_array? methods_array