Permalink
Browse files

Use 1.9 hash style on code and docs.

  • Loading branch information...
1 parent e206a53 commit 34312c9fbc00ceb918c55d2ca7d36e3b94be301c @rmascarenhas rmascarenhas committed Jan 28, 2013
Showing with 792 additions and 792 deletions.
  1. +1 −1 CHANGELOG.md
  2. +64 −64 README.md
  3. +1 −1 Rakefile
  4. +3 −3 lib/generators/simple_form/install_generator.rb
  5. +1 −1 lib/generators/simple_form/templates/README
  6. +8 −8 lib/generators/simple_form/templates/config/initializers/simple_form.rb
  7. +14 −14 lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb
  8. +3 −3 lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb
  9. +6 −6 lib/simple_form.rb
  10. +1 −1 lib/simple_form/action_view_extensions/form_helper.rb
  11. +1 −1 lib/simple_form/components.rb
  12. +1 −1 lib/simple_form/components/html5.rb
  13. +3 −3 lib/simple_form/components/labels.rb
  14. +2 −2 lib/simple_form/error_notification.rb
  15. +33 −33 lib/simple_form/form_builder.rb
  16. +1 −1 lib/simple_form/helpers.rb
  17. +2 −2 lib/simple_form/inputs/base.rb
  18. +1 −1 lib/simple_form/inputs/block_input.rb
  19. +1 −1 lib/simple_form/inputs/boolean_input.rb
  20. +6 −6 lib/simple_form/inputs/collection_input.rb
  21. +4 −4 lib/simple_form/tags.rb
  22. +1 −1 lib/simple_form/wrappers.rb
  23. +5 −5 lib/simple_form/wrappers/builder.rb
  24. +63 −63 test/action_view_extensions/builder_test.rb
  25. +12 −12 test/action_view_extensions/form_helper_test.rb
  26. +46 −46 test/components/label_test.rb
  27. +22 −22 test/form_builder/association_test.rb
  28. +4 −4 test/form_builder/button_test.rb
  29. +8 −8 test/form_builder/error_notification_test.rb
  30. +12 −12 test/form_builder/error_test.rb
  31. +43 −43 test/form_builder/general_test.rb
  32. +22 −22 test/form_builder/hint_test.rb
  33. +6 −6 test/form_builder/input_field_test.rb
  34. +6 −6 test/form_builder/label_test.rb
  35. +21 −21 test/form_builder/wrapper_test.rb
  36. +23 −23 test/inputs/boolean_input_test.rb
  37. +55 −55 test/inputs/collection_check_boxes_input_test.rb
  38. +70 −70 test/inputs/collection_radio_buttons_input_test.rb
  39. +45 −45 test/inputs/collection_select_input_test.rb
  40. +11 −11 test/inputs/datetime_input_test.rb
  41. +10 −10 test/inputs/disabled_test.rb
  42. +4 −4 test/inputs/discovery_test.rb
  43. +1 −1 test/inputs/file_input_test.rb
  44. +12 −12 test/inputs/general_test.rb
  45. +20 −20 test/inputs/grouped_collection_select_input_test.rb
  46. +1 −1 test/inputs/hidden_input_test.rb
  47. +3 −3 test/inputs/numeric_input_test.rb
  48. +3 −3 test/inputs/priority_input_test.rb
  49. +12 −12 test/inputs/readonly_test.rb
  50. +5 −5 test/inputs/required_test.rb
  51. +8 −8 test/inputs/string_input_test.rb
  52. +1 −1 test/inputs/text_input_test.rb
  53. +24 −24 test/support/misc_helpers.rb
  54. +37 −37 test/support/models.rb
  55. +19 −19 test/test_helper.rb
View
2 CHANGELOG.md
@@ -117,7 +117,7 @@
* Generate configuration file with `browser_validations` disabled.
* Add option and configuration to specify the collection wrapper class. ([@mfila](https://github.com/mfila))
* Add proc support to `collection` option. ([@jeffkreeftmeijer](https://github.com/jeffkreeftmeijer))
- * `simple_form_for` allows default options for its inputs `:defaults => {}`.
+ * `simple_form_for` allows default options for its inputs `defaults: {}`.
* Add `readonly` as option of input method. ([@Untainted123](https://github.com/Untainted123))
* `simple_fields_for` for inherits wrapper option form the form builder. ([@nashby](https://github.com/nashby))
* Use action prefix in the form css class. Closes [#360](https://github.com/plataformatec/simple_form/issues/360).
View
128 README.md
@@ -95,10 +95,10 @@ even a placeholder. For boolean inputs, you can add an inline label as well:
```erb
<%= simple_form_for @user do |f| %>
- <%= f.input :username, :label => 'Your username please' %>
- <%= f.input :password, :hint => 'No special characters.' %>
- <%= f.input :email, :placeholder => 'user@domain.com' %>
- <%= f.input :remember_me, :inline_label => 'Yes, remember me' %>
+ <%= f.input :username, label: 'Your username please' %>
+ <%= f.input :password, hint: 'No special characters.' %>
+ <%= f.input :email, placeholder: 'user@domain.com' %>
+ <%= f.input :remember_me, inline_label: 'Yes, remember me' %>
<%= f.button :submit %>
<% end %>
```
@@ -108,9 +108,9 @@ of any of them:
```erb
<%= simple_form_for @user do |f| %>
- <%= f.input :username, :label_html => { :class => 'my_class' } %>
- <%= f.input :password, :hint => false, :error_html => { :id => 'password_error'} %>
- <%= f.input :password_confirmation, :label => false %>
+ <%= f.input :username, label_html: { class: 'my_class' } %>
+ <%= f.input :password, hint: false, error_html: { id: 'password_error'} %>
+ <%= f.input :password_confirmation, label: false %>
<%= f.button :submit %>
<% end %>
```
@@ -120,9 +120,9 @@ option, for instance:
```erb
<%= simple_form_for @user do |f| %>
- <%= f.input :username, :input_html => { :class => 'special' } %>
- <%= f.input :password, :input_html => { :maxlength => 20 } %>
- <%= f.input :remember_me, :input_html => { :value => '1' } %>
+ <%= f.input :username, input_html: { class: 'special' } %>
+ <%= f.input :password, input_html: { maxlength: 20 } %>
+ <%= f.input :remember_me, input_html: { value: '1' } %>
<%= f.button :submit %>
<% end %>
```
@@ -132,10 +132,10 @@ you can use the `:defaults` option in `simple_form_for`. Specific options in `in
overwrite the defaults:
```erb
-<%= simple_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f| %>
- <%= f.input :username, :input_html => { :class => 'special' } %>
- <%= f.input :password, :input_html => { :maxlength => 20 } %>
- <%= f.input :remember_me, :input_html => { :value => '1' } %>
+<%= simple_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f| %>
+ <%= f.input :username, input_html: { class: 'special' } %>
+ <%= f.input :password, input_html: { maxlength: 20 } %>
+ <%= f.input :remember_me, input_html: { value: '1' } %>
<%= f.button :submit %>
<% end %>
```
@@ -145,9 +145,9 @@ any html attribute to that wrapper as well using the `:wrapper_html` option, lik
```erb
<%= simple_form_for @user do |f| %>
- <%= f.input :username, :wrapper_html => { :class => 'username' } %>
- <%= f.input :password, :wrapper_html => { :id => 'password' } %>
- <%= f.input :remember_me, :wrapper_html => { :class => 'options' } %>
+ <%= f.input :username, wrapper_html: { class: 'username' } %>
+ <%= f.input :password, wrapper_html: { id: 'password' } %>
+ <%= f.input :remember_me, wrapper_html: { class: 'options' } %>
<%= f.button :submit %>
<% end %>
```
@@ -160,7 +160,7 @@ And of course, the `required` property of any input can be overwritten as needed
```erb
<%= simple_form_for @user do |f| %>
- <%= f.input :name, :required => false %>
+ <%= f.input :name, required: false %>
<%= f.input :username %>
<%= f.input :password %>
<%= f.button :submit %>
@@ -173,23 +173,23 @@ And of course, the `required` property of any input can be overwritten as needed
<%= simple_form_for @user do |f| %>
<%= f.input :username %>
<%= f.input :password %>
- <%= f.input :description, :as => :text %>
- <%= f.input :accepts, :as => :radio_buttons %>
+ <%= f.input :description, as: :text %>
+ <%= f.input :accepts, as: :radio_buttons %>
<%= f.button :submit %>
<% end %>
```
So instead of a checkbox for the *accepts* attribute, you'll have a pair of radio buttons with yes/no
labels and a text area instead of a text field for the description. You can also render boolean
-attributes using `:as => :select` to show a dropdown.
+attributes using `as: :select` to show a dropdown.
It is also possible to give the `:disabled` option to **SimpleForm**, and it'll automatically mark
the wrapper as disabled with a css class, so you can style labels, hints and other components inside
the wrapper as well:
```erb
<%= simple_form_for @user do |f| %>
- <%= f.input :username, :disabled => true, :hint => 'You cannot change your username.' %>
+ <%= f.input :username, disabled: true, hint: 'You cannot change your username.' %>
<%= f.button :submit %>
<% end %>
```
@@ -198,9 +198,9 @@ the wrapper as well:
```erb
<%= simple_form_for @user do |f| %>
- <%= f.input :date_of_birth, :as => :date, :start_year => Date.today.year - 90,
- :end_year => Date.today.year - 12, :discard_day => true,
- :order => [:month, :year] %>
+ <%= f.input :date_of_birth, as: :date, start_year: Date.today.year - 90,
+ end_year: Date.today.year - 12, discard_day: true,
+ order: [:month, :year] %>
<%= f.button :submit %>
<% end %>
```
@@ -213,7 +213,7 @@ the wrapper as well:
<%= f.label :username %>
<%= f.input_field :username %>
<%= f.hint 'No special characters, please!' %>
- <%= f.error :username, :id => 'user_name_error' %>
+ <%= f.error :username, id: 'user_name_error' %>
<%= f.full_error :token %>
<%= f.submit 'Save' %>
<% end %>
@@ -229,13 +229,13 @@ overriding the `:collection` option:
```erb
<%= simple_form_for @user do |f| %>
<%= f.input :user %>
- <%= f.input :age, :collection => 18..60 %>
+ <%= f.input :age, collection: 18..60 %>
<%= f.button :submit %>
<% end %>
```
Collections can be arrays or ranges, and when a `:collection` is given the `:select` input will be
-rendered by default, so we don't need to pass the `:as => :select` option. Other types of collection
+rendered by default, so we don't need to pass the `as: :select` option. Other types of collection
are `:radio_buttons` and `:check_boxes`. Those are added by **SimpleForm** to Rails set of form
helpers (read Extra Helpers session below for more information).
@@ -252,13 +252,13 @@ translation. All other options given are sent straight to the underlying helper.
can give prompt as:
```ruby
-f.input :age, :collection => 18..60, :prompt => "Select your age"
+f.input :age, collection: 18..60, prompt: "Select your age"
```
It is also possible to create grouped collection selects, that will use the html *optgroup* tags, like this:
```ruby
-f.input :country_id, :collection => @continents, :as => :grouped_select, :group_method => :countries
+f.input :country_id, collection: @continents, as: :grouped_select, group_method: :countries
```
Grouped collection inputs accept the same `:label_method` and `:value_method` options, which will be
@@ -277,8 +277,8 @@ used to retrieve label/value attributes for the `option` tags. Besides that, you
`:priority` as option to select which time zones and/or countries should be given higher priority:
```ruby
-f.input :residence_country, :priority => [ "Brazil" ]
-f.input :time_zone, :priority => /US/
+f.input :residence_country, priority: [ "Brazil" ]
+f.input :time_zone, priority: /US/
```
Those values can also be configured with a default value to be used site use through the
@@ -288,7 +288,7 @@ Note: While using `country_select` if you want to restrict to only a subset of c
drop down then you may use the `:collection` option:
```ruby
-f.input :shipping_country, :priority => [ "Brazil" ], :collection => [ "Australia", "Brazil", "New Zealand"]
+f.input :shipping_country, priority: [ "Brazil" ], collection: [ "Australia", "Brazil", "New Zealand"]
```
### Associations
@@ -328,22 +328,22 @@ Simple enough, right? This is going to render a `:select` input for choosing the
buttons and check boxes as well:
```ruby
-f.association :company, :as => :radio_buttons
-f.association :roles, :as => :check_boxes
+f.association :company, as: :radio_buttons
+f.association :roles, as: :check_boxes
```
The association helper just invokes `input` under the hood, so all options available to `:select`,
`:radio_buttons` and `:check_boxes` are also available to association. Additionally, you can specify
the collection by hand, all together with the prompt:
```ruby
-f.association :company, :collection => Company.active.all(:order => 'name'), :prompt => "Choose a Company"
+f.association :company, collection: Company.active.all(order: 'name'), prompt: "Choose a Company"
```
In case you want to declare different labels and values:
```ruby
-f.association :company, :label_method => :company_name, :value_method => :id, :include_blank => false
+f.association :company, label_method: :company_name, value_method: :id, include_blank: false
```
### Buttons
@@ -366,7 +366,7 @@ calling input with a block like so:
```erb
<%= f.input :role do %>
- <%= f.select :role, Role.all.map { |r| [r.name, r.id, { :class => r.company.id }] }, :include_blank => true %>
+ <%= f.select :role, Role.all.map { |r| [r.name, r.id, { class: r.company.id }] }, include_blank: true %>
<% end %>
```
@@ -485,7 +485,7 @@ end
And use it in your views:
```ruby
-f.input :money, :as => :currency
+f.input :money, as: :currency
```
You can also redefine existing **SimpleForm** inputs by creating a new class with the same name. For
@@ -520,7 +520,7 @@ Create a helper method that calls `simple_form_for` with a custom builder:
```ruby
def custom_form_for(object, *args, &block)
options = args.extract_options!
- simple_form_for(object, *(args << options.merge(:builder => CustomFormBuilder)), &block)
+ simple_form_for(object, *(args << options.merge(builder: CustomFormBuilder)), &block)
end
```
@@ -529,7 +529,7 @@ Create a form builder class that inherits from `SimpleForm::FormBuilder`.
```ruby
class CustomFormBuilder < SimpleForm::FormBuilder
def input(attribute_name, options = {}, &block)
- options[:input_html].merge! :class => 'custom'
+ options[:input_html].merge! class: 'custom'
super
end
end
@@ -612,7 +612,7 @@ that would post either `male` or `female` as value. With **SimpleForm** you coul
like this:
```ruby
-f.input :gender, :collection => [:male, :female]
+f.input :gender, collection: [:male, :female]
```
And **SimpleForm** will try a lookup like this in your locale file, to find the right labels to show:
@@ -674,7 +674,7 @@ en:
This difference exists because **SimpleForm** relies on `object_name` provided by Rails'
FormBuilder to determine the translation path for a given object instead of `i18n_key` from the
object itself. Thus, similarly, if a form for an `Admin::User` object is defined by calling
-`simple_form_for @admin_user, :as => :some_user`, **SimpleForm** will look for translations
+`simple_form_for @admin_user, as: :some_user`, **SimpleForm** will look for translations
under `some_user` instead of `admin_user`.
## Configuration
@@ -690,8 +690,8 @@ With **SimpleForm** you can configure how your components will be rendered using
The syntax looks like this:
```ruby
-config.wrappers :tag => :div, :class => :input,
- :error_class => :field_with_errors do |b|
+config.wrappers tag: :div, class: :input,
+ error_class: :field_with_errors do |b|
# Form extensions
b.use :html5
@@ -702,8 +702,8 @@ config.wrappers :tag => :div, :class => :input,
# Form components
b.use :label_input
- b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
- b.use :error, :wrap_with => { :tag => :span, :class => :error }
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
+ b.use :error, wrap_with: { tag: :span, class: :error }
end
```
@@ -726,9 +726,9 @@ You can create new _Form components_ using the wrappers API as in the following
config.wrappers do |b|
b.use :placeholder
b.use :label_input
- b.wrapper :tag => :div, :class => 'separator' do |component|
- component.use :hint, :wrap_with => { :tag => :span, :class => :hint }
- component.use :error, :wrap_with => { :tag => :span, :class => :error }
+ b.wrapper tag: :div, class: 'separator' do |component|
+ component.use :hint, wrap_with: { tag: :span, class: :hint }
+ component.use :error, wrap_with: { tag: :span, class: :error }
end
end
```
@@ -741,9 +741,9 @@ If you want to customize the custom _Form components_ on demand you can give it
config.wrappers do |b|
b.use :placeholder
b.use :label_input
- b.wrapper :my_wrapper, :tag => :div, :class => 'separator' do |component|
- component.use :hint, :wrap_with => { :tag => :span, :class => :hint }
- component.use :error, :wrap_with => { :tag => :span, :class => :error }
+ b.wrapper :my_wrapper, tag: :div, class: 'separator' do |component|
+ component.use :hint, wrap_with: { tag: :span, class: :hint }
+ component.use :error, wrap_with: { tag: :span, class: :error }
end
end
```
@@ -752,13 +752,13 @@ and now you can pass options to your `input` calls to customize the `:my_wrapper
```ruby
# Completely turns off the custom wrapper
-f.input :name, :my_wrapper => false
+f.input :name, my_wrapper: false
# Configure the html
-f.input :name, :my_wrapper_html => { :id => 'special_id' }
+f.input :name, my_wrapper_html: { id: 'special_id' }
# Configure the tag
-f.input :name, :my_wrapper_tag => :p
+f.input :name, my_wrapper_tag: :p
```
You can also define more than one wrapper and pick one to render in a specific form or input.
@@ -775,13 +775,13 @@ and use it in this way:
```ruby
# Specifying to whole form
-simple_form_for @user, :wrapper => :small do |f|
+simple_form_for @user, wrapper: :small do |f|
f.input :name
end
# Specifying to one input
simple_form_for @user do |f|
- f.input :name, :wrapper => :small
+ f.input :name, wrapper: :small
end
```
@@ -790,17 +790,17 @@ hints or placeholders, but you don't want them to be generated automatically. Yo
default values to `false` or use the `optional` method. Is preferible to use the `optional` syntax:
```ruby
-config.wrappers :placeholder => false do |b|
+config.wrappers placeholder: false do |b|
b.use :placeholder
b.use :label_input
- b.wrapper :tag => :div, :class => 'separator' do |component|
- component.optional :hint, :wrap_with => { :tag => :span, :class => :hint }
- component.use :error, :wrap_with => { :tag => :span, :class => :error }
+ b.wrapper tag: :div, class: 'separator' do |component|
+ component.optional :hint, wrap_with: { tag: :span, class: :hint }
+ component.use :error, wrap_with: { tag: :span, class: :error }
end
end
```
-By setting it as `optional`, a hint will only be generated when `:hint => true` is explicitly used.
+By setting it as `optional`, a hint will only be generated when `hint: true` is explicitly used.
The same for placehold.
## HTML 5 Notice
@@ -835,7 +835,7 @@ help you to use some generic javascript validation.
You can also add `novalidate` to a specific form by setting the option on the form itself:
```erb
-<%= simple_form_for(resource, :html => {:novalidate => true}) do |form| %>
+<%= simple_form_for(resource, html: {novalidate: true}) do |form| %>
```
Please notice that any of the configurations above will disable the `placeholder` component,
View
2 Rakefile
@@ -7,7 +7,7 @@ require 'rake/testtask'
require 'rdoc/task'
desc 'Default: run unit tests.'
-task :default => :test
+task default: :test
desc 'Test the simple_form plugin.'
Rake::TestTask.new(:test) do |t|
View
6 lib/generators/simple_form/install_generator.rb
@@ -3,9 +3,9 @@ module Generators
class InstallGenerator < Rails::Generators::Base
desc "Copy SimpleForm default files"
source_root File.expand_path('../templates', __FILE__)
- class_option :template_engine, :desc => 'Template engine to be invoked (erb, haml or slim).'
- class_option :bootstrap, :type => :boolean, :desc => 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
- class_option :foundation, :type => :boolean, :desc => 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
+ class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'
+ class_option :bootstrap, type: :boolean, desc: 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
+ class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
def info_bootstrap
return if options.bootstrap? || options.foundation?
View
2 lib/generators/simple_form/templates/README
@@ -7,6 +7,6 @@
classes, '.form-horizontal', '.form-inline', '.form-search' or
'.form-vertical', as the following:
- = simple_form_for(@user, :html => {:class => 'form-horizontal' }) do |form|
+ = simple_form_for(@user, html: {class: 'form-horizontal' }) do |form|
===============================================================================
View
16 lib/generators/simple_form/templates/config/initializers/simple_form.rb
@@ -5,8 +5,8 @@
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
- config.wrappers :default, :class => :input,
- :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
+ config.wrappers :default, class: :input,
+ hint_class: :field_with_hint, error_class: :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
@@ -18,7 +18,7 @@
b.use :html5
# Calculates placeholders automatically from I18n
- # You can also pass a string as f.input :placeholder => "Placeholder"
+ # You can also pass a string as f.input placeholder: "Placeholder"
b.use :placeholder
## Optional extensions
@@ -41,17 +41,17 @@
## Inputs
b.use :label_input
- b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
- b.use :error, :wrap_with => { :tag => :span, :class => :error }
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
+ b.use :error, wrap_with: { tag: :span, class: :error }
end
# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default
# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
- # :inline => input + label
- # :nested => label > input
+ # inline: input + label
+ # nested: label > input
config.boolean_style = :nested
# Default class for buttons
@@ -120,7 +120,7 @@
# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
- # config.wrapper_mappings = { :string => :prepend }
+ # config.wrapper_mappings = { string: :prepend }
# Default priority for time_zone inputs.
# config.time_zone_priority = nil
View
28 lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb
@@ -1,39 +1,39 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
- config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
+ config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |ba|
+ b.wrapper tag: 'div', class: 'controls' do |ba|
ba.use :input
- ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
- ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
- config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
+ config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |input|
- input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
+ b.wrapper tag: 'div', class: 'controls' do |input|
+ input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
prepend.use :input
end
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
+ input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
+ input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
- config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
+ config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |input|
- input.wrapper :tag => 'div', :class => 'input-append' do |append|
+ b.wrapper tag: 'div', class: 'controls' do |input|
+ input.wrapper tag: 'div', class: 'input-append' do |append|
append.use :input
end
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
+ input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
+ input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
View
6 lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb
@@ -1,18 +1,18 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
- config.wrappers :foundation, :class => :input, :hint_class => :field_with_hint, :error_class => :error do |b|
+ config.wrappers :foundation, class: :input, hint_class: :field_with_hint, error_class: :error do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :label_input
- b.use :error, :wrap_with => { :tag => :small }
+ b.use :error, wrap_with: { tag: :small }
# Uncomment the following line to enable hints. The line is commented out by default since Foundation
# does't provide styles for hints. You will need to provide your own CSS styles for hints.
- # b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
+ # b.use :hint, wrap_with: { tag: :span, class: :hint }
end
# CSS class for buttons
View
12 lib/simple_form.rb
@@ -73,8 +73,8 @@ def self.eager_load!
@@label_class = nil
# Define the way to render check boxes / radio buttons with labels.
- # :inline => input + label (default)
- # :nested => label > input
+ # inline: input + label (default)
+ # nested: label > input
mattr_accessor :boolean_style
@@boolean_style = :inline
@@ -106,7 +106,7 @@ def self.eager_load!
# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
- # e.g { :string => :string_wrapper, :boolean => :boolean_wrapper }
+ # e.g { string: :string_wrapper, boolean: :boolean_wrapper }
mattr_accessor :wrapper_mappings
@@wrapper_mappings = nil
@@ -174,7 +174,7 @@ def self.build(options={})
SimpleForm::Wrappers::Root.new(builder.to_a, options)
end
- wrappers :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
+ wrappers class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b|
b.use :html5
b.use :min_max
@@ -184,8 +184,8 @@ def self.build(options={})
b.optional :readonly
b.use :label_input
- b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
- b.use :error, :wrap_with => { :tag => :span, :class => :error }
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
+ b.use :error, wrap_with: { tag: :span, class: :error }
end
def self.additional_classes_for(component)
View
2 lib/simple_form/action_view_extensions/form_helper.rb
@@ -5,7 +5,7 @@ module ActionViewExtensions
# Example:
#
# simple_form_for @user do |f|
- # f.input :name, :hint => 'My hint'
+ # f.input :name, hint: 'My hint'
# end
#
module FormHelper
View
2 lib/simple_form/components.rb
@@ -2,7 +2,7 @@ module SimpleForm
# Components are a special type of helpers that can work on their own.
# For example, by using a component, it will automatically change the
# output under given circumstances without user input. For example,
- # the disabled helper always need a :disabled => true option given
+ # the disabled helper always need a disabled: true option given
# to the input in order to be enabled. On the other hand, things like
# hints can generate output automatically by doing I18n lookups.
module Components
View
2 lib/simple_form/components/html5.rb
@@ -23,4 +23,4 @@ def has_required?
end
end
end
-end
+end
View
6 lib/simple_form/components/labels.rb
@@ -6,18 +6,18 @@ module Labels
module ClassMethods #:nodoc:
def translate_required_html
i18n_cache :translate_required_html do
- I18n.t(:"simple_form.required.html", :default =>
+ I18n.t(:"simple_form.required.html", default:
%[<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>]
)
end
end
def translate_required_text
- I18n.t(:"simple_form.required.text", :default => 'required')
+ I18n.t(:"simple_form.required.text", default: 'required')
end
def translate_required_mark
- I18n.t(:"simple_form.required.mark", :default => '*')
+ I18n.t(:"simple_form.required.mark", default: '*')
end
end
View
4 lib/simple_form/error_notification.rb
@@ -1,6 +1,6 @@
module SimpleForm
class ErrorNotification
- delegate :object, :object_name, :template, :to => :@builder
+ delegate :object, :object_name, :template, to: :@builder
def initialize(builder, options)
@builder = builder
@@ -42,7 +42,7 @@ def translate_error_notification
lookups << :"#{object_name}"
lookups << :default_message
lookups << "Please review the problems below:"
- I18n.t(lookups.shift, :scope => :"simple_form.error_notification", :default => lookups)
+ I18n.t(lookups.shift, scope: :"simple_form.error_notification", default: lookups)
end
end
end
View
66 lib/simple_form/form_builder.rb
@@ -8,26 +8,26 @@ class FormBuilder < ActionView::Helpers::FormBuilder
# When action is create or update, we still should use new and edit
ACTIONS = {
- :create => :new,
- :update => :edit
+ create: :new,
+ update: :edit
}
extend MapType
include SimpleForm::Inputs
- map_type :text, :to => SimpleForm::Inputs::TextInput
- map_type :file, :to => SimpleForm::Inputs::FileInput
- map_type :string, :email, :search, :tel, :url, :to => SimpleForm::Inputs::StringInput
- map_type :password, :to => SimpleForm::Inputs::PasswordInput
- map_type :integer, :decimal, :float, :to => SimpleForm::Inputs::NumericInput
- map_type :range, :to => SimpleForm::Inputs::RangeInput
- map_type :check_boxes, :to => SimpleForm::Inputs::CollectionCheckBoxesInput
- map_type :radio_buttons, :to => SimpleForm::Inputs::CollectionRadioButtonsInput
- map_type :select, :to => SimpleForm::Inputs::CollectionSelectInput
- map_type :grouped_select, :to => SimpleForm::Inputs::GroupedCollectionSelectInput
- map_type :date, :time, :datetime, :to => SimpleForm::Inputs::DateTimeInput
- map_type :country, :time_zone, :to => SimpleForm::Inputs::PriorityInput
- map_type :boolean, :to => SimpleForm::Inputs::BooleanInput
+ map_type :text, to: SimpleForm::Inputs::TextInput
+ map_type :file, to: SimpleForm::Inputs::FileInput
+ map_type :string, :email, :search, :tel, :url, to: SimpleForm::Inputs::StringInput
+ map_type :password, to: SimpleForm::Inputs::PasswordInput
+ map_type :integer, :decimal, :float, to: SimpleForm::Inputs::NumericInput
+ map_type :range, to: SimpleForm::Inputs::RangeInput
+ map_type :check_boxes, to: SimpleForm::Inputs::CollectionCheckBoxesInput
+ map_type :radio_buttons, to: SimpleForm::Inputs::CollectionRadioButtonsInput
+ map_type :select, to: SimpleForm::Inputs::CollectionSelectInput
+ map_type :grouped_select, to: SimpleForm::Inputs::GroupedCollectionSelectInput
+ map_type :date, :time, :datetime, to: SimpleForm::Inputs::DateTimeInput
+ map_type :country, :time_zone, to: SimpleForm::Inputs::PriorityInput
+ map_type :boolean, to: SimpleForm::Inputs::BooleanInput
def self.discovery_cache
@discovery_cache ||= {}
@@ -49,7 +49,7 @@ def initialize(*) #:nodoc:
#
# # Imagine @user has error "can't be blank" on name
# simple_form_for @user do |f|
- # f.input :name, :hint => 'My hint'
+ # f.input :name, hint: 'My hint'
# end
#
# This is the output html (only the input portion, not the form):
@@ -67,15 +67,15 @@ def initialize(*) #:nodoc:
#
# You have some options for the input to enable/disable some functions:
#
- # :as => allows you to define the input type you want, for instance you
+ # as: allows you to define the input type you want, for instance you
# can use it to generate a text field for a date column.
#
- # :required => defines whether this attribute is required or not. True
+ # required: defines whether this attribute is required or not. True
# by default.
#
# The fact SimpleForm is built in components allow the interface to be unified.
# So, for instance, if you need to disable :hint for a given input, you can pass
- # :hint => false. The same works for :error, :label and :wrapper.
+ # hint: false. The same works for :error, :label and :wrapper.
#
# Besides the html for any component can be changed. So, if you want to change
# the label html you just need to give a hash to :label_html. To configure the
@@ -86,18 +86,18 @@ def initialize(*) #:nodoc:
# Some inputs, as datetime, time and select allow you to give extra options, like
# prompt and/or include blank. Such options are given in plainly:
#
- # f.input :created_at, :include_blank => true
+ # f.input :created_at, include_blank: true
#
# == Collection
#
# When playing with collections (:radio_buttons, :check_boxes and :select
# inputs), you have three extra options:
#
- # :collection => use to determine the collection to generate the radio or select
+ # collection: use to determine the collection to generate the radio or select
#
- # :label_method => the method to apply on the array collection to get the label
+ # label_method: the method to apply on the array collection to get the label
#
- # :value_method => the method to apply on the array collection to get the value
+ # value_method: the method to apply on the array collection to get the value
#
# == Priority
#
@@ -138,7 +138,7 @@ def input_field(attribute_name, options={})
options[:input_html] = options.except(:as, :collection, :label_method, :value_method)
options = @defaults.deep_dup.deep_merge(options) if @defaults
- SimpleForm::Wrappers::Root.new([:input], :wrapper => false).render find_input(attribute_name, options)
+ SimpleForm::Wrappers::Root.new([:input], wrapper: false).render find_input(attribute_name, options)
end
# Helper for dealing with association selects/radios, generating the
@@ -152,7 +152,7 @@ def input_field(attribute_name, options={})
# f.association :company # Company.all
# end
#
- # f.association :company, :collection => Company.all(:order => 'name')
+ # f.association :company, collection: Company.all(order: 'name')
# # Same as using :order option, but overriding collection
#
# == Block
@@ -203,7 +203,7 @@ def association(association, options={}, &block)
:"#{reflection.name.to_s.singularize}_ids"
end
- input(attribute, options.merge(:reflection => reflection))
+ input(attribute, options.merge(reflection: reflection))
end
# Creates a button:
@@ -234,7 +234,7 @@ def button(type, *args, &block)
# == Examples
#
# f.error :name
- # f.error :name, :id => "cool_error"
+ # f.error :name, id: "cool_error"
#
def error(attribute_name, options={})
options = options.dup
@@ -272,7 +272,7 @@ def full_error(attribute_name, options={})
# == Examples
#
# f.hint :name # Do I18n lookup
- # f.hint :name, :id => "cool_hint"
+ # f.hint :name, id: "cool_hint"
# f.hint "Don't forget to accept this"
#
def hint(attribute_name, options={})
@@ -299,10 +299,10 @@ def hint(attribute_name, options={})
#
# f.label :name # Do I18n lookup
# f.label :name, "Name" # Same behavior as Rails, do not add required tag
- # f.label :name, :label => "Name" # Same as above, but adds required tag
+ # f.label :name, label: "Name" # Same as above, but adds required tag
#
- # f.label :name, :required => false
- # f.label :name, :id => "cool_label"
+ # f.label :name, required: false
+ # f.label :name, id: "cool_label"
#
def label(attribute_name, *args)
return super if args.first.is_a?(String) || block_given?
@@ -323,8 +323,8 @@ def label(attribute_name, *args)
# == Examples
#
# f.error_notification
- # f.error_notification :message => 'Something went wrong'
- # f.error_notification :id => 'user_error_message', :class => 'form_error'
+ # f.error_notification message: 'Something went wrong'
+ # f.error_notification id: 'user_error_message', class: 'form_error'
#
def error_notification(options={})
SimpleForm::ErrorNotification.new(self, options).render
View
2 lib/simple_form/helpers.rb
@@ -1,7 +1,7 @@
module SimpleForm
# Helpers are made of several helpers that cannot be turned on automatically.
# For instance, disabled cannot be turned on automatically, it requires the
- # user to explicitly pass the option :disabled => true so it may work.
+ # user to explicitly pass the option disabled: true so it may work.
module Helpers
autoload :Autofocus, 'simple_form/helpers/autofocus'
autoload :Disabled, 'simple_form/helpers/disabled'
View
4 lib/simple_form/inputs/base.rb
@@ -24,7 +24,7 @@ class Base
attr_reader :attribute_name, :column, :input_type, :reflection,
:options, :input_html_options, :input_html_classes, :html_classes
- delegate :template, :object, :object_name, :lookup_model_names, :lookup_action, :to => :@builder
+ delegate :template, :object, :object_name, :lookup_model_names, :lookup_action, to: :@builder
class_attribute :default_options
self.default_options = {}
@@ -175,7 +175,7 @@ def translate(namespace, default='')
lookups << :"defaults.#{reflection_or_attribute_name}"
lookups << default
- I18n.t(lookups.shift, :scope => :"simple_form.#{namespace}", :default => lookups).presence
+ I18n.t(lookups.shift, scope: :"simple_form.#{namespace}", default: lookups).presence
end
end
end
View
2 lib/simple_form/inputs/block_input.rb
@@ -11,4 +11,4 @@ def input
end
end
end
-end
+end
View
2 lib/simple_form/inputs/boolean_input.rb
@@ -4,7 +4,7 @@ class BooleanInput < Base
def input
if nested_boolean_style?
build_hidden_field_for_checkbox +
- template.label_tag(nil, :class => "checkbox") {
+ template.label_tag(nil, class: "checkbox") {
build_check_box_without_hidden_field + inline_label
}
else
View
12 lib/simple_form/inputs/collection_input.rb
@@ -7,8 +7,8 @@ class CollectionInput < Base
# "simple_form.no" keys. See the example locale file.
def self.boolean_collection
i18n_cache :boolean_collection do
- [ [I18n.t(:"simple_form.yes", :default => 'Yes'), true],
- [I18n.t(:"simple_form.no", :default => 'No'), false] ]
+ [ [I18n.t(:"simple_form.yes", default: 'Yes'), true],
+ [I18n.t(:"simple_form.no", default: 'No'), false] ]
end
end
@@ -66,14 +66,14 @@ def detect_common_display_methods(collection_classes = detect_collection_classes
collection_translated = translate_collection if collection_classes == [Symbol]
if collection_translated || collection_classes.include?(Array)
- { :label => :first, :value => :last }
+ { label: :first, value: :last }
elsif collection_includes_basic_objects?(collection_classes)
- { :label => :to_s, :value => :to_s }
+ { label: :to_s, value: :to_s }
else
sample = collection.first || collection.last
- { :label => SimpleForm.collection_label_methods.find { |m| sample.respond_to?(m) },
- :value => SimpleForm.collection_value_methods.find { |m| sample.respond_to?(m) } }
+ { label: SimpleForm.collection_label_methods.find { |m| sample.respond_to?(m) },
+ value: SimpleForm.collection_value_methods.find { |m| sample.respond_to?(m) } }
end
end
View
8 lib/simple_form/tags.rb
@@ -14,7 +14,7 @@ def render_collection
rendered_item = yield item, value, text, default_html_options
- item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, :class => item_wrapper_class) : rendered_item
+ item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
end.join.html_safe
end
@@ -23,7 +23,7 @@ def wrap_rendered_collection(collection)
if wrapper_tag
wrapper_class = @options[:collection_wrapper_class]
- @template_object.content_tag(wrapper_tag, collection, :class => wrapper_class)
+ @template_object.content_tag(wrapper_tag, collection, class: wrapper_class)
else
collection
end
@@ -40,7 +40,7 @@ def render
private
def render_component(builder)
- builder.radio_button + builder.label(:class => "collection_radio_buttons")
+ builder.radio_button + builder.label(class: "collection_radio_buttons")
end
end
@@ -54,7 +54,7 @@ def render
private
def render_component(builder)
- builder.check_box + builder.label(:class => "collection_check_boxes")
+ builder.check_box + builder.label(class: "collection_check_boxes")
end
end
end
View
2 lib/simple_form/wrappers.rb
@@ -5,4 +5,4 @@ module Wrappers
autoload :Root, 'simple_form/wrappers/root'
autoload :Single, 'simple_form/wrappers/single'
end
-end
+end
View
10 lib/simple_form/wrappers/builder.rb
@@ -12,18 +12,18 @@ module Wrappers
# b.optional :placeholder
#
# # Use a component with specific wrapper options
- # b.use :error, :wrap_with => { :tag => "span", :class => "error" }
+ # b.use :error, wrap_with: { tag: "span", class: "error" }
#
# # Use a set of components by wrapping them in a tag+class.
- # b.wrapper :tag => "div", :class => "another" do |ba|
+ # b.wrapper tag: "div", class: "another" do |ba|
# ba.use :label
# ba.use :input
# end
#
# # Use a set of components by wrapping them in a tag+class.
# # This wrapper is identified by :label_input, which means it can
- # # be turned off on demand with `f.input :name, :label_input => false`
- # b.wrapper :label_input, :tag => "div", :class => "another" do |ba|
+ # # be turned off on demand with `f.input :name, label_input: false`
+ # b.wrapper :label_input, tag: "div", class: "another" do |ba|
# ba.use :label
# ba.use :input
# end
@@ -32,7 +32,7 @@ module Wrappers
# The builder also accepts default options at the root level. This is usually
# used if you want a component to be disabled by default:
#
- # config.wrappers :hint => false do |b|
+ # config.wrappers hint: false do |b|
# b.use :hint
# b.use :label_input
# end
View
126 test/action_view_extensions/builder_test.rb
@@ -58,21 +58,21 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
end
test "collection radio accepts checked item" do
- with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => true
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: true
assert_select 'form input[type=radio][value=true][checked=checked]'
assert_no_select 'form input[type=radio][value=false][checked=checked]'
end
test "collection radio accepts checked item which has a value of false" do
- with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => false
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: false
assert_no_select 'form input[type=radio][value=true][checked=checked]'
assert_select 'form input[type=radio][value=false][checked=checked]'
end
test "collection radio accepts multiple disabled items" do
collection = [[1, true], [0, false], [2, 'other']]
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => [true, false]
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: [true, false]
assert_select 'form input[type=radio][value=true][disabled=disabled]'
assert_select 'form input[type=radio][value=false][disabled=disabled]'
@@ -81,58 +81,58 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection radio accepts single disable item" do
collection = [[1, true], [0, false]]
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => true
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: true
assert_select 'form input[type=radio][value=true][disabled=disabled]'
assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
end
test "collection radio accepts html options as input" do
collection = [[1, true], [0, false]]
- with_collection_radio_buttons @user, :active, collection, :last, :first, {}, :class => 'special-radio'
+ with_collection_radio_buttons @user, :active, collection, :last, :first, {}, class: 'special-radio'
assert_select 'form input[type=radio][value=true].special-radio#user_active_true'
assert_select 'form input[type=radio][value=false].special-radio#user_active_false'
end
test "collection radio wraps the collection in the given collection wrapper tag" do
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
- assert_select 'form ul input[type=radio]', :count => 2
+ assert_select 'form ul input[type=radio]', count: 2
end
test "collection radio does not render any wrapper tag by default" do
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
- assert_select 'form input[type=radio]', :count => 2
+ assert_select 'form input[type=radio]', count: 2
assert_no_select 'form ul'
end
test "collection radio does not wrap the collection when given falsy values" do
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
- assert_select 'form input[type=radio]', :count => 2
+ assert_select 'form input[type=radio]', count: 2
assert_no_select 'form ul'
end
test "collection radio uses the given class for collection wrapper tag" do
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
- assert_select 'form ul.items-list input[type=radio]', :count => 2
+ assert_select 'form ul.items-list input[type=radio]', count: 2
end
test "collection radio uses no class for collection wrapper tag when no wrapper tag is given" do
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
- :collection_wrapper_class => "items-list"
+ collection_wrapper_class: "items-list"
- assert_select 'form input[type=radio]', :count => 2
+ assert_select 'form input[type=radio]', count: 2
assert_no_select 'form ul'
assert_no_select '.items-list'
end
test "collection radio uses no class for collection wrapper tag by default" do
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
assert_select 'form ul'
assert_no_select 'form ul[class]'
@@ -146,39 +146,39 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
end
test "collection radio wraps each item in the given item wrapper tag" do
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
- assert_select 'form li input[type=radio]', :count => 2
+ assert_select 'form li input[type=radio]', count: 2
end
test "collection radio does not wrap each item when given explicitly falsy value" do
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
assert_select 'form input[type=radio]'
assert_no_select 'form span input[type=radio]'
end
test "collection radio uses the given class for item wrapper tag" do
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
- assert_select "form li.inline input[type=radio]", :count => 2
+ assert_select "form li.inline input[type=radio]", count: 2
end
test "collection radio uses no class for item wrapper tag when no wrapper tag is given" do
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
- assert_select 'form input[type=radio]', :count => 2
+ assert_select 'form input[type=radio]', count: 2
assert_no_select 'form li'
assert_no_select '.inline'
end
test "collection radio uses no class for item wrapper tag by default" do
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
- :item_wrapper_tag => :li
+ item_wrapper_tag: :li
- assert_select "form li", :count => 2
+ assert_select "form li", count: 2
assert_no_select "form li[class]"
end
@@ -209,7 +209,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection radio with block helpers accept extra html options" do
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
- b.label(:class => "radio_button") + b.radio_button(:class => "radio_button")
+ b.label(class: "radio_button") + b.radio_button(class: "radio_button")
end
assert_select 'label.radio_button[for=user_active_true] + input#user_active_true.radio_button[type=radio]'
@@ -231,7 +231,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
- b.label(:class => b.object) { b.radio_button + b.text }
+ b.label(class: b.object) { b.radio_button + b.text }
end
assert_select 'label.true[for=user_active_true]', 'true' do
@@ -245,7 +245,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection radio with block helpers does not leak the template" do
with_concat_form_for(@user) do |f|
collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
- b.label(:class => b.object) { b.radio_button + b.text }
+ b.label(class: b.object) { b.radio_button + b.text }
end
concat collection_input
@@ -272,7 +272,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
- assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :count => 1
+ assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
end
test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
@@ -309,7 +309,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check box accepts selected values as :checked option" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
assert_select 'form input[type=checkbox][value=1][checked=checked]'
assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -318,7 +318,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check boxes accepts selected string values as :checked option" do
collection = (1..3).map{|i| [i, "Category #{i}"] }
- with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ['1', '3']
+ with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
assert_select 'input[type=checkbox][value=1][checked=checked]'
assert_select 'input[type=checkbox][value=3][checked=checked]'
@@ -327,7 +327,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check box accepts a single checked value" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => 3
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
assert_select 'form input[type=checkbox][value=3][checked=checked]'
assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -337,7 +337,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check box accepts selected values as :checked option and override the model values" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
@user.tag_ids = [2]
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
assert_select 'form input[type=checkbox][value=1][checked=checked]'
assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -346,7 +346,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check box accepts multiple disabled items" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => [1, 3]
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -355,7 +355,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check box accepts single disable item" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => 1
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -364,7 +364,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check box accepts a proc to disabled items" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -373,7 +373,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check box accepts html options" do
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :class => 'check'
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'
assert_select 'form input.check[type=checkbox][value=1]'
assert_select 'form input.check[type=checkbox][value=2]'
@@ -395,43 +395,43 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
end
test "collection check boxes wraps the collection in the given collection wrapper tag" do
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
- assert_select 'form ul input[type=checkbox]', :count => 2
+ assert_select 'form ul input[type=checkbox]', count: 2
end
test "collection check boxes does not render any wrapper tag by default" do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
- assert_select 'form input[type=checkbox]', :count => 2
+ assert_select 'form input[type=checkbox]', count: 2
assert_no_select 'form ul'
end
test "collection check boxes does not wrap the collection when given falsy values" do
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
- assert_select 'form input[type=checkbox]', :count => 2
+ assert_select 'form input[type=checkbox]', count: 2
assert_no_select 'form ul'
end
test "collection check boxes uses the given class for collection wrapper tag" do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
- assert_select 'form ul.items-list input[type=checkbox]', :count => 2
+ assert_select 'form ul.items-list input[type=checkbox]', count: 2
end
test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
- :collection_wrapper_class => "items-list"
+ collection_wrapper_class: "items-list"
- assert_select 'form input[type=checkbox]', :count => 2
+ assert_select 'form input[type=checkbox]', count: 2
assert_no_select 'form ul'
assert_no_select '.items-list'
end
test "collection check boxes uses no class for collection wrapper tag by default" do
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
assert_select 'form ul'
assert_no_select 'form ul[class]'
@@ -440,43 +440,43 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check boxes wrap items in a span tag by default" do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
- assert_select 'form span input[type=checkbox]', :count => 2
+ assert_select 'form span input[type=checkbox]', count: 2
end
test "collection check boxes wraps each item in the given item wrapper tag" do
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
- assert_select 'form li input[type=checkbox]', :count => 2
+ assert_select 'form li input[type=checkbox]', count: 2
end
test "collection check boxes does not wrap each item when given explicitly falsy value" do
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
assert_select 'form input[type=checkbox]'
assert_no_select 'form span input[type=checkbox]'
end
test "collection check boxes uses the given class for item wrapper tag" do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
- assert_select "form li.inline input[type=checkbox]", :count => 2
+ assert_select "form li.inline input[type=checkbox]", count: 2
end
test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
- assert_select 'form input[type=checkbox]', :count => 2
+ assert_select 'form input[type=checkbox]', count: 2
assert_no_select 'form li'
assert_no_select '.inline'
end
test "collection check boxes uses no class for item wrapper tag by default" do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
- :item_wrapper_tag => :li
+ item_wrapper_tag: :li
- assert_select "form li", :count => 2
+ assert_select "form li", count: 2
assert_no_select "form li[class]"
end
@@ -507,7 +507,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check boxes with block helpers accept extra html options" do
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
- b.label(:class => "check_box") + b.check_box(:class => "check_box")
+ b.label(class: "check_box") + b.check_box(class: "check_box")
end
assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]'
@@ -529,7 +529,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
- b.label(:class => b.object) { b.check_box + b.text }
+ b.label(class: b.object) { b.check_box + b.text }
end
assert_select 'label.true[for=user_active_true]', 'true' do
@@ -543,7 +543,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "collection check boxes with block helpers does not leak the template" do
with_concat_form_for(@user) do |f|
collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
- b.label(:class => b.object) { b.check_box + b.text }
+ b.label(class: b.object) { b.check_box + b.text }
end
concat collection_input
@@ -588,15 +588,15 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "fields for yields an instance of FormBuilder if it was set in options" do
with_custom_form_for(:user) do |f|
- f.simple_fields_for(:company, :builder => SimpleForm::FormBuilder) do |company|
+ f.simple_fields_for(:company, builder: SimpleForm::FormBuilder) do |company|
assert company.instance_of?(SimpleForm::FormBuilder)
end
end
end
test "fields inherites wrapper option from the parent form" do
swap_wrapper :another do
- simple_form_for(:user, :wrapper => :another) do |f|
+ simple_form_for(:user, wrapper: :another) do |f|
f.simple_fields_for(:company) do |company|
assert_equal :another, company.options[:wrapper]
end
@@ -606,8 +606,8 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test "fields overrides wrapper option from the parent form" do
swap_wrapper :another do
- simple_form_for(:user, :wrapper => :another) do |f|
- f.simple_fields_for(:company, :wrapper => false) do |company|
+ simple_form_for(:user, wrapper: :another) do |f|
+ f.simple_fields_for(:company, wrapper: false) do |company|
assert_equal false, company.options[:wrapper]
end
end
View
24 test/action_view_extensions/form_helper_test.rb
@@ -19,31 +19,31 @@ class FormHelperTest < ActionView::TestCase
end
test 'SimpleForm should not use default browser validations if specified in the configuration options' do
- swap SimpleForm, :browser_validations => false do
+ swap SimpleForm, browser_validations: false do
with_concat_form_for(:user)
assert_select 'form[novalidate="novalidate"]'
end
end
test 'a form specific disabled validation option should override the default enabled browser validation configuration option' do
- with_concat_form_for(:user, :html => { :novalidate => true })
+ with_concat_form_for(:user, html: { novalidate: true })
assert_select 'form[novalidate="novalidate"]'
end
test 'a form specific enabled validation option should override the disabled browser validation configuration option' do
- swap SimpleForm, :browser_validations => false do
- with_concat_form_for(:user, :html => { :novalidate => false })
+ swap SimpleForm, browser_validations: false do
+ with_concat_form_for(:user, html: { novalidate: false })
assert_no_select 'form[novalidate]'
end
end
test 'SimpleForm should add object name as css class to form when object is not present' do
- with_concat_form_for(:user, :html => { :novalidate => true })
+ with_concat_form_for(:user, html: { novalidate: true })
assert_select 'form.simple_form.user'
end
test 'SimpleForm should add :as option as css class to form when object is not present' do
- with_concat_form_for(:user, :as => 'superuser')
+ with_concat_form_for(:user, as: 'superuser')
assert_select 'form.simple_form.superuser'
end
@@ -55,7 +55,7 @@ class FormHelperTest < ActionView::TestCase
test 'SimpleForm should add :as option with new prefix as css class to form if record is not persisted' do
@user.new_record!
- with_concat_form_for(@user, :as => 'superuser')
+ with_concat_form_for(@user, as: 'superuser')
assert_select 'form.simple_form.new_superuser'
end
@@ -65,7 +65,7 @@ class FormHelperTest < ActionView::TestCase
end
test 'SimpleForm should add :as options with edit prefix as css class to form if record is persisted' do
- with_concat_form_for(@user, :as => 'superuser')
+ with_concat_form_for(@user, as: 'superuser')
assert_select 'form.simple_form.edit_superuser'
end
@@ -75,17 +75,17 @@ class FormHelperTest < ActionView::TestCase
end
test 'SimpleForm should not add object class to form if css_class is specified' do
- with_concat_form_for(:user, :html => {:class => nil})
+ with_concat_form_for(:user, html: {class: nil})
assert_no_select 'form.user'
end
test 'SimpleForm should add custom class to form if css_class is specified' do
- with_concat_form_for(:user, :html => {:class => 'my_class'})
+ with_concat_form_for(:user, html: {class: 'my_class'})
assert_select 'form.my_class'
end
test 'pass options to SimpleForm' do
- with_concat_form_for(:user, :url => '/account', :html => { :id => 'my_form' })
+ with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
assert_select 'form#my_form'
assert_select 'form[action=/account]'
end
@@ -134,7 +134,7 @@ class FormHelperTest < ActionView::TestCase
private
def swap_field_error_proc(expected_error_proc = lambda {})
- swap ActionView::Base, :field_error_proc => expected_error_proc do
+ swap ActionView::Base, field_error_proc: expected_error_proc do
yield
assert_equal expected_error_proc, ActionView::Base.field_error_proc
View
92 test/components/label_test.rb
@@ -20,7 +20,7 @@ def with_label_for(object, attribute_name, type, options={})
end
test 'label should allow a customized description' do
- with_label_for @user, :name, :string, :label => 'My label!'
+ with_label_for @user, :name, :string, label: 'My label!'
assert_select 'label[for=user_name]', /My label!/
end
@@ -30,14 +30,14 @@ def with_label_for(object, attribute_name, type, options={})
end
test 'label should use human attribute name based on association name' do
- with_label_for @user, :company_id, :string, :setup_association => true
+ with_label_for @user, :company_id, :string, setup_association: true
assert_select 'label', /Company Human Name!/
end
test 'label should use i18n based on model, action, and attribute to lookup translation' do
@controller.action_name = "new"
- store_translations(:en, :simple_form => { :labels => { :user => {
- :new => { :description => 'Nova descrição' }
+ store_translations(:en, simple_form: { labels: { user: {
+ new: { description: 'Nova descrição' }
} } }) do
with_label_for @user, :description, :text
assert_select 'label[for=user_description]', /Nova descrição/
@@ -46,8 +46,8 @@ def with_label_for(object, attribute_name, type, options={})
test 'label should fallback to new when action is create' do
@controller.action_name = "create"
- store_translations(:en, :simple_form => { :labels => { :user => {
- :new => { :description => 'Nova descrição' }
+ store_translations(:en, simple_form: { labels: { user: {
+ new: { description: 'Nova descrição' }
} } }) do
with_label_for @user, :description, :text
assert_select 'label[for=user_description]', /Nova descrição/
@@ -64,44 +64,44 @@ def @controller.action_name; nil; end
end
test 'label should use i18n based on model and attribute to lookup translation' do
- store_translations(:en, :simple_form => { :labels => { :user => {
- :description => 'Descrição'
+ store_translations(:en, simple_form: { labels: { user: {
+ description: 'Descrição'
} } }) do
with_label_for @user, :description, :text
assert_select 'label[for=user_description]', /Descrição/
end
end
test 'label should use i18n under defaults to lookup translation' do
- store_translations(:en, :simple_form => { :labels => { :defaults => { :age => 'Idade' } } }) do
+ store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
with_label_for @user, :age, :integer
assert_select 'label[for=user_age]', /Idade/
end
end
test 'label should not use i18n label if translate is false' do
- swap SimpleForm, :translate_labels => false do
- store_translations(:en, :simple_form => { :labels => { :defaults => { :age => 'Idade' } } }) do
+ swap SimpleForm, translate_labels: false do
+ store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
with_label_for @user, :age, :integer
assert_select 'label[for=user_age]', /Age/
end
end
end
test 'label uses i18n with lookup for association name' do
- store_translations(:en, :simple_form => { :labels => {
- :user => { :company => 'My company!' }
+ store_translations(:en, simple_form: { labels: {
+ user: { company: 'My company!' }
} }) do
- with_label_for @user, :company_id, :string, :setup_association => true
+ with_label_for @user, :company_id, :string, setup_association: true
assert_select 'label[for=user_company_id]', /My company!/
end
end
test 'label uses i18n under defaults namespace to lookup for association name' do
- store_translations(:en, :simple_form => { :labels => {
- :defaults => { :company => 'Plataformatec' }
+ store_translations(:en, simple_form: { labels: {
+ defaults: { company: 'Plataformatec' }
} }) do
- with_label_for @user, :company, :string, :setup_association => true
+ with_label_for @user, :company, :string, setup_association: true
assert_select 'form label', /Plataformatec/
end
@@ -110,8 +110,8 @@ def @controller.action_name; nil; end
test 'label should do correct i18n lookup for nested models with nested translation' do
@user.company = Company.new(1, 'Empresa')
- store_translations(:en, :simple_form => { :labels => {
- :user => { :name => 'Usuario', :company => { :name => 'Nome da empresa' } }
+ store_translations(:en, simple_form: { labels: {
+ user: { name: 'Usuario', company: { name: 'Nome da empresa' } }
} }) do
with_concat_form_for @user do |f|
concat f.input :name
@@ -128,9 +128,9 @@ def @controller.action_name; nil; end
test 'label should do correct i18n lookup for nested models with no nested translation' do
@user.company = Company.new(1, 'Empresa')
- store_translations(:en, :simple_form => { :labels => {
- :user => { :name => 'Usuario' },
- :company => { :name => 'Nome da empresa' }
+ store_translations(:en, simple_form: { labels: {
+ user: { name: 'Usuario' },
+ company: { name: 'Nome da empresa' }
} }) do
with_concat_form_for @user do |f|
concat f.input :name
@@ -147,13 +147,13 @@ def @controller.action_name; nil; end
test 'label should do correct i18n lookup for nested has_many models with no nested translation' do
@user.tags = [Tag.new(1, 'Empresa')]