Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Capture returns from formtastic and append them to the output_buffer …

…if running with rails3

This is an ugly hack that hopefully goes away once rspec 2.0 supports testing viewhelpers
  • Loading branch information...
commit d7a729d0b1a19ff42563ddc5d0372897963b49f6 1 parent aefd9c8
@yabawock yabawock authored
View
31 spec/buttons_spec.rb
@@ -13,26 +13,31 @@
describe 'with a block' do
describe 'when no options are provided' do
before do
- semantic_form_for(@new_post) do |builder|
- builder.buttons do
+ @form = semantic_form_for(@new_post) do |builder|
+ buttons = builder.buttons do
concat('hello')
end
+ concat(buttons)
end
end
it 'should render a fieldset inside the form, with a class of "inputs"' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset.buttons")
end
it 'should render an ol inside the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset.buttons ol")
end
it 'should render the contents of the block inside the ol' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset.buttons ol", /hello/)
end
it 'should not render a legend inside the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form fieldset.buttons legend")
end
end
@@ -41,12 +46,13 @@
before do
@legend_text = "Advanced options"
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
builder.buttons :name => @legend_text do
end
end
end
it 'should render a fieldset inside the form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
end
end
@@ -56,12 +62,13 @@
@id_option = 'advanced'
@class_option = 'wide'
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
builder.buttons :id => @id_option, :class => @class_option do
end
end
end
it 'should pass the options into the fieldset tag as attributes' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset##{@id_option}")
output_buffer.should have_tag("form fieldset.#{@class_option}")
end
@@ -74,32 +81,38 @@
describe 'with no args (default buttons)' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.buttons)
end
end
it 'should render a form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form')
end
it 'should render a buttons fieldset inside the form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons')
end
it 'should not render a legend in the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form fieldset.buttons legend')
end
it 'should render an ol in the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons ol')
end
it 'should render a list item in the ol for each default button' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons ol li', :count => 1)
end
it 'should render a commit list item for the commit button' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons ol li.commit')
end
@@ -108,12 +121,13 @@
describe 'with button names as args' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.buttons(:commit))
end
end
it 'should render a form with a fieldset containing a list item for each button arg' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit')
end
@@ -123,21 +137,24 @@
describe 'with button names as args and an options hash' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.buttons(:commit, :name => "Now click a button", :id => "my-id"))
end
end
it 'should render a form with a fieldset containing a list item for each button arg' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit', :count => 1)
end
it 'should pass the options down to the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset#my-id.buttons')
end
it 'should use the special :name option as a text for the legend tag' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset#my-id.buttons > legend', /Now click a button/)
end
View
82 spec/commit_button_spec.rb
@@ -14,29 +14,33 @@
before do
@new_post.stub!(:new_record?).and_return(false)
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
end
it 'should render a commit li' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit')
end
it 'should render an input with a type attribute of "submit"' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@type="submit"]')
end
it 'should render an input with a name attribute of "commit"' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@name="commit"]')
end
it 'should pass options given in :button_html to the button' do
@new_post.stub!(:new_record?).and_return(false)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button('text', :button_html => {:class => 'my_class', :id => 'my_id'}))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input#my_id')
output_buffer.should have_tag('li.commit input.my_class')
end
@@ -54,9 +58,10 @@
it 'should use the default if set' do
with_config :default_commit_button_accesskey, 's' do
@new_post.stub!(:new_record?).and_return(false)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button('text', :button_html => {}))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@accesskey="s"]')
end
end
@@ -64,9 +69,10 @@
it 'should use the value set in options over the default' do
with_config :default_commit_button_accesskey, 's' do
@new_post.stub!(:new_record?).and_return(false)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button('text', :accesskey => 'o'))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
output_buffer.should have_tag('li.commit input[@accesskey="o"]')
end
@@ -75,9 +81,10 @@
it 'should use the value set in button_html over options' do
with_config :default_commit_button_accesskey, 's' do
@new_post.stub!(:new_record?).and_return(false)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button('text', :accesskey => 'o', :button_html => {:accesskey => 't'}))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
output_buffer.should_not have_tag('li.commit input[@accesskey="o"]')
output_buffer.should have_tag('li.commit input[@accesskey="t"]')
@@ -90,16 +97,18 @@
before do
@new_post.stub!(:new_record?).and_return(false)
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button("a string", :button_html => { :class => "pretty"}))
end
end
it "should render the string as the value of the button" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li input[@value="a string"]')
end
it "should deal with the options hash" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li input.pretty')
end
@@ -109,12 +118,13 @@
before do
@new_post.stub!(:new_record?).and_return(false)
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button(:button_html => { :class => "pretty"}))
end
end
it "should deal with the options hash" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li input.pretty')
end
@@ -126,9 +136,10 @@
describe 'when used without object' do
describe 'when explicit label is provided' do
it 'should render an input with the explicitly specified label' do
- semantic_form_for(:post, :url => 'http://example.com') do |builder|
+ form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
concat(builder.commit_button("Click!"))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="submit"]')
end
end
@@ -144,9 +155,10 @@
end
it 'should render an input with default I18n-localized label (fallback)' do
- semantic_form_for(:post, :url => 'http://example.com') do |builder|
+ form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@value="Submit Post"][@class~="submit"]')
end
end
@@ -175,16 +187,18 @@
}
}
}
- semantic_form_for(:post, :url => 'http://example.com') do |builder|
+ form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
end
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- semantic_form_for(:post, :url => 'http://example.com') do |builder|
+ form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
end
@@ -200,9 +214,10 @@
describe 'when explicit label is provided' do
it 'should render an input with the explicitly specified label' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button("Click!"))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="create"]')
end
end
@@ -218,9 +233,10 @@
end
it 'should render an input with default I18n-localized label (fallback)' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@value="Create Post"][@class~="create"]')
end
end
@@ -249,17 +265,19 @@
}
}
}
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
end
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
end
end
@@ -274,9 +292,10 @@
describe 'when explicit label is provided' do
it 'should render an input with the explicitly specified label' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button("Click!"))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="update"]')
end
end
@@ -292,15 +311,17 @@
end
it 'should render an input with default I18n-localized label (fallback)' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li.commit input[@value="Save Post"][@class~="update"]')
end
end
describe 'when I18n-localized label is provided' do
before do
+ ::I18n.backend.reload!
::I18n.backend.store_translations :en,
:formtastic => {
:actions => {
@@ -323,16 +344,18 @@
}
}
}
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
end
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
::I18n.backend.store_translations :en, :formtastic => {}
end
@@ -345,16 +368,31 @@
describe 'when the model is two words' do
before do
output_buffer = ''
- class ::UserPost; def id; end; def self.human_name; "Userpost"; end; end # Rails does crappy human_name
+ class ::UserPost
+ extend ActiveModel::Naming if defined?(ActiveModel::Naming)
+ include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
+
+ def id
+ end
+
+ def persisted?
+ end
+
+ # Rails does crappy human_name
+ def self.human_name
+ "User post"
+ end
+ end
@new_user_post = ::UserPost.new
@new_user_post.stub!(:new_record?).and_return(true)
- semantic_form_for(@new_user_post, :url => '') do |builder|
+ @form = semantic_form_for(@new_user_post, :url => '') do |builder|
concat(builder.commit_button())
end
end
it "should render the string as the value of the button" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('li input[@value="Create User post"]')
end
View
93 spec/custom_macros.rb
@@ -8,66 +8,77 @@ module ClassMethods
def it_should_have_input_wrapper_with_class(class_name)
it "should have input wrapper with class '#{class_name}'" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li.#{class_name}")
end
end
def it_should_have_input_wrapper_with_id(id_string)
it "should have input wrapper with id '#{id_string}'" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li##{id_string}")
end
end
def it_should_not_have_a_label
it "should not have a label" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li label")
end
end
def it_should_have_a_nested_fieldset
it "should have a nested_fieldset" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset")
end
end
def it_should_have_label_with_text(string_or_regex)
it "should have a label with text '#{string_or_regex}'" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label", string_or_regex)
end
end
def it_should_have_label_for(element_id)
it "should have a label for ##{element_id}" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label[@for='#{element_id}']")
end
end
def it_should_have_input_with_id(element_id)
it "should have an input with id '#{element_id}'" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input##{element_id}")
end
end
def it_should_have_input_with_type(input_type)
it "should have a #{input_type} input" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input[@type=\"#{input_type}\"]")
end
end
def it_should_have_input_with_name(name)
it "should have an input named #{name}" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input[@name=\"#{name}\"]")
end
end
def it_should_have_textarea_with_name(name)
it "should have an input named #{name}" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li 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.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li textarea##{element_id}")
end
end
@@ -76,27 +87,30 @@ def it_should_use_default_text_field_size_when_method_has_no_database_column(as)
it 'should use default_text_field_size when method has no database column' do
@new_post.stub!(:column_for_attribute).and_return(nil) # Return a nil column
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => as))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input[@size='#{Formtastic::SemanticFormBuilder.default_text_field_size}']")
end
end
def it_should_apply_custom_input_attributes_when_input_html_provided(as)
it 'it should apply custom input attributes when input_html provided' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => as, :input_html => { :class => 'myclass' }))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input.myclass")
end
end
def it_should_apply_custom_for_to_label_when_input_html_id_provided(as)
it 'it should apply custom for to label when input_html :id provided' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => as, :input_html => { :id => 'myid' }))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label[@for="myid"]')
end
end
@@ -104,6 +118,7 @@ def it_should_apply_custom_for_to_label_when_input_html_id_provided(as)
def it_should_have_maxlength_matching_column_limit
it 'should have a maxlength matching column limit' do
@new_post.column_for_attribute(:title).limit.should == 50
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input[@maxlength='50']")
end
end
@@ -113,10 +128,11 @@ def it_should_use_default_text_field_size_for_columns_longer_than_default_text_f
default_size = Formtastic::SemanticFormBuilder.default_text_field_size
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => default_size * 2))
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => as))
end
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input[@size='#{default_size}']")
end
end
@@ -126,10 +142,11 @@ def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(a
column_limit_shorted_than_default = 1
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => column_limit_shorted_than_default))
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => as))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
end
end
@@ -144,72 +161,82 @@ def it_should_apply_error_logic_for_input_type(type)
end
it 'should apply an errors class to the list item' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => type))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.error')
end
it 'should not wrap the input with the Rails default error wrapping' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => type))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('div.fieldWithErrors')
end
it 'should render a paragraph for the errors' do
::Formtastic::SemanticFormBuilder.inline_errors = :sentence
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => type))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.error p.inline-errors')
end
it 'should not display an error list' do
::Formtastic::SemanticFormBuilder.inline_errors = :list
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => type))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.error ul.errors')
end
end
describe 'when there are no errors on the object for this method' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => type))
end
end
it 'should not apply an errors class to the list item' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.error')
end
it 'should not render a paragraph for the errors' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.error p.inline-errors')
end
it 'should not display an error list' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.error ul.errors')
end
end
describe 'when no object is provided' do
before do
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ @form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:title, :as => type))
end
end
it 'should not apply an errors class to the list item' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.error')
end
it 'should not render a paragraph for the errors' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.error p.inline-errors')
end
it 'should not display an error list' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.error ul.errors')
end
end
@@ -218,7 +245,7 @@ def it_should_apply_error_logic_for_input_type(type)
def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
it "should call find on the association class when no collection is provided" do
::Author.should_receive(:find)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as))
end
end
@@ -240,9 +267,10 @@ def it_should_use_the_collection_when_provided(as, countable)
end
it 'should use the provided collection' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :collection => @authors))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li.#{as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
end
@@ -252,9 +280,10 @@ def it_should_use_the_collection_when_provided(as, countable)
end
it "should use the string as the label text and value for each #{countable}" do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:category_name, :as => as, :collection => @categories))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
@categories.each do |value|
output_buffer.should have_tag("form li.#{as}", /#{value}/)
@@ -265,11 +294,13 @@ def it_should_use_the_collection_when_provided(as, countable)
if as == :radio
it 'should generate a sanitized label for attribute' do
@bob.stub!(:category_name).and_return(@categories)
- semantic_form_for(@new_post) do |builder|
- builder.semantic_fields_for(@bob) do |bob_builder|
+ form = semantic_form_for(@new_post) do |builder|
+ fields = builder.semantic_fields_for(@bob) do |bob_builder|
concat(bob_builder.input(:category_name, :as => as, :collection => @categories))
end
+ concat(fields)
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_general']")
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_design']")
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_development']")
@@ -284,9 +315,10 @@ def it_should_use_the_collection_when_provided(as, countable)
end
it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:category_name, :as => as, :collection => @categories))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
@categories.each do |label, value|
output_buffer.should have_tag("form li.#{as}", /#{label}/)
@@ -301,9 +333,10 @@ def it_should_use_the_collection_when_provided(as, countable)
end
it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:category_name, :as => as, :collection => @categories))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
@categories.each do |text, value|
label = as == :select ? :option : :label
@@ -321,9 +354,10 @@ def it_should_use_the_collection_when_provided(as, countable)
end
it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:category_name, :as => as, :collection => @choices))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_true")
output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_false")
@@ -337,9 +371,10 @@ def it_should_use_the_collection_when_provided(as, countable)
end
it "should use the symbol as the label text and value for each #{countable}" do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:category_name, :as => as, :collection => @categories))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
@categories.each do |value|
label = as == :select ? :option : :label
@@ -355,9 +390,10 @@ def it_should_use_the_collection_when_provided(as, countable)
end
it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:category_name, :as => as, :collection => @categories))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
@categories.each do |label, value|
output_buffer.should have_tag("form li.#{as}", /#{label}/)
@@ -371,12 +407,13 @@ def it_should_use_the_collection_when_provided(as, countable)
describe 'as a symbol' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :label_method => :login))
end
end
it 'should have options with text content from the specified method' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Author.find(:all).each do |author|
output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
end
@@ -385,12 +422,13 @@ def it_should_use_the_collection_when_provided(as, countable)
describe 'as a proc' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
end
end
it 'should have options with the proc applied to each' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Author.find(:all).each do |author|
output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
end
@@ -407,12 +445,13 @@ def it_should_use_the_collection_when_provided(as, countable)
@fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method }
::Author.find(:all).each { |a| a.stub!(label_method).and_return('The Label Text') }
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as))
end
end
it "should render the options with #{label_method} as the label" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Author.find(:all).each do |author|
output_buffer.should have_tag("form li.#{as}", /The Label Text/)
end
@@ -426,12 +465,13 @@ def it_should_use_the_collection_when_provided(as, countable)
describe 'as a symbol' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :value_method => :login))
end
end
it 'should have options with values from specified method' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Author.find(:all).each do |author|
output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
end
@@ -440,12 +480,13 @@ def it_should_use_the_collection_when_provided(as, countable)
describe 'as a proc' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
end
end
it 'should have options with the proc applied to each value' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Author.find(:all).each do |author|
output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
end
View
20 spec/form_helper_spec.rb
@@ -19,48 +19,56 @@
end
it 'adds a class of "formtastic" to the generated form' do
- semantic_form_for(:post, ::Post.new, :url => '/hello') do |builder|
+ form = semantic_form_for(:post, ::Post.new, :url => '/hello') do |builder|
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form.formtastic")
end
it 'adds class matching the object name to the generated form when a symbol is provided' do
- semantic_form_for(:post, ::Post.new, :url => '/hello') do |builder|
+ form = semantic_form_for(:post, ::Post.new, :url => '/hello') do |builder|
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form.post")
- semantic_form_for(:project, :url => '/hello') do |builder|
+ form = semantic_form_for(:project, :url => '/hello') do |builder|
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form.project")
end
it 'adds class matching the object\'s class to the generated form when an object is provided' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form.post")
end
it 'adds a namespaced class to the generated form' do
- semantic_form_for(::Namespaced::Post.new, :url => '/hello') do |builder|
+ form = semantic_form_for(::Namespaced::Post.new, :url => '/hello') do |builder|
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form.namespaced_post")
end
describe 'allows :html options' do
before(:each) do
- semantic_form_for(:post, ::Post.new, :url => '/hello', :html => { :id => "something-special", :class => "something-extra", :multipart => true }) do |builder|
+ @form = semantic_form_for(:post, ::Post.new, :url => '/hello', :html => { :id => "something-special", :class => "something-extra", :multipart => true }) do |builder|
end
end
it 'to add a id of "something-special" to generated form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form#something-special")
end
it 'to add a class of "something-extra" to generated form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form.something-extra")
end
it 'to add enctype="multipart/form-data"' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form[@enctype="multipart/form-data"]')
end
end
View
6 spec/i18n_spec.rb
@@ -108,16 +108,18 @@
end
it "should be able to translate with namespaced object" do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form label", /Hello post!/)
end
it "should be able to translate without form-object" do
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:title))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form label", /Hello project!/)
end
View
12 spec/include_blank_spec.rb
@@ -24,9 +24,10 @@
it 'blank value should be included if the default value specified in config is true' do
::Formtastic::SemanticFormBuilder.include_blank_for_select_by_default = true
@select_input_types.each do |as, attribute|
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(attribute, :as => as))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li select option[@value='']", "")
end
end
@@ -34,9 +35,10 @@
it 'blank value should not be included if the default value specified in config is false' do
::Formtastic::SemanticFormBuilder.include_blank_for_select_by_default = false
@select_input_types.each do |as, attribute|
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(attribute, :as => as))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li select option[@value='']", "")
end
end
@@ -49,9 +51,10 @@
describe 'when :include_blank is set to false' do
it 'should not have a blank option' do
@select_input_types.each do |as, attribute|
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(attribute, :as => as, :include_blank => false))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li select option[@value='']", "")
end
end
@@ -60,9 +63,10 @@
describe 'when :include_blank => true is set' do
it 'should have a blank select option' do
@select_input_types.each do |as, attribute|
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(attribute, :as => as, :include_blank => true))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li select option[@value='']", "")
end
end
View
117 spec/input_spec.rb
@@ -38,7 +38,7 @@
it 'should require the first argument (the method on form\'s object)' do
lambda {
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input()) # no args passed in at all
end
}.should raise_error(ArgumentError)
@@ -59,17 +59,19 @@
end
it 'should set a "required" class' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :required => true))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.optional')
output_buffer.should have_tag('form li.required')
end
it 'should append the "required" string to the label' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :required => true))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.required label', /#{@new_string}$/)
end
@@ -87,17 +89,19 @@
end
it 'should set an "optional" class' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :required => false))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.required')
output_buffer.should have_tag('form li.optional')
end
it 'should append the "optional" string to the label' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :required => false))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.optional label', /#{@string}$/)
end
@@ -111,9 +115,10 @@
::Formtastic::SemanticFormBuilder.all_fields_required_by_default.should == true
::Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
- semantic_form_for(:project, :url => 'http://test.host/') do |builder|
+ form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
concat(builder.input(:title))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.required')
output_buffer.should have_tag('form li.optional')
@@ -139,10 +144,11 @@
mock('MacroReflection', :macro => :validates_presence_of, :name => :body, :options => {:if => true})
])
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
concat(builder.input(:body))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.required')
output_buffer.should_not have_tag('form li.optional')
end
@@ -194,9 +200,11 @@ def should_be_required(options)
mock('MacroReflection', :macro => :validates_presence_of, :name => :body, :options => options[:options])
])
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:body))
end
+
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
if options[:required]
output_buffer.should_not have_tag('form li.optional')
@@ -213,9 +221,10 @@ def should_be_required(options)
end
it 'should not be required' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.required')
output_buffer.should have_tag('form li.optional')
end
@@ -229,9 +238,10 @@ def should_be_required(options)
::Formtastic::SemanticFormBuilder.all_fields_required_by_default.should == true
::Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li.required')
output_buffer.should have_tag('form li.optional')
@@ -251,18 +261,20 @@ def should_be_required(options)
describe 'when not provided' do
it 'should default to a string for forms without objects unless column is password' do
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:anything))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.string')
end
it 'should default to password for forms without objects if column is password' do
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:password))
concat(builder.input(:password_confirmation))
concat(builder.input(:confirm_password))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.password', :count => 3)
end
@@ -337,7 +349,8 @@ def should_be_required(options)
column = mock('column')
::Formtastic::SemanticFormBuilder.file_methods.each do |test|
- column.stub!(:respond_to?).with(test).and_return(method == test)
+ ### TODO: Check if this is ok
+ column.stub!(method).with(test).and_return(method == test)
end
@new_post.should_receive(method).and_return(column)
@@ -377,23 +390,27 @@ def should_be_required(options)
describe 'when provided' do
it 'should be passed down to the label tag' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :label => "Kustom"))
end
+
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label", /Kustom/)
end
it 'should not generate a label if false' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :label => false))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li label")
end
it 'should be dupped if frozen' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :label => "Kustom".freeze))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label", /Kustom/)
end
end
@@ -408,10 +425,11 @@ def should_be_required(options)
@new_post.stub!(:meta_description)
@new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return(@localized_label_text)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:meta_description))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label', @localized_label_text)
end
end
@@ -424,10 +442,11 @@ def should_be_required(options)
it 'should default the humanized method name, passing it down to the label tag' do
::Formtastic::SemanticFormBuilder.label_str_method = :humanize
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:meta_description))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
end
end
@@ -437,10 +456,11 @@ def should_be_required(options)
@new_post.stub!(:meta_description) # a two word method name
@new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:meta_description))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
end
end
@@ -450,10 +470,11 @@ def should_be_required(options)
with_config :label_str_method, :capitalize do
@new_post.stub!(:meta_description)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:meta_description))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label", /#{'meta_description'.capitalize}/)
end
end
@@ -479,10 +500,11 @@ def should_be_required(options)
end
it 'should render a label with localized label (I18n)' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :label => true))
concat(builder.input(:published, :as => :boolean, :label => true))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label', @localized_label_text)
end
@@ -496,10 +518,11 @@ def should_be_required(options)
}
}
}
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :label => true))
concat(builder.input(:published, :as => :boolean, :label => true))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label', @default_localized_label_text)
end
end
@@ -512,9 +535,10 @@ def should_be_required(options)
describe 'when provided' do
it 'should be passed down to the paragraph tag' do
hint_text = "this is the title of the post"
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :hint => hint_text))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li p.inline-hints", hint_text)
end
end
@@ -528,43 +552,47 @@ def should_be_required(options)
:formtastic => {
:hints => {
:title => @default_localized_hint_text,
- :post => {
- :title => @localized_hint_text
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
end
-
+
+ after do
+ ::I18n.backend.reload!
+ end
+
describe 'when provided value (hint value) is set to TRUE' do
it 'should render a hint paragraph containing a localized hint (I18n)' do
- semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :hint => true))
- end
- output_buffer.should have_tag('form li p.inline-hints', @localized_hint_text)
- end
-
- it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
::I18n.backend.store_translations :en,
:formtastic => {
:hints => {
:post => {
- :title => nil
+ :title => @localized_hint_text
}
}
}
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :hint => true))
+ end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
+ output_buffer.should have_tag('form li p.inline-hints', @localized_hint_text)
+ end
+
+ it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :hint => true))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li p.inline-hints', @default_localized_hint_text)
end
end
describe 'when provided value (label value) is set to FALSE' do
it 'should not render a hint paragraph' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :hint => false))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li p.inline-hints', @localized_hint_text)
end
end
@@ -572,9 +600,10 @@ def should_be_required(options)
describe 'when localized hint (I18n) is not provided' do
it 'should not render a hint paragraph' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li p.inline-hints')
end
end
@@ -586,25 +615,28 @@ def should_be_required(options)
describe 'when provided' do
it 'should be passed down to the li tag' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :wrapper_html => {:id => :another_id}))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li#another_id")
end
it 'should append given classes to li default classes' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :wrapper_html => {:class => :another_class}, :required => true))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li.string")
output_buffer.should have_tag("form li.required")
output_buffer.should have_tag("form li.another_class")
end
it 'should allow classes to be an array' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :wrapper_html => {:class => [ :my_class, :another_class ]}))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li.string")
output_buffer.should have_tag("form li.my_class")
output_buffer.should have_tag("form li.another_class")
@@ -613,9 +645,10 @@ def should_be_required(options)
describe 'when not provided' do
it 'should use default id and class' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li#post_title_input")
output_buffer.should have_tag("form li.string")
end
View
19 spec/inputs/boolean_input_spec.rb
@@ -9,16 +9,17 @@
@output_buffer = ''
mock_everything
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean))
end
end
-
+
it_should_have_input_wrapper_with_class("boolean")
it_should_have_input_wrapper_with_id("post_allow_comments_input")
it_should_apply_error_logic_for_input_type(:boolean)
it 'should generate a label containing the input' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label', :count => 1)
output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
output_buffer.should have_tag('form li label', /Allow comments/)
@@ -26,6 +27,7 @@
end
it 'should generate a checkbox input' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label input')
output_buffer.should have_tag('form li label input#post_allow_comments')
output_buffer.should have_tag('form li label input[@type="checkbox"]')
@@ -34,19 +36,22 @@
end
it 'should allow checked and unchecked values to be sent' do
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]')
output_buffer.should have_tag('form li label input[@type="hidden"][@value="unchecked"]')
end
it 'should generate a label and a checkbox even if no object is given' do
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:allow_comments, :as => :boolean))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
+
output_buffer.should have_tag('form li label[@for="project_allow_comments"]')
output_buffer.should have_tag('form li label', /Allow comments/)
output_buffer.should have_tag('form li label input[@type="checkbox"]')
@@ -66,13 +71,14 @@
@new_post.stub!(:allow_comments).and_return(true)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean, :selected => false))
end
end
end
it 'should not be selected' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li label input[@type='checkbox'][@checked='checked']")
end
end
@@ -82,13 +88,14 @@
@new_post.stub!(:allow_comments).and_return(false)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean, :selected => true))
end
end
end
it 'should be selected' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li label input[@type='checkbox'][@checked='checked']")
end
end
View
35 spec/inputs/check_boxes_input_spec.rb
@@ -10,7 +10,7 @@
@output_buffer = ''
mock_everything
- semantic_form_for(@fred) do |builder|
+ @form = semantic_form_for(@fred) do |builder|
concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true))
end
end
@@ -23,31 +23,37 @@
it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
it 'should generate a legend containing a label with text for the input' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li fieldset legend.label label')
output_buffer.should have_tag('form li fieldset legend.label label', /Posts/)
end
it 'should not link the label within the legend to any input' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
end
it 'should generate an ordered list with a list item for each choice' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li fieldset ol')
output_buffer.should have_tag('form li fieldset ol li', :count => ::Post.find(:all).size)
end
it 'should have one option with a "checked" attribute' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li input[@checked]', :count => 1)
end
it 'should generate hidden inputs with default value blank' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.find(:all).size)
end
describe "each choice" do
it 'should contain a label for the radio input with a nested input and label text' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Post.find(:all).each do |post|
output_buffer.should have_tag('form li fieldset ol li label', /#{post.to_label}/)
output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
@@ -55,12 +61,14 @@
end
it 'should use values as li.class when value_as_class is true' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Post.find(:all).each do |post|
output_buffer.should have_tag("form li fieldset ol li.post_#{post.id} label")
end
end
it 'should have a checkbox input for each post' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Post.find(:all).each do |post|
output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
@@ -69,6 +77,7 @@
it "should mark input as checked if it's the the existing choice" do
::Post.find(:all).include?(@fred.posts.first).should be_true
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
end
end
@@ -76,20 +85,23 @@
describe 'and no object is given' do
before(:each) do
output_buffer.replace ''
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ @form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.find(:all)))
end
end
it 'should generate a fieldset with legend' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li fieldset legend', /Author/)
end
it 'shold generate an li tag for each item in the collection' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.find(:all).size)
end
it 'should generate labels for each item' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Author.find(:all).each do |author|
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
@@ -97,6 +109,7 @@
end
it 'should generate inputs for each item' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
::Author.find(:all).each do |author|
output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
output_buffer.should have_tag("form li fieldset ol li label input[@type='checkbox']")
@@ -116,13 +129,14 @@
@new_post.stub!(:author_ids).and_return(nil)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :selected => nil))
end
end
end
it 'should not have any selected item(s)' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li fieldset ol li label input[@checked='checked']")
end
end
@@ -132,13 +146,14 @@
@new_post.stub!(:author_ids).and_return(nil)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :selected => @fred.id))
end
end
end
it "should have one item selected; the specified one" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']", :count => 1)
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked'][@value='#{@fred.id}']")
@@ -150,13 +165,14 @@
@new_post.stub!(:author_ids).and_return(nil)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :selected => [@bob.id, @fred.id]))
end
end
end
it "should have multiple items selected; the specified ones" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']", :count => 2)
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked'][@value='#{@bob.id}']")
@@ -186,12 +202,13 @@
before do
@new_post.stub!(:author_ids).and_return(nil)
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
end
end
it 'should not have any disabled item(s)' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li fieldset ol li label input[@disabled='disabled']")
end
end
@@ -200,12 +217,13 @@
before do
@new_post.stub!(:author_ids).and_return(nil)
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
end
end
it "should have one item disabled; the specified one" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
@@ -216,12 +234,13 @@
before do
@new_post.stub!(:author_ids).and_return(nil)
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
end
end
it "should have multiple items disabled; the specified ones" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
View
6 spec/inputs/country_input_spec.rb
@@ -25,8 +25,8 @@
describe "when country_select is available as a helper (from a plugin)" do
before do
- semantic_form_for(@new_post) do |builder|
- builder.stub!(:country_select).and_return("<select><option>...</option></select>")
+ @form = semantic_form_for(@new_post) do |builder|
+ builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
concat(builder.input(:country, :as => :country))
end
end
@@ -38,12 +38,14 @@
#it_should_apply_error_logic_for_input_type(:country)
it 'should generate a label for the input' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li label')
output_buffer.should have_tag('form li label[@for="post_country"]')
output_buffer.should have_tag('form li label', /Country/)
end
it "should generate a select" do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li select")
end
View
28 spec/inputs/date_input_spec.rb
@@ -14,7 +14,7 @@
before do
output_buffer.replace ''
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:publish_at, :as => :date))
end
end
@@ -25,10 +25,12 @@
it_should_apply_error_logic_for_input_type(:date)
it 'should have a legend and label with the label text inside the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.date fieldset legend.label label', /Publish at/)
end
it 'should associate the legend label with the first select' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.date fieldset legend.label')
output_buffer.should have_tag('form li.date fieldset legend.label label')
output_buffer.should have_tag('form li.date fieldset legend.label label[@for]')
@@ -36,11 +38,13 @@
end
it 'should have an ordered list of three items inside the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.date fieldset ol')
output_buffer.should have_tag('form li.date fieldset ol li', :count => 3)
end
it 'should have three labels for year, month and day' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
@@ -48,6 +52,7 @@
end
it 'should have three selects for year, month and day' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.date fieldset ol li select', :count => 3)
end
end
@@ -59,10 +64,11 @@
output_buffer.replace ''
@new_post.stub!(:created_at => Time.mktime(2012))
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :date, :selected => Time.mktime(1999)))
end
end
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='2012'][@selected]", :count => 1)
end
@@ -73,10 +79,11 @@
output_buffer.replace ''
@new_post.stub!(:created_at => nil)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :date, :selected => Date.new(1999)))
end
end
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
end
@@ -85,10 +92,11 @@
output_buffer.replace ''
@new_post.stub!(:created_at => nil)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :date, :selected => Time.mktime(1999)))
end
end
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
end
@@ -97,19 +105,21 @@
output_buffer.replace ''
@new_post.stub!(:created_at => nil)
with_deprecation_silenced do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :date, :selected => nil))
end
end
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form li ol li select#post_created_at_1i option[@selected]")
end
it "should select Time.now if a :selected is not provided" do
output_buffer.replace ''
@new_post.stub!(:created_at => nil)
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :date))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='#{Time.now.year}'][@selected]", :count => 1)
@@ -123,9 +133,10 @@
fields.each do |field|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
output_buffer.replace ''
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :date, :labels => { field => "another #{field} label" }))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length)
fields.each do |f|
output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
@@ -134,9 +145,10 @@
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
output_buffer.replace ''
- semantic_form_for(@new_post) do |builder|
+ form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :date, :labels => { field => "" }))
end
+ output_buffer.concat(form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
fields.each do |f|
output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
View
45 spec/inputs/datetime_input_spec.rb
@@ -19,7 +19,7 @@
before do
output_buffer.replace ''
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:publish_at, :as => :datetime))
end
end
@@ -30,19 +30,23 @@
it_should_apply_error_logic_for_input_type(:datetime)