simple_form 3.1.0.rc1 → 3.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -1
  3. data/README.md +37 -6
  4. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +6 -2
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +37 -14
  6. data/lib/simple_form.rb +8 -0
  7. data/lib/simple_form/components/labels.rb +1 -1
  8. data/lib/simple_form/form_builder.rb +29 -15
  9. data/lib/simple_form/inputs/boolean_input.rb +7 -4
  10. data/lib/simple_form/tags.rb +1 -0
  11. data/lib/simple_form/version.rb +1 -1
  12. data/lib/simple_form/wrappers/builder.rb +2 -2
  13. data/lib/simple_form/wrappers/many.rb +1 -0
  14. data/test/action_view_extensions/builder_test.rb +3 -3
  15. data/test/action_view_extensions/form_helper_test.rb +13 -13
  16. data/test/components/label_test.rb +35 -35
  17. data/test/form_builder/association_test.rb +4 -4
  18. data/test/form_builder/button_test.rb +5 -5
  19. data/test/form_builder/error_test.rb +18 -18
  20. data/test/form_builder/general_test.rb +65 -60
  21. data/test/form_builder/hint_test.rb +15 -15
  22. data/test/form_builder/input_field_test.rb +16 -16
  23. data/test/form_builder/label_test.rb +22 -13
  24. data/test/form_builder/wrapper_test.rb +54 -20
  25. data/test/inputs/boolean_input_test.rb +8 -8
  26. data/test/inputs/collection_check_boxes_input_test.rb +24 -7
  27. data/test/inputs/collection_radio_buttons_input_test.rb +40 -23
  28. data/test/inputs/collection_select_input_test.rb +45 -45
  29. data/test/inputs/datetime_input_test.rb +23 -23
  30. data/test/inputs/disabled_test.rb +15 -15
  31. data/test/inputs/discovery_test.rb +44 -5
  32. data/test/inputs/file_input_test.rb +2 -2
  33. data/test/inputs/general_test.rb +20 -20
  34. data/test/inputs/grouped_collection_select_input_test.rb +2 -2
  35. data/test/inputs/hidden_input_test.rb +4 -4
  36. data/test/inputs/numeric_input_test.rb +24 -24
  37. data/test/inputs/priority_input_test.rb +7 -7
  38. data/test/inputs/readonly_test.rb +19 -19
  39. data/test/inputs/required_test.rb +13 -13
  40. data/test/inputs/string_input_test.rb +23 -23
  41. data/test/inputs/text_input_test.rb +4 -4
  42. data/test/support/discovery_inputs.rb +20 -0
  43. data/test/support/misc_helpers.rb +22 -0
  44. data/test/support/models.rb +2 -1
  45. metadata +2 -2
@@ -2,100 +2,100 @@
2
2
  require 'test_helper'
3
3
 
4
4
  class StringInputTest < ActionView::TestCase
5
- test 'input should map text field to string attribute' do
5
+ test 'input maps text field to string attribute' do
6
6
  with_input_for @user, :name, :string
7
7
  assert_select "input#user_name[type=text][name='user[name]'][value=New in SimpleForm!]"
8
8
  end
9
9
 
10
- test 'input should generate a password field for password attributes' do
10
+ test 'input generates a password field for password attributes' do
11
11
  with_input_for @user, :password, :password
12
12
  assert_select "input#user_password.password[type=password][name='user[password]']"
13
13
  end
14
14
 
15
- test 'input should get maxlength from column definition for string attributes' do
15
+ test 'input gets maxlength from column definition for string attributes' do
16
16
  with_input_for @user, :name, :string
17
17
  assert_select 'input.string[maxlength=100]'
18
18
  end
19
19
 
20
- test 'input should not get maxlength from column without size definition for string attributes' do
20
+ test 'input does not get maxlength from column without size definition for string attributes' do
21
21
  with_input_for @user, :action, :string
22
22
  assert_no_select 'input.string[maxlength]'
23
23
  end
24
24
 
25
- test 'input should get maxlength from column definition for password attributes' do
25
+ test 'input gets maxlength from column definition for password attributes' do
26
26
  with_input_for @user, :password, :password
27
27
  assert_select 'input.password[type=password][maxlength=100]'
28
28
  end
29
29
 
30
- test 'input should infer maxlength column definition from validation when present' do
30
+ test 'input infers maxlength column definition from validation when present' do
31
31
  with_input_for @validating_user, :name, :string
32
32
  assert_select 'input.string[maxlength=25]'
33
33
  end
34
34
 
35
- test 'input should not get maxlength from validation when tokenizer present' do
35
+ test 'input does not get maxlength from validation when tokenizer present' do
36
36
  with_input_for @validating_user, :action, :string
37
37
  assert_no_select 'input.string[maxlength]'
38
38
  end
39
39
 
40
- test 'input should get maxlength from validation when :is option present' do
40
+ test 'input gets maxlength from validation when :is option present' do
41
41
  with_input_for @validating_user, :home_picture, :string
42
42
  assert_select 'input.string[maxlength=12]'
43
43
  end
44
44
 
45
- test 'input maxlength should be the column limit plus one to make room for decimal point' do
45
+ test 'input maxlength is the column limit plus one to make room for decimal point' do
46
46
  with_input_for @user, :credit_limit, :string
47
47
 
48
48
  assert_select "input.string[maxlength=16]"
49
49
  end
50
50
 
51
- test 'input should not generate placeholder by default' do
51
+ test 'input does not generate placeholder by default' do
52
52
  with_input_for @user, :name, :string
53
53
  assert_no_select 'input[placeholder]'
54
54
  end
55
55
 
56
- test 'input should accept the placeholder option' do
56
+ test 'input accepts the placeholder option' do
57
57
  with_input_for @user, :name, :string, placeholder: 'Put in some text'
58
58
  assert_select 'input.string[placeholder=Put in some text]'
59
59
  end
60
60
 
61
- test 'input should generate a password field for password attributes that accept placeholder' do
61
+ test 'input generates a password field for password attributes that accept placeholder' do
62
62
  with_input_for @user, :password, :password, placeholder: 'Password Confirmation'
63
63
  assert_select 'input[type=password].password[placeholder=Password Confirmation]#user_password'
64
64
  end
65
65
 
66
- test 'input should not infer pattern from attributes by default' do
66
+ test 'input does not infer pattern from attributes by default' do
67
67
  with_input_for @other_validating_user, :country, :string
68
68
  assert_no_select 'input[pattern="\w+"]'
69
69
  end
70
70
 
71
- test 'input should infer pattern from attributes' do
71
+ test 'input infers pattern from attributes' do
72
72
  with_input_for @other_validating_user, :country, :string, pattern: true
73
73
  assert_select 'input[pattern="\w+"]'
74
74
  end
75
75
 
76
- test 'input should infer pattern from attributes using proc' do
76
+ test 'input infers pattern from attributes using proc' do
77
77
  with_input_for @other_validating_user, :name, :string, pattern: true
78
78
  assert_select 'input[pattern="\w+"]'
79
79
  end
80
80
 
81
- test 'input should not infer pattern from attributes if root default is false' do
81
+ test 'input does not infer pattern from attributes if root default is false' do
82
82
  swap_wrapper do
83
83
  with_input_for @other_validating_user, :country, :string
84
84
  assert_no_select 'input[pattern="\w+"]'
85
85
  end
86
86
  end
87
87
 
88
- test 'input should use given pattern from attributes' do
88
+ test 'input uses given pattern from attributes' do
89
89
  with_input_for @other_validating_user, :country, :string, input_html: { pattern: "\\d+" }
90
90
  assert_select 'input[pattern="\d+"]'
91
91
  end
92
92
 
93
- test 'input should not use pattern if model has :without validation option' do
93
+ test 'input does not use pattern if model has :without validation option' do
94
94
  with_input_for @other_validating_user, :description, :string, pattern: true
95
95
  assert_no_select 'input[pattern="\d+"]'
96
96
  end
97
97
 
98
- test 'input should use i18n to translate placeholder text' do
98
+ test 'input uses i18n to translate placeholder text' do
99
99
  store_translations(:en, simple_form: { placeholders: { user: {
100
100
  name: 'Name goes here'
101
101
  } } }) do
@@ -104,7 +104,7 @@ class StringInputTest < ActionView::TestCase
104
104
  end
105
105
  end
106
106
 
107
- test 'input should use custom i18n scope to translate placeholder text' do
107
+ test 'input uses custom i18n scope to translate placeholder text' do
108
108
  store_translations(:en, my_scope: { placeholders: { user: {
109
109
  name: 'Name goes here'
110
110
  } } }) do
@@ -115,7 +115,7 @@ class StringInputTest < ActionView::TestCase
115
115
  end
116
116
  end
117
117
 
118
- test 'input should translate a key prefixed with _html and return the html markup' do
118
+ test 'input translates a key prefixed with _html and return the html markup' do
119
119
  store_translations(:en, simple_form: { labels: { user: {
120
120
  name_html: '<b>Name</b>'
121
121
  } } }) do
@@ -125,13 +125,13 @@ class StringInputTest < ActionView::TestCase
125
125
  end
126
126
 
127
127
  [:email, :url, :search, :tel].each do |type|
128
- test "input should allow type #{type}" do
128
+ test "input allows type #{type}" do
129
129
  with_input_for @user, :name, type
130
130
  assert_select "input.string.#{type}"
131
131
  assert_select "input[type=#{type}]"
132
132
  end
133
133
 
134
- test "input should not allow type #{type} if HTML5 compatibility is disabled" do
134
+ test "input does not allow type #{type} if HTML5 compatibility is disabled" do
135
135
  swap_wrapper do
136
136
  with_input_for @user, :name, type
137
137
  assert_select "input[type=text]"
@@ -2,22 +2,22 @@
2
2
  require 'test_helper'
3
3
 
4
4
  class TextInputTest < ActionView::TestCase
5
- test 'input should generate a text area for text attributes' do
5
+ test 'input generates a text area for text attributes' do
6
6
  with_input_for @user, :description, :text
7
7
  assert_select 'textarea.text#user_description'
8
8
  end
9
9
 
10
- test 'input should generate a text area for text attributes that accept placeholder' do
10
+ test 'input generates a text area for text attributes that accept placeholder' do
11
11
  with_input_for @user, :description, :text, placeholder: 'Put in some text'
12
12
  assert_select 'textarea.text[placeholder=Put in some text]'
13
13
  end
14
14
 
15
- test 'input should get maxlength from column definition for text attributes' do
15
+ test 'input gets maxlength from column definition for text attributes' do
16
16
  with_input_for @user, :description, :text
17
17
  assert_select 'textarea.text[maxlength=200]'
18
18
  end
19
19
 
20
- test 'input should infer maxlength column definition from validation when present for text attributes' do
20
+ test 'input infers maxlength column definition from validation when present for text attributes' do
21
21
  with_input_for @validating_user, :description, :text
22
22
  assert_select 'textarea.text[maxlength=50]'
23
23
  end
@@ -35,3 +35,23 @@ class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
35
35
  super.push('chosen')
36
36
  end
37
37
  end
38
+
39
+ module CustomInputs
40
+ class CustomizedInput < SimpleForm::Inputs::StringInput
41
+ def input_html_classes
42
+ super.push('customized-namespace-custom-input')
43
+ end
44
+ end
45
+
46
+ class PasswordInput < SimpleForm::Inputs::PasswordInput
47
+ def input_html_classes
48
+ super.push('password-custom-input')
49
+ end
50
+ end
51
+
52
+ class NumericInput < SimpleForm::Inputs::PasswordInput
53
+ def input_html_classes
54
+ super.push('numeric-custom-input')
55
+ end
56
+ end
57
+ end
@@ -68,6 +68,22 @@ module MiscHelpers
68
68
  end
69
69
  end
70
70
 
71
+ def custom_wrapper_with_wrapped_optional_component
72
+ SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
73
+ b.wrapper tag: :div, class: 'no_output_wrapper' do |ba|
74
+ ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
75
+ end
76
+ end
77
+ end
78
+
79
+ def custom_wrapper_with_unless_blank
80
+ SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
81
+ b.wrapper tag: :div, class: 'no_output_wrapper', unless_blank: true do |ba|
82
+ ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
83
+ end
84
+ end
85
+ end
86
+
71
87
  def custom_wrapper_with_input_class
72
88
  SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
73
89
  b.use :label
@@ -156,6 +172,12 @@ module MiscHelpers
156
172
  end
157
173
  end
158
174
 
175
+ def custom_wrapper_with_custom_label_component
176
+ SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
177
+ b.use :label_text
178
+ end
179
+ end
180
+
159
181
  def custom_form_for(object, *args, &block)
160
182
  simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
161
183
  end
@@ -74,7 +74,7 @@ class User
74
74
  :avatar, :home_picture, :email, :status, :residence_country, :phone_number,
75
75
  :post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
76
76
  :extra_special_company_id, :pictures, :picture_ids, :special_pictures,
77
- :special_picture_ids
77
+ :special_picture_ids, :uuid
78
78
 
79
79
  def self.build(extra_attributes = {})
80
80
  attributes = {
@@ -125,6 +125,7 @@ class User
125
125
  when :attempts then :integer
126
126
  when :action then :string
127
127
  when :credit_card then :string
128
+ when :uuid then :uuid
128
129
  end
129
130
  Column.new(attribute, column_type, limit)
130
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.rc1
4
+ version: 3.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-14 00:00:00.000000000 Z
13
+ date: 2014-07-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel