speedo-formstrap 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/Gemfile +0 -1
  2. data/README.md +4 -4
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/speedo-formstrap/form_builder.rb +7 -5
  6. data/lib/speedo-formstrap/helpers.rb +3 -1
  7. data/lib/speedo-formstrap/helpers/buttons_helper.rb +13 -9
  8. data/lib/speedo-formstrap/helpers/fieldset_wrapper.rb +11 -6
  9. data/lib/speedo-formstrap/helpers/inputs_helper.rb +4 -4
  10. data/lib/speedo-formstrap/inputs/base.rb +2 -1
  11. data/lib/speedo-formstrap/inputs/base/choices.rb +12 -23
  12. data/lib/speedo-formstrap/inputs/base/labelling.rb +16 -6
  13. data/lib/speedo-formstrap/inputs/base/timeish.rb +5 -12
  14. data/lib/speedo-formstrap/inputs/base/wrapping.rb +32 -14
  15. data/lib/speedo-formstrap/inputs/number_input.rb +2 -2
  16. data/lib/speedo-formstrap/inputs/radio_input.rb +13 -12
  17. data/lib/speedo-formstrap/inputs/range_input.rb +2 -2
  18. data/spec/builder/semantic_fields_for_spec.rb +16 -16
  19. data/spec/helpers/buttons_helper_spec.rb +56 -46
  20. data/spec/helpers/input_helper_spec.rb +209 -209
  21. data/spec/helpers/inputs_helper_spec.rb +117 -103
  22. data/spec/inputs/boolean_input_spec.rb +74 -46
  23. data/spec/inputs/check_boxes_input_spec.rb +110 -82
  24. data/spec/inputs/date_input_spec.rb +81 -15
  25. data/spec/inputs/datetime_input_spec.rb +13 -13
  26. data/spec/inputs/email_input_spec.rb +34 -6
  27. data/spec/inputs/file_input_spec.rb +34 -6
  28. data/spec/inputs/hidden_input_spec.rb +41 -13
  29. data/spec/inputs/number_input_spec.rb +127 -97
  30. data/spec/inputs/password_input_spec.rb +34 -6
  31. data/spec/inputs/phone_input_spec.rb +34 -6
  32. data/spec/inputs/radio_input_spec.rb +73 -45
  33. data/spec/inputs/range_input_spec.rb +94 -66
  34. data/spec/inputs/search_input_spec.rb +33 -6
  35. data/spec/inputs/select_input_spec.rb +124 -78
  36. data/spec/inputs/string_input_spec.rb +67 -22
  37. data/spec/inputs/text_input_spec.rb +42 -15
  38. data/spec/inputs/time_input_spec.rb +23 -23
  39. data/spec/inputs/time_zone_input_spec.rb +20 -20
  40. data/spec/inputs/url_input_spec.rb +34 -6
  41. data/spec/support/custom_macros.rb +67 -196
  42. data/spec/support/formtastic_spec_helper.rb +22 -6
  43. data/speedo-formstrap.gemspec +2 -2
  44. metadata +17 -17
@@ -8,15 +8,15 @@ describe 'password input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
12
 
13
13
  concat(semantic_form_for(@new_post) do |builder|
14
14
  concat(builder.input(:title, :as => :password))
15
15
  end)
16
16
  end
17
17
 
18
- it_should_have_input_wrapper_with_class(:password)
19
- it_should_have_input_wrapper_with_class(:clearfix)
18
+ it_should_have_input_wrapper_with_class('password-wrapper')
19
+ it_should_have_input_wrapper_with_class("control-group")
20
20
  it_should_have_input_wrapper_with_class(:stringish)
21
21
  it_should_have_input_class_in_the_right_place
22
22
  it_should_have_input_wrapper_with_id("post_title_input")
@@ -58,10 +58,38 @@ describe 'password input' do
58
58
  it_should_have_label_and_input_with_id("context2_post_title")
59
59
 
60
60
  end
61
-
61
+
62
+ describe "when index is provided" do
63
+
64
+ before do
65
+ @output_buffer = ''
66
+ mock_everything
67
+
68
+ concat(semantic_form_for(@new_post) do |builder|
69
+ concat(builder.fields_for(:author, :index => 3) do |author|
70
+ concat(author.input(:name, :as => :password))
71
+ end)
72
+ end)
73
+ end
74
+
75
+ it 'should index the id of the wrapper' do
76
+ output_buffer.should have_tag("div#post_author_attributes_3_name_input")
77
+ end
78
+
79
+ it 'should index the id of the select tag' do
80
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
81
+ end
82
+
83
+ it 'should index the name of the select tag' do
84
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
85
+ end
86
+
87
+ end
88
+
89
+
62
90
  describe "when required" do
63
91
  it "should add the required attribute to the input's html options" do
64
- with_config :use_required_attribute, true do
92
+ with_config :use_required_attribute, true do
65
93
  concat(semantic_form_for(@new_post) do |builder|
66
94
  concat(builder.input(:title, :as => :password, :required => true))
67
95
  end)
@@ -69,5 +97,5 @@ describe 'password input' do
69
97
  end
70
98
  end
71
99
  end
72
-
100
+
73
101
  end
@@ -8,7 +8,7 @@ describe 'phone input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
12
  end
13
13
 
14
14
  describe "when object is provided" do
@@ -18,8 +18,8 @@ describe 'phone input' do
18
18
  end)
19
19
  end
20
20
 
21
- it_should_have_input_wrapper_with_class(:phone)
22
- it_should_have_input_wrapper_with_class(:clearfix)
21
+ it_should_have_input_wrapper_with_class('phone-wrapper')
22
+ it_should_have_input_wrapper_with_class("control-group")
23
23
  it_should_have_input_wrapper_with_class(:stringish)
24
24
  it_should_have_input_class_in_the_right_place
25
25
  it_should_have_input_wrapper_with_id("post_phone_input")
@@ -43,10 +43,38 @@ describe 'phone input' do
43
43
  it_should_have_label_and_input_with_id("context2_post_phone")
44
44
 
45
45
  end
46
-
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 => :phone))
56
+ end)
57
+ end)
58
+ end
59
+
60
+ it 'should index the id of the wrapper' do
61
+ output_buffer.should have_tag("div#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
+
74
+
47
75
  describe "when required" do
48
76
  it "should add the required attribute to the input's html options" do
49
- with_config :use_required_attribute, true do
77
+ with_config :use_required_attribute, true do
50
78
  concat(semantic_form_for(@new_post) do |builder|
51
79
  concat(builder.input(:title, :as => :phone, :required => true))
52
80
  end)
@@ -54,6 +82,6 @@ describe 'phone input' do
54
82
  end
55
83
  end
56
84
  end
57
-
85
+
58
86
  end
59
87
 
@@ -8,7 +8,7 @@ describe 'radio input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
12
  end
13
13
 
14
14
  describe 'for belongs_to association' do
@@ -18,64 +18,64 @@ describe 'radio input' do
18
18
  end)
19
19
  end
20
20
 
21
- it_should_have_input_wrapper_with_class("radio")
22
- it_should_have_input_wrapper_with_class(:clearfix)
21
+ it_should_have_input_wrapper_with_class("radio-wrapper")
22
+ it_should_have_input_wrapper_with_class("control-group")
23
23
  it_should_have_input_class_in_the_right_place
24
24
  it_should_have_input_wrapper_with_id("post_author_input")
25
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')
26
+ it_should_have_a_nested_div_with_class('choices.controls')
27
+ #it_should_have_a_nested_unordered_list_with_class('choices-group.inputs-list')
28
28
  it_should_apply_error_logic_for_input_type(:radio, :block)
29
- it_should_use_the_collection_when_provided(:radio, 'input')
29
+ it_should_use_the_collection_when_provided(:radio, 'input[@type="radio"]')
30
30
 
31
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/)
32
+ output_buffer.should have_tag('form div.control-group label.control-label')
33
+ output_buffer.should have_tag('form div.control-group label.control-label', /Author/)
34
34
  end
35
35
 
36
36
  it 'should not link the \'legend\' label to any input' do
37
- output_buffer.should_not have_tag('form div.clearfix > label[@for]')
37
+ output_buffer.should_not have_tag('form div.control-group > label.control-label[@for]')
38
38
  end
39
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)
43
- end
40
+ # it 'should generate an unordered list with a list item for each choice' do
41
+ # output_buffer.should have_tag('form div.control-group div.controls ul')
42
+ # output_buffer.should have_tag('form div.control-group div.controls ul li.choice', :count => ::Author.all.size)
43
+ # end
44
44
 
45
45
  it 'should have one option with a "checked" attribute' do
46
- output_buffer.should have_tag('form ul input[@checked]', :count => 1)
46
+ output_buffer.should have_tag('form .controls input[@checked]', :count => 1)
47
47
  end
48
48
 
49
49
  describe "each choice" do
50
-
51
- it 'should not give the choice label the .label class' do
52
- output_buffer.should_not have_tag('li.choice label.label')
50
+
51
+ it 'should not give the choice label the .control-label class' do
52
+ output_buffer.should_not have_tag('div.controls label.control-label')
53
53
  end
54
-
54
+
55
55
  it 'should not add the required attribute to each input' do
56
56
  output_buffer.should_not have_tag('li.choice input[@required]')
57
57
  end
58
-
59
-
58
+
59
+
60
60
  it 'should contain a label for the radio input with a nested input and label text' do
61
61
  ::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}']")
62
+ output_buffer.should have_tag('form div.control-group div.controls label.radio', /#{author.to_label}/)
63
+ output_buffer.should have_tag("form div.control-group div.controls label.radio[@for='post_author_id_#{author.id}']")
64
64
  end
65
65
  end
66
66
 
67
67
  it 'should use values as li.class when value_as_class is true' do
68
68
  ::Author.all.each do |author|
69
- output_buffer.should have_tag("form div.clearfix ul li.author_#{author.id} label")
69
+ output_buffer.should have_tag("form div.control-group label.radio.author_#{author.id}")
70
70
  end
71
71
  end
72
72
 
73
73
  it "should have a radio input" do
74
74
  ::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]']")
75
+ output_buffer.should have_tag("form div.control-group div.controls label.radio input#post_author_id_#{author.id}")
76
+ output_buffer.should have_tag("form div.control-group div.controls label.radio input[@type='radio']")
77
+ output_buffer.should have_tag("form div.control-group div.controls label.radio input[@value='#{author.id}']")
78
+ output_buffer.should have_tag("form div.control-group div.controls label.radio input[@name='post[author_id]']")
79
79
  end
80
80
  end
81
81
 
@@ -88,7 +88,7 @@ describe 'radio input' do
88
88
  concat(builder.input(:author, :as => :radio))
89
89
  end)
90
90
 
91
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@checked='checked']")
91
+ output_buffer.should have_tag("form div.control-group div.controls label.radio input[@checked='checked']")
92
92
  end
93
93
 
94
94
  it "should mark the input as disabled if options attached for disabling" do
@@ -96,8 +96,8 @@ describe 'radio input' do
96
96
  concat(builder.input(:author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]))
97
97
  end)
98
98
 
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']")
99
+ output_buffer.should_not have_tag("form div.control-group div.controls label.radio input[@value='test'][@disabled='disabled']")
100
+ output_buffer.should have_tag("form div.control-group div.controls label.radio input[@value='try'][@disabled='disabled']")
101
101
  end
102
102
 
103
103
  it "should not contain invalid HTML attributes" do
@@ -106,7 +106,7 @@ describe 'radio input' do
106
106
  concat(builder.input(:author, :as => :radio))
107
107
  end)
108
108
 
109
- output_buffer.should_not have_tag("form div.clearfix div.input ul li input[@find_options]")
109
+ output_buffer.should_not have_tag("form div.control-group div.controls input[@find_options]")
110
110
  end
111
111
 
112
112
  end
@@ -120,17 +120,17 @@ describe 'radio input' do
120
120
  end
121
121
 
122
122
  it 'should generate a div with a label' do
123
- output_buffer.should have_tag('form div.clearfix label', /Author/)
123
+ output_buffer.should have_tag('form div.control-group label.control-label', /Author/)
124
124
  end
125
125
 
126
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)
127
+ output_buffer.should have_tag('form div.control-group div label.radio', :count => ::Author.all.size)
128
128
  end
129
129
 
130
130
  it 'should generate labels for each item' do
131
131
  ::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}']")
132
+ output_buffer.should have_tag('form div div label.radio', /#{author.to_label}/)
133
+ output_buffer.should have_tag("form div div label.radio[@for='project_author_id_#{author.id}']")
134
134
  end
135
135
  end
136
136
 
@@ -138,7 +138,7 @@ describe 'radio input' do
138
138
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
139
139
  concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
140
140
  end)
141
- output_buffer.should have_tag('form div div ul li label') do |label|
141
+ output_buffer.should have_tag('form div div label.radio') do |label|
142
142
  # label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
143
143
  label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;/
144
144
  end
@@ -146,10 +146,10 @@ describe 'radio input' do
146
146
 
147
147
  it 'should generate inputs for each item' do
148
148
  ::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]']")
149
+ output_buffer.should have_tag("form div div label.radio input#project_author_id_#{author.id}")
150
+ output_buffer.should have_tag("form div div label.radio input[@type='radio']")
151
+ output_buffer.should have_tag("form div div label.radio input[@value='#{author.id}']")
152
+ output_buffer.should have_tag("form div div label.radio input[@name='project[author_id]']")
153
153
  end
154
154
  end
155
155
  end
@@ -173,7 +173,7 @@ describe 'radio input' do
173
173
  end
174
174
 
175
175
  it "should do foo" do
176
- output_buffer.should have_tag("div.clearfix > label", /Translated/)
176
+ output_buffer.should have_tag("div.control-group > label.control-label", /Translated/)
177
177
  end
178
178
 
179
179
  end
@@ -187,7 +187,7 @@ describe 'radio input' do
187
187
  end
188
188
 
189
189
  it "should output the correct label title" do
190
- output_buffer.should have_tag("div.clearfix > label", /The authors/)
190
+ output_buffer.should have_tag("div.control-group > label.control-label", /The authors/)
191
191
  end
192
192
  end
193
193
 
@@ -201,10 +201,10 @@ describe 'radio input' do
201
201
  end
202
202
 
203
203
  it "should not output the legend" do
204
- output_buffer.should_not have_tag("legend.label")
204
+ output_buffer.should_not have_tag("legend.control-label")
205
205
  output_buffer.should_not include("&gt;")
206
206
  end
207
-
207
+
208
208
  it "should not cause escaped HTML" do
209
209
  output_buffer.should_not include("&gt;")
210
210
  end
@@ -219,7 +219,7 @@ describe 'radio input' do
219
219
  end
220
220
 
221
221
  it "should output the correct label title" do
222
- output_buffer.should have_tag("div.clearfix label abbr")
222
+ output_buffer.should have_tag("div.control-group label.control-label abbr")
223
223
  end
224
224
  end
225
225
 
@@ -237,4 +237,32 @@ describe 'radio input' do
237
237
  it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
238
238
  end
239
239
 
240
+ describe "when index is provided" do
241
+
242
+ before do
243
+ @output_buffer = ''
244
+ mock_everything
245
+
246
+ concat(semantic_form_for(@new_post) do |builder|
247
+ concat(builder.fields_for(:author, :index => 3) do |author|
248
+ concat(author.input(:name, :as => :radio))
249
+ end)
250
+ end)
251
+ end
252
+
253
+ it 'should index the id of the wrapper' do
254
+ output_buffer.should have_tag("div#post_author_attributes_3_name_input")
255
+ end
256
+
257
+ it 'should index the id of the select tag' do
258
+ output_buffer.should have_tag("input#post_author_attributes_3_name_true")
259
+ output_buffer.should have_tag("input#post_author_attributes_3_name_false")
260
+ end
261
+
262
+ it 'should index the name of the select tag' do
263
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
264
+ end
265
+
266
+ end
267
+
240
268
  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,7 @@ describe 'range input' do
9
8
  before do
10
9
  @output_buffer = ''
11
10
  mock_everything
12
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
13
12
  end
14
13
 
15
14
  describe "when object is provided" do
@@ -19,9 +18,10 @@ describe 'range input' do
19
18
  end)
20
19
  end
21
20
 
22
- 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
21
+ it_should_have_input_wrapper_with_class('range-wrapper')
22
+ it_should_have_input_wrapper_with_class("control-group")
23
+ it_should_have_input_wrapper_with_class(:numeric)
24
+ it_should_have_input_wrapper_with_class(:stringish)
25
25
  it_should_have_input_class_in_the_right_place
26
26
  it_should_have_input_wrapper_with_id("author_age_input")
27
27
  it_should_have_label_with_text(/Age/)
@@ -45,46 +45,74 @@ describe 'range input' do
45
45
 
46
46
  end
47
47
 
48
+ describe "when index is provided" do
49
+
50
+ before do
51
+ @output_buffer = ''
52
+ mock_everything
53
+
54
+ concat(semantic_form_for(@new_post) do |builder|
55
+ concat(builder.fields_for(:author, :index => 3) do |author|
56
+ concat(author.input(:name, :as => :range))
57
+ end)
58
+ end)
59
+ end
60
+
61
+ it 'should index the id of the wrapper' do
62
+ output_buffer.should have_tag("div#post_author_attributes_3_name_input")
63
+ end
64
+
65
+ it 'should index the id of the select tag' do
66
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
67
+ end
68
+
69
+ it 'should index the name of the select tag' do
70
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
71
+ end
72
+
73
+ end
74
+
75
+
48
76
  describe "when validations require a minimum value (:greater_than)" do
49
77
  before do
50
78
  @new_post.class.stub!(:validators_on).with(:title).and_return([
51
79
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
52
80
  ])
53
81
  end
54
-
82
+
55
83
  it "should allow :input_html to override :min" do
56
84
  concat(semantic_form_for(@new_post) do |builder|
57
85
  builder.input(:title, :as => :range, :input_html => { :min => 5 })
58
86
  end)
59
87
  output_buffer.should have_tag('input[@min="5"]')
60
88
  end
61
-
89
+
62
90
  it "should allow :input_html to override :min through :in" do
63
91
  concat(semantic_form_for(@new_post) do |builder|
64
92
  builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
65
93
  end)
66
94
  output_buffer.should have_tag('input[@min="5"]')
67
95
  end
68
-
96
+
69
97
  it "should allow options to override :min" do
70
98
  concat(semantic_form_for(@new_post) do |builder|
71
99
  builder.input(:title, :as => :range, :min => 5)
72
100
  end)
73
101
  output_buffer.should have_tag('input[@min="5"]')
74
102
  end
75
-
103
+
76
104
  it "should allow options to override :min through :in" do
77
105
  concat(semantic_form_for(@new_post) do |builder|
78
106
  builder.input(:title, :as => :range, :in => 5..102)
79
107
  end)
80
108
  output_buffer.should have_tag('input[@min="5"]')
81
109
  end
82
-
110
+
83
111
  describe "and the column is an integer" do
84
112
  before do
85
113
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
86
114
  end
87
-
115
+
88
116
  it "should add a min attribute to the input one greater than the validation" do
89
117
  concat(semantic_form_for(@new_post) do |builder|
90
118
  builder.input(:title, :as => :range)
@@ -92,12 +120,12 @@ describe 'range input' do
92
120
  output_buffer.should have_tag('input[@min="3"]')
93
121
  end
94
122
  end
95
-
123
+
96
124
  describe "and the column is a float" do
97
125
  before do
98
126
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
99
127
  end
100
-
128
+
101
129
  it "should raise an error" do
102
130
  lambda {
103
131
  concat(semantic_form_for(@new_post) do |builder|
@@ -106,12 +134,12 @@ describe 'range input' do
106
134
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
107
135
  end
108
136
  end
109
-
137
+
110
138
  describe "and the column is a big decimal" do
111
139
  before do
112
140
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
113
141
  end
114
-
142
+
115
143
  it "should raise an error" do
116
144
  lambda {
117
145
  concat(semantic_form_for(@new_post) do |builder|
@@ -120,23 +148,23 @@ describe 'range input' do
120
148
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
121
149
  end
122
150
  end
123
-
151
+
124
152
  end
125
-
153
+
126
154
  describe "when validations require a minimum value (:greater_than_or_equal_to)" do
127
155
  before do
128
156
  @new_post.class.stub!(:validators_on).with(:title).and_return([
129
157
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
130
158
  ])
131
159
  end
132
-
160
+
133
161
  it "should allow :input_html to override :min" do
134
162
  concat(semantic_form_for(@new_post) do |builder|
135
163
  builder.input(:title, :as => :range, :input_html => { :min => 5 })
136
164
  end)
137
165
  output_buffer.should have_tag('input[@min="5"]')
138
166
  end
139
-
167
+
140
168
  it "should allow options to override :min" do
141
169
  concat(semantic_form_for(@new_post) do |builder|
142
170
  builder.input(:title, :as => :range, :min => 5)
@@ -150,14 +178,14 @@ describe 'range input' do
150
178
  end)
151
179
  output_buffer.should have_tag('input[@min="5"]')
152
180
  end
153
-
181
+
154
182
  it "should allow options to override :min with :in" do
155
183
  concat(semantic_form_for(@new_post) do |builder|
156
184
  builder.input(:title, :as => :range, :in => 5..102)
157
185
  end)
158
186
  output_buffer.should have_tag('input[@min="5"]')
159
187
  end
160
-
188
+
161
189
 
162
190
  [:integer, :decimal, :float].each do |column_type|
163
191
  describe "and the column is a #{column_type}" do
@@ -178,7 +206,7 @@ describe 'range input' do
178
206
  before do
179
207
  @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
180
208
  end
181
-
209
+
182
210
  it "should add a max attribute to the input equal to the validation" do
183
211
  concat(semantic_form_for(@new_post) do |builder|
184
212
  builder.input(:title, :as => :range)
@@ -189,14 +217,14 @@ describe 'range input' do
189
217
  end
190
218
 
191
219
  describe "when validations do not require a minimum value" do
192
-
220
+
193
221
  it "should default to 1" do
194
222
  concat(semantic_form_for(@new_post) do |builder|
195
223
  builder.input(:title, :as => :range)
196
224
  end)
197
225
  output_buffer.should have_tag('input[@min="1"]')
198
226
  end
199
-
227
+
200
228
  end
201
229
 
202
230
  describe "when validations require a maximum value (:less_than)" do
@@ -205,21 +233,21 @@ describe 'range input' do
205
233
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
206
234
  ])
207
235
  end
208
-
236
+
209
237
  it "should allow :input_html to override :max" do
210
238
  concat(semantic_form_for(@new_post) do |builder|
211
239
  builder.input(:title, :as => :range, :input_html => { :max => 102 })
212
240
  end)
213
241
  output_buffer.should have_tag('input[@max="102"]')
214
242
  end
215
-
243
+
216
244
  it "should allow option to override :max" do
217
245
  concat(semantic_form_for(@new_post) do |builder|
218
246
  builder.input(:title, :as => :range, :max => 102)
219
247
  end)
220
248
  output_buffer.should have_tag('input[@max="102"]')
221
249
  end
222
-
250
+
223
251
  it "should allow :input_html to override :max with :in" do
224
252
  concat(semantic_form_for(@new_post) do |builder|
225
253
  builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
@@ -233,12 +261,12 @@ describe 'range input' do
233
261
  end)
234
262
  output_buffer.should have_tag('input[@max="102"]')
235
263
  end
236
-
264
+
237
265
  describe "and the column is an integer" do
238
266
  before do
239
267
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
240
268
  end
241
-
269
+
242
270
  it "should add a max attribute to the input one greater than the validation" do
243
271
  concat(semantic_form_for(@new_post) do |builder|
244
272
  builder.input(:title, :as => :range)
@@ -246,12 +274,12 @@ describe 'range input' do
246
274
  output_buffer.should have_tag('input[@max="19"]')
247
275
  end
248
276
  end
249
-
277
+
250
278
  describe "and the column is a float" do
251
279
  before do
252
280
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
253
281
  end
254
-
282
+
255
283
  it "should raise an error" do
256
284
  lambda {
257
285
  concat(semantic_form_for(@new_post) do |builder|
@@ -260,12 +288,12 @@ describe 'range input' do
260
288
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
261
289
  end
262
290
  end
263
-
291
+
264
292
  describe "and the column is a big decimal" do
265
293
  before do
266
294
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
267
295
  end
268
-
296
+
269
297
  it "should raise an error" do
270
298
  lambda {
271
299
  concat(semantic_form_for(@new_post) do |builder|
@@ -274,37 +302,37 @@ describe 'range input' do
274
302
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
275
303
  end
276
304
  end
277
-
305
+
278
306
  end
279
-
307
+
280
308
  describe "when validations require a maximum value (:less_than_or_equal_to)" do
281
309
  before do
282
310
  @new_post.class.stub!(:validators_on).with(:title).and_return([
283
311
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
284
312
  ])
285
313
  end
286
-
314
+
287
315
  it "should allow :input_html to override :max" do
288
316
  concat(semantic_form_for(@new_post) do |builder|
289
317
  builder.input(:title, :as => :range, :input_html => { :max => 102 })
290
318
  end)
291
319
  output_buffer.should have_tag('input[@max="102"]')
292
320
  end
293
-
321
+
294
322
  it "should allow options to override :max" do
295
323
  concat(semantic_form_for(@new_post) do |builder|
296
324
  builder.input(:title, :as => :range, :max => 102)
297
325
  end)
298
326
  output_buffer.should have_tag('input[@max="102"]')
299
327
  end
300
-
328
+
301
329
  it "should allow :input_html to override :max with :in" do
302
330
  concat(semantic_form_for(@new_post) do |builder|
303
331
  builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
304
332
  end)
305
333
  output_buffer.should have_tag('input[@max="102"]')
306
334
  end
307
-
335
+
308
336
  it "should allow options to override :max with :in" do
309
337
  concat(semantic_form_for(@new_post) do |builder|
310
338
  builder.input(:title, :as => :range, :in => 1..102)
@@ -331,7 +359,7 @@ describe 'range input' do
331
359
  before do
332
360
  @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
333
361
  end
334
-
362
+
335
363
  it "should add a max attribute to the input equal to the validation" do
336
364
  concat(semantic_form_for(@new_post) do |builder|
337
365
  builder.input(:title, :as => :range)
@@ -340,25 +368,25 @@ describe 'range input' do
340
368
  end
341
369
  end
342
370
  end
343
-
371
+
344
372
  describe "when validations do not require a maximum value" do
345
-
373
+
346
374
  it "should default to 1" do
347
375
  concat(semantic_form_for(@new_post) do |builder|
348
376
  builder.input(:title, :as => :range)
349
377
  end)
350
378
  output_buffer.should have_tag('input[@max="100"]')
351
379
  end
352
-
380
+
353
381
  end
354
-
382
+
355
383
  describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
356
384
  before do
357
385
  @new_post.class.stub!(:validators_on).with(:title).and_return([
358
386
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
359
387
  ])
360
388
  end
361
-
389
+
362
390
  it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
363
391
  concat(semantic_form_for(@new_post) do |builder|
364
392
  builder.input(:title, :as => :range)
@@ -366,14 +394,14 @@ describe 'range input' do
366
394
  output_buffer.should have_tag('input[@min="2"]')
367
395
  end
368
396
  end
369
-
397
+
370
398
  describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
371
399
  before do
372
400
  @new_post.class.stub!(:validators_on).with(:title).and_return([
373
401
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
374
402
  ])
375
403
  end
376
-
404
+
377
405
  it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
378
406
  concat(semantic_form_for(@new_post) do |builder|
379
407
  builder.input(:title, :as => :range)
@@ -381,99 +409,99 @@ describe 'range input' do
381
409
  output_buffer.should have_tag('input[@max="2"]')
382
410
  end
383
411
  end
384
-
412
+
385
413
  describe "when validations require only an integer (:only_integer)" do
386
-
414
+
387
415
  before do
388
416
  @new_post.class.stub!(:validators_on).with(:title).and_return([
389
417
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
390
418
  ])
391
419
  end
392
-
420
+
393
421
  it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
394
422
  concat(semantic_form_for(@new_post) do |builder|
395
423
  builder.input(:title, :as => :range)
396
424
  end)
397
425
  output_buffer.should have_tag('input[@step="1"]')
398
426
  end
399
-
427
+
400
428
  it "should let input_html override :step" do
401
429
  concat(semantic_form_for(@new_post) do |builder|
402
430
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
403
431
  end)
404
432
  output_buffer.should have_tag('input[@step="3"]')
405
433
  end
406
-
434
+
407
435
  it "should let options override :step" do
408
436
  concat(semantic_form_for(@new_post) do |builder|
409
437
  builder.input(:title, :as => :range, :step => 3)
410
438
  end)
411
439
  output_buffer.should have_tag('input[@step="3"]')
412
440
  end
413
-
441
+
414
442
  end
415
-
443
+
416
444
  describe "when validations require a :step (non standard)" do
417
-
445
+
418
446
  before do
419
447
  @new_post.class.stub!(:validators_on).with(:title).and_return([
420
448
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
421
449
  ])
422
450
  end
423
-
451
+
424
452
  it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
425
453
  concat(semantic_form_for(@new_post) do |builder|
426
454
  builder.input(:title, :as => :range)
427
455
  end)
428
456
  output_buffer.should have_tag('input[@step="2"]')
429
457
  end
430
-
458
+
431
459
  it "should let input_html override :step" do
432
460
  concat(semantic_form_for(@new_post) do |builder|
433
461
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
434
462
  end)
435
463
  output_buffer.should have_tag('input[@step="3"]')
436
464
  end
437
-
465
+
438
466
  it "should let options override :step" do
439
467
  concat(semantic_form_for(@new_post) do |builder|
440
468
  builder.input(:title, :as => :range, :step => 3)
441
469
  end)
442
470
  output_buffer.should have_tag('input[@step="3"]')
443
471
  end
444
-
472
+
445
473
  end
446
-
474
+
447
475
  describe "when validations do not specify :step (non standard) or :only_integer" do
448
-
476
+
449
477
  before do
450
478
  @new_post.class.stub!(:validators_on).with(:title).and_return([
451
479
  active_model_numericality_validator([:title], {:allow_nil=>false})
452
480
  ])
453
481
  end
454
-
482
+
455
483
  it "should default step to 1" do
456
484
  concat(semantic_form_for(@new_post) do |builder|
457
485
  builder.input(:title, :as => :range)
458
486
  end)
459
487
  output_buffer.should have_tag('input[@step="1"]')
460
488
  end
461
-
489
+
462
490
  it "should let input_html set :step" do
463
491
  concat(semantic_form_for(@new_post) do |builder|
464
492
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
465
493
  end)
466
494
  output_buffer.should have_tag('input[@step="3"]')
467
495
  end
468
-
496
+
469
497
  it "should let options set :step" do
470
498
  concat(semantic_form_for(@new_post) do |builder|
471
499
  builder.input(:title, :as => :range, :step => 3)
472
500
  end)
473
501
  output_buffer.should have_tag('input[@step="3"]')
474
502
  end
475
-
503
+
476
504
  end
477
-
505
+
478
506
  end
479
507