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