formtastic-bootstrap 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/Gemfile +5 -3
  2. data/Gemfile.lock +72 -60
  3. data/README.md +4 -1
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/formtastic-bootstrap.gemspec +49 -16
  7. data/lib/formtastic-bootstrap/actions/base.rb +22 -0
  8. data/lib/formtastic-bootstrap/actions/button_action.rb +13 -0
  9. data/lib/formtastic-bootstrap/actions/input_action.rb +13 -0
  10. data/lib/formtastic-bootstrap/actions/link_action.rb +12 -0
  11. data/lib/formtastic-bootstrap/actions.rb +10 -0
  12. data/lib/formtastic-bootstrap/form_builder.rb +4 -2
  13. data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
  14. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +24 -0
  15. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +2 -4
  16. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +0 -2
  17. data/lib/formtastic-bootstrap/helpers.rb +6 -8
  18. data/lib/formtastic-bootstrap/inputs/base/choices.rb +6 -35
  19. data/lib/formtastic-bootstrap/inputs/base/collections.rb +9 -0
  20. data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +9 -0
  21. data/lib/formtastic-bootstrap/inputs/base/hints.rb +1 -1
  22. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +14 -3
  23. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +9 -0
  24. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +4 -5
  25. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +38 -18
  26. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +22 -34
  27. data/lib/formtastic-bootstrap/inputs/base.rb +29 -6
  28. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +14 -18
  29. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +16 -11
  30. data/lib/formtastic-bootstrap/inputs/date_input.rb +3 -9
  31. data/lib/formtastic-bootstrap/inputs/date_select_input.rb +8 -0
  32. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +3 -12
  33. data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +8 -0
  34. data/lib/formtastic-bootstrap/inputs/email_input.rb +1 -1
  35. data/lib/formtastic-bootstrap/inputs/file_input.rb +1 -1
  36. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +1 -1
  37. data/lib/formtastic-bootstrap/inputs/number_input.rb +3 -3
  38. data/lib/formtastic-bootstrap/inputs/password_input.rb +1 -1
  39. data/lib/formtastic-bootstrap/inputs/phone_input.rb +1 -1
  40. data/lib/formtastic-bootstrap/inputs/radio_input.rb +28 -14
  41. data/lib/formtastic-bootstrap/inputs/range_input.rb +1 -1
  42. data/lib/formtastic-bootstrap/inputs/search_input.rb +1 -1
  43. data/lib/formtastic-bootstrap/inputs/select_input.rb +3 -1
  44. data/lib/formtastic-bootstrap/inputs/string_input.rb +0 -7
  45. data/lib/formtastic-bootstrap/inputs/text_input.rb +1 -1
  46. data/lib/formtastic-bootstrap/inputs/time_input.rb +3 -9
  47. data/lib/formtastic-bootstrap/inputs/time_select_input.rb +8 -0
  48. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +1 -1
  49. data/lib/formtastic-bootstrap/inputs/url_input.rb +1 -1
  50. data/lib/formtastic-bootstrap/inputs.rb +30 -23
  51. data/lib/formtastic-bootstrap.rb +16 -1
  52. data/spec/actions/button_action_spec.rb +63 -0
  53. data/spec/actions/input_action_spec.rb +59 -0
  54. data/spec/actions/link_action_spec.rb +92 -0
  55. data/spec/helpers/action_helper_spec.rb +368 -0
  56. data/spec/helpers/actions_helper_spec.rb +147 -0
  57. data/spec/helpers/input_helper_spec.rb +238 -259
  58. data/spec/helpers/inputs_helper_spec.rb +84 -25
  59. data/spec/inputs/boolean_input_spec.rb +108 -75
  60. data/spec/inputs/check_boxes_input_spec.rb +106 -91
  61. data/spec/inputs/date_select_input_spec.rb +164 -0
  62. data/spec/inputs/datetime_select_input_spec.rb +112 -0
  63. data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +48 -0
  64. data/spec/inputs/email_input_spec.rb +30 -3
  65. data/spec/inputs/file_input_spec.rb +31 -4
  66. data/spec/inputs/hidden_input_spec.rb +63 -32
  67. data/spec/inputs/number_input_spec.rb +37 -8
  68. data/spec/inputs/password_input_spec.rb +30 -3
  69. data/spec/inputs/phone_input_spec.rb +30 -3
  70. data/spec/inputs/radio_input_spec.rb +87 -60
  71. data/spec/inputs/range_input_spec.rb +32 -5
  72. data/spec/inputs/search_input_spec.rb +29 -3
  73. data/spec/inputs/select_input_spec.rb +164 -107
  74. data/spec/inputs/string_input_spec.rb +33 -22
  75. data/spec/inputs/text_input_spec.rb +39 -14
  76. data/spec/inputs/time_select_input_spec.rb +191 -0
  77. data/spec/inputs/time_zone_input_spec.rb +17 -19
  78. data/spec/inputs/url_input_spec.rb +30 -3
  79. data/spec/spec_helper.rb +21 -15
  80. data/spec/support/custom_macros.rb +61 -228
  81. data/spec/support/fb_custom_macros.rb +23 -0
  82. metadata +109 -28
  83. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +0 -52
  84. data/spec/builder/errors_spec.rb +0 -214
  85. data/spec/helpers/buttons_helper_spec.rb +0 -149
  86. data/spec/inputs/date_input_spec.rb +0 -147
  87. data/spec/inputs/datetime_input_spec.rb +0 -101
  88. data/spec/inputs/time_input_spec.rb +0 -206
  89. data/spec/support/depracation.rb +0 -6
  90. data/spec/support/formtastic_spec_helper.rb +0 -382
@@ -8,7 +8,6 @@ describe 'radio input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
  end
13
12
 
14
13
  describe 'for belongs_to association' do
@@ -18,64 +17,55 @@ describe 'radio input' do
18
17
  end)
19
18
  end
20
19
 
21
- it_should_have_input_wrapper_with_class("radio")
22
- it_should_have_input_wrapper_with_class(:clearfix)
23
- it_should_have_input_class_in_the_right_place
20
+ it_should_have_bootstrap_horizontal_wrapping
21
+ it_should_have_input_wrapper_with_class("radio_buttons")
22
+ it_should_have_input_wrapper_with_class(:input)
24
23
  it_should_have_input_wrapper_with_id("post_author_input")
25
- it_should_have_a_nested_div
26
- it_should_have_a_nested_div_with_class('choices.input')
27
- it_should_have_a_nested_unordered_list_with_class('choices-group.inputs-list')
28
- it_should_apply_error_logic_for_input_type(:radio, :block)
24
+ # it_should_have_a_nested_fieldset
25
+ # it_should_have_a_nested_fieldset_with_class('choices')
26
+ # it_should_have_a_nested_ordered_list_with_class('choices-group')
27
+ it_should_apply_error_logic_for_input_type(:radio)
29
28
  it_should_use_the_collection_when_provided(:radio, 'input')
30
29
 
31
- it 'should generate a \'legend\' containing a label with text for the input' do
32
- output_buffer.should have_tag('form div.clearfix label')
33
- output_buffer.should have_tag('form div.clearfix label', /Author/)
34
- end
35
-
36
- it 'should not link the \'legend\' label to any input' do
37
- output_buffer.should_not have_tag('form div.clearfix > label[@for]')
38
- end
39
-
40
- it 'should generate an unordered list with a list item for each choice' do
41
- output_buffer.should have_tag('form div.clearfix div.input ul')
42
- output_buffer.should have_tag('form div.clearfix div.input ul li.choice', :count => ::Author.all.size)
30
+ it 'should generate a control label with text for the input' do
31
+ output_buffer.should have_tag('form div.control-group > label.control-label')
32
+ output_buffer.should have_tag('form div.control-group > label.control-label', /Author/)
43
33
  end
44
34
 
45
35
  it 'should have one option with a "checked" attribute' do
46
- output_buffer.should have_tag('form ul input[@checked]', :count => 1)
36
+ output_buffer.should have_tag('form div.control-group div.controls input[@checked]', :count => 1)
47
37
  end
48
38
 
49
39
  describe "each choice" do
50
-
40
+
51
41
  it 'should not give the choice label the .label class' do
52
- output_buffer.should_not have_tag('li.choice label.label')
42
+ output_buffer.should_not have_tag('div.controls label.label')
53
43
  end
54
-
44
+
55
45
  it 'should not add the required attribute to each input' do
56
- output_buffer.should_not have_tag('li.choice input[@required]')
46
+ output_buffer.should_not have_tag('div.controls input[@required]')
57
47
  end
58
-
59
-
48
+
49
+
60
50
  it 'should contain a label for the radio input with a nested input and label text' do
61
51
  ::Author.all.each do |author|
62
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /#{author.to_label}/)
63
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='post_author_id_#{author.id}']")
52
+ output_buffer.should have_tag('form div.control-group div.controls label', /#{author.to_label}/)
53
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_id_#{author.id}']")
64
54
  end
65
55
  end
66
56
 
67
57
  it 'should use values as li.class when value_as_class is true' do
68
58
  ::Author.all.each do |author|
69
- output_buffer.should have_tag("form div.clearfix ul li.author_#{author.id} label")
59
+ output_buffer.should have_tag("form div.control-group div.controls label.author_#{author.id}")
70
60
  end
71
61
  end
72
62
 
73
63
  it "should have a radio input" do
74
64
  ::Author.all.each do |author|
75
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#post_author_id_#{author.id}")
76
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@type='radio']")
77
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='#{author.id}']")
78
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='post[author_id]']")
65
+ output_buffer.should have_tag("form div.control-group div.controls label input#post_author_id_#{author.id}")
66
+ output_buffer.should have_tag("form div.control-group div.controls label input[@type='radio']")
67
+ output_buffer.should have_tag("form div.control-group div.controls label input[@value='#{author.id}']")
68
+ output_buffer.should have_tag("form div.control-group div.controls label input[@name='post[author_id]']")
79
69
  end
80
70
  end
81
71
 
@@ -88,7 +78,7 @@ describe 'radio input' do
88
78
  concat(builder.input(:author, :as => :radio))
89
79
  end)
90
80
 
91
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@checked='checked']")
81
+ output_buffer.should have_tag("form div.control-group div.controls label input[@checked='checked']")
92
82
  end
93
83
 
94
84
  it "should mark the input as disabled if options attached for disabling" do
@@ -96,8 +86,8 @@ describe 'radio input' do
96
86
  concat(builder.input(:author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]))
97
87
  end)
98
88
 
99
- output_buffer.should_not have_tag("form div.clearfix div.input ul li label input[@value='test'][@disabled='disabled']")
100
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='try'][@disabled='disabled']")
89
+ output_buffer.should_not have_tag("form div.control-group div.controls label input[@value='test'][@disabled='disabled']")
90
+ output_buffer.should have_tag("form div.control-group div.controls label input[@value='try'][@disabled='disabled']")
101
91
  end
102
92
 
103
93
  it "should not contain invalid HTML attributes" do
@@ -106,7 +96,7 @@ describe 'radio input' do
106
96
  concat(builder.input(:author, :as => :radio))
107
97
  end)
108
98
 
109
- output_buffer.should_not have_tag("form div.clearfix div.input ul li input[@find_options]")
99
+ output_buffer.should_not have_tag("form li fieldset ol li input[@find_options]")
110
100
  end
111
101
 
112
102
  end
@@ -119,18 +109,10 @@ describe 'radio input' do
119
109
  end)
120
110
  end
121
111
 
122
- it 'should generate a div with a label' do
123
- output_buffer.should have_tag('form div.clearfix label', /Author/)
124
- end
125
-
126
- it 'should generate an li tag for each item in the collection' do
127
- output_buffer.should have_tag('form div.clearfix div ul li', :count => ::Author.all.size)
128
- end
129
-
130
112
  it 'should generate labels for each item' do
131
113
  ::Author.all.each do |author|
132
- output_buffer.should have_tag('form div div ul li label', /#{author.to_label}/)
133
- output_buffer.should have_tag("form div div ul li label[@for='project_author_id_#{author.id}']")
114
+ output_buffer.should have_tag('form div.control-group div.controls label', /#{author.to_label}/)
115
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='project_author_id_#{author.id}']")
134
116
  end
135
117
  end
136
118
 
@@ -138,18 +120,17 @@ describe 'radio input' do
138
120
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
139
121
  concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
140
122
  end)
141
- output_buffer.should have_tag('form div div ul li label') do |label|
142
- # label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
143
- label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;/
123
+ output_buffer.should have_tag('form div.control-group div.controls label') do |label|
124
+ label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
144
125
  end
145
126
  end
146
127
 
147
128
  it 'should generate inputs for each item' do
148
129
  ::Author.all.each do |author|
149
- output_buffer.should have_tag("form div div ul li label input#project_author_id_#{author.id}")
150
- output_buffer.should have_tag("form div div ul li label input[@type='radio']")
151
- output_buffer.should have_tag("form div div ul li label input[@value='#{author.id}']")
152
- output_buffer.should have_tag("form div div ul li label input[@name='project[author_id]']")
130
+ output_buffer.should have_tag("form div.control-group div.controls label input#project_author_id_#{author.id}")
131
+ output_buffer.should have_tag("form div.control-group div.controls label input[@type='radio']")
132
+ output_buffer.should have_tag("form div.control-group div.controls label input[@value='#{author.id}']")
133
+ output_buffer.should have_tag("form div.control-group div.controls label input[@name='project[author_id]']")
153
134
  end
154
135
  end
155
136
  end
@@ -173,7 +154,7 @@ describe 'radio input' do
173
154
  end
174
155
 
175
156
  it "should do foo" do
176
- output_buffer.should have_tag("div.clearfix > label", /Translated/)
157
+ output_buffer.should have_tag("label.control-label", /Translated/)
177
158
  end
178
159
 
179
160
  end
@@ -187,7 +168,7 @@ describe 'radio input' do
187
168
  end
188
169
 
189
170
  it "should output the correct label title" do
190
- output_buffer.should have_tag("div.clearfix > label", /The authors/)
171
+ output_buffer.should have_tag("label.control-label", /The authors/)
191
172
  end
192
173
  end
193
174
 
@@ -201,10 +182,11 @@ describe 'radio input' do
201
182
  end
202
183
 
203
184
  it "should not output the legend" do
204
- output_buffer.should_not have_tag("legend.label")
185
+ # TODO I think this is not supported in FB.
186
+ output_buffer.should_not have_tag("label.control-label")
205
187
  output_buffer.should_not include("&gt;")
206
188
  end
207
-
189
+
208
190
  it "should not cause escaped HTML" do
209
191
  output_buffer.should_not include("&gt;")
210
192
  end
@@ -219,7 +201,7 @@ describe 'radio input' do
219
201
  end
220
202
 
221
203
  it "should output the correct label title" do
222
- output_buffer.should have_tag("div.clearfix label abbr")
204
+ output_buffer.should have_tag("label.control-label abbr")
223
205
  end
224
206
  end
225
207
 
@@ -237,4 +219,49 @@ describe 'radio input' do
237
219
  it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
238
220
  end
239
221
 
222
+ describe "when index is provided" do
223
+
224
+ before do
225
+ @output_buffer = ''
226
+ mock_everything
227
+
228
+ concat(semantic_form_for(@new_post) do |builder|
229
+ concat(builder.fields_for(:author, :index => 3) do |author|
230
+ concat(author.input(:name, :as => :radio))
231
+ end)
232
+ end)
233
+ end
234
+
235
+ it 'should index the id of the control-group' do
236
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
237
+ end
238
+
239
+ it 'should index the id of the select tag' do
240
+ output_buffer.should have_tag("input#post_author_attributes_3_name_true")
241
+ output_buffer.should have_tag("input#post_author_attributes_3_name_false")
242
+ end
243
+
244
+ it 'should index the name of the select tag' do
245
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
246
+ end
247
+
248
+ end
249
+
250
+ describe "when collection contains integers" do
251
+ before do
252
+ @output_buffer = ''
253
+ mock_everything
254
+
255
+ concat(semantic_form_for(:project) do |builder|
256
+ concat(builder.input(:author_id, :as => :radio, :collection => [1, 2, 3]))
257
+ end)
258
+ end
259
+
260
+ it 'should output the correct labels' do
261
+ output_buffer.should have_tag("div.controls label", /1/)
262
+ output_buffer.should have_tag("div.controls label", /2/)
263
+ output_buffer.should have_tag("div.controls label", /3/)
264
+ end
265
+ end
266
+
240
267
  end
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
- require 'active_record'
4
3
 
5
4
  describe 'range input' do
6
5
 
@@ -9,7 +8,6 @@ describe 'range input' do
9
8
  before do
10
9
  @output_buffer = ''
11
10
  mock_everything
12
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
13
11
  end
14
12
 
15
13
  describe "when object is provided" do
@@ -19,10 +17,11 @@ describe 'range input' do
19
17
  end)
20
18
  end
21
19
 
20
+ it_should_have_bootstrap_horizontal_wrapping
22
21
  it_should_have_input_wrapper_with_class(:range)
23
- it_should_have_input_wrapper_with_class(:clearfix)
24
- it_should_have_input_wrapper_with_class(:stringish) # might be removed
25
- it_should_have_input_class_in_the_right_place
22
+ it_should_have_input_wrapper_with_class(:input)
23
+ it_should_have_input_wrapper_with_class(:numeric)
24
+ it_should_have_input_wrapper_with_class(:stringish)
26
25
  it_should_have_input_wrapper_with_id("author_age_input")
27
26
  it_should_have_label_with_text(/Age/)
28
27
  it_should_have_label_for("author_age")
@@ -44,6 +43,34 @@ describe 'range input' do
44
43
  it_should_have_label_and_input_with_id("context2_author_age")
45
44
 
46
45
  end
46
+
47
+ describe "when index is provided" do
48
+
49
+ before do
50
+ @output_buffer = ''
51
+ mock_everything
52
+
53
+ concat(semantic_form_for(@new_post) do |builder|
54
+ concat(builder.fields_for(:author, :index => 3) do |author|
55
+ concat(author.input(:name, :as => :range))
56
+ end)
57
+ end)
58
+ end
59
+
60
+ it 'should index the id of the control-group' do
61
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
62
+ end
63
+
64
+ it 'should index the id of the select tag' do
65
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
66
+ end
67
+
68
+ it 'should index the name of the select tag' do
69
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
70
+ end
71
+
72
+ end
73
+
47
74
 
48
75
  describe "when validations require a minimum value (:greater_than)" do
49
76
  before do
@@ -8,7 +8,6 @@ describe 'search input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
  end
13
12
 
14
13
  describe "when object is provided" do
@@ -18,10 +17,10 @@ describe 'search input' do
18
17
  end)
19
18
  end
20
19
 
20
+ it_should_have_bootstrap_horizontal_wrapping
21
21
  it_should_have_input_wrapper_with_class(:search)
22
- it_should_have_input_wrapper_with_class(:clearfix)
22
+ it_should_have_input_wrapper_with_class(:input)
23
23
  it_should_have_input_wrapper_with_class(:stringish)
24
- it_should_have_input_class_in_the_right_place
25
24
  it_should_have_input_wrapper_with_id("post_search_input")
26
25
  it_should_have_label_with_text(/Search/)
27
26
  it_should_have_label_for("post_search")
@@ -44,6 +43,33 @@ describe 'search input' do
44
43
 
45
44
  end
46
45
 
46
+ describe "when index is provided" do
47
+
48
+ before do
49
+ @output_buffer = ''
50
+ mock_everything
51
+
52
+ concat(semantic_form_for(@new_post) do |builder|
53
+ concat(builder.fields_for(:author, :index => 3) do |author|
54
+ concat(author.input(:name, :as => :search))
55
+ end)
56
+ end)
57
+ end
58
+
59
+ it 'should index the id of the control-group' do
60
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
61
+ end
62
+
63
+ it 'should index the id of the select tag' do
64
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
65
+ end
66
+
67
+ it 'should index the name of the select tag' do
68
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
69
+ end
70
+
71
+ end
72
+
47
73
  describe "when required" do
48
74
  it "should add the required attribute to the input's html options" do
49
75
  with_config :use_required_attribute, true do