speedo-formstrap 1.2.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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +117 -0
- data/LICENSE.txt +20 -0
- data/README.md +192 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/formtastic-bootstrap.gemspec +56 -0
- data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
- data/lib/formtastic-bootstrap.rb +7 -0
- data/lib/formtastic-bootstrap/actions.rb +4 -0
- data/lib/formtastic-bootstrap/actions/base.rb +18 -0
- data/lib/formtastic-bootstrap/actions/button_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/input_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/link_action.rb +7 -0
- data/lib/formtastic-bootstrap/engine.rb +4 -0
- data/lib/formtastic-bootstrap/form_builder.rb +40 -0
- data/lib/formtastic-bootstrap/helpers.rb +21 -0
- data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/actions_helper.rb +23 -0
- data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +56 -0
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +42 -0
- data/lib/formtastic-bootstrap/helpers/input_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +36 -0
- data/lib/formtastic-bootstrap/inputs.rb +29 -0
- data/lib/formtastic-bootstrap/inputs/base.rb +23 -0
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +38 -0
- data/lib/formtastic-bootstrap/inputs/base/errors.rb +48 -0
- data/lib/formtastic-bootstrap/inputs/base/hints.rb +27 -0
- data/lib/formtastic-bootstrap/inputs/base/html.rb +21 -0
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +28 -0
- data/lib/formtastic-bootstrap/inputs/base/numeric.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/stringish.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +28 -0
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +74 -0
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +29 -0
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +36 -0
- data/lib/formtastic-bootstrap/inputs/date_input.rb +16 -0
- data/lib/formtastic-bootstrap/inputs/datetime_input.rb +19 -0
- data/lib/formtastic-bootstrap/inputs/email_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/file_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/number_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/password_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/phone_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/radio_input.rb +33 -0
- data/lib/formtastic-bootstrap/inputs/range_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/search_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/select_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/string_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/text_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/time_input.rb +16 -0
- data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/url_input.rb +14 -0
- data/spec/actions/button_action_spec.rb +68 -0
- data/spec/actions/generic_action_spec.rb +486 -0
- data/spec/actions/input_action_spec.rb +64 -0
- data/spec/actions/link_action_spec.rb +93 -0
- data/spec/builder/semantic_fields_for_spec.rb +130 -0
- data/spec/helpers/action_helper_spec.rb +365 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/buttons_helper_spec.rb +159 -0
- data/spec/helpers/input_helper_spec.rb +956 -0
- data/spec/helpers/inputs_helper_spec.rb +591 -0
- data/spec/inputs/boolean_input_spec.rb +221 -0
- data/spec/inputs/check_boxes_input_spec.rb +467 -0
- data/spec/inputs/date_input_spec.rb +213 -0
- data/spec/inputs/datetime_input_spec.rb +101 -0
- data/spec/inputs/email_input_spec.rb +87 -0
- data/spec/inputs/file_input_spec.rb +91 -0
- data/spec/inputs/hidden_input_spec.rb +150 -0
- data/spec/inputs/number_input_spec.rb +817 -0
- data/spec/inputs/password_input_spec.rb +101 -0
- data/spec/inputs/phone_input_spec.rb +87 -0
- data/spec/inputs/radio_input_spec.rb +268 -0
- data/spec/inputs/range_input_spec.rb +507 -0
- data/spec/inputs/search_input_spec.rb +86 -0
- data/spec/inputs/select_input_spec.rb +613 -0
- data/spec/inputs/string_input_spec.rb +227 -0
- data/spec/inputs/text_input_spec.rb +190 -0
- data/spec/inputs/time_input_spec.rb +206 -0
- data/spec/inputs/time_zone_input_spec.rb +120 -0
- data/spec/inputs/url_input_spec.rb +87 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/custom_macros.rb +575 -0
- data/spec/support/depracation.rb +6 -0
- data/spec/support/formtastic_spec_helper.rb +398 -0
- metadata +216 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'date input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "general" do
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
output_buffer.replace ''
|
|
18
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
19
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
|
|
20
|
+
end)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it_should_have_input_wrapper_with_class("date-wrapper")
|
|
24
|
+
it_should_have_input_wrapper_with_class("control-group")
|
|
25
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
|
26
|
+
it_should_have_input_class_in_the_right_place
|
|
27
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
|
28
|
+
it_should_have_a_nested_div
|
|
29
|
+
# it_should_have_a_nested_fieldset_with_class('fragments')
|
|
30
|
+
# it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
|
31
|
+
it_should_apply_error_logic_for_input_type(:date)
|
|
32
|
+
|
|
33
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
|
34
|
+
output_buffer.should have_tag('form div.control-group.date-wrapper label.control-label', /Publish at/)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# it 'should associate the legend label with the first select' do
|
|
38
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label')
|
|
39
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label label')
|
|
40
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label label[@for]')
|
|
41
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_1i"]')
|
|
42
|
+
# end
|
|
43
|
+
|
|
44
|
+
it 'should (sort of) associate the label with the input' do
|
|
45
|
+
output_buffer.should have_tag('form div.control-group.date-wrapper label.control-label[@for="post_publish_at"]')
|
|
46
|
+
output_buffer.should have_tag('form div.control-group.date-wrapper div.controls input[@id="post_publish_at[date]"]')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# it 'should have an ordered list of three items inside the fieldset' do
|
|
50
|
+
# output_buffer.should have_tag('form li.date fieldset ol.fragments-group')
|
|
51
|
+
# output_buffer.should have_tag('form li.date fieldset ol li.fragment', :count => 3)
|
|
52
|
+
# end
|
|
53
|
+
|
|
54
|
+
# it 'should have three labels for year, month and day' do
|
|
55
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
|
|
56
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
|
|
57
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
|
|
58
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
|
|
59
|
+
# end
|
|
60
|
+
it 'should have an text input inside the div' do
|
|
61
|
+
output_buffer.should have_tag('form div.control-group.date-wrapper div.controls input[@type="text"]')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# it 'should have three selects for year, month and day' do
|
|
65
|
+
# output_buffer.should have_tag('form li.date fieldset ol li select', :count => 3)
|
|
66
|
+
# end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "when namespace is provided" do
|
|
70
|
+
|
|
71
|
+
before do
|
|
72
|
+
output_buffer.replace ''
|
|
73
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
|
74
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
|
|
75
|
+
end)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
|
79
|
+
it_should_have_input_with_id("context2_post_publish_at[date]")
|
|
80
|
+
# it_should_have_select_with_id("context2_post_publish_at_2i")
|
|
81
|
+
# it_should_have_select_with_id("context2_post_publish_at_3i")
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# We only use a single label for the entire entity.
|
|
86
|
+
|
|
87
|
+
# describe ':labels option' do
|
|
88
|
+
# fields = [:year, :month, :day]
|
|
89
|
+
# fields.each do |field|
|
|
90
|
+
# it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
|
91
|
+
# output_buffer.replace ''
|
|
92
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
93
|
+
# concat(builder.input(:created_at, :as => :date, :labels => { field => "another #{field} label" }))
|
|
94
|
+
# end)
|
|
95
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length)
|
|
96
|
+
# fields.each do |f|
|
|
97
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
|
98
|
+
# end
|
|
99
|
+
# end
|
|
100
|
+
#
|
|
101
|
+
# it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
|
102
|
+
# output_buffer.replace ''
|
|
103
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
104
|
+
# concat(builder.input(:created_at, :as => :date, :labels => { field => "" }))
|
|
105
|
+
# end)
|
|
106
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
|
|
107
|
+
# fields.each do |f|
|
|
108
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
|
109
|
+
# end
|
|
110
|
+
# end
|
|
111
|
+
#
|
|
112
|
+
# it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
|
|
113
|
+
# output_buffer.replace ''
|
|
114
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
115
|
+
# concat(builder.input(:created_at, :as => :date, :labels => { field => false }))
|
|
116
|
+
# end)
|
|
117
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
|
|
118
|
+
# fields.each do |f|
|
|
119
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
|
120
|
+
# end
|
|
121
|
+
# end
|
|
122
|
+
#
|
|
123
|
+
# it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
|
124
|
+
# output_buffer.replace ''
|
|
125
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
126
|
+
# concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
|
|
127
|
+
# end)
|
|
128
|
+
# output_buffer.should_not include(">")
|
|
129
|
+
# end
|
|
130
|
+
#
|
|
131
|
+
# end
|
|
132
|
+
# end
|
|
133
|
+
|
|
134
|
+
describe "when required" do
|
|
135
|
+
it "should add the required attribute to the input's html options" do
|
|
136
|
+
with_config :use_required_attribute, true do
|
|
137
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
138
|
+
concat(builder.input(:title, :as => :date, :required => true))
|
|
139
|
+
end)
|
|
140
|
+
# output_buffer.should have_tag("select[@required]", :count => 3)
|
|
141
|
+
# We only have one text field.
|
|
142
|
+
output_buffer.should have_tag("input[@required]", :count => 1)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# We use text field for dates
|
|
148
|
+
|
|
149
|
+
# describe "when order does not include day" do
|
|
150
|
+
# before do
|
|
151
|
+
# output_buffer.replace ''
|
|
152
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
153
|
+
# concat(builder.input(:publish_at, :as => :date, :order => [:year, :month]))
|
|
154
|
+
# end)
|
|
155
|
+
# end
|
|
156
|
+
#
|
|
157
|
+
# it "should include a hidden input for day" do
|
|
158
|
+
# output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(3i)]"][@value="1"]')
|
|
159
|
+
# end
|
|
160
|
+
#
|
|
161
|
+
# it "should not include a select for day" do
|
|
162
|
+
# output_buffer.should_not have_tag('select[@name="post[publish_at(3i)]"]')
|
|
163
|
+
# end
|
|
164
|
+
# end
|
|
165
|
+
#
|
|
166
|
+
# describe "when order does not include month" do
|
|
167
|
+
# before do
|
|
168
|
+
# output_buffer.replace ''
|
|
169
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
170
|
+
# concat(builder.input(:publish_at, :as => :date, :order => [:year, :day]))
|
|
171
|
+
# end)
|
|
172
|
+
# end
|
|
173
|
+
#
|
|
174
|
+
# it "should include a hidden input for month" do
|
|
175
|
+
# output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(2i)]"][@value="1"]')
|
|
176
|
+
# end
|
|
177
|
+
#
|
|
178
|
+
# it "should not include a select for month" do
|
|
179
|
+
# output_buffer.should_not have_tag('select[@name="post[publish_at(2i)]"]')
|
|
180
|
+
# end
|
|
181
|
+
# end
|
|
182
|
+
#
|
|
183
|
+
# describe "when order does not include year" do
|
|
184
|
+
# before do
|
|
185
|
+
# output_buffer.replace ''
|
|
186
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
187
|
+
# concat(builder.input(:publish_at, :as => :date, :order => [:month, :day]))
|
|
188
|
+
# end)
|
|
189
|
+
# end
|
|
190
|
+
#
|
|
191
|
+
# it "should include a hidden input for month" do
|
|
192
|
+
# output_buffer.should have_tag("input[@type=\"hidden\"][@name=\"post[publish_at(1i)]\"][@value=\"#{Time.now.year}\"]")
|
|
193
|
+
# end
|
|
194
|
+
#
|
|
195
|
+
# it "should not include a select for month" do
|
|
196
|
+
# output_buffer.should_not have_tag('select[@name="post[publish_at(1i)]"]')
|
|
197
|
+
# end
|
|
198
|
+
# end
|
|
199
|
+
#
|
|
200
|
+
# describe "when order does not have year first" do
|
|
201
|
+
# before do
|
|
202
|
+
# output_buffer.replace ''
|
|
203
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
204
|
+
# concat(builder.input(:publish_at, :as => :date, :order => [:day, :month, :year]))
|
|
205
|
+
# end)
|
|
206
|
+
# end
|
|
207
|
+
#
|
|
208
|
+
# it 'should associate the legend label with the new first select' do
|
|
209
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_3i"]')
|
|
210
|
+
# end
|
|
211
|
+
# end
|
|
212
|
+
|
|
213
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'datetime input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "general" do
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
::I18n.backend.store_translations :en, {}
|
|
18
|
+
output_buffer.replace ''
|
|
19
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
20
|
+
concat(builder.input(:publish_at, :as => :datetime))
|
|
21
|
+
end)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it_should_have_input_wrapper_with_class("datetime-wrapper")
|
|
25
|
+
it_should_have_input_wrapper_with_class("control-group")
|
|
26
|
+
it_should_have_input_wrapper_with_class(:stringish) # Decide about this.
|
|
27
|
+
it_should_have_input_class_in_the_right_place
|
|
28
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
|
29
|
+
it_should_have_a_nested_div
|
|
30
|
+
# it_should_have_a_nested_fieldset_with_class('fragments')
|
|
31
|
+
# it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
|
32
|
+
it_should_apply_error_logic_for_input_type(:datetime)
|
|
33
|
+
|
|
34
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
|
35
|
+
output_buffer.should have_tag('form div.control-group.datetime-wrapper label.control-label', /Publish at/)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# it 'should associate the legend label with the first select' do
|
|
39
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label')
|
|
40
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label label')
|
|
41
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for]')
|
|
42
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_1i"]')
|
|
43
|
+
# end
|
|
44
|
+
|
|
45
|
+
# it 'should have an ordered list of five items inside the fieldset' do
|
|
46
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol.fragments-group')
|
|
47
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li.fragment', :count => 5)
|
|
48
|
+
# end
|
|
49
|
+
|
|
50
|
+
# it 'should have five labels for year, month and day' do
|
|
51
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
|
|
52
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /year/i)
|
|
53
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /month/i)
|
|
54
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /day/i)
|
|
55
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
|
|
56
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /min/i)
|
|
57
|
+
# end
|
|
58
|
+
|
|
59
|
+
# it 'should have five selects' do
|
|
60
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
|
|
61
|
+
# end
|
|
62
|
+
|
|
63
|
+
it 'should have two inputs' do
|
|
64
|
+
output_buffer.should have_tag('form div.control-group.datetime-wrapper div.controls input', :count => 2)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "when namespace is provided" do
|
|
70
|
+
|
|
71
|
+
before do
|
|
72
|
+
output_buffer.replace ''
|
|
73
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
|
74
|
+
concat(builder.input(:publish_at, :as => :datetime))
|
|
75
|
+
end)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
|
79
|
+
it_should_have_input_with_id("context2_post_publish_at[date]")
|
|
80
|
+
it_should_have_input_with_id("context2_post_publish_at[time]")
|
|
81
|
+
# it_should_have_input_with_id("context2_post_publish_at_1i")
|
|
82
|
+
# it_should_have_select_with_id("context2_post_publish_at_2i")
|
|
83
|
+
# it_should_have_select_with_id("context2_post_publish_at_3i")
|
|
84
|
+
# it_should_have_select_with_id("context2_post_publish_at_4i")
|
|
85
|
+
# it_should_have_select_with_id("context2_post_publish_at_5i")
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe "when required" do
|
|
90
|
+
it "should add the required attribute to the input's html options" do
|
|
91
|
+
with_config :use_required_attribute, true do
|
|
92
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
93
|
+
concat(builder.input(:title, :as => :datetime, :required => true))
|
|
94
|
+
end)
|
|
95
|
+
# output_buffer.should have_tag("select[@required]", :count => 5)
|
|
96
|
+
output_buffer.should have_tag("input[@required]", :count => 2)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'email input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "when object is provided" do
|
|
15
|
+
before do
|
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
17
|
+
concat(builder.input(:email))
|
|
18
|
+
end)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it_should_have_input_wrapper_with_class('email-wrapper')
|
|
22
|
+
it_should_have_input_wrapper_with_class("control-group")
|
|
23
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
|
24
|
+
it_should_have_input_class_in_the_right_place
|
|
25
|
+
it_should_have_input_wrapper_with_id("post_email_input")
|
|
26
|
+
it_should_have_label_with_text(/Email/)
|
|
27
|
+
it_should_have_label_for("post_email")
|
|
28
|
+
it_should_have_input_with_id("post_email")
|
|
29
|
+
it_should_have_input_with_type(:email)
|
|
30
|
+
it_should_have_input_with_name("post[email]")
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "when namespace is provided" do
|
|
35
|
+
|
|
36
|
+
before do
|
|
37
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
38
|
+
concat(builder.input(:email))
|
|
39
|
+
end)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it_should_have_input_wrapper_with_id("context2_post_email_input")
|
|
43
|
+
it_should_have_label_and_input_with_id("context2_post_email")
|
|
44
|
+
|
|
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 => :email))
|
|
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
|
+
|
|
75
|
+
describe "when required" do
|
|
76
|
+
it "should add the required attribute to the input's html options" do
|
|
77
|
+
with_config :use_required_attribute, true do
|
|
78
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
79
|
+
concat(builder.input(:title, :as => :email, :required => true))
|
|
80
|
+
end)
|
|
81
|
+
output_buffer.should have_tag("input[@required]")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'file input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
|
12
|
+
|
|
13
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
14
|
+
concat(builder.input(:body, :as => :file))
|
|
15
|
+
end)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it_should_have_input_wrapper_with_class("file-wrapper")
|
|
19
|
+
it_should_have_input_wrapper_with_class("control-group")
|
|
20
|
+
it_should_have_input_class_in_the_right_place
|
|
21
|
+
it_should_have_input_wrapper_with_id("post_body_input")
|
|
22
|
+
it_should_have_label_with_text(/Body/)
|
|
23
|
+
it_should_have_label_for("post_body")
|
|
24
|
+
it_should_have_input_with_id("post_body")
|
|
25
|
+
it_should_have_input_with_name("post[body]")
|
|
26
|
+
it_should_apply_error_logic_for_input_type(:file)
|
|
27
|
+
|
|
28
|
+
it 'should use input_html to style inputs' do
|
|
29
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
30
|
+
concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
|
|
31
|
+
end)
|
|
32
|
+
output_buffer.should have_tag("form div.control-group div.controls input.myclass")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "when namespace is provided" do
|
|
36
|
+
|
|
37
|
+
before do
|
|
38
|
+
@output_buffer = ''
|
|
39
|
+
mock_everything
|
|
40
|
+
|
|
41
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
42
|
+
concat(builder.input(:body, :as => :file))
|
|
43
|
+
end)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it_should_have_input_wrapper_with_id("context2_post_body_input")
|
|
47
|
+
it_should_have_label_and_input_with_id("context2_post_body")
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "when index is provided" do
|
|
52
|
+
|
|
53
|
+
before do
|
|
54
|
+
@output_buffer = ''
|
|
55
|
+
mock_everything
|
|
56
|
+
|
|
57
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
58
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
59
|
+
concat(author.input(:name, :as => :file))
|
|
60
|
+
end)
|
|
61
|
+
end)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'should index the id of the wrapper' do
|
|
65
|
+
output_buffer.should have_tag("div#post_author_attributes_3_name_input")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'should index the id of the select tag' do
|
|
69
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'should index the name of the select tag' do
|
|
73
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
context "when required" do
|
|
80
|
+
it "should add the required attribute to the input's html options" do
|
|
81
|
+
with_config :use_required_attribute, true do
|
|
82
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
83
|
+
concat(builder.input(:title, :as => :file, :required => true))
|
|
84
|
+
end)
|
|
85
|
+
output_buffer.should have_tag("input[@required]")
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|