Permalink
Browse files

Merge pull request #83 from skuark/master

Blank class not being applied to field wrapper when the result of a Proc is blank
  • Loading branch information...
2 parents 72a20f1 + 2c7f285 commit fe906e78083d770728524c81e43e99dc100b30ca @rafaelfranca rafaelfranca committed Nov 25, 2017
Showing with 9 additions and 2 deletions.
  1. +6 −1 lib/show_for/builder.rb
  2. +2 −1 test/attribute_test.rb
  3. +1 −0 test/test_helper.rb
View
@@ -53,7 +53,7 @@ def apply_default_options!(name, options) #:nodoc:
def apply_wrapper_options!(type, options, value)
options[:"#{type}_html"] ||= {}
- options[:"#{type}_html"][:class] = [options[:"#{type}_html"][:class], ShowFor.blank_content_class].join(' ') if value.blank? && value != false
+ options[:"#{type}_html"][:class] = [options[:"#{type}_html"][:class], ShowFor.blank_content_class].join(' ') if is_empty?(value)
options
end
@@ -84,6 +84,11 @@ def collection_block?(block) #:nodoc:
def skip_blanks?(value) #:nodoc:
ShowFor.skip_blanks && value.blank? && value != false
end
+
+ def is_empty?(value) #:nodoc:
+ value = @template.capture(&value) if value.is_a?(Proc)
+ value.blank? && value != false
+ end
end
end
View
@@ -224,8 +224,9 @@ class AttributeTest < ActionView::TestCase
test "show_for should wrap blank attributes with no_attribute" do
swap ShowFor, :blank_content_class => 'no_attribute' do
- with_attributes_for @user, :name, :birthday
+ with_attributes_for @user, :name, :birthday, :karma
assert_select ".wrapper.user_birthday.no_attribute"
+ assert_select ".wrapper.user_karma.no_attribute"
assert_select ".wrapper.user_name.no_attribute", false
end
end
View
@@ -35,6 +35,7 @@ def setup_new_user(options={})
:invalid => false,
:scopes => ["admin", "manager", "visitor"],
:birthday => nil,
+ :karma => Proc.new { nil },
:created_at => Time.now,
:updated_at => Date.today
}.merge(options))

0 comments on commit fe906e7

Please sign in to comment.