8000 Merge pull request #4938 from Fivell/issue_4602 · parse/activeadmin@ab81e13 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab81e13

Browse files
authored
Merge pull request activeadmin#4938 from Fivell/issue_4602
Properly format boolean values using status_tag
2 parents 8a916e5 + 155c919 commit ab81e13

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/active_admin/view_helpers/display_helper.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def format_attribute(resource, attr)
4545

4646
if value.is_a?(Arbre::Element)
4747
value
48-
elsif boolean_attr?(resource, attr)
48+
elsif boolean_attr?(resource, attr, value)
4949
Arbre::Context.new { status_tag value }
5050
else
5151
pretty_format value
@@ -79,9 +79,14 @@ def pretty_format(object)
7979
8000 end
8080
end
8181

82-
def boolean_attr?(resource, attr)
83-
if resource.class.respond_to? :columns_hash
84-
column = resource.class.columns_hash[attr.to_s] and column.type == :boolean
82+
def boolean_attr?(resource, attr, value)
83+
case value
84+
when TrueClass, FalseClass
85+
true
86+
else
87+
if resource.class.respond_to? :columns_hash
88+
column = resource.class.columns_hash[attr.to_s] and column.type == :boolean
89+
end
8590
end
8691
end
8792

spec/unit/view_helpers/display_helper_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,20 @@ class ThisMode A70F l
176176

177177
expect(value.to_s).to eq "<span class=\"status_tag yes\">Yes</span>\n"
178178
end
179+
180+
it 'calls status_tag for boolean non-database values' do
181+
post = Post.new
182+
post.define_singleton_method(:true_method) do
183+
true
184+
end
185+
post.define_singleton_method(:false_method) do
186+
false
187+
end
188+
true_value = format_attribute post, :true_method
189+
expect(true_value.to_s).to eq "<span class=\"status_tag yes\">Yes</span>\n"
190+
false_value = format_attribute post, :false_method
191+
expect(false_value.to_s).to eq "<span class=\"status_tag no\">No</span>\n"
192+
end
193+
179194
end
180195
end

0 commit comments

Comments
 (0)
0