Permalink
Browse files

Fix use of inputs with block in Rails integration

Add tests for this case to both the sinatra and rails integration.
  • Loading branch information...
1 parent fb6acfc commit 8f4fee8fe5e55c9a63cfec6db6280518df6e3f32 @jeremyevans committed May 2, 2012
Showing with 35 additions and 2 deletions.
  1. +6 −2 lib/forme/rails.rb
  2. +14 −0 spec/rails_integration_spec.rb
  3. +15 −0 spec/sinatra_integration_spec.rb
View
@@ -21,9 +21,13 @@ def emit(tag)
end
# Capture the inputs into a new output buffer, and return
- # the buffer.
+ # the buffer if not given a block
def inputs(*)
- template.send(:with_output_buffer){super}
+ if block_given?
+ super
+ else
+ template.send(:with_output_buffer){super}
+ end
end
# If a block is not given, emit the inputs into the current output
@@ -26,6 +26,16 @@ def index
END
end
+ def inputs_block
+ render :inline => <<END
+<%= forme([:foo, :bar], :action=>'/baz') do |f| %>
+ <%= f.inputs(:legend=>'FBB') do %>
+ <%= f.input(:last) %>
+ <% end %>
+<% end %>
+END
+ end
+
def nest
render :inline => <<END
<%= forme([:foo, :bar], :action=>'/baz') do |f| %>
@@ -136,6 +146,10 @@ def o.puts(*) end
sin_get('/index').should == '<form action="/baz"> <p>FBB</p> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </form>'
end
+ specify "#form should have inputs work with a block" do
+ sin_get('/inputs_block').should == '<form action="/baz"> <fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
+ end
+
specify "#form should add start and end tags and yield Forme::Form instance" do
sin_get('/nest').should == '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
end
@@ -21,6 +21,16 @@ class FormeSinatraTest < Sinatra::Base
END
end
+ get '/inputs_block' do
+ erb <<END
+<% form([:foo, :bar], :action=>'/baz') do |f| %>
+ <% f.inputs(:legend=>'FBB') do %>
+ <%= f.input(:last) %>
+ <% end %>
+<% end %>
+END
+ end
+
get '/nest' do
erb <<END
<% form([:foo, :bar], :action=>'/baz') do |f| %>
@@ -124,10 +134,15 @@ def sin_get(path)
def o.puts(*) end
@rack = {'rack.input'=>'', 'REQUEST_METHOD'=>'GET', 'rack.errors'=>o}
end
+
specify "#form should add start and end tags and yield Forme::Form instance" do
sin_get('/').should == '<form action="/baz"> <p>FBB</p> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </form>'
end
+ specify "#form should have inputs work with a block" do
+ sin_get('/inputs_block').should == '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
+ end
+
specify "#form should add start and end tags and yield Forme::Form instance" do
sin_get('/nest').should == '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
end

0 comments on commit 8f4fee8

Please sign in to comment.