formtastic 1.2.4 → 3.1.5
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +46 -0
- data/.yardopts +1 -0
- data/Appraisals +43 -0
- data/CHANGELOG +54 -0
- data/DEPRECATIONS +52 -0
- data/Gemfile +3 -0
- data/README.md +629 -0
- data/RELEASE_PROCESS +6 -0
- data/Rakefile +35 -0
- data/app/assets/stylesheets/formtastic.css +289 -0
- data/app/assets/stylesheets/formtastic_ie6.css +33 -0
- data/app/assets/stylesheets/formtastic_ie7.css +23 -0
- data/formtastic.gemspec +42 -0
- data/gemfiles/rails_3.2.gemfile +9 -0
- data/gemfiles/rails_4.0.4.gemfile +8 -0
- data/gemfiles/rails_4.1.gemfile +8 -0
- data/gemfiles/rails_4.2.gemfile +8 -0
- data/gemfiles/rails_4.gemfile +8 -0
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_edge.gemfile +15 -0
- data/lib/formtastic.rb +40 -1945
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions.rb +11 -0
- data/lib/formtastic/actions/base.rb +156 -0
- data/lib/formtastic/actions/button_action.rb +67 -0
- data/lib/formtastic/actions/buttonish.rb +17 -0
- data/lib/formtastic/actions/input_action.rb +70 -0
- data/lib/formtastic/actions/link_action.rb +88 -0
- data/lib/formtastic/deprecation.rb +42 -0
- data/lib/formtastic/engine.rb +11 -0
- data/lib/formtastic/form_builder.rb +124 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/action_helper.rb +162 -0
- data/lib/formtastic/helpers/actions_helper.rb +168 -0
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +81 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +80 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +203 -0
- data/lib/formtastic/helpers/input_helper.rb +407 -0
- data/lib/formtastic/helpers/inputs_helper.rb +411 -0
- data/lib/formtastic/helpers/reflection.rb +37 -0
- data/lib/formtastic/html_attributes.rb +32 -0
- data/lib/formtastic/i18n.rb +4 -2
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs.rb +39 -0
- data/lib/formtastic/inputs/base.rb +76 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +108 -0
- data/lib/formtastic/inputs/base/collections.rb +159 -0
- data/lib/formtastic/inputs/base/database.rb +22 -0
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +53 -0
- data/lib/formtastic/inputs/base/labelling.rb +52 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/numeric.rb +50 -0
- data/lib/formtastic/inputs/base/options.rb +17 -0
- data/lib/formtastic/inputs/base/placeholder.rb +17 -0
- data/lib/formtastic/inputs/base/stringish.rb +38 -0
- data/lib/formtastic/inputs/base/timeish.rb +241 -0
- data/lib/formtastic/inputs/base/validations.rb +215 -0
- data/lib/formtastic/inputs/base/wrapping.rb +50 -0
- data/lib/formtastic/inputs/boolean_input.rb +118 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +197 -0
- data/lib/formtastic/inputs/color_input.rb +42 -0
- data/lib/formtastic/inputs/country_input.rb +86 -0
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/date_select_input.rb +34 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
- data/lib/formtastic/inputs/email_input.rb +41 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +62 -0
- data/lib/formtastic/inputs/number_input.rb +88 -0
- data/lib/formtastic/inputs/password_input.rb +41 -0
- data/lib/formtastic/inputs/phone_input.rb +42 -0
- data/lib/formtastic/inputs/radio_input.rb +163 -0
- data/lib/formtastic/inputs/range_input.rb +95 -0
- data/lib/formtastic/inputs/search_input.rb +41 -0
- data/lib/formtastic/inputs/select_input.rb +235 -0
- data/lib/formtastic/inputs/string_input.rb +36 -0
- data/lib/formtastic/inputs/text_input.rb +48 -0
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/time_select_input.rb +38 -0
- data/lib/formtastic/inputs/time_zone_input.rb +58 -0
- data/lib/formtastic/inputs/url_input.rb +41 -0
- data/lib/formtastic/localized_string.rb +17 -0
- data/lib/formtastic/localizer.rb +152 -0
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/util.rb +35 -16
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/form/form_generator.rb +64 -37
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +13 -5
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/_form.html.slim +8 -0
- data/lib/generators/templates/formtastic.rb +77 -44
- data/lib/generators/templates/input.rb +19 -0
- data/lib/locale/en.yml +3 -0
- data/sample/basic_inputs.html +224 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +63 -0
- data/spec/actions/generic_action_spec.rb +521 -0
- data/spec/actions/input_action_spec.rb +59 -0
- data/spec/actions/link_action_spec.rb +92 -0
- data/spec/builder/custom_builder_spec.rb +116 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/semantic_fields_for_spec.rb +142 -0
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +131 -0
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
- data/spec/helpers/action_helper_spec.rb +19 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/form_helper_spec.rb +218 -0
- data/spec/helpers/input_helper_spec.rb +6 -0
- data/spec/helpers/inputs_helper_spec.rb +655 -0
- data/spec/helpers/namespaced_action_helper_spec.rb +43 -0
- data/spec/helpers/namespaced_input_helper_spec.rb +36 -0
- data/spec/helpers/reflection_helper_spec.rb +32 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +210 -0
- data/spec/input_class_finder_spec.rb +10 -0
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +342 -0
- data/spec/inputs/boolean_input_spec.rb +254 -0
- data/spec/inputs/check_boxes_input_spec.rb +546 -0
- data/spec/inputs/color_input_spec.rb +97 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +55 -0
- data/spec/inputs/datalist_input_spec.rb +61 -0
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/date_select_input_spec.rb +235 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +193 -0
- data/spec/inputs/email_input_spec.rb +85 -0
- data/spec/inputs/file_input_spec.rb +89 -0
- data/spec/inputs/hidden_input_spec.rb +135 -0
- data/spec/inputs/include_blank_spec.rb +78 -0
- data/spec/inputs/label_spec.rb +149 -0
- data/spec/inputs/number_input_spec.rb +815 -0
- data/spec/inputs/password_input_spec.rb +99 -0
- data/spec/inputs/phone_input_spec.rb +85 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +328 -0
- data/spec/inputs/range_input_spec.rb +505 -0
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +84 -0
- data/spec/inputs/select_input_spec.rb +615 -0
- data/spec/inputs/string_input_spec.rb +260 -0
- data/spec/inputs/text_input_spec.rb +187 -0
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +248 -0
- data/spec/inputs/time_zone_input_spec.rb +143 -0
- data/spec/inputs/url_input_spec.rb +85 -0
- data/spec/inputs/with_options_spec.rb +43 -0
- data/spec/localizer_spec.rb +130 -0
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +525 -0
- data/spec/support/custom_macros.rb +564 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/shared_examples.rb +1313 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +31 -0
- data/spec/util_spec.rb +66 -0
- metadata +434 -161
- data/README.textile +0 -682
- data/generators/form/USAGE +0 -16
- data/generators/form/form_generator.rb +0 -111
- data/generators/formtastic/formtastic_generator.rb +0 -26
- data/init.rb +0 -5
- data/lib/formtastic/layout_helper.rb +0 -12
- data/lib/formtastic/railtie.rb +0 -14
- data/lib/generators/templates/formtastic.css +0 -145
- data/lib/generators/templates/formtastic_changes.css +0 -14
- data/lib/generators/templates/rails2/_form.html.erb +0 -5
- data/lib/generators/templates/rails2/_form.html.haml +0 -4
- data/rails/init.rb +0 -2
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'datetime select input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "general" do
|
|
14
|
+
|
|
15
|
+
before do
|
|
16
|
+
::I18n.backend.store_translations :en, {}
|
|
17
|
+
output_buffer.replace ''
|
|
18
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
19
|
+
concat(builder.input(:publish_at, :as => :datetime_select))
|
|
20
|
+
end)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it_should_have_input_wrapper_with_class("datetime_select")
|
|
24
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
25
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
|
26
|
+
it_should_have_a_nested_fieldset
|
|
27
|
+
it_should_have_a_nested_fieldset_with_class('fragments')
|
|
28
|
+
it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
|
29
|
+
it_should_apply_error_logic_for_input_type(:datetime_select)
|
|
30
|
+
|
|
31
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
|
32
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label', /Publish at/)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should associate the legend label with the first select' do
|
|
36
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label')
|
|
37
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label')
|
|
38
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for]')
|
|
39
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_1i"]')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should have an ordered list of five items inside the fieldset' do
|
|
43
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol.fragments-group')
|
|
44
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li.fragment', :count => 5)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'should have five labels for year, month and day' do
|
|
48
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => 5)
|
|
49
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /year/i)
|
|
50
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /month/i)
|
|
51
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /day/i)
|
|
52
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /hour/i)
|
|
53
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /min/i)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should have five selects' do
|
|
57
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li select', :count => 5)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "when namespace is provided" do
|
|
62
|
+
|
|
63
|
+
before do
|
|
64
|
+
output_buffer.replace ''
|
|
65
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
|
66
|
+
concat(builder.input(:publish_at, :as => :datetime_select))
|
|
67
|
+
end)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
|
71
|
+
it_should_have_select_with_id("context2_post_publish_at_1i")
|
|
72
|
+
it_should_have_select_with_id("context2_post_publish_at_2i")
|
|
73
|
+
it_should_have_select_with_id("context2_post_publish_at_3i")
|
|
74
|
+
it_should_have_select_with_id("context2_post_publish_at_4i")
|
|
75
|
+
it_should_have_select_with_id("context2_post_publish_at_5i")
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "when index is provided" do
|
|
80
|
+
|
|
81
|
+
before do
|
|
82
|
+
@output_buffer = ''
|
|
83
|
+
mock_everything
|
|
84
|
+
|
|
85
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
86
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
87
|
+
concat(author.input(:created_at, :as => :datetime_select))
|
|
88
|
+
end)
|
|
89
|
+
end)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should index the id of the wrapper' do
|
|
93
|
+
output_buffer.should have_tag("li#post_author_attributes_3_created_at_input")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should index the id of the select tag' do
|
|
97
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_1i")
|
|
98
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_2i")
|
|
99
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_3i")
|
|
100
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_4i")
|
|
101
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_5i")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'should index the name of the select tag' do
|
|
105
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(1i)]']")
|
|
106
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(2i)]']")
|
|
107
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(3i)]']")
|
|
108
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
|
|
109
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
describe ':labels option' do
|
|
116
|
+
fields = [:year, :month, :day, :hour, :minute]
|
|
117
|
+
fields.each do |field|
|
|
118
|
+
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
|
119
|
+
output_buffer.replace ''
|
|
120
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
121
|
+
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "another #{field} label" }))
|
|
122
|
+
end)
|
|
123
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length)
|
|
124
|
+
fields.each do |f|
|
|
125
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
|
130
|
+
output_buffer.replace ''
|
|
131
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
132
|
+
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "" }))
|
|
133
|
+
end)
|
|
134
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
|
|
135
|
+
fields.each do |f|
|
|
136
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /#{f}/i) unless field == f
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
|
|
141
|
+
output_buffer.replace ''
|
|
142
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
143
|
+
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => false }))
|
|
144
|
+
end)
|
|
145
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
|
|
146
|
+
fields.each do |f|
|
|
147
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /#{f}/i) unless field == f
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
|
152
|
+
output_buffer.replace ''
|
|
153
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
154
|
+
concat(builder.input(:created_at, :as => :datetime_select, :include_seconds => true, :labels => { field => false }))
|
|
155
|
+
end)
|
|
156
|
+
output_buffer.should_not include(">")
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "should not display labels for any fields when :labels is falsy" do
|
|
161
|
+
output_buffer.replace ''
|
|
162
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
163
|
+
concat(builder.input(:created_at, :as => :datetime_select, :labels => false))
|
|
164
|
+
end)
|
|
165
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => 0)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
describe "when required" do
|
|
170
|
+
it "should add the required attribute to the input's html options" do
|
|
171
|
+
with_config :use_required_attribute, true do
|
|
172
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
173
|
+
concat(builder.input(:title, :as => :datetime_select, :required => true))
|
|
174
|
+
end)
|
|
175
|
+
output_buffer.should have_tag("select[@required]", :count => 5)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
describe "when order does not have year first" do
|
|
181
|
+
before do
|
|
182
|
+
output_buffer.replace ''
|
|
183
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
184
|
+
concat(builder.input(:publish_at, :as => :datetime_select, :order => [:day, :month, :year]))
|
|
185
|
+
end)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it 'should associate the legend label with the new first select' do
|
|
189
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_3i"]')
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "when object is provided" do
|
|
14
|
+
before do
|
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
16
|
+
concat(builder.input(:email))
|
|
17
|
+
end)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it_should_have_input_wrapper_with_class(:email)
|
|
21
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
22
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
|
23
|
+
it_should_have_input_wrapper_with_id("post_email_input")
|
|
24
|
+
it_should_have_label_with_text(/Email/)
|
|
25
|
+
it_should_have_label_for("post_email")
|
|
26
|
+
it_should_have_input_with_id("post_email")
|
|
27
|
+
it_should_have_input_with_type(:email)
|
|
28
|
+
it_should_have_input_with_name("post[email]")
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "when namespace is provided" do
|
|
33
|
+
|
|
34
|
+
before do
|
|
35
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
36
|
+
concat(builder.input(:email))
|
|
37
|
+
end)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it_should_have_input_wrapper_with_id("context2_post_email_input")
|
|
41
|
+
it_should_have_label_and_input_with_id("context2_post_email")
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "when index is provided" do
|
|
46
|
+
|
|
47
|
+
before do
|
|
48
|
+
@output_buffer = ''
|
|
49
|
+
mock_everything
|
|
50
|
+
|
|
51
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
52
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
53
|
+
concat(author.input(:name, :as => :email))
|
|
54
|
+
end)
|
|
55
|
+
end)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'should index the id of the wrapper' do
|
|
59
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'should index the id of the select tag' do
|
|
63
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'should index the name of the select tag' do
|
|
67
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
describe "when required" do
|
|
74
|
+
it "should add the required attribute to the input's html options" do
|
|
75
|
+
with_config :use_required_attribute, true do
|
|
76
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
77
|
+
concat(builder.input(:title, :as => :email, :required => true))
|
|
78
|
+
end)
|
|
79
|
+
output_buffer.should have_tag("input[@required]")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
|
|
12
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
13
|
+
concat(builder.input(:body, :as => :file))
|
|
14
|
+
end)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it_should_have_input_wrapper_with_class("file")
|
|
18
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
19
|
+
it_should_have_input_wrapper_with_id("post_body_input")
|
|
20
|
+
it_should_have_label_with_text(/Body/)
|
|
21
|
+
it_should_have_label_for("post_body")
|
|
22
|
+
it_should_have_input_with_id("post_body")
|
|
23
|
+
it_should_have_input_with_name("post[body]")
|
|
24
|
+
it_should_apply_error_logic_for_input_type(:file)
|
|
25
|
+
|
|
26
|
+
it 'should use input_html to style inputs' do
|
|
27
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
28
|
+
concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
|
|
29
|
+
end)
|
|
30
|
+
output_buffer.should have_tag("form li input.myclass")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "when namespace is provided" do
|
|
34
|
+
|
|
35
|
+
before do
|
|
36
|
+
@output_buffer = ''
|
|
37
|
+
mock_everything
|
|
38
|
+
|
|
39
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
40
|
+
concat(builder.input(:body, :as => :file))
|
|
41
|
+
end)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it_should_have_input_wrapper_with_id("context2_post_body_input")
|
|
45
|
+
it_should_have_label_and_input_with_id("context2_post_body")
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "when index is provided" do
|
|
50
|
+
|
|
51
|
+
before do
|
|
52
|
+
@output_buffer = ''
|
|
53
|
+
mock_everything
|
|
54
|
+
|
|
55
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
56
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
57
|
+
concat(author.input(:name, :as => :file))
|
|
58
|
+
end)
|
|
59
|
+
end)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'should index the id of the wrapper' do
|
|
63
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'should index the id of the select tag' do
|
|
67
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'should index the name of the select tag' do
|
|
71
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
context "when required" do
|
|
78
|
+
it "should add the required attribute to the input's html options" do
|
|
79
|
+
with_config :use_required_attribute, true do
|
|
80
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
81
|
+
concat(builder.input(:title, :as => :file, :required => true))
|
|
82
|
+
end)
|
|
83
|
+
output_buffer.should have_tag("input[@required]")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'hidden input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
|
|
12
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
13
|
+
concat(builder.input(:secret, :as => :hidden))
|
|
14
|
+
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
|
15
|
+
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
|
16
|
+
end)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it_should_have_input_wrapper_with_class("hidden")
|
|
20
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
21
|
+
it_should_have_input_wrapper_with_id("post_secret_input")
|
|
22
|
+
it_should_not_have_a_label
|
|
23
|
+
|
|
24
|
+
it "should generate a input field" do
|
|
25
|
+
output_buffer.should have_tag("form li input#post_secret")
|
|
26
|
+
output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"]")
|
|
27
|
+
output_buffer.should have_tag("form li input#post_secret[@name=\"post[secret]\"]")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should get value from the object" do
|
|
31
|
+
output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should pass any explicitly specified value - using :input_html options" do
|
|
35
|
+
output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should pass any option specified using :input_html" do
|
|
39
|
+
output_buffer.should have_tag("form li input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should not render inline errors" do
|
|
43
|
+
@errors = double('errors')
|
|
44
|
+
@errors.stub(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
|
|
45
|
+
@new_post.stub(:errors).and_return(@errors)
|
|
46
|
+
|
|
47
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
48
|
+
concat(builder.input(:secret, :as => :hidden))
|
|
49
|
+
end)
|
|
50
|
+
|
|
51
|
+
output_buffer.should_not have_tag("form li p.inline-errors")
|
|
52
|
+
output_buffer.should_not have_tag("form li ul.errors")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should not render inline hints" do
|
|
56
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
57
|
+
concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
|
|
58
|
+
end)
|
|
59
|
+
|
|
60
|
+
output_buffer.should_not have_tag("form li p.inline-hints")
|
|
61
|
+
output_buffer.should_not have_tag("form li ul.hints")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "when namespace is provided" do
|
|
65
|
+
|
|
66
|
+
before do
|
|
67
|
+
@output_buffer = ''
|
|
68
|
+
mock_everything
|
|
69
|
+
|
|
70
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
71
|
+
concat(builder.input(:secret, :as => :hidden))
|
|
72
|
+
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
|
73
|
+
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
|
74
|
+
end)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
attributes_to_check = [:secret, :published, :reviewer]
|
|
78
|
+
attributes_to_check.each do |a|
|
|
79
|
+
it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
(attributes_to_check - [:reviewer]).each do |a|
|
|
83
|
+
it_should_have_input_with_id("context2_post_#{a}")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "when index is provided" do
|
|
89
|
+
|
|
90
|
+
before do
|
|
91
|
+
@output_buffer = ''
|
|
92
|
+
mock_everything
|
|
93
|
+
|
|
94
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
95
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
96
|
+
concat(author.input(:name, :as => :hidden))
|
|
97
|
+
end)
|
|
98
|
+
end)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should index the id of the wrapper' do
|
|
102
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'should index the id of the select tag' do
|
|
106
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'should index the name of the select tag' do
|
|
110
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
context "when required" do
|
|
117
|
+
it "should not add the required attribute to the input's html options" do
|
|
118
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
119
|
+
concat(builder.input(:title, :as => :hidden, :required => true))
|
|
120
|
+
end)
|
|
121
|
+
output_buffer.should_not have_tag("input[@required]")
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
context "when :autofocus is provided in :input_html" do
|
|
126
|
+
it "should not add the autofocus attribute to the input's html options" do
|
|
127
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
128
|
+
concat(builder.input(:title, :as => :hidden, :input_html => {:autofocus => true}))
|
|
129
|
+
end)
|
|
130
|
+
output_buffer.should_not have_tag("input[@autofocus]")
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
|