formtastic 3.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,94 +1,83 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
describe 'color input' do
|
5
|
+
RSpec.describe 'color 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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
concat(builder.input(:color))
|
19
|
-
end)
|
20
|
-
}.to raise_error "The :color input requires the color_field form helper, which is only available in Rails 4+"
|
21
|
-
end
|
14
|
+
describe "when object is provided" do
|
15
|
+
before do
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
17
|
+
concat(builder.input(:color))
|
18
|
+
end)
|
22
19
|
end
|
23
|
-
else
|
24
|
-
describe "when object is provided" do
|
25
|
-
before do
|
26
|
-
concat(semantic_form_for(@new_post) do |builder|
|
27
|
-
concat(builder.input(:color))
|
28
|
-
end)
|
29
|
-
end
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
21
|
+
it_should_have_input_wrapper_with_class(:color)
|
22
|
+
it_should_have_input_wrapper_with_class(:input)
|
23
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
24
|
+
it_should_have_input_wrapper_with_id("post_color_input")
|
25
|
+
it_should_have_label_with_text(/Color/)
|
26
|
+
it_should_have_label_for("post_color")
|
27
|
+
it_should_have_input_with_id("post_color")
|
28
|
+
it_should_have_input_with_type(:color)
|
29
|
+
it_should_have_input_with_name("post[color]")
|
40
30
|
|
41
|
-
|
31
|
+
end
|
42
32
|
|
43
|
-
|
33
|
+
describe "when namespace is provided" do
|
44
34
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
35
|
+
before do
|
36
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
37
|
+
concat(builder.input(:color))
|
38
|
+
end)
|
39
|
+
end
|
50
40
|
|
51
|
-
|
52
|
-
|
41
|
+
it_should_have_input_wrapper_with_id("context2_post_color_input")
|
42
|
+
it_should_have_label_and_input_with_id("context2_post_color")
|
53
43
|
|
54
|
-
|
44
|
+
end
|
55
45
|
|
56
|
-
|
46
|
+
describe "when index is provided" do
|
57
47
|
|
58
|
-
|
59
|
-
|
60
|
-
|
48
|
+
before do
|
49
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
50
|
+
mock_everything
|
61
51
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end)
|
52
|
+
concat(semantic_form_for(@new_post) do |builder|
|
53
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
54
|
+
concat(author.input(:name, :as => :color))
|
66
55
|
end)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should index the id of the wrapper' do
|
70
|
-
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
71
|
-
end
|
56
|
+
end)
|
57
|
+
end
|
72
58
|
|
73
|
-
|
74
|
-
|
75
|
-
|
59
|
+
it 'should index the id of the wrapper' do
|
60
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
61
|
+
end
|
76
62
|
|
77
|
-
|
78
|
-
|
79
|
-
|
63
|
+
it 'should index the id of the select tag' do
|
64
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
65
|
+
end
|
80
66
|
|
67
|
+
it 'should index the name of the select tag' do
|
68
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
|
81
69
|
end
|
82
70
|
|
71
|
+
end
|
72
|
+
|
83
73
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
74
|
+
describe "when required" do
|
75
|
+
it "should add the required attribute to the input's html options" do
|
76
|
+
with_config :use_required_attribute, true do
|
77
|
+
concat(semantic_form_for(@new_post) do |builder|
|
78
|
+
concat(builder.input(:title, :as => :color, :required => true))
|
79
|
+
end)
|
80
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
92
81
|
end
|
93
82
|
end
|
94
83
|
end
|
@@ -1,23 +1,24 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
describe 'country input' do
|
5
|
+
RSpec.describe 'country 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
|
describe "when country_select is not available as a helper from a plugin" do
|
14
15
|
|
15
16
|
it "should raise an error, sugesting the author installs a plugin" do
|
16
|
-
|
17
|
+
expect {
|
17
18
|
semantic_form_for(@new_post) do |builder|
|
18
19
|
concat(builder.input(:country, :as => :country))
|
19
20
|
end
|
20
|
-
}.
|
21
|
+
}.to raise_error(Formtastic::Inputs::CountryInput::CountrySelectPluginMissing)
|
21
22
|
end
|
22
23
|
|
23
24
|
end
|
@@ -26,7 +27,7 @@ describe 'country input' do
|
|
26
27
|
|
27
28
|
before do
|
28
29
|
concat(semantic_form_for(@new_post) do |builder|
|
29
|
-
builder.
|
30
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
30
31
|
concat(builder.input(:country, :as => :country))
|
31
32
|
end)
|
32
33
|
end
|
@@ -39,13 +40,13 @@ describe 'country input' do
|
|
39
40
|
#it_should_apply_error_logic_for_input_type(:country)
|
40
41
|
|
41
42
|
it 'should generate a label for the input' do
|
42
|
-
output_buffer.
|
43
|
-
output_buffer.
|
44
|
-
output_buffer.
|
43
|
+
expect(output_buffer.to_str).to have_tag('form li label')
|
44
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="post_country"]')
|
45
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Country/)
|
45
46
|
end
|
46
47
|
|
47
48
|
it "should generate a select" do
|
48
|
-
output_buffer.
|
49
|
+
expect(output_buffer.to_str).to have_tag("form li select")
|
49
50
|
end
|
50
51
|
|
51
52
|
end
|
@@ -55,8 +56,8 @@ describe 'country input' do
|
|
55
56
|
it "should be passed down to the country_select helper when provided" do
|
56
57
|
priority_countries = ["Foo", "Bah"]
|
57
58
|
semantic_form_for(@new_post) do |builder|
|
58
|
-
builder.
|
59
|
-
builder.
|
59
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
60
|
+
expect(builder).to receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
|
60
61
|
|
61
62
|
concat(builder.input(:country, :as => :country, :priority_countries => priority_countries))
|
62
63
|
end
|
@@ -64,12 +65,12 @@ describe 'country input' do
|
|
64
65
|
|
65
66
|
it "should default to the @@priority_countries config when absent" do
|
66
67
|
priority_countries = Formtastic::FormBuilder.priority_countries
|
67
|
-
priority_countries.
|
68
|
-
priority_countries.
|
68
|
+
expect(priority_countries).not_to be_empty
|
69
|
+
expect(priority_countries).not_to be_nil
|
69
70
|
|
70
71
|
semantic_form_for(@new_post) do |builder|
|
71
|
-
builder.
|
72
|
-
builder.
|
72
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
73
|
+
expect(builder).to receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
|
73
74
|
|
74
75
|
concat(builder.input(:country, :as => :country))
|
75
76
|
end
|
@@ -80,12 +81,12 @@ describe 'country input' do
|
|
80
81
|
describe "when namespace is provided" do
|
81
82
|
|
82
83
|
before do
|
83
|
-
@output_buffer = ''
|
84
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
84
85
|
mock_everything
|
85
86
|
|
86
87
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
87
|
-
builder.
|
88
|
-
builder.
|
88
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
89
|
+
expect(builder).to receive(:country_select).with(:country, [], {}, {:id => "context2_post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
|
89
90
|
concat(builder.input(:country, :priority_countries => []))
|
90
91
|
end)
|
91
92
|
end
|
@@ -101,13 +102,13 @@ describe 'country input' do
|
|
101
102
|
|
102
103
|
before do
|
103
104
|
concat(semantic_form_for(@new_post) do |builder|
|
104
|
-
builder.
|
105
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
105
106
|
concat(builder.input(:country))
|
106
107
|
end)
|
107
108
|
end
|
108
109
|
|
109
110
|
it "should render a country input" do
|
110
|
-
output_buffer.
|
111
|
+
expect(output_buffer.to_str).to have_tag "form li.country"
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
@@ -121,8 +122,8 @@ describe 'country input' do
|
|
121
122
|
end
|
122
123
|
|
123
124
|
it "should render a country input" do
|
124
|
-
output_buffer.
|
125
|
-
output_buffer.
|
125
|
+
expect(output_buffer.to_str).not_to have_tag "form li.country"
|
126
|
+
expect(output_buffer.to_str).to have_tag "form li.string", :count => 2
|
126
127
|
end
|
127
128
|
|
128
129
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
# TODO extract out
|
@@ -11,11 +12,7 @@ module TestInputs
|
|
11
12
|
@method = :title
|
12
13
|
@options = {}
|
13
14
|
@proc = Proc.new {}
|
14
|
-
|
15
|
-
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options)
|
16
|
-
else
|
17
|
-
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options, @proc)
|
18
|
-
end
|
15
|
+
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options)
|
19
16
|
[@builder, @template, @object, @object_name, @method, @options]
|
20
17
|
end
|
21
18
|
|
@@ -31,7 +28,7 @@ module TestInputs
|
|
31
28
|
|
32
29
|
end
|
33
30
|
|
34
|
-
describe 'AnyCustomInput' do
|
31
|
+
RSpec.describe 'AnyCustomInput' do
|
35
32
|
|
36
33
|
include TestInputs
|
37
34
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe "datalist inputs" do
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "renders correctly" do
|
14
|
+
lists_without_values =[
|
15
|
+
%w(a b c),
|
16
|
+
["a", "b", "c"],
|
17
|
+
("a".."c")
|
18
|
+
]
|
19
|
+
lists_with_values = [
|
20
|
+
{a: 1, b: 2, c:3},
|
21
|
+
{"a" => 1, "b" => 2, "c" =>3},
|
22
|
+
[["a",1], ["b",2], ["c", 3]]
|
23
|
+
]
|
24
|
+
|
25
|
+
def self.common_tests(list)
|
26
|
+
it_should_have_label_with_text(/Document/)
|
27
|
+
it_should_have_label_for("post_document")
|
28
|
+
it_should_have_input_wrapper_with_class(:datalist)
|
29
|
+
it_should_have_input_with(id: "post_document", type: :text, list:"post_document_datalist")
|
30
|
+
it_should_have_tag_with(:datalist, id: "post_document_datalist" )
|
31
|
+
it_should_have_many_tags(:option, list.count)
|
32
|
+
end
|
33
|
+
|
34
|
+
context "Rendering list of simple items" do
|
35
|
+
lists_without_values.each do |list|
|
36
|
+
describe "renders #{list.to_s} correctly" do
|
37
|
+
before do
|
38
|
+
concat(semantic_form_for(@new_post) do |builder|
|
39
|
+
concat(builder.input(:document, as: :datalist, collection: list))
|
40
|
+
end)
|
41
|
+
end
|
42
|
+
common_tests list
|
43
|
+
it_should_have_tag_with :option, value: list.first
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "Rendering list of complex items, key-value pairs and such" do
|
49
|
+
lists_with_values.each do |list|
|
50
|
+
describe "renders #{list.to_s} correctly" do
|
51
|
+
before do
|
52
|
+
concat(semantic_form_for(@new_post) do |builder|
|
53
|
+
concat(builder.input(:document, as: :datalist, collection: list))
|
54
|
+
end)
|
55
|
+
end
|
56
|
+
common_tests list
|
57
|
+
it_should_have_tag_with :option, value: list.first.last
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|