Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

… and block values
  • Loading branch information...
commit 5cbad803be42cf1cc4c2381cb88449e0ff7d7acc 1 parent 7f2dc58
@tfwright tfwright authored
Showing with 11 additions and 4 deletions.
  1. +4 −4 lib/show_for/content.rb
  2. +7 −0 test/attribute_test.rb
View
8 lib/show_for/content.rb
@@ -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
7 test/attribute_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.