diff --git a/app/helpers/active_admin/display_helper.rb b/app/helpers/active_admin/display_helper.rb index 60eef0ff783..f86172af422 100644 --- a/app/helpers/active_admin/display_helper.rb +++ b/app/helpers/active_admin/display_helper.rb @@ -108,8 +108,8 @@ def boolean_attr?(resource, attr, value) when TrueClass, FalseClass true else - if resource.class.respond_to? :columns_hash - column = resource.class.columns_hash[attr.to_s] and column.type == :boolean + if resource.class.respond_to? :attribute_types + resource.class.attribute_types[attr.to_s].is_a?(ActiveModel::Type::Boolean) end end end diff --git a/spec/helpers/display_helper_spec.rb b/spec/helpers/display_helper_spec.rb index aff9cf6d995..9860435d109 100644 --- a/spec/helpers/display_helper_spec.rb +++ b/spec/helpers/display_helper_spec.rb @@ -223,6 +223,22 @@ class ThisModel expect(value.to_s).to eq "Yes\n" end + context "with non-database boolean attribute" do + let(:model_class) do + Class.new(Post) do + attribute :a_virtual_attribute, :boolean + end + end + + it "calls status_tag even when attribute is nil" do + post = model_class.new a_virtual_attribute: nil + + value = helper.format_attribute post, :a_virtual_attribute + + expect(value.to_s).to eq "Unknown\n" + end + end + it "calls status_tag for boolean non-database values" do post = Post.new post.define_singleton_method(:true_method) do