formtastic 3.1.5 → 4.0.0.rc1
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 +5 -5
- data/.gitattributes +1 -0
- data/.gitignore +3 -2
- data/.travis.yml +28 -40
- data/CHANGELOG.md +49 -0
- data/DEPRECATIONS +1 -1
- data/Gemfile.lock +104 -0
- data/README.md +628 -629
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +8 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +5 -11
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +1 -38
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +8 -24
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +7 -3
- data/lib/formtastic/helpers/input_helper.rb +18 -76
- data/lib/formtastic/helpers/inputs_helper.rb +12 -3
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/collections.rb +1 -5
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +19 -9
- data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/select_input.rb +1 -1
- data/lib/formtastic/localizer.rb +5 -7
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/formtastic.rb +4 -6
- data/script/integration-template.rb +71 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +1 -1
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +60 -60
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +36 -20
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +31 -31
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +328 -10
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +33 -33
- data/spec/helpers/input_helper_spec.rb +975 -2
- data/spec/helpers/inputs_helper_spec.rb +120 -105
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +1 -1
- data/spec/inputs/base/collections_spec.rb +6 -6
- data/spec/inputs/base/validations_spec.rb +157 -19
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +96 -95
- data/spec/inputs/color_input_spec.rb +51 -63
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +2 -6
- data/spec/inputs/datalist_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +42 -42
- data/spec/inputs/date_select_input_spec.rb +51 -37
- data/spec/inputs/datetime_picker_input_spec.rb +46 -46
- data/spec/inputs/datetime_select_input_spec.rb +53 -37
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +18 -18
- data/spec/inputs/include_blank_spec.rb +8 -8
- data/spec/inputs/label_spec.rb +20 -20
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +5 -5
- data/spec/inputs/radio_input_spec.rb +63 -65
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +4 -4
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +92 -96
- data/spec/inputs/string_input_spec.rb +23 -23
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +43 -43
- data/spec/inputs/time_select_input_spec.rb +67 -54
- data/spec/inputs/time_zone_input_spec.rb +19 -19
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +17 -17
- data/spec/namespaced_class_finder_spec.rb +2 -2
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +163 -223
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1301
- data/spec/support/test_environment.rb +23 -9
- metadata +33 -123
- data/Appraisals +0 -43
- data/CHANGELOG +0 -54
- data/gemfiles/rails_3.2.gemfile +0 -9
- data/gemfiles/rails_4.0.4.gemfile +0 -8
- data/gemfiles/rails_4.1.gemfile +0 -8
- data/gemfiles/rails_4.2.gemfile +0 -8
- data/gemfiles/rails_4.gemfile +0 -8
- data/gemfiles/rails_5.0.gemfile +0 -8
- data/gemfiles/rails_edge.gemfile +0 -15
- data/lib/formtastic/util.rb +0 -57
- data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/util_spec.rb +0 -66
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'datetime select input' do
|
4
|
+
RSpec.describe 'datetime select input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -29,32 +29,32 @@ describe 'datetime select input' do
|
|
29
29
|
it_should_apply_error_logic_for_input_type(:datetime_select)
|
30
30
|
|
31
31
|
it 'should have a legend and label with the label text inside the fieldset' do
|
32
|
-
output_buffer.
|
32
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset legend.label label', :text => /Publish at/)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should associate the legend label with the first select' do
|
36
|
-
output_buffer.
|
37
|
-
output_buffer.
|
38
|
-
output_buffer.
|
39
|
-
output_buffer.
|
36
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset legend.label')
|
37
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset legend.label label')
|
38
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset legend.label label[@for]')
|
39
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_1i"]')
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should have an ordered list of five items inside the fieldset' do
|
43
|
-
output_buffer.
|
44
|
-
output_buffer.
|
43
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol.fragments-group')
|
44
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li.fragment', :count => 5)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should have five labels for year, month and day' do
|
48
|
-
output_buffer.
|
49
|
-
output_buffer.
|
50
|
-
output_buffer.
|
51
|
-
output_buffer.
|
52
|
-
output_buffer.
|
53
|
-
output_buffer.
|
48
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :count => 5)
|
49
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => /year/i)
|
50
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => /month/i)
|
51
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => /day/i)
|
52
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => /hour/i)
|
53
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => /min/i)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should have five selects' do
|
57
|
-
output_buffer.
|
57
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li select', :count => 5)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -90,23 +90,23 @@ describe 'datetime select input' do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should index the id of the wrapper' do
|
93
|
-
output_buffer.
|
93
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_created_at_input")
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'should index the id of the select tag' do
|
97
|
-
output_buffer.
|
98
|
-
output_buffer.
|
99
|
-
output_buffer.
|
100
|
-
output_buffer.
|
101
|
-
output_buffer.
|
97
|
+
expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_1i")
|
98
|
+
expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_2i")
|
99
|
+
expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_3i")
|
100
|
+
expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_4i")
|
101
|
+
expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_5i")
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should index the name of the select tag' do
|
105
|
-
output_buffer.
|
106
|
-
output_buffer.
|
107
|
-
output_buffer.
|
108
|
-
output_buffer.
|
109
|
-
output_buffer.
|
105
|
+
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(1i)]']")
|
106
|
+
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(2i)]']")
|
107
|
+
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(3i)]']")
|
108
|
+
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
|
109
|
+
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
|
110
110
|
end
|
111
111
|
|
112
112
|
end
|
@@ -120,9 +120,9 @@ describe 'datetime select input' do
|
|
120
120
|
concat(semantic_form_for(@new_post) do |builder|
|
121
121
|
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "another #{field} label" }))
|
122
122
|
end)
|
123
|
-
output_buffer.
|
123
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :count => fields.length)
|
124
124
|
fields.each do |f|
|
125
|
-
output_buffer.
|
125
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => f == field ? /another #{f} label/i : /#{f}/i)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -131,9 +131,9 @@ describe 'datetime select input' do
|
|
131
131
|
concat(semantic_form_for(@new_post) do |builder|
|
132
132
|
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "" }))
|
133
133
|
end)
|
134
|
-
output_buffer.
|
134
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
|
135
135
|
fields.each do |f|
|
136
|
-
output_buffer.
|
136
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
@@ -142,9 +142,9 @@ describe 'datetime select input' do
|
|
142
142
|
concat(semantic_form_for(@new_post) do |builder|
|
143
143
|
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => false }))
|
144
144
|
end)
|
145
|
-
output_buffer.
|
145
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
|
146
146
|
fields.each do |f|
|
147
|
-
output_buffer.
|
147
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
@@ -153,7 +153,7 @@ describe 'datetime select input' do
|
|
153
153
|
concat(semantic_form_for(@new_post) do |builder|
|
154
154
|
concat(builder.input(:created_at, :as => :datetime_select, :include_seconds => true, :labels => { field => false }))
|
155
155
|
end)
|
156
|
-
output_buffer.
|
156
|
+
expect(output_buffer).not_to include(">")
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
@@ -162,17 +162,33 @@ describe 'datetime select input' do
|
|
162
162
|
concat(semantic_form_for(@new_post) do |builder|
|
163
163
|
concat(builder.input(:created_at, :as => :datetime_select, :labels => false))
|
164
164
|
end)
|
165
|
-
output_buffer.
|
165
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset ol li label', :count => 0)
|
166
166
|
end
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
|
+
describe ":selected option for setting a value" do
|
170
|
+
it "should set the selected value for the form" do
|
171
|
+
concat(
|
172
|
+
semantic_form_for(@new_post) do |f|
|
173
|
+
concat(f.input(:created_at, :as => :datetime_select, :selected => DateTime.new(2018, 10, 4, 12, 00)))
|
174
|
+
end
|
175
|
+
)
|
176
|
+
|
177
|
+
expect(output_buffer).to have_tag "option[value='2018'][selected='selected']"
|
178
|
+
expect(output_buffer).to have_tag "option[value='10'][selected='selected']"
|
179
|
+
expect(output_buffer).to have_tag "option[value='4'][selected='selected']"
|
180
|
+
expect(output_buffer).to have_tag "option[value='12'][selected='selected']"
|
181
|
+
expect(output_buffer).to have_tag "option[value='00'][selected='selected']"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
169
185
|
describe "when required" do
|
170
186
|
it "should add the required attribute to the input's html options" do
|
171
187
|
with_config :use_required_attribute, true do
|
172
188
|
concat(semantic_form_for(@new_post) do |builder|
|
173
189
|
concat(builder.input(:title, :as => :datetime_select, :required => true))
|
174
190
|
end)
|
175
|
-
output_buffer.
|
191
|
+
expect(output_buffer).to have_tag("select[@required]", :count => 5)
|
176
192
|
end
|
177
193
|
end
|
178
194
|
end
|
@@ -186,7 +202,7 @@ describe 'datetime select input' do
|
|
186
202
|
end
|
187
203
|
|
188
204
|
it 'should associate the legend label with the new first select' do
|
189
|
-
output_buffer.
|
205
|
+
expect(output_buffer).to have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_3i"]')
|
190
206
|
end
|
191
207
|
end
|
192
208
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'email input' do
|
4
|
+
RSpec.describe 'email input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -56,15 +56,15 @@ describe 'email input' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should index the id of the wrapper' do
|
59
|
-
output_buffer.
|
59
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should index the id of the select tag' do
|
63
|
-
output_buffer.
|
63
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should index the name of the select tag' do
|
67
|
-
output_buffer.
|
67
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
@@ -76,7 +76,7 @@ describe 'email input' do
|
|
76
76
|
concat(semantic_form_for(@new_post) do |builder|
|
77
77
|
concat(builder.input(:title, :as => :email, :required => true))
|
78
78
|
end)
|
79
|
-
output_buffer.
|
79
|
+
expect(output_buffer).to have_tag("input[@required]")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'file input' do
|
4
|
+
RSpec.describe 'file input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -27,7 +27,7 @@ describe 'file input' do
|
|
27
27
|
concat(semantic_form_for(@new_post) do |builder|
|
28
28
|
concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
|
29
29
|
end)
|
30
|
-
output_buffer.
|
30
|
+
expect(output_buffer).to have_tag("form li input.myclass")
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "when namespace is provided" do
|
@@ -60,15 +60,15 @@ describe 'file input' do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should index the id of the wrapper' do
|
63
|
-
output_buffer.
|
63
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should index the id of the select tag' do
|
67
|
-
output_buffer.
|
67
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should index the name of the select tag' do
|
71
|
-
output_buffer.
|
71
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
@@ -80,7 +80,7 @@ describe 'file input' do
|
|
80
80
|
concat(semantic_form_for(@new_post) do |builder|
|
81
81
|
concat(builder.input(:title, :as => :file, :required => true))
|
82
82
|
end)
|
83
|
-
output_buffer.
|
83
|
+
expect(output_buffer).to have_tag("input[@required]")
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'hidden input' do
|
4
|
+
RSpec.describe 'hidden input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -22,34 +22,34 @@ describe 'hidden input' do
|
|
22
22
|
it_should_not_have_a_label
|
23
23
|
|
24
24
|
it "should generate a input field" do
|
25
|
-
output_buffer.
|
26
|
-
output_buffer.
|
27
|
-
output_buffer.
|
25
|
+
expect(output_buffer).to have_tag("form li input#post_secret")
|
26
|
+
expect(output_buffer).to have_tag("form li input#post_secret[@type=\"hidden\"]")
|
27
|
+
expect(output_buffer).to have_tag("form li input#post_secret[@name=\"post[secret]\"]")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should get value from the object" do
|
31
|
-
output_buffer.
|
31
|
+
expect(output_buffer).to have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should pass any explicitly specified value - using :input_html options" do
|
35
|
-
output_buffer.
|
35
|
+
expect(output_buffer).to have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should pass any option specified using :input_html" do
|
39
|
-
output_buffer.
|
39
|
+
expect(output_buffer).to have_tag("form li input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should not render inline errors" do
|
43
43
|
@errors = double('errors')
|
44
|
-
@errors.
|
45
|
-
@new_post.
|
44
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
|
45
|
+
allow(@new_post).to receive(:errors).and_return(@errors)
|
46
46
|
|
47
47
|
concat(semantic_form_for(@new_post) do |builder|
|
48
48
|
concat(builder.input(:secret, :as => :hidden))
|
49
49
|
end)
|
50
50
|
|
51
|
-
output_buffer.
|
52
|
-
output_buffer.
|
51
|
+
expect(output_buffer).not_to have_tag("form li p.inline-errors")
|
52
|
+
expect(output_buffer).not_to have_tag("form li ul.errors")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not render inline hints" do
|
@@ -57,8 +57,8 @@ describe 'hidden input' do
|
|
57
57
|
concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
|
58
58
|
end)
|
59
59
|
|
60
|
-
output_buffer.
|
61
|
-
output_buffer.
|
60
|
+
expect(output_buffer).not_to have_tag("form li p.inline-hints")
|
61
|
+
expect(output_buffer).not_to have_tag("form li ul.hints")
|
62
62
|
end
|
63
63
|
|
64
64
|
describe "when namespace is provided" do
|
@@ -99,15 +99,15 @@ describe 'hidden input' do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should index the id of the wrapper' do
|
102
|
-
output_buffer.
|
102
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should index the id of the select tag' do
|
106
|
-
output_buffer.
|
106
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should index the name of the select tag' do
|
110
|
-
output_buffer.
|
110
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
|
111
111
|
end
|
112
112
|
|
113
113
|
end
|
@@ -118,7 +118,7 @@ describe 'hidden input' do
|
|
118
118
|
concat(semantic_form_for(@new_post) do |builder|
|
119
119
|
concat(builder.input(:title, :as => :hidden, :required => true))
|
120
120
|
end)
|
121
|
-
output_buffer.
|
121
|
+
expect(output_buffer).not_to have_tag("input[@required]")
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -127,7 +127,7 @@ describe 'hidden input' do
|
|
127
127
|
concat(semantic_form_for(@new_post) do |builder|
|
128
128
|
concat(builder.input(:title, :as => :hidden, :input_html => {:autofocus => true}))
|
129
129
|
end)
|
130
|
-
output_buffer.
|
130
|
+
expect(output_buffer).not_to have_tag("input[@autofocus]")
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe "*select: options[:include_blank]" do
|
4
|
+
RSpec.describe "*select: options[:include_blank]" do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -9,8 +9,8 @@ describe "*select: options[:include_blank]" do
|
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
|
12
|
-
@new_post.
|
13
|
-
@new_post.
|
12
|
+
allow(@new_post).to receive(:author_id).and_return(nil)
|
13
|
+
allow(@new_post).to receive(:publish_at).and_return(nil)
|
14
14
|
end
|
15
15
|
|
16
16
|
SELECT_INPUT_TYPES = {
|
@@ -29,7 +29,7 @@ describe "*select: options[:include_blank]" do
|
|
29
29
|
concat(semantic_form_for(@new_post) do |builder|
|
30
30
|
concat(builder.input(attribute, :as => as))
|
31
31
|
end)
|
32
|
-
output_buffer.
|
32
|
+
expect(output_buffer).to have_tag("form li select option[@value='']", "")
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'blank value should not be included if the default value specified in config is false' do
|
@@ -37,7 +37,7 @@ describe "*select: options[:include_blank]" do
|
|
37
37
|
concat(semantic_form_for(@new_post) do |builder|
|
38
38
|
concat(builder.input(attribute, :as => as))
|
39
39
|
end)
|
40
|
-
output_buffer.
|
40
|
+
expect(output_buffer).not_to have_tag("form li select option[@value='']", "")
|
41
41
|
end
|
42
42
|
|
43
43
|
after do
|
@@ -50,7 +50,7 @@ describe "*select: options[:include_blank]" do
|
|
50
50
|
concat(semantic_form_for(@new_post) do |builder|
|
51
51
|
concat(builder.input(attribute, :as => as, :include_blank => false))
|
52
52
|
end)
|
53
|
-
output_buffer.
|
53
|
+
expect(output_buffer).not_to have_tag("form li select option[@value='']", "")
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -59,7 +59,7 @@ describe "*select: options[:include_blank]" do
|
|
59
59
|
concat(semantic_form_for(@new_post) do |builder|
|
60
60
|
concat(builder.input(attribute, :as => as, :include_blank => true))
|
61
61
|
end)
|
62
|
-
output_buffer.
|
62
|
+
expect(output_buffer).to have_tag("form li select option[@value='']", "")
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -69,7 +69,7 @@ describe "*select: options[:include_blank]" do
|
|
69
69
|
concat(semantic_form_for(@new_post) do |builder|
|
70
70
|
concat(builder.input(attribute, :as => as, :include_blank => 'string'))
|
71
71
|
end)
|
72
|
-
output_buffer.
|
72
|
+
expect(output_buffer).to have_tag("form li select option[@value='']", "string")
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
data/spec/inputs/label_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'Formtastic::FormBuilder#label' do
|
4
|
+
RSpec.describe 'Formtastic::FormBuilder#label' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -28,7 +28,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
28
28
|
::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
|
29
29
|
Formtastic::FormBuilder.required_string = default_required_str
|
30
30
|
|
31
|
-
output_buffer.scan(required_string).count.
|
31
|
+
expect(output_buffer.scan(required_string).count).to eq(1)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -36,7 +36,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
36
36
|
concat(semantic_form_for(@new_post) do |builder|
|
37
37
|
builder.input(:title)
|
38
38
|
end)
|
39
|
-
output_buffer.
|
39
|
+
expect(output_buffer).to have_tag('label', :text => /Title/)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should use i18n instead of the method name when method given as a String' do
|
@@ -46,7 +46,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
46
46
|
builder.input("title")
|
47
47
|
end)
|
48
48
|
::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
|
49
|
-
output_buffer.
|
49
|
+
expect(output_buffer).to have_tag('label', :text => /I18n title/)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -54,7 +54,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
54
54
|
concat(semantic_form_for(@new_post) do |builder|
|
55
55
|
builder.input(:publish_at)
|
56
56
|
end)
|
57
|
-
output_buffer.
|
57
|
+
expect(output_buffer).to have_tag('label', :text => /Publish at/)
|
58
58
|
end
|
59
59
|
|
60
60
|
describe 'when required is given' do
|
@@ -62,7 +62,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
62
62
|
concat(semantic_form_for(@new_post) do |builder|
|
63
63
|
builder.input(:title, :required => true)
|
64
64
|
end)
|
65
|
-
output_buffer.
|
65
|
+
expect(output_buffer).to have_tag('label abbr', '*')
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -73,7 +73,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
73
73
|
concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => :to_s, :member_label => proc {|f| ('Label_%s' % [f])}))
|
74
74
|
end)
|
75
75
|
end
|
76
|
-
output_buffer.
|
76
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /Label_[abc]/, :count => 3)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'should use a supplied value_method for simple collections' do
|
@@ -82,9 +82,9 @@ describe 'Formtastic::FormBuilder#label' do
|
|
82
82
|
concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => proc {|f| ('Value_%s' % [f.to_s])}))
|
83
83
|
end)
|
84
84
|
end
|
85
|
-
output_buffer.
|
86
|
-
output_buffer.
|
87
|
-
output_buffer.
|
85
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label input[value="Value_a"]')
|
86
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label input[value="Value_b"]')
|
87
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label input[value="Value_c"]')
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -93,38 +93,38 @@ describe 'Formtastic::FormBuilder#label' do
|
|
93
93
|
concat(semantic_form_for(@new_post) do |builder|
|
94
94
|
builder.input(:title, :label => 'My label')
|
95
95
|
end)
|
96
|
-
output_buffer.
|
96
|
+
expect(output_buffer).to have_tag('label', :text => /My label/)
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should allow the text to be given as label option for date fields' do
|
100
100
|
concat(semantic_form_for(@new_post) do |builder|
|
101
101
|
builder.input(:publish_at, :label => 'My other label')
|
102
102
|
end)
|
103
|
-
output_buffer.
|
103
|
+
expect(output_buffer).to have_tag('label', :text => /My other label/)
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'should return nil if label is false' do
|
107
107
|
concat(semantic_form_for(@new_post) do |builder|
|
108
108
|
builder.input(:title, :label => false)
|
109
109
|
end)
|
110
|
-
output_buffer.
|
111
|
-
output_buffer.
|
110
|
+
expect(output_buffer).not_to have_tag('label')
|
111
|
+
expect(output_buffer).not_to include(">")
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'should return nil if label is false for timeish fragments' do
|
115
115
|
concat(semantic_form_for(@new_post) do |builder|
|
116
116
|
builder.input(:title, :as => :time_select, :label => false)
|
117
117
|
end)
|
118
|
-
output_buffer.
|
119
|
-
output_buffer.
|
118
|
+
expect(output_buffer).not_to have_tag('li.time > label')
|
119
|
+
expect(output_buffer).not_to include(">")
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should html escape the label string by default' do
|
123
123
|
concat(semantic_form_for(@new_post) do |builder|
|
124
124
|
builder.input(:title, :label => '<b>My label</b>')
|
125
125
|
end)
|
126
|
-
output_buffer.
|
127
|
-
output_buffer.
|
126
|
+
expect(output_buffer).to include('<b>')
|
127
|
+
expect(output_buffer).not_to include('<b>')
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'should not html escape the label if configured that way' do
|
@@ -132,7 +132,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
132
132
|
concat(semantic_form_for(@new_post) do |builder|
|
133
133
|
builder.input(:title, :label => '<b>My label</b>')
|
134
134
|
end)
|
135
|
-
output_buffer.
|
135
|
+
expect(output_buffer).to have_tag("label b", :text => "My label")
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'should not html escape the label string for html_safe strings' do
|
@@ -140,7 +140,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
140
140
|
concat(semantic_form_for(@new_post) do |builder|
|
141
141
|
builder.input(:title, :label => '<b>My label</b>'.html_safe)
|
142
142
|
end)
|
143
|
-
output_buffer.
|
143
|
+
expect(output_buffer).to have_tag('label b')
|
144
144
|
end
|
145
145
|
|
146
146
|
end
|