formtastic 2.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +4 -2
- data/CHANGELOG.md +52 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +105 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +204 -219
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +27 -29
- data/app/assets/stylesheets/formtastic.css +3 -2
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +11 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions/button_action.rb +55 -60
- data/lib/formtastic/actions/input_action.rb +59 -57
- data/lib/formtastic/actions/link_action.rb +68 -67
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +5 -0
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +35 -16
- data/lib/formtastic/helpers/action_helper.rb +34 -28
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
- data/lib/formtastic/helpers/form_helper.rb +19 -16
- data/lib/formtastic/helpers/input_helper.rb +69 -97
- data/lib/formtastic/helpers/inputs_helper.rb +35 -25
- data/lib/formtastic/helpers/reflection.rb +4 -4
- data/lib/formtastic/helpers.rb +1 -2
- data/lib/formtastic/html_attributes.rb +12 -1
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs/base/choices.rb +2 -2
- data/lib/formtastic/inputs/base/collections.rb +46 -14
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -7
- data/lib/formtastic/inputs/base/hints.rb +2 -2
- data/lib/formtastic/inputs/base/html.rb +10 -9
- data/lib/formtastic/inputs/base/labelling.rb +5 -8
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -1
- data/lib/formtastic/inputs/base/options.rb +3 -4
- data/lib/formtastic/inputs/base/stringish.rb +10 -2
- data/lib/formtastic/inputs/base/timeish.rb +34 -22
- data/lib/formtastic/inputs/base/validations.rb +41 -13
- data/lib/formtastic/inputs/base/wrapping.rb +29 -26
- data/lib/formtastic/inputs/base.rb +22 -15
- data/lib/formtastic/inputs/boolean_input.rb +26 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
- data/lib/formtastic/inputs/color_input.rb +41 -0
- data/lib/formtastic/inputs/country_input.rb +24 -5
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
- data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
- data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
- data/lib/formtastic/inputs/file_input.rb +2 -2
- data/lib/formtastic/inputs/hidden_input.rb +2 -6
- data/lib/formtastic/inputs/radio_input.rb +28 -22
- data/lib/formtastic/inputs/select_input.rb +36 -39
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/inputs.rb +32 -21
- data/lib/formtastic/localized_string.rb +1 -1
- data/lib/formtastic/localizer.rb +24 -24
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/formtastic.rb +20 -10
- data/lib/generators/formtastic/form/form_generator.rb +10 -4
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +5 -19
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +46 -25
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +23 -3
- data/script/integration-template.rb +74 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +92 -56
- 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 +28 -29
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +75 -103
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +84 -33
- data/spec/helpers/input_helper_spec.rb +333 -285
- data/spec/helpers/inputs_helper_spec.rb +167 -121
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
- data/spec/i18n_spec.rb +26 -26
- 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 +480 -0
- data/spec/inputs/boolean_input_spec.rb +100 -65
- data/spec/inputs/check_boxes_input_spec.rb +200 -101
- data/spec/inputs/color_input_spec.rb +85 -0
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +3 -4
- 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 +249 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +209 -0
- 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 +22 -35
- data/spec/inputs/include_blank_spec.rb +11 -11
- data/spec/inputs/label_spec.rb +62 -25
- 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 +6 -6
- data/spec/inputs/radio_input_spec.rb +99 -55
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +170 -170
- data/spec/inputs/string_input_spec.rb +68 -16
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +261 -0
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +39 -17
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +254 -221
- data/spec/support/custom_macros.rb +128 -95
- data/spec/support/shared_examples.rb +12 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +26 -10
- metadata +177 -238
- data/.travis.yml +0 -8
- data/Appraisals +0 -11
- data/CHANGELOG +0 -371
- data/gemfiles/rails-3.0.gemfile +0 -7
- data/gemfiles/rails-3.1.gemfile +0 -7
- data/gemfiles/rails-3.2.gemfile +0 -7
- data/lib/formtastic/helpers/buttons_helper.rb +0 -310
- data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
- data/lib/formtastic/util.rb +0 -25
- data/lib/tasks/verify_rcov.rb +0 -44
- data/spec/helpers/buttons_helper_spec.rb +0 -166
- data/spec/helpers/commit_button_helper_spec.rb +0 -530
- data/spec/inputs/date_input_spec.rb +0 -227
- data/spec/inputs/datetime_input_spec.rb +0 -185
- data/spec/inputs/time_input_spec.rb +0 -267
- data/spec/support/deferred_garbage_collection.rb +0 -21
@@ -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,20 +1,18 @@
|
|
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
|
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
|
11
|
+
|
12
12
|
concat(semantic_form_for(@new_post) do |builder|
|
13
13
|
concat(builder.input(:secret, :as => :hidden))
|
14
|
-
concat(builder.input(:author_id, :as => :hidden, :value => 99))
|
15
14
|
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
16
15
|
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
17
|
-
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
|
18
16
|
end)
|
19
17
|
end
|
20
18
|
|
@@ -24,43 +22,34 @@ describe 'hidden input' do
|
|
24
22
|
it_should_not_have_a_label
|
25
23
|
|
26
24
|
it "should generate a input field" do
|
27
|
-
output_buffer.
|
28
|
-
output_buffer.
|
29
|
-
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]\"]")
|
30
28
|
end
|
31
29
|
|
32
30
|
it "should get value from the object" do
|
33
|
-
output_buffer.
|
31
|
+
expect(output_buffer).to have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
|
34
32
|
end
|
35
33
|
|
36
|
-
it "should pass any explicitly specified value - using :value" do
|
37
|
-
output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
|
38
|
-
end
|
39
|
-
|
40
|
-
# Handle Formtastic :input_html options for consistency.
|
41
34
|
it "should pass any explicitly specified value - using :input_html options" do
|
42
|
-
output_buffer.
|
35
|
+
expect(output_buffer).to have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
|
43
36
|
end
|
44
37
|
|
45
38
|
it "should pass any option specified using :input_html" do
|
46
|
-
output_buffer.
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should prefer :input_html over directly supplied options" do
|
50
|
-
output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
|
39
|
+
expect(output_buffer).to have_tag("form li input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
|
51
40
|
end
|
52
41
|
|
53
42
|
it "should not render inline errors" do
|
54
|
-
@errors =
|
55
|
-
@errors.
|
56
|
-
@new_post.
|
43
|
+
@errors = double('errors')
|
44
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
|
45
|
+
allow(@new_post).to receive(:errors).and_return(@errors)
|
57
46
|
|
58
47
|
concat(semantic_form_for(@new_post) do |builder|
|
59
48
|
concat(builder.input(:secret, :as => :hidden))
|
60
49
|
end)
|
61
50
|
|
62
|
-
output_buffer.
|
63
|
-
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")
|
64
53
|
end
|
65
54
|
|
66
55
|
it "should not render inline hints" do
|
@@ -68,8 +57,8 @@ describe 'hidden input' do
|
|
68
57
|
concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
|
69
58
|
end)
|
70
59
|
|
71
|
-
output_buffer.
|
72
|
-
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")
|
73
62
|
end
|
74
63
|
|
75
64
|
describe "when namespace is provided" do
|
@@ -77,17 +66,15 @@ describe 'hidden input' do
|
|
77
66
|
before do
|
78
67
|
@output_buffer = ''
|
79
68
|
mock_everything
|
80
|
-
|
69
|
+
|
81
70
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
82
71
|
concat(builder.input(:secret, :as => :hidden))
|
83
|
-
concat(builder.input(:author_id, :as => :hidden, :value => 99))
|
84
72
|
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
85
73
|
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
86
|
-
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
|
87
74
|
end)
|
88
75
|
end
|
89
76
|
|
90
|
-
attributes_to_check = [:secret, :
|
77
|
+
attributes_to_check = [:secret, :published, :reviewer]
|
91
78
|
attributes_to_check.each do |a|
|
92
79
|
it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
|
93
80
|
end
|
@@ -112,15 +99,15 @@ describe 'hidden input' do
|
|
112
99
|
end
|
113
100
|
|
114
101
|
it 'should index the id of the wrapper' do
|
115
|
-
output_buffer.
|
102
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
116
103
|
end
|
117
104
|
|
118
105
|
it 'should index the id of the select tag' do
|
119
|
-
output_buffer.
|
106
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
120
107
|
end
|
121
108
|
|
122
109
|
it 'should index the name of the select tag' do
|
123
|
-
output_buffer.
|
110
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
|
124
111
|
end
|
125
112
|
|
126
113
|
end
|
@@ -131,7 +118,7 @@ describe 'hidden input' do
|
|
131
118
|
concat(semantic_form_for(@new_post) do |builder|
|
132
119
|
concat(builder.input(:title, :as => :hidden, :required => true))
|
133
120
|
end)
|
134
|
-
output_buffer.
|
121
|
+
expect(output_buffer).not_to have_tag("input[@required]")
|
135
122
|
end
|
136
123
|
end
|
137
124
|
|
@@ -140,7 +127,7 @@ describe 'hidden input' do
|
|
140
127
|
concat(semantic_form_for(@new_post) do |builder|
|
141
128
|
concat(builder.input(:title, :as => :hidden, :input_html => {:autofocus => true}))
|
142
129
|
end)
|
143
|
-
output_buffer.
|
130
|
+
expect(output_buffer).not_to have_tag("input[@autofocus]")
|
144
131
|
end
|
145
132
|
end
|
146
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,15 +9,15 @@ 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 = {
|
17
17
|
:select => :author,
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
18
|
+
:datetime_select => :publish_at,
|
19
|
+
:date_select => :publish_at,
|
20
|
+
:time_select => :publish_at
|
21
21
|
}
|
22
22
|
|
23
23
|
SELECT_INPUT_TYPES.each do |as, attribute|
|
@@ -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
|
|
@@ -10,18 +10,51 @@ describe 'Formtastic::FormBuilder#label' do
|
|
10
10
|
mock_everything
|
11
11
|
end
|
12
12
|
|
13
|
+
it 'should add "required string" only once with caching enabled' do
|
14
|
+
with_config :i18n_cache_lookups, true do
|
15
|
+
::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => "I18n title" } } } }
|
16
|
+
required_string = "[req_string]"
|
17
|
+
default_required_str = Formtastic::FormBuilder.required_string
|
18
|
+
Formtastic::FormBuilder.required_string = required_string
|
19
|
+
|
20
|
+
concat(semantic_form_for(@new_post) do |builder|
|
21
|
+
builder.input(:title, :required => true, :label => true)
|
22
|
+
end)
|
23
|
+
output_buffer.replace ''
|
24
|
+
concat(semantic_form_for(@new_post) do |builder|
|
25
|
+
builder.input(:title, :required => true, :label => true)
|
26
|
+
end)
|
27
|
+
|
28
|
+
::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
|
29
|
+
Formtastic::FormBuilder.required_string = default_required_str
|
30
|
+
|
31
|
+
expect(output_buffer.scan(required_string).count).to eq(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
13
35
|
it 'should humanize the given attribute' do
|
14
36
|
concat(semantic_form_for(@new_post) do |builder|
|
15
37
|
builder.input(:title)
|
16
38
|
end)
|
17
|
-
output_buffer.
|
39
|
+
expect(output_buffer).to have_tag('label', :text => /Title/)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should use i18n instead of the method name when method given as a String' do
|
43
|
+
with_config :i18n_cache_lookups, true do
|
44
|
+
::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => "I18n title" } } } }
|
45
|
+
concat(semantic_form_for(@new_post) do |builder|
|
46
|
+
builder.input("title")
|
47
|
+
end)
|
48
|
+
::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
|
49
|
+
expect(output_buffer).to have_tag('label', :text => /I18n title/)
|
50
|
+
end
|
18
51
|
end
|
19
52
|
|
20
53
|
it 'should humanize the given attribute for date fields' do
|
21
54
|
concat(semantic_form_for(@new_post) do |builder|
|
22
55
|
builder.input(:publish_at)
|
23
56
|
end)
|
24
|
-
output_buffer.
|
57
|
+
expect(output_buffer).to have_tag('label', :text => /Publish at/)
|
25
58
|
end
|
26
59
|
|
27
60
|
describe 'when required is given' do
|
@@ -29,25 +62,29 @@ describe 'Formtastic::FormBuilder#label' do
|
|
29
62
|
concat(semantic_form_for(@new_post) do |builder|
|
30
63
|
builder.input(:title, :required => true)
|
31
64
|
end)
|
32
|
-
output_buffer.
|
65
|
+
expect(output_buffer).to have_tag('label abbr', '*')
|
33
66
|
end
|
34
67
|
end
|
35
68
|
|
36
69
|
describe 'when a collection is given' do
|
37
70
|
it 'should use a supplied label_method for simple collections' do
|
38
|
-
|
39
|
-
concat(
|
40
|
-
|
41
|
-
|
71
|
+
with_deprecation_silenced do
|
72
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
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
|
+
end)
|
75
|
+
end
|
76
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /Label_[abc]/, :count => 3)
|
42
77
|
end
|
43
78
|
|
44
79
|
it 'should use a supplied value_method for simple collections' do
|
45
|
-
|
46
|
-
concat(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
output_buffer.
|
80
|
+
with_deprecation_silenced do
|
81
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
82
|
+
concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => proc {|f| ('Value_%s' % [f.to_s])}))
|
83
|
+
end)
|
84
|
+
end
|
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"]')
|
51
88
|
end
|
52
89
|
end
|
53
90
|
|
@@ -56,38 +93,38 @@ describe 'Formtastic::FormBuilder#label' do
|
|
56
93
|
concat(semantic_form_for(@new_post) do |builder|
|
57
94
|
builder.input(:title, :label => 'My label')
|
58
95
|
end)
|
59
|
-
output_buffer.
|
96
|
+
expect(output_buffer).to have_tag('label', :text => /My label/)
|
60
97
|
end
|
61
98
|
|
62
99
|
it 'should allow the text to be given as label option for date fields' do
|
63
100
|
concat(semantic_form_for(@new_post) do |builder|
|
64
101
|
builder.input(:publish_at, :label => 'My other label')
|
65
102
|
end)
|
66
|
-
output_buffer.
|
103
|
+
expect(output_buffer).to have_tag('label', :text => /My other label/)
|
67
104
|
end
|
68
105
|
|
69
106
|
it 'should return nil if label is false' do
|
70
107
|
concat(semantic_form_for(@new_post) do |builder|
|
71
108
|
builder.input(:title, :label => false)
|
72
109
|
end)
|
73
|
-
output_buffer.
|
74
|
-
output_buffer.
|
110
|
+
expect(output_buffer).not_to have_tag('label')
|
111
|
+
expect(output_buffer).not_to include(">")
|
75
112
|
end
|
76
113
|
|
77
114
|
it 'should return nil if label is false for timeish fragments' do
|
78
115
|
concat(semantic_form_for(@new_post) do |builder|
|
79
|
-
builder.input(:title, :as => :
|
116
|
+
builder.input(:title, :as => :time_select, :label => false)
|
80
117
|
end)
|
81
|
-
output_buffer.
|
82
|
-
output_buffer.
|
118
|
+
expect(output_buffer).not_to have_tag('li.time > label')
|
119
|
+
expect(output_buffer).not_to include(">")
|
83
120
|
end
|
84
121
|
|
85
122
|
it 'should html escape the label string by default' do
|
86
123
|
concat(semantic_form_for(@new_post) do |builder|
|
87
124
|
builder.input(:title, :label => '<b>My label</b>')
|
88
125
|
end)
|
89
|
-
output_buffer.
|
90
|
-
output_buffer.
|
126
|
+
expect(output_buffer).to include('<b>')
|
127
|
+
expect(output_buffer).not_to include('<b>')
|
91
128
|
end
|
92
129
|
|
93
130
|
it 'should not html escape the label if configured that way' do
|
@@ -95,7 +132,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
95
132
|
concat(semantic_form_for(@new_post) do |builder|
|
96
133
|
builder.input(:title, :label => '<b>My label</b>')
|
97
134
|
end)
|
98
|
-
output_buffer.
|
135
|
+
expect(output_buffer).to have_tag("label b", :text => "My label")
|
99
136
|
end
|
100
137
|
|
101
138
|
it 'should not html escape the label string for html_safe strings' do
|
@@ -103,7 +140,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
103
140
|
concat(semantic_form_for(@new_post) do |builder|
|
104
141
|
builder.input(:title, :label => '<b>My label</b>'.html_safe)
|
105
142
|
end)
|
106
|
-
output_buffer.
|
143
|
+
expect(output_buffer).to have_tag('label b')
|
107
144
|
end
|
108
145
|
|
109
146
|
end
|