Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/active_admin/view_helpers/display_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/view_helpers/display_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ class ThisModel
expect(value.to_s).to eq "<span class=\"status_tag yes\">Yes</span>\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 = view.format_attribute post, :a_virtual_attribute

expect(value.to_s).to eq "<span class=\"status_tag unset no\">No</span>\n"
end
end

it "calls status_tag for boolean non-database values" do
post = Post.new
post.define_singleton_method(:true_method) do
Expand Down