Permalink
Browse files

Moves blank check to after content transformation to catch blank proc…

… and block values
  • Loading branch information...
tfwright committed Jul 25, 2013
1 parent 7f2dc58 commit 5cbad803be42cf1cc4c2381cb88449e0ff7d7acc
Showing with 11 additions and 4 deletions.
  1. +4 −4 lib/show_for/content.rb
  2. +7 −0 test/attribute_test.rb
View
@@ -5,10 +5,6 @@ def content(value, options={}, apply_options=true, &block)
# cache value for apply_wrapper_options!
sample_value = value
- if value.blank? && value != false
- value = blank_value(options)
- end
-
# We need to convert value to_a because when dealing with ActiveRecord
# Array proxies, the follow statement Array# === value return false
value = value.to_a if value.is_a?(Array)
@@ -34,6 +30,10 @@ def content(value, options={}, apply_options=true, &block)
end
end
+ if content.blank?
+ content = blank_value(options)
+ end
+
options[:content_html] = options.except(:content_tag) if apply_options
wrap_with(:content, content, apply_wrapper_options!(:content, options, sample_value) )
end
View
@@ -133,6 +133,13 @@ class AttributeTest < ActionView::TestCase
assert_select "div.show_for p.wrapper", /This description/
end
+ test "show_for uses :if_blank if the block content is blank" do
+ with_attribute_for @user, :description, :if_blank => "No description provided" do
+ ""
+ end
+ assert_select "div.show_for p.wrapper", /No description provided/
+ end
+
test "show_for#content given a block should be wrapped in the result" do
with_attribute_for @user, :name do |name|
"<div class='block'>#{name}</div>".html_safe

0 comments on commit 5cbad80

Please sign in to comment.