Skip to content

Commit

Permalink
add support for separator override
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobarreto committed Sep 15, 2014
1 parent 2b92c12 commit e377492
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/show_for/builder.rb
Expand Up @@ -34,7 +34,7 @@ def object_name #:nodoc:
def wrap_label_and_content(name, value, options, &block) #:nodoc:
return if skip_blanks?(value)
label = label(name, options, false)
label += ShowFor.separator.to_s.html_safe if label.present?
label += (options[:separator] || ShowFor.separator).to_s.html_safe if label.present?
wrap_with(:wrapper, label + content(value, options, false, &block), apply_wrapper_options!(:wrapper, options, value))
end

Expand Down
13 changes: 13 additions & 0 deletions test/builder_test.rb
Expand Up @@ -38,6 +38,19 @@ class BuilderTest < ActionView::TestCase
end

# SEPARATOR
test "show_for allows separator to be configured globally" do
swap ShowFor, :separator => "<span class='separator'></span>" do
with_attribute_for @user, :name
assert_select "div.show_for p.user_name span.separator"
assert_select "div.show_for p.wrapper span.separator"
end
end

test "show_for allows separator to be changed by attribute"do
with_attribute_for @user, :name, :separator => "<span class='separator'></span>"
assert_select "div.show_for p.wrapper span.separator"
end

test "show_for uses a separator if requested" do
with_attribute_for @user, :name
assert_select "div.show_for p.wrapper br"
Expand Down

0 comments on commit e377492

Please sign in to comment.