Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove deprecated ButtonsHelper, buttons DSL and commit_button helper

  • Loading branch information...
commit 9ccff73ae07207e11f78a580934ee8c3a8ebf94b 1 parent 30a7644
@justinfrench authored
View
6 CHANGELOG
@@ -1,3 +1,9 @@
+HEAD
+
+* removed deprecated buttons DSL, ButtonHelper and commit_button helper
+
+2.1.0
+
2.1.0.rc
* documentation improvements
View
1  lib/formtastic/form_builder.rb
@@ -41,7 +41,6 @@ def self.configure(name, value = nil)
include Formtastic::Helpers::InputHelper
include Formtastic::Helpers::InputsHelper
- include Formtastic::Helpers::ButtonsHelper
include Formtastic::Helpers::ActionHelper
include Formtastic::Helpers::ActionsHelper
include Formtastic::Helpers::ErrorsHelper
View
310 lib/formtastic/helpers/buttons_helper.rb
@@ -1,310 +0,0 @@
-module Formtastic
- module Helpers
-
- # ButtonsHelper encapsulates the responsibilties of the {#buttons} and {#commit_button} helpers
- # for submitting forms.
- #
- # {#buttons} is used to wrap the form's button(s) and actions in a `<fieldset>` and `<ol>`,
- # with each item in the list containing the markup representing a single button.
- #
- # {#buttons} is usually called with a block containing a single {#commit_button} call:
- #
- # <%= semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons do %>
- # <%= f.commit_button
- # <% end %>
- # <% end %>
- #
- # The HTML output will be something like:
- #
- # <form class="formtastic" method="post" action="...">
- # ...
- # <fieldset class="buttons">
- # <ol>
- # <li class="commit button">
- # <input type="submit" name="commit" value="Create Post" class="create">
- # </li>
- # </ol>
- # </fieldset>
- # </form>
- #
- # While this may seem slightly over-engineered, it is consistent with the way form inputs are
- # handled, and makes room for other types of buttons and actions in future versions (such as
- # cancel buttons or links, reset buttons and even alternate actions like 'save and continue
- # editing').
- #
- # It's important to note that the `semantic_form_for` and {#buttons} blocks wrap the
- # standard Rails `form_for` helper and form builder, so you have full access to every standard
- # Rails form helper, with any HTML markup and ERB syntax, allowing you to "break free" from
- # Formtastic when it doesn't suit to create your own buttons, links and actions:
- #
- # <%= semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons do %>
- # <li class="save">
- # <%= f.submit "Save" %>
- # <li>
- # <li class="cancel-link">
- # Or <%= link_to "Cancel", posts_url %>
- # <li>
- # <% end %>
- # <% end %>
- #
- # There are many other syntax variations and arguments to customize your form. See the
- # full documentation of {#buttons} and {#commit_button} for details.
- #
- # @deprecated ButtonsHelper will be removed after 2.1
- module ButtonsHelper
- include Formtastic::Helpers::FieldsetWrapper
- include Formtastic::LocalizedString
-
- # Creates a fieldset and ol tag wrapping for use around a set of buttons. It can be
- # called either with a block (in which you can do the usual Rails form stuff, HTML, ERB, etc),
- # or with a list of named buttons. These two examples are functionally equivalent:
- #
- # # With a block:
- # <% semantic_form_for @post do |f| %>
- # ...
- # <% f.buttons do %>
- # <%= f.commit_button %>
- # <% end %>
- # <% end %>
- #
- # # With a list of fields:
- # <% semantic_form_for @post do |f| %>
- # <%= f.buttons :commit %>
- # <% end %>
- #
- # # Output:
- # <form ...>
- # <fieldset class="buttons">
- # <ol>
- # <li class="commit button">
- # <input type="submit" ...>
- # </li>
- # </ol>
- # </fieldset>
- # </form>
- #
- # Only one type of named button is supported at this time (:commit), and it's assumed to be
- # the default choice, so this is also functionally equivalent, but may change in the future:
- #
- # # With no args:
- # <% semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons %>
- # <% end %>
- #
- # While this may seem slightly over-engineered, it is consistent with the way form inputs are
- # handled, and makes room for other types of buttons and actions in future versions (such as
- # cancel buttons or links, reset buttons and even alternate actions like 'save and continue
- # editing').
- #
- # All options except `:name` and `:title` are passed down to the fieldset as HTML
- # attributes (`id`, `class`, `style`...). If provided, the `:name` or `:title` option is
- # passed into a `<legend>` inside the `<fieldset>` to name the set of buttons.
- #
- # @example Quickly add button(s) to the form, accepting all default values, options and behaviors
- # <% semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons %>
- # <% end %>
- #
- # @example Specify which named buttons you want, accepting all default values, options and behaviors
- # <% semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons :commit %>
- # <% end %>
- #
- # @example Specify which named buttons you want, and name the fieldset
- # <% semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons :commit, :name => "Actions" %>
- # or
- # <%= f.buttons :commit, :label => "Actions" %>
- # <% end %>
- #
- # @example Get full control over the commit_button options
- # <% semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons do %>
- # <%= f.commit_button :label => "Go", :button_html => { :class => "pretty" :disable_with => "Wait..." }, :wrapper_html => { ... }
- # <% end %>
- # <% end %>
- #
- # @example Make your own custom buttons, links or actions with standard Rails helpers or HTML
- # <% semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons do %>
- # <li class="submit">
- # <%= f.submit "Submit" %>
- # </li>
- # <li class="reset">
- # <input type="reset" value="Reset">
- # </li>
- # <li class="cancel">
- # <%= link_to "Cancel", posts_url %>
- # </li>
- # <% end %>
- # <% end %>
- #
- # @example Add HTML attributes to the fieldset
- # <% semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons :commit, :style => "border:1px;" %>
- # or
- # <%= f.buttons :style => "border:1px;" do %>
- # ...
- # <% end %>
- # <% end %>
- #
- # @option *args :label [String, Symbol]
- # Optionally specify text for the legend of the fieldset
- #
- # @option *args :name [String, Symbol]
- # Optionally specify text for the legend of the fieldset (alias for `:label`)
- #
- # @todo document i18n keys
- # @deprecated f.buttons is deprecated in favor of f.actions and will be removed after 2.1
- def buttons(*args, &block)
- ::ActiveSupport::Deprecation.warn("f.buttons is deprecated in favour of f.actions and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")
-
- html_options = args.extract_options!
- html_options[:class] ||= "buttons"
-
- if block_given?
- field_set_and_list_wrapping(html_options, &block)
- else
- args = [:commit] if args.empty?
- contents = args.map { |button_name| send(:"#{button_name}_button") }
- field_set_and_list_wrapping(html_options, contents)
- end
- end
-
- # Creates a submit input tag with the value "Save [model name]" (for existing records) or
- # "Create [model name]" (for new records) by default. The output is an `<input>` tag with the
- # `type` of `submit` and a class of either `create` or `update` (if Formtastic can determin if)
- # the record is new or not) with `submit` as a fallback class. The submit button is wrapped in
- # an `<li>` tag with a class of `commit`, and is intended to be rendered inside a {#buttons}
- # block which wraps the button in a `fieldset` and `ol`.
- #
- # The textual value of the label can be changed from this default through the `:label`
- # argument or through i18n.
- #
- # You can pass HTML attributes down to the `<input>` tag with the `:button_html` option, and
- # pass HTML attributes to the wrapping `<li>` tag with the `:wrapper_html` option.
- #
- # @example Basic usage
- # # form
- # <%= semantic_form_for @post do |f| %>
- # ...
- # <%= f.buttons do %>
- # <%= f.commit_button %>
- # <% end %>
- # <% end %>
- #
- # # output
- # <form ...>
- # ...
- # <fieldset class="buttons">
- # <ol>
- # <li class="commit button">
- # <input name="commit" type="submit" value="Create Post" class="create">
- # </li>
- # </ol>
- # </fieldset>
- # </form>
- #
- # @example Set the value through the `:label` option
- # <%= f.commit_button :label => "Go" %>
- #
- # @example Set the value through the optional first argument (like Rails' `f.submit`)
- # <%= f.commit_button "Go" %>
- #
- # @example Pass HTML attributes down to the `<input>`
- # <%= f.commit_button :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
- # <%= f.commit_button :label => "Go", :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
- # <%= f.commit_button "Go", :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
- #
- # @example Pass HTML attributes down to the `<li>` wrapper
- # <%= f.commit_button :wrapper_html => { :class => 'special', :id => 'whatever' } %>
- # <%= f.commit_button :label => "Go", :wrapper_html => { :class => 'special', :id => 'whatever' } %>
- # <%= f.commit_button "Go", :wrapper_html => { :class => 'special', :id => 'whatever' } %>
- #
- # @option *args :label [String, Symbol]
- # Override the label text with a String or a symbold for an i18n translation key
- #
- # @option *args :button_html [Hash]
- # Override or add to the HTML attributes to be passed down to the `<input>` tag
- #
- # @option *args :wrapper_html [Hash]
- # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
- #
- # @todo document i18n keys
- # @todo strange that `:accesskey` seems to be supported in the top level args as well as `:button_html`
- # @deprecated f.commit_button is deprecated in favor of f.actions and will be removed after 2.1
- def commit_button(*args)
- ::ActiveSupport::Deprecation.warn("f.commit_button is deprecated in favour of f.action(:submit) and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")
-
- options = args.extract_options!
- text = options.delete(:label) || args.shift
-
- text = (localized_string(commit_button_i18n_key, text, :action, :model => commit_button_object_name) ||
- Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)
-
- button_html = options.delete(:button_html) || {}
- button_html[:id] ||= "#{@object_name}_submit"
- button_html.merge!(:class => [button_html[:class], commit_button_i18n_key].compact.join(' '))
-
- wrapper_html = options.delete(:wrapper_html) || {}
- wrapper_html[:class] = (commit_button_wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
-
- accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
- button_html = button_html.merge(:accesskey => accesskey) if accesskey
-
- template.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
- end
-
- def commit_button_object_name
- if new_or_persisted_object?
- # Deal with some complications with ActiveRecord::Base.human_name and two name models (eg UserPost)
- # ActiveRecord::Base.human_name falls back to ActiveRecord::Base.name.humanize ("Userpost")
- # if there's no i18n, which is pretty crappy. In this circumstance we want to detect this
- # fall back (human_name == name.humanize) and do our own thing name.underscore.humanize ("User Post")
- if @object.class.model_name.respond_to?(:human)
- object_name = @object.class.model_name.human
- else
- object_human_name = @object.class.human_name # default is UserPost => "Userpost", but i18n may do better ("User post")
- crappy_human_name = @object.class.name.humanize # UserPost => "Userpost"
- decent_human_name = @object.class.name.underscore.humanize # UserPost => "User post"
- object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
- end
- else
- object_name = @object_name.to_s.send(label_str_method)
- end
-
- object_name
- end
-
- def commit_button_i18n_key
- if new_or_persisted_object?
- key = @object.persisted? ? :update : :create
- else
- key = :submit
- end
-
- key
- end
-
- def commit_button_wrapper_html_class
- ['commit', 'button'] # TODO: Add class reflecting on form action.
- end
-
- def new_or_persisted_object?
- @object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
- end
-
- end
- end
-end
View
166 spec/helpers/buttons_helper_spec.rb
@@ -1,166 +0,0 @@
-# encoding: utf-8
-require 'spec_helper'
-
-describe 'Formtastic::FormBuilder#buttons' do
-
- include FormtasticSpecHelper
-
- before do
- @output_buffer = ''
- mock_everything
- end
-
- describe 'with a block' do
- describe 'when no options are provided' do
- before do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- buttons = builder.buttons do
- concat('hello')
- end
- concat(buttons)
- end)
- end
- end
-
- it 'should render a fieldset inside the form, with a class of "inputs"' do
- output_buffer.should have_tag("form fieldset.buttons")
- end
-
- it 'should render an ol inside the fieldset' do
- output_buffer.should have_tag("form fieldset.buttons ol")
- end
-
- it 'should render the contents of the block inside the ol' do
- output_buffer.should have_tag("form fieldset.buttons ol", /hello/)
- end
-
- it 'should not render a legend inside the fieldset' do
- output_buffer.should_not have_tag("form fieldset.buttons legend")
- end
- end
-
- describe 'when a :name option is provided' do
- before do
- @legend_text = "Advanced options"
-
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- builder.buttons :name => @legend_text do
- end
- end)
- end
- end
-
- it 'should render a fieldset inside the form' do
- output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
- end
-
- end
-
- describe 'when other options are provided' do
- before do
- @id_option = 'advanced'
- @class_option = 'wide'
-
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- builder.buttons :id => @id_option, :class => @class_option do
- end
- end)
- end
- end
-
- it 'should pass the options into the fieldset tag as attributes' do
- output_buffer.should have_tag("form fieldset##{@id_option}")
- output_buffer.should have_tag("form fieldset.#{@class_option}")
- end
-
- end
-
- end
-
- describe 'without a block' do
-
- describe 'with no args (default buttons)' do
-
- before do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.buttons)
- end)
- end
- end
-
- it 'should render a form' do
- output_buffer.should have_tag('form')
- end
-
- it 'should render a buttons fieldset inside the form' do
- output_buffer.should have_tag('form fieldset.buttons')
- end
-
- it 'should not render a legend in the fieldset' do
- output_buffer.should_not have_tag('form fieldset.buttons legend')
- end
-
- it 'should render an ol in the fieldset' do
- 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.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.should have_tag('form fieldset.buttons ol li.commit')
- end
-
- end
-
- describe 'with button names as args' do
-
- before do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.buttons(:commit))
- end)
- end
- end
-
- it 'should render a form with a fieldset containing a list item for each button arg' do
- output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
- output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit')
- end
-
- end
-
- describe 'with button names as args and an options hash' do
-
- before do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.buttons(:commit, :name => "Now click a button", :id => "my-id"))
- end)
- end
- end
-
- it 'should render a form with a fieldset containing a list item for each button arg' do
- 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.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.should have_tag('form > fieldset#my-id.buttons > legend', /Now click a button/)
- end
-
- end
-
- end
-
-end
-
View
530 spec/helpers/commit_button_helper_spec.rb
@@ -1,530 +0,0 @@
-# encoding: utf-8
-require 'spec_helper'
-
-describe 'Formtastic::FormBuilder#commit_button' do
-
- include FormtasticSpecHelper
-
- before do
- @output_buffer = ''
- mock_everything
- end
-
- describe 'when the object responds to :persisted? (ActiveModel)' do
-
- before do
- @new_post.stub(:respond_to?).with(:to_model).and_return("X")
- @new_post.stub(:respond_to?).with(:persisted?).and_return(true)
- @new_post.stub(:respond_to?).with(:new_record?).and_return(false)
- end
-
- it 'should call :persisted?' do
- with_deprecation_silenced do
- with_config :i18n_lookups_by_default, false do
- @new_post.should_receive(:persisted?)
- @new_post.should_not_receive(:new_record?)
- semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end
- end
- end
- end
-
- end
-
- describe 'when not persisted' do
-
- before do
- @new_post.stub(:respond_to?).with(:to_model).and_return("X")
- @new_post.stub(:respond_to?).with(:persisted?).and_return(false)
- @new_post.stub(:respond_to?).with(:new_record?).and_return(false)
- end
-
- it 'should have a submit button label' do
- with_deprecation_silenced do
- with_config :i18n_lookups_by_default, false do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- end
-
- output_buffer.should have_tag('.commit input[@value="Submit Post"]')
- end
- end
-
- describe 'when used on any record' do
-
- before do
- @new_post.stub!(:new_record?).and_return(false)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- end
-
- it 'should render a commit li' do
- output_buffer.should have_tag('li.commit')
- end
-
- it 'should render a button li' do
- output_buffer.should have_tag('li.button')
- end
-
- it 'should render an input with a type attribute of "submit"' do
- 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.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)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text', :button_html => {:class => 'my_class', :id => 'my_id'}))
- end)
- end
-
- output_buffer.should have_tag('li.commit input#my_id')
- output_buffer.should have_tag('li.commit input.my_class')
- end
-
- end
-
- describe "its accesskey" do
-
- it 'should allow nil default' do
- with_config :default_commit_button_accesskey, nil do
- output_buffer.should_not have_tag('li.commit input[@accesskey]')
- end
- end
-
- it 'should use the default if set' do
- with_config :default_commit_button_accesskey, 's' do
- @new_post.stub!(:new_record?).and_return(false)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text', :button_html => {}))
- end)
- end
- output_buffer.should have_tag('li.commit input[@accesskey="s"]')
- end
- end
-
- 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)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text', :accesskey => 'o'))
- end)
- end
- output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
- output_buffer.should have_tag('li.commit input[@accesskey="o"]')
- end
- end
-
- 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)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text', :accesskey => 'o', :button_html => {:accesskey => 't'}))
- end)
- end
- 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"]')
- end
- end
-
- end
-
- describe 'when the first option is a string and the second is a hash' do
-
- before do
- @new_post.stub!(:new_record?).and_return(false)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button("a string", :button_html => { :class => "pretty"}))
- end)
- end
- end
-
- it "should render the string as the value of the button" do
- output_buffer.should have_tag('li input[@value="a string"]')
- end
-
- it "should deal with the options hash" do
- output_buffer.should have_tag('li input.pretty')
- end
-
- end
-
- describe 'when the first option is a hash' do
-
- before do
- @new_post.stub!(:new_record?).and_return(false)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button(:button_html => { :class => "pretty"}))
- end)
- end
- end
-
- it "should deal with the options hash" do
- output_buffer.should have_tag('li input.pretty')
- end
-
- end
-
- describe 'label' do
-
- # No object
- describe 'when used without object' do
- describe 'when explicit label is provided' do
- it 'should render an input with the explicitly specified label' do
- with_deprecation_silenced do
- concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
- concat(builder.commit_button("Click!"))
- end)
- end
- output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="submit"]')
- end
- end
-
- describe 'when no explicit label is provided' do
- describe 'when no I18n-localized label is provided' do
- before do
- ::I18n.backend.store_translations :en, :formtastic => {:submit => 'Submit %{model}'}
- end
-
- after do
- ::I18n.backend.reload!
- end
-
- it 'should render an input with default I18n-localized label (fallback)' do
- with_deprecation_silenced do
- concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag('li.commit input[@value="Submit Post"][@class~="submit"]')
- end
- end
-
- describe 'when I18n-localized label is provided' do
- before do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :submit => 'Custom Submit',
- }
- }
- end
-
- after do
- ::I18n.backend.reload!
- end
-
- it 'should render an input with localized label (I18n)' do
- with_config :i18n_lookups_by_default, true do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :post => {
- :submit => 'Custom Submit %{model}'
- }
- }
- }
- with_deprecation_silenced do
- concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
- end
- end
-
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- with_config :i18n_lookups_by_default, true do
- with_deprecation_silenced do
- concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
- end
- end
-
- end
- end
- end
-
- # New record
- describe 'when used on a new record' do
- before do
- @new_post.stub!(:new_record?).and_return(true)
- end
-
- describe 'when explicit label is provided' do
- it 'should render an input with the explicitly specified label' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button("Click!"))
- end)
- end
- output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="create"]')
- end
- end
-
- describe 'when no explicit label is provided' do
- describe 'when no I18n-localized label is provided' do
- before do
- ::I18n.backend.store_translations :en, :formtastic => {:create => 'Create %{model}'}
- end
-
- after do
- ::I18n.backend.reload!
- end
-
- it 'should render an input with default I18n-localized label (fallback)' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag('li.commit input[@value="Create Post"][@class~="create"]')
- end
- end
-
- describe 'when I18n-localized label is provided' do
- before do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :create => 'Custom Create',
- }
- }
- end
-
- after do
- ::I18n.backend.reload!
- end
-
- it 'should render an input with localized label (I18n)' do
- with_config :i18n_lookups_by_default, true do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :post => {
- :create => 'Custom Create %{model}'
- }
- }
- }
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
- end
- end
-
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- with_config :i18n_lookups_by_default, true do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
- end
- end
-
- end
- end
- end
-
- # Existing record
- describe 'when used on an existing record' do
- before do
- @new_post.stub!(:persisted?).and_return(true)
- end
-
- describe 'when explicit label is provided' do
- it 'should render an input with the explicitly specified label' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button("Click!"))
- end)
- end
- output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="update"]')
- end
- end
-
- describe 'when no explicit label is provided' do
- describe 'when no I18n-localized label is provided' do
- before do
- ::I18n.backend.store_translations :en, :formtastic => {:update => 'Save %{model}'}
- end
-
- after do
- ::I18n.backend.reload!
- end
-
- it 'should render an input with default I18n-localized label (fallback)' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- 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 => {
- :update => 'Custom Save',
- }
- }
- end
-
- after do
- ::I18n.backend.reload!
- end
-
- it 'should render an input with localized label (I18n)' do
- with_config :i18n_lookups_by_default, true do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :post => {
- :update => 'Custom Save %{model}'
- }
- }
- }
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
- end
- end
-
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- with_config :i18n_lookups_by_default, true do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
- ::I18n.backend.store_translations :en, :formtastic => {}
- end
- end
-
- end
- end
- end
- end
-
- describe 'when the model is two words' do
- before do
- output_buffer = ''
- 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)
- with_deprecation_silenced do
- concat(semantic_form_for(@new_user_post, :url => '') do |builder|
- concat(builder.commit_button())
- end)
- end
- end
-
- it "should render the string as the value of the button" do
- output_buffer.should have_tag('li input[@value="Create User post"]')
- end
-
- end
-
- describe ':wrapper_html option' do
-
- describe 'when provided' do
- it 'should be passed down to the li tag' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text', :wrapper_html => {:id => :another_id}))
- end)
- end
- output_buffer.should have_tag("form li#another_id")
- end
-
- it 'should append given classes to li default classes' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text', :wrapper_html => {:class => :another_class}))
- end)
- end
- output_buffer.should have_tag("form li.commit")
- output_buffer.should have_tag("form li.another_class")
- end
-
- it 'should allow classes to be an array' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text', :wrapper_html => {:class => [ :my_class, :another_class ]}))
- end)
- end
- output_buffer.should have_tag("form li.commit")
- output_buffer.should have_tag("form li.my_class")
- output_buffer.should have_tag("form li.another_class")
- end
- end
-
- describe 'when not provided' do
- it 'should use default class' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text'))
- end)
- end
- output_buffer.should have_tag("form li.commit.button")
- end
-
- it 'should use default id' do
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button('text'))
- end)
- end
- output_buffer.should have_tag("form li.commit.button input#post_submit")
- end
- end
-
- end
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.