From 85b70e184cec4d17090dbf9262eed182da374866 Mon Sep 17 00:00:00 2001 From: Eito Katagiri Date: Wed, 1 May 2019 02:34:27 +0900 Subject: [PATCH] fix to catch error when it retrieves polymorphic association closes #113 --- lib/comma/header_extractor.rb | 3 ++- spec/comma/rails/active_record_spec.rb | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/comma/header_extractor.rb b/lib/comma/header_extractor.rb index d6c2109..9a5a03a 100644 --- a/lib/comma/header_extractor.rb +++ b/lib/comma/header_extractor.rb @@ -45,7 +45,8 @@ def get_association_class(model_class, association) begin model_class.reflect_on_association(association)&.klass - rescue NameError + rescue ArgumentError, NameError + # Since Rails 5.2, ArgumentError is raised. nil end end diff --git a/spec/comma/rails/active_record_spec.rb b/spec/comma/rails/active_record_spec.rb index eedfb27..16f0554 100644 --- a/spec/comma/rails/active_record_spec.rb +++ b/spec/comma/rails/active_record_spec.rb @@ -144,8 +144,7 @@ def name describe 'github pull-request 83' do it 'should not raise NameError' do - expect { Picture.all.to_comma(:pr_83) } - .not_to raise_exception(NameError) + expect { Picture.all.to_comma(:pr_83) }.not_to raise_error end end end