8000 Use attribute_types instead of columns_hash to determine type by til · Pull Request #8457 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Use attribute_types instead of columns_hash to determine type #8457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 app/helpers/active_admin/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/helpers/display_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ class ThisModel
expect(value.to_s).to eq "<span class=\"status-tag\" data-status=\"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 = helper.format_attribute post, :a_virtual_attribute

expect(value.to_s).to eq "<span class=\"status-tag\" data-status=\"unset\">Unknown</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
0