formtastic 3.0.0 → 5.0.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.
- checksums.yaml +5 -13
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +61 -0
- data/Gemfile.lock +140 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +191 -168
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +24 -8
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +13 -17
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_7.0/Gemfile +5 -0
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +19 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +56 -53
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +60 -57
- data/lib/formtastic/actions/link_action.rb +69 -67
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +6 -0
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +32 -25
- data/lib/formtastic/helpers/action_helper.rb +22 -31
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +14 -0
- data/lib/formtastic/helpers/errors_helper.rb +3 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -11
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +4 -3
- data/lib/formtastic/helpers/input_helper.rb +59 -80
- data/lib/formtastic/helpers/inputs_helper.rb +33 -27
- data/lib/formtastic/helpers/reflection.rb +5 -4
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +13 -1
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +19 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +4 -3
- data/lib/formtastic/inputs/base/collections.rb +47 -11
- data/lib/formtastic/inputs/base/database.rb +8 -5
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -6
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +2 -1
- data/lib/formtastic/inputs/base/html.rb +12 -10
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +5 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +3 -3
- data/lib/formtastic/inputs/base/placeholder.rb +1 -0
- data/lib/formtastic/inputs/base/stringish.rb +1 -0
- data/lib/formtastic/inputs/base/timeish.rb +9 -4
- data/lib/formtastic/inputs/base/validations.rb +39 -12
- data/lib/formtastic/inputs/base/wrapping.rb +2 -3
- data/lib/formtastic/inputs/base.rb +17 -12
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
- data/lib/formtastic/inputs/color_input.rb +1 -1
- data/lib/formtastic/inputs/country_input.rb +4 -1
- data/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/lib/formtastic/inputs/date_picker_input.rb +1 -0
- data/lib/formtastic/inputs/date_select_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
- data/lib/formtastic/inputs/email_input.rb +1 -0
- data/lib/formtastic/inputs/file_input.rb +3 -2
- data/lib/formtastic/inputs/hidden_input.rb +3 -2
- data/lib/formtastic/inputs/number_input.rb +1 -0
- data/lib/formtastic/inputs/password_input.rb +1 -0
- data/lib/formtastic/inputs/phone_input.rb +1 -0
- data/lib/formtastic/inputs/radio_input.rb +26 -21
- data/lib/formtastic/inputs/range_input.rb +1 -0
- data/lib/formtastic/inputs/search_input.rb +1 -0
- data/lib/formtastic/inputs/select_input.rb +32 -10
- data/lib/formtastic/inputs/string_input.rb +1 -0
- data/lib/formtastic/inputs/text_input.rb +1 -0
- data/lib/formtastic/inputs/time_picker_input.rb +1 -0
- data/lib/formtastic/inputs/time_select_input.rb +1 -0
- data/lib/formtastic/inputs/time_zone_input.rb +17 -6
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +33 -28
- data/lib/formtastic/localized_string.rb +2 -1
- data/lib/formtastic/localizer.rb +23 -24
- data/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +19 -14
- data/lib/generators/formtastic/form/form_generator.rb +8 -2
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +2 -0
- data/lib/generators/templates/formtastic.rb +29 -7
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +73 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +13 -0
- data/spec/actions/button_action_spec.rb +21 -20
- data/spec/actions/generic_action_spec.rb +134 -133
- data/spec/actions/input_action_spec.rb +20 -19
- data/spec/actions/link_action_spec.rb +30 -29
- data/spec/builder/custom_builder_spec.rb +39 -22
- data/spec/builder/error_proc_spec.rb +6 -5
- data/spec/builder/semantic_fields_for_spec.rb +46 -45
- data/spec/fast_spec_helper.rb +13 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
- data/spec/helpers/action_helper_spec.rb +70 -97
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +56 -39
- data/spec/helpers/input_helper_spec.rb +314 -255
- data/spec/helpers/inputs_helper_spec.rb +217 -202
- data/spec/helpers/reflection_helper_spec.rb +7 -6
- data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
- data/spec/i18n_spec.rb +30 -29
- data/spec/input_class_finder_spec.rb +11 -0
- data/spec/inputs/base/collections_spec.rb +78 -0
- data/spec/inputs/base/validations_spec.rb +481 -0
- data/spec/inputs/boolean_input_spec.rb +73 -72
- data/spec/inputs/check_boxes_input_spec.rb +174 -123
- data/spec/inputs/color_input_spec.rb +53 -64
- data/spec/inputs/country_input_spec.rb +23 -22
- data/spec/inputs/custom_input_spec.rb +3 -6
- data/spec/inputs/datalist_input_spec.rb +62 -0
- data/spec/inputs/date_picker_input_spec.rb +114 -113
- data/spec/inputs/date_select_input_spec.rb +76 -61
- data/spec/inputs/datetime_picker_input_spec.rb +123 -122
- data/spec/inputs/datetime_select_input_spec.rb +85 -68
- data/spec/inputs/email_input_spec.rb +17 -16
- data/spec/inputs/file_input_spec.rb +18 -17
- data/spec/inputs/hidden_input_spec.rb +32 -31
- data/spec/inputs/include_blank_spec.rb +10 -9
- data/spec/inputs/label_spec.rb +36 -31
- data/spec/inputs/number_input_spec.rb +212 -211
- data/spec/inputs/password_input_spec.rb +17 -16
- data/spec/inputs/phone_input_spec.rb +17 -16
- data/spec/inputs/placeholder_spec.rb +18 -17
- data/spec/inputs/radio_input_spec.rb +92 -65
- data/spec/inputs/range_input_spec.rb +136 -135
- data/spec/inputs/readonly_spec.rb +51 -0
- data/spec/inputs/search_input_spec.rb +16 -15
- data/spec/inputs/select_input_spec.rb +209 -102
- data/spec/inputs/string_input_spec.rb +51 -50
- data/spec/inputs/text_input_spec.rb +34 -33
- data/spec/inputs/time_picker_input_spec.rb +115 -114
- data/spec/inputs/time_select_input_spec.rb +84 -70
- data/spec/inputs/time_zone_input_spec.rb +58 -31
- data/spec/inputs/url_input_spec.rb +17 -16
- data/spec/inputs/with_options_spec.rb +9 -8
- data/spec/localizer_spec.rb +18 -17
- data/spec/namespaced_class_finder_spec.rb +91 -0
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +180 -249
- data/spec/support/custom_macros.rb +128 -98
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +13 -0
- data/spec/support/specialized_class_finder_shared_example.rb +28 -0
- data/spec/support/test_environment.rb +25 -10
- metadata +95 -136
- data/.travis.yml +0 -28
- data/Appraisals +0 -25
- data/CHANGELOG +0 -27
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -53
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -52
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'password input' do
|
|
5
|
+
RSpec.describe 'password input' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
12
|
|
|
12
13
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -56,11 +57,11 @@ describe 'password input' do
|
|
|
56
57
|
it_should_have_label_and_input_with_id("context2_post_title")
|
|
57
58
|
|
|
58
59
|
end
|
|
59
|
-
|
|
60
|
+
|
|
60
61
|
describe "when index is provided" do
|
|
61
62
|
|
|
62
63
|
before do
|
|
63
|
-
@output_buffer = ''
|
|
64
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
64
65
|
mock_everything
|
|
65
66
|
|
|
66
67
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -69,31 +70,31 @@ describe 'password input' do
|
|
|
69
70
|
end)
|
|
70
71
|
end)
|
|
71
72
|
end
|
|
72
|
-
|
|
73
|
+
|
|
73
74
|
it 'should index the id of the wrapper' do
|
|
74
|
-
output_buffer.
|
|
75
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
75
76
|
end
|
|
76
|
-
|
|
77
|
+
|
|
77
78
|
it 'should index the id of the select tag' do
|
|
78
|
-
output_buffer.
|
|
79
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
|
79
80
|
end
|
|
80
|
-
|
|
81
|
+
|
|
81
82
|
it 'should index the name of the select tag' do
|
|
82
|
-
output_buffer.
|
|
83
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
|
|
83
84
|
end
|
|
84
|
-
|
|
85
|
+
|
|
85
86
|
end
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
|
|
88
|
+
|
|
88
89
|
describe "when required" do
|
|
89
90
|
it "should add the required attribute to the input's html options" do
|
|
90
|
-
with_config :use_required_attribute, true do
|
|
91
|
+
with_config :use_required_attribute, true do
|
|
91
92
|
concat(semantic_form_for(@new_post) do |builder|
|
|
92
93
|
concat(builder.input(:title, :as => :password, :required => true))
|
|
93
94
|
end)
|
|
94
|
-
output_buffer.
|
|
95
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
|
95
96
|
end
|
|
96
97
|
end
|
|
97
98
|
end
|
|
98
|
-
|
|
99
|
+
|
|
99
100
|
end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'phone input' do
|
|
5
|
+
RSpec.describe 'phone input' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -41,11 +42,11 @@ describe 'phone input' do
|
|
|
41
42
|
it_should_have_label_and_input_with_id("context2_post_phone")
|
|
42
43
|
|
|
43
44
|
end
|
|
44
|
-
|
|
45
|
+
|
|
45
46
|
describe "when index is provided" do
|
|
46
47
|
|
|
47
48
|
before do
|
|
48
|
-
@output_buffer = ''
|
|
49
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
49
50
|
mock_everything
|
|
50
51
|
|
|
51
52
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -54,32 +55,32 @@ describe 'phone input' do
|
|
|
54
55
|
end)
|
|
55
56
|
end)
|
|
56
57
|
end
|
|
57
|
-
|
|
58
|
+
|
|
58
59
|
it 'should index the id of the wrapper' do
|
|
59
|
-
output_buffer.
|
|
60
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
60
61
|
end
|
|
61
|
-
|
|
62
|
+
|
|
62
63
|
it 'should index the id of the select tag' do
|
|
63
|
-
output_buffer.
|
|
64
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
|
64
65
|
end
|
|
65
|
-
|
|
66
|
+
|
|
66
67
|
it 'should index the name of the select tag' do
|
|
67
|
-
output_buffer.
|
|
68
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
|
|
68
69
|
end
|
|
69
|
-
|
|
70
|
+
|
|
70
71
|
end
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
|
|
73
74
|
describe "when required" do
|
|
74
75
|
it "should add the required attribute to the input's html options" do
|
|
75
|
-
with_config :use_required_attribute, true do
|
|
76
|
+
with_config :use_required_attribute, true do
|
|
76
77
|
concat(semantic_form_for(@new_post) do |builder|
|
|
77
78
|
concat(builder.input(:title, :as => :phone, :required => true))
|
|
78
79
|
end)
|
|
79
|
-
output_buffer.
|
|
80
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
|
80
81
|
end
|
|
81
82
|
end
|
|
82
83
|
end
|
|
83
|
-
|
|
84
|
+
|
|
84
85
|
end
|
|
85
86
|
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'string input' do
|
|
5
|
+
RSpec.describe 'string input' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
after do
|
|
14
15
|
::I18n.backend.reload!
|
|
15
16
|
end
|
|
16
|
-
|
|
17
|
+
|
|
17
18
|
describe "placeholder text" do
|
|
18
|
-
|
|
19
|
+
|
|
19
20
|
[:email, :number, :password, :phone, :search, :string, :url, :text, :date_picker, :time_picker, :datetime_picker].each do |type|
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
describe "for #{type} inputs" do
|
|
22
|
-
|
|
23
|
+
|
|
23
24
|
describe "when found in i18n" do
|
|
24
25
|
it "should have a placeholder containing i18n text" do
|
|
25
26
|
with_config :i18n_lookups_by_default, true do
|
|
@@ -27,20 +28,20 @@ describe 'string input' do
|
|
|
27
28
|
concat(semantic_form_for(@new_post) do |builder|
|
|
28
29
|
concat(builder.input(:title, :as => type))
|
|
29
30
|
end)
|
|
30
|
-
output_buffer.
|
|
31
|
+
expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="War and Peace"]')
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
end
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
describe "when not found in i18n" do
|
|
36
37
|
it "should not have placeholder" do
|
|
37
38
|
concat(semantic_form_for(@new_post) do |builder|
|
|
38
39
|
concat(builder.input(:title, :as => type))
|
|
39
40
|
end)
|
|
40
|
-
output_buffer.
|
|
41
|
+
expect(output_buffer.to_str).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder]')
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
describe "when found in i18n and :input_html" do
|
|
45
46
|
it "should favor :input_html" do
|
|
46
47
|
with_config :i18n_lookups_by_default, true do
|
|
@@ -48,24 +49,24 @@ describe 'string input' do
|
|
|
48
49
|
concat(semantic_form_for(@new_post) do |builder|
|
|
49
50
|
concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Foo" }))
|
|
50
51
|
end)
|
|
51
|
-
output_buffer.
|
|
52
|
+
expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Foo"]')
|
|
52
53
|
end
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
describe "when found in :input_html" do
|
|
57
58
|
it "should use the :input_html placeholder" do
|
|
58
59
|
concat(semantic_form_for(@new_post) do |builder|
|
|
59
60
|
concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Untitled" }))
|
|
60
61
|
end)
|
|
61
|
-
output_buffer.
|
|
62
|
+
expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Untitled"]')
|
|
62
63
|
end
|
|
63
64
|
end
|
|
64
|
-
|
|
65
|
+
|
|
65
66
|
end
|
|
66
|
-
|
|
67
|
+
|
|
67
68
|
end
|
|
68
|
-
|
|
69
|
+
|
|
69
70
|
end
|
|
70
|
-
|
|
71
|
+
|
|
71
72
|
end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'radio input' do
|
|
5
|
+
RSpec.describe 'radio input' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -27,66 +28,66 @@ describe 'radio input' do
|
|
|
27
28
|
it_should_use_the_collection_when_provided(:radio, 'input')
|
|
28
29
|
|
|
29
30
|
it 'should generate a legend containing a label with text for the input' do
|
|
30
|
-
output_buffer.
|
|
31
|
-
output_buffer.
|
|
31
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label')
|
|
32
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label', :text => /Author/)
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
it 'should not link the label within the legend to any input' do
|
|
35
|
-
output_buffer.
|
|
36
|
+
expect(output_buffer.to_str).not_to have_tag('form li fieldset legend label[@for]')
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
it 'should generate an ordered list with a list item for each choice' do
|
|
39
|
-
output_buffer.
|
|
40
|
-
output_buffer.
|
|
40
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol')
|
|
41
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li.choice', :count => ::Author.all.size)
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
it 'should have one option with a "checked" attribute' do
|
|
44
|
-
output_buffer.
|
|
45
|
+
expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 1)
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
describe "each choice" do
|
|
48
49
|
|
|
49
50
|
it 'should not give the choice label the .label class' do
|
|
50
|
-
output_buffer.
|
|
51
|
+
expect(output_buffer.to_str).not_to have_tag('li.choice label.label')
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
it 'should not add the required attribute to each input' do
|
|
54
|
-
output_buffer.
|
|
55
|
+
expect(output_buffer.to_str).not_to have_tag('li.choice input[@required]')
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
|
|
58
59
|
it 'should contain a label for the radio input with a nested input and label text' do
|
|
59
60
|
::Author.all.each do |author|
|
|
60
|
-
output_buffer.
|
|
61
|
-
output_buffer.
|
|
61
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', /#{author.to_label}/)
|
|
62
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
|
|
62
63
|
end
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
it 'should use values as li.class when value_as_class is true' do
|
|
66
67
|
::Author.all.each do |author|
|
|
67
|
-
output_buffer.
|
|
68
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li.author_#{author.id} label")
|
|
68
69
|
end
|
|
69
70
|
end
|
|
70
71
|
|
|
71
72
|
it "should have a radio input" do
|
|
72
73
|
::Author.all.each do |author|
|
|
73
|
-
output_buffer.
|
|
74
|
-
output_buffer.
|
|
75
|
-
output_buffer.
|
|
76
|
-
output_buffer.
|
|
74
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
|
|
75
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@type='radio']")
|
|
76
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
|
77
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='post[author_id]']")
|
|
77
78
|
end
|
|
78
79
|
end
|
|
79
80
|
|
|
80
81
|
it "should mark input as checked if it's the the existing choice" do
|
|
81
|
-
@new_post.author_id.
|
|
82
|
-
@new_post.author.id.
|
|
83
|
-
@new_post.author.
|
|
82
|
+
expect(@new_post.author_id).to eq(@bob.id)
|
|
83
|
+
expect(@new_post.author.id).to eq(@bob.id)
|
|
84
|
+
expect(@new_post.author).to eq(@bob)
|
|
84
85
|
|
|
85
86
|
concat(semantic_form_for(@new_post) do |builder|
|
|
86
87
|
concat(builder.input(:author, :as => :radio))
|
|
87
88
|
end)
|
|
88
89
|
|
|
89
|
-
output_buffer.
|
|
90
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
|
|
90
91
|
end
|
|
91
92
|
|
|
92
93
|
it "should mark the input as disabled if options attached for disabling" do
|
|
@@ -94,8 +95,8 @@ describe 'radio input' do
|
|
|
94
95
|
concat(builder.input(:author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]))
|
|
95
96
|
end)
|
|
96
97
|
|
|
97
|
-
output_buffer.
|
|
98
|
-
output_buffer.
|
|
98
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@value='test'][@disabled='disabled']")
|
|
99
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='try'][@disabled='disabled']")
|
|
99
100
|
end
|
|
100
101
|
|
|
101
102
|
it "should not contain invalid HTML attributes" do
|
|
@@ -104,31 +105,31 @@ describe 'radio input' do
|
|
|
104
105
|
concat(builder.input(:author, :as => :radio))
|
|
105
106
|
end)
|
|
106
107
|
|
|
107
|
-
output_buffer.
|
|
108
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li input[@find_options]")
|
|
108
109
|
end
|
|
109
110
|
|
|
110
111
|
end
|
|
111
112
|
|
|
112
113
|
describe 'and no object is given' do
|
|
113
|
-
before(:
|
|
114
|
-
output_buffer.
|
|
114
|
+
before(:example) do
|
|
115
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
115
116
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
116
117
|
concat(builder.input(:author_id, :as => :radio, :collection => ::Author.all))
|
|
117
118
|
end)
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
it 'should generate a fieldset with legend' do
|
|
121
|
-
output_buffer.
|
|
122
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend', :text => /Author/)
|
|
122
123
|
end
|
|
123
124
|
|
|
124
125
|
it 'should generate an li tag for each item in the collection' do
|
|
125
|
-
output_buffer.
|
|
126
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li', :count => ::Author.all.size)
|
|
126
127
|
end
|
|
127
128
|
|
|
128
129
|
it 'should generate labels for each item' do
|
|
129
130
|
::Author.all.each do |author|
|
|
130
|
-
output_buffer.
|
|
131
|
-
output_buffer.
|
|
131
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
|
|
132
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
|
|
132
133
|
end
|
|
133
134
|
end
|
|
134
135
|
|
|
@@ -136,29 +137,55 @@ describe 'radio input' do
|
|
|
136
137
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
137
138
|
concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
|
|
138
139
|
end)
|
|
139
|
-
output_buffer.
|
|
140
|
-
label.body.should match /<b>Item [12]<\/b>$/
|
|
141
|
-
end
|
|
140
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2)
|
|
142
141
|
end
|
|
143
142
|
|
|
144
143
|
it 'should generate inputs for each item' do
|
|
145
144
|
::Author.all.each do |author|
|
|
146
|
-
output_buffer.
|
|
147
|
-
output_buffer.
|
|
148
|
-
output_buffer.
|
|
149
|
-
output_buffer.
|
|
145
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
|
|
146
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@type='radio']")
|
|
147
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
|
148
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='project[author_id]']")
|
|
150
149
|
end
|
|
151
150
|
end
|
|
152
151
|
end
|
|
153
152
|
end
|
|
154
153
|
|
|
154
|
+
describe 'for a enum column' do
|
|
155
|
+
before do
|
|
156
|
+
allow(@new_post).to receive(:status) { 'inactive' }
|
|
157
|
+
statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
|
|
158
|
+
allow(@new_post.class).to receive(:statuses) { statuses }
|
|
159
|
+
allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
before do
|
|
163
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
164
|
+
concat(builder.input(:status, :as => :radio))
|
|
165
|
+
end)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'should have a radio input for each defined enum status' do
|
|
169
|
+
expect(output_buffer.to_str).to have_tag("form li input[@name='post[status]'][@type='radio']", :count => @new_post.class.statuses.count)
|
|
170
|
+
@new_post.class.statuses.each do |label, value|
|
|
171
|
+
expect(output_buffer.to_str).to have_tag("form li input[@value='#{label}']")
|
|
172
|
+
expect(output_buffer.to_str).to have_tag("form li label", :text => /#{label.humanize}/)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it 'should have one radio input with a "checked" attribute' do
|
|
177
|
+
expect(output_buffer.to_str).to have_tag("form li input[@name='post[status]'][@checked]", :count => 1)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
|
|
155
182
|
describe "with i18n of the legend label" do
|
|
156
183
|
|
|
157
184
|
before do
|
|
158
185
|
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
|
159
186
|
|
|
160
187
|
with_config :i18n_lookups_by_default, true do
|
|
161
|
-
@new_post.
|
|
188
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
162
189
|
concat(semantic_form_for(@new_post) do |builder|
|
|
163
190
|
concat(builder.input(:authors, :as => :radio))
|
|
164
191
|
end)
|
|
@@ -170,66 +197,66 @@ describe 'radio input' do
|
|
|
170
197
|
end
|
|
171
198
|
|
|
172
199
|
it "should do foo" do
|
|
173
|
-
output_buffer.
|
|
200
|
+
expect(output_buffer.to_str).to have_tag("legend.label label", :text => /Translated/)
|
|
174
201
|
end
|
|
175
202
|
|
|
176
203
|
end
|
|
177
204
|
|
|
178
205
|
describe "when :label option is set" do
|
|
179
206
|
before do
|
|
180
|
-
@new_post.
|
|
207
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
181
208
|
concat(semantic_form_for(@new_post) do |builder|
|
|
182
209
|
concat(builder.input(:authors, :as => :radio, :label => 'The authors'))
|
|
183
210
|
end)
|
|
184
211
|
end
|
|
185
212
|
|
|
186
213
|
it "should output the correct label title" do
|
|
187
|
-
output_buffer.
|
|
214
|
+
expect(output_buffer.to_str).to have_tag("legend.label label", :text => /The authors/)
|
|
188
215
|
end
|
|
189
216
|
end
|
|
190
217
|
|
|
191
218
|
describe "when :label option is false" do
|
|
192
219
|
before do
|
|
193
|
-
@output_buffer = ''
|
|
194
|
-
@new_post.
|
|
220
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
221
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
195
222
|
concat(semantic_form_for(@new_post) do |builder|
|
|
196
223
|
concat(builder.input(:authors, :as => :radio, :label => false))
|
|
197
224
|
end)
|
|
198
225
|
end
|
|
199
226
|
|
|
200
227
|
it "should not output the legend" do
|
|
201
|
-
output_buffer.
|
|
202
|
-
output_buffer.
|
|
228
|
+
expect(output_buffer.to_str).not_to have_tag("legend.label")
|
|
229
|
+
expect(output_buffer.to_str).not_to include(">")
|
|
203
230
|
end
|
|
204
231
|
|
|
205
232
|
it "should not cause escaped HTML" do
|
|
206
|
-
output_buffer.
|
|
233
|
+
expect(output_buffer.to_str).not_to include(">")
|
|
207
234
|
end
|
|
208
235
|
end
|
|
209
236
|
|
|
210
237
|
describe "when :required option is true" do
|
|
211
238
|
before do
|
|
212
|
-
@new_post.
|
|
239
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
213
240
|
concat(semantic_form_for(@new_post) do |builder|
|
|
214
241
|
concat(builder.input(:authors, :as => :radio, :required => true))
|
|
215
242
|
end)
|
|
216
243
|
end
|
|
217
244
|
|
|
218
245
|
it "should output the correct label title" do
|
|
219
|
-
output_buffer.
|
|
246
|
+
expect(output_buffer.to_str).to have_tag("legend.label label abbr")
|
|
220
247
|
end
|
|
221
248
|
end
|
|
222
249
|
|
|
223
250
|
describe "when :namespace is given on form" do
|
|
224
251
|
before do
|
|
225
|
-
@output_buffer = ''
|
|
226
|
-
@new_post.
|
|
252
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
253
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
227
254
|
concat(semantic_form_for(@new_post, :namespace => "custom_prefix") do |builder|
|
|
228
255
|
concat(builder.input(:authors, :as => :radio, :label => ''))
|
|
229
256
|
end)
|
|
230
257
|
|
|
231
|
-
output_buffer.
|
|
232
|
-
output_buffer.
|
|
258
|
+
expect(output_buffer.to_str).to match(/for="custom_prefix_post_author_ids_(\d+)"/)
|
|
259
|
+
expect(output_buffer.to_str).to match(/id="custom_prefix_post_author_ids_(\d+)"/)
|
|
233
260
|
end
|
|
234
261
|
it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
|
|
235
262
|
end
|
|
@@ -237,7 +264,7 @@ describe 'radio input' do
|
|
|
237
264
|
describe "when index is provided" do
|
|
238
265
|
|
|
239
266
|
before do
|
|
240
|
-
@output_buffer = ''
|
|
267
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
241
268
|
mock_everything
|
|
242
269
|
|
|
243
270
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -248,23 +275,23 @@ describe 'radio input' do
|
|
|
248
275
|
end
|
|
249
276
|
|
|
250
277
|
it 'should index the id of the wrapper' do
|
|
251
|
-
output_buffer.
|
|
278
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
252
279
|
end
|
|
253
280
|
|
|
254
281
|
it 'should index the id of the select tag' do
|
|
255
|
-
output_buffer.
|
|
256
|
-
output_buffer.
|
|
282
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name_true")
|
|
283
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name_false")
|
|
257
284
|
end
|
|
258
285
|
|
|
259
286
|
it 'should index the name of the select tag' do
|
|
260
|
-
output_buffer.
|
|
287
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
|
|
261
288
|
end
|
|
262
289
|
|
|
263
290
|
end
|
|
264
291
|
|
|
265
292
|
describe "when collection contains integers" do
|
|
266
293
|
before do
|
|
267
|
-
@output_buffer = ''
|
|
294
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
268
295
|
mock_everything
|
|
269
296
|
|
|
270
297
|
concat(semantic_form_for(:project) do |builder|
|
|
@@ -273,15 +300,15 @@ describe 'radio input' do
|
|
|
273
300
|
end
|
|
274
301
|
|
|
275
302
|
it 'should output the correct labels' do
|
|
276
|
-
output_buffer.
|
|
277
|
-
output_buffer.
|
|
278
|
-
output_buffer.
|
|
303
|
+
expect(output_buffer.to_str).to have_tag("li.choice label", :text => /1/)
|
|
304
|
+
expect(output_buffer.to_str).to have_tag("li.choice label", :text => /2/)
|
|
305
|
+
expect(output_buffer.to_str).to have_tag("li.choice label", :text => /3/)
|
|
279
306
|
end
|
|
280
307
|
end
|
|
281
308
|
|
|
282
309
|
describe "when collection contains symbols" do
|
|
283
310
|
before do
|
|
284
|
-
@output_buffer = ''
|
|
311
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
285
312
|
mock_everything
|
|
286
313
|
|
|
287
314
|
concat(semantic_form_for(:project) do |builder|
|
|
@@ -290,9 +317,9 @@ describe 'radio input' do
|
|
|
290
317
|
end
|
|
291
318
|
|
|
292
319
|
it 'should output the correct labels' do
|
|
293
|
-
output_buffer.
|
|
294
|
-
output_buffer.
|
|
295
|
-
output_buffer.
|
|
320
|
+
expect(output_buffer.to_str).to have_tag("li.choice label", :text => /A/)
|
|
321
|
+
expect(output_buffer.to_str).to have_tag("li.choice label", :text => /B/)
|
|
322
|
+
expect(output_buffer.to_str).to have_tag("li.choice label", :text => /C/)
|
|
296
323
|
end
|
|
297
324
|
end
|
|
298
325
|
|