Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow :builder option to specify custom show_for builder class

  • Loading branch information...
commit dd8b7c651242c723ab350764cefa672e6368cf3f 1 parent 7cf6af1
@adzap adzap authored josevalim committed
Showing with 12 additions and 2 deletions.
  1. +3 −2 lib/show_for/helper.rb
  2. +9 −0 test/helper_test.rb
View
5 lib/show_for/helper.rb
@@ -14,10 +14,11 @@ def show_for(object, html_options={}, &block)
html_options[:id] ||= dom_id(object)
html_options[:class] = "show_for #{dom_class(object)} #{html_options[:class]}".strip
+ builder_class = html_options.delete(:builder) || ShowFor::Builder
- concat content_tag(tag, capture(ShowFor::Builder.new(object, self), &block), html_options)
+ concat content_tag(tag, capture(builder_class.new(object, self), &block), html_options)
end
end
end
-ActionView::Base.send :include, ShowFor::Helper
+ActionView::Base.send :include, ShowFor::Helper
View
9 test/helper_test.rb
@@ -1,5 +1,8 @@
require "test_helper"
+class CustomBuilder < ShowFor::Builder
+end
+
class HelperTest < ActionView::TestCase
test "show for yields an instance of ShowFor::Builder" do
show_for(@user) do |f|
@@ -7,6 +10,12 @@ class HelperTest < ActionView::TestCase
end
end
+ test "show for yields an instance of builder class specified by builder option" do
+ show_for(@user, :builder => CustomBuilder) do |f|
+ assert f.instance_of?(CustomBuilder)
+ end
+ end
+
test "show for should add default class to form" do
show_for(@user) do |f| end
assert_select "div.show_for"
Please sign in to comment.
Something went wrong with that request. Please try again.