Permalink
Browse files

Implement TextInput.

  • Loading branch information...
1 parent 3b797ed commit 8b7da1bbbc2392202ff8aa577232f8df2a5db036 @mjbellantoni committed Sep 3, 2012
@@ -24,7 +24,7 @@ module Inputs
autoload :SearchInput, "formtastic-bootstrap/inputs/search_input"
autoload :SelectInput, "formtastic-bootstrap/inputs/select_input"
autoload :StringInput, "formtastic-bootstrap/inputs/string_input"
- # autoload :TextInput
+ autoload :TextInput, "formtastic-bootstrap/inputs/text_input"
autoload :TimeInput, "formtastic-bootstrap/inputs/time_input"
# autoload :TimePickerInput # TODO Come back to this.
autoload :TimeSelectInput, "formtastic-bootstrap/inputs/time_select_input"
@@ -4,7 +4,7 @@ class TextInput < Formtastic::Inputs::TextInput
include Base
def to_html
- generic_input_wrapping do
+ bootstrap_wrapping do
builder.text_area(method, input_html_options)
end
end
@@ -8,53 +8,52 @@
before do
@output_buffer = ''
mock_everything
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:body, :as => :text))
end)
end
+ it_should_have_bootstrap_horizontal_wrapping
it_should_have_input_wrapper_with_class("text")
- it_should_have_input_wrapper_with_class(:clearfix)
- it_should_have_input_class_in_the_right_place
+ it_should_have_input_wrapper_with_class(:input)
it_should_have_input_wrapper_with_id("post_body_input")
it_should_have_label_with_text(/Body/)
it_should_have_label_for("post_body")
it_should_have_textarea_with_id("post_body")
it_should_have_textarea_with_name("post[body]")
- it_should_apply_error_logic_for_input_type(:text)
+ it_should_apply_error_logic_for_input_type(:number)
it 'should use input_html to style inputs' do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text, :input_html => { :class => 'myclass' }))
end)
- output_buffer.should have_tag("form div.clearfix div.input textarea.myclass")
+ output_buffer.should have_tag("form div.control-group div.controls textarea.myclass")
end
it "should have a cols attribute when :cols is a number in :input_html" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text, :input_html => { :cols => 42 }))
end)
- output_buffer.should have_tag("form div.clearfix div.input textarea[@cols='42']")
+ output_buffer.should have_tag("form div.control-group div.controls textarea[@cols='42']")
end
it "should not have a cols attribute when :cols is nil in :input_html" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text, :input_html => { :cols => nil }))
end)
- output_buffer.should_not have_tag("form div.clearfix div.input textarea[@cols]")
+ output_buffer.should_not have_tag("form div.control-group div.controls textarea[@cols]")
end
it "should have a rows attribute when :rows is a number in :input_html" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text, :input_html => { :rows => 42 }))
end)
- output_buffer.should have_tag("form div.clearfix div.input textarea[@rows='42']")
+ output_buffer.should have_tag("form div.control-group div.controls textarea[@rows='42']")
end
@@ -63,15 +62,14 @@
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text, :input_html => { :rows => nil }))
end)
- output_buffer.should_not have_tag("form div.clearfix div.input textarea[@rows]")
+ output_buffer.should_not have_tag("form div.control-group div.controls textarea[@rows]")
end
describe "when namespace is provided" do
before do
@output_buffer = ''
mock_everything
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
concat(builder.input(:body, :as => :text))
@@ -84,6 +82,33 @@
end
+ describe "when index is provided" do
+
+ before do
+ @output_buffer = ''
+ mock_everything
+
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.fields_for(:author, :index => 3) do |author|
+ concat(author.input(:name, :as => :text))
+ end)
+ end)
+ end
+
+ it 'should index the id of the control-group' do
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
+ end
+
+ it 'should index the id of the select tag' do
+ output_buffer.should have_tag("textarea#post_author_attributes_3_name")
+ end
+
+ it 'should index the name of the select tag' do
+ output_buffer.should have_tag("textarea[@name='post[author_attributes][3][name]']")
+ end
+
+ end
+
context "when required" do
it "should add the required attribute to the input's html options" do
with_config :use_required_attribute, true do
@@ -119,7 +144,7 @@
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text))
end)
- output_buffer.should have_tag("form div.clearfix div.input textarea[@rows='12']")
+ output_buffer.should have_tag("form div.control-group div.controls textarea[@rows='12']")
end
end
@@ -128,7 +153,7 @@
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text))
end)
- output_buffer.should_not have_tag("form div.clearfix div.input textarea[@rows]")
+ output_buffer.should_not have_tag("form div.control-group div.controls textarea[@rows]")
end
end
@@ -144,7 +169,7 @@
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text))
end)
- output_buffer.should have_tag("form div.clearfix div.input textarea[@cols='10']")
+ output_buffer.should have_tag("form div.control-group div.controls textarea[@cols='10']")
end
end
@@ -153,7 +178,7 @@
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :text))
end)
- output_buffer.should_not have_tag("form div.clearfix div.input textarea[@cols]")
+ output_buffer.should_not have_tag("form div.control-group div.controls textarea[@cols]")
end
end
@@ -94,13 +94,13 @@ def it_should_have_select_with_name(name)
def it_should_have_textarea_with_name(name)
it "should have an input named #{name}" do
- output_buffer.should have_tag("form li textarea[@name=\"#{name}\"]")
+ output_buffer.should have_tag("form div.control-group div.controls textarea[@name=\"#{name}\"]")
end
end
def it_should_have_textarea_with_id(element_id)
it "should have an input with id '#{element_id}'" do
- output_buffer.should have_tag("form li textarea##{element_id}")
+ output_buffer.should have_tag("form div.control-group div.controls textarea##{element_id}")
end
end

0 comments on commit 8b7da1b

Please sign in to comment.