formtastic 3.1.3 → 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 +7 -0
- 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} +183 -167
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +12 -16
- 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 +1 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +1 -0
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +1 -0
- data/lib/formtastic/actions/link_action.rb +1 -0
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +2 -38
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +12 -24
- data/lib/formtastic/helpers/action_helper.rb +2 -48
- 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 +14 -9
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +2 -1
- data/lib/formtastic/helpers/input_helper.rb +20 -76
- data/lib/formtastic/helpers/inputs_helper.rb +29 -23
- data/lib/formtastic/helpers/reflection.rb +1 -0
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +1 -0
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +1 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +3 -2
- data/lib/formtastic/inputs/base/collections.rb +46 -10
- data/lib/formtastic/inputs/base/database.rb +5 -7
- 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 +9 -7
- 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 +1 -0
- data/lib/formtastic/inputs/base.rb +3 -2
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +15 -6
- 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 +1 -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 +1 -0
- 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 +21 -0
- 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 +30 -1
- 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 -29
- data/lib/formtastic/localized_string.rb +1 -0
- data/lib/formtastic/localizer.rb +21 -22
- data/lib/formtastic/namespaced_class_finder.rb +8 -9
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +10 -11
- data/lib/generators/formtastic/form/form_generator.rb +2 -1
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +1 -0
- data/lib/generators/templates/formtastic.rb +15 -13
- 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 +2 -1
- 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 +329 -10
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +45 -38
- data/spec/helpers/input_helper_spec.rb +976 -2
- 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 +2 -1
- 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 +169 -121
- 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 +3 -2
- 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 +26 -25
- 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 +18 -6
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +172 -260
- data/spec/support/custom_macros.rb +74 -76
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +2 -1233
- data/spec/support/specialized_class_finder_shared_example.rb +1 -0
- data/spec/support/test_environment.rb +24 -9
- metadata +78 -170
- data/.travis.yml +0 -29
- data/Appraisals +0 -29
- data/CHANGELOG +0 -39
- data/DEPRECATIONS +0 -49
- 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.2.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- 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/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -66
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'check_boxes input' do
|
|
5
|
+
RSpec.describe 'check_boxes input' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
9
|
+
before do
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
11
|
+
mock_everything
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
describe 'for a has_many association' do
|
|
9
15
|
before do
|
|
10
|
-
@output_buffer = ''
|
|
16
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
11
17
|
mock_everything
|
|
12
18
|
|
|
13
19
|
concat(semantic_form_for(@fred) do |builder|
|
|
@@ -26,127 +32,127 @@ describe 'check_boxes input' do
|
|
|
26
32
|
it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
|
|
27
33
|
|
|
28
34
|
it 'should generate a legend containing a label with text for the input' do
|
|
29
|
-
output_buffer.
|
|
30
|
-
output_buffer.
|
|
35
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label')
|
|
36
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label', :text => /Posts/)
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
it 'should not link the label within the legend to any input' do
|
|
34
|
-
output_buffer.
|
|
40
|
+
expect(output_buffer.to_str).not_to have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
it 'should generate an ordered list with an li.choice for each choice' do
|
|
38
|
-
output_buffer.
|
|
39
|
-
output_buffer.
|
|
44
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol')
|
|
45
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
|
|
40
46
|
end
|
|
41
47
|
|
|
42
48
|
it 'should have one option with a "checked" attribute' do
|
|
43
|
-
output_buffer.
|
|
49
|
+
expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 1)
|
|
44
50
|
end
|
|
45
51
|
|
|
46
52
|
it 'should not generate hidden inputs with default value blank' do
|
|
47
|
-
output_buffer.
|
|
53
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
|
|
48
54
|
end
|
|
49
55
|
|
|
50
56
|
it 'should not render hidden inputs inside the ol' do
|
|
51
|
-
output_buffer.
|
|
57
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li input[@type='hidden']")
|
|
52
58
|
end
|
|
53
59
|
|
|
54
60
|
it 'should render one hidden input for each choice outside the ol' do
|
|
55
|
-
output_buffer.
|
|
61
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type='hidden']", :count => 1)
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
describe "each choice" do
|
|
59
|
-
|
|
65
|
+
|
|
60
66
|
it 'should not give the choice label the .label class' do
|
|
61
|
-
output_buffer.
|
|
67
|
+
expect(output_buffer.to_str).not_to have_tag('li.choice label.label')
|
|
62
68
|
end
|
|
63
|
-
|
|
69
|
+
|
|
64
70
|
it 'should not be marked as required' do
|
|
65
|
-
output_buffer.
|
|
71
|
+
expect(output_buffer.to_str).not_to have_tag('li.choice input[@required]')
|
|
66
72
|
end
|
|
67
|
-
|
|
73
|
+
|
|
68
74
|
it 'should contain a label for the radio input with a nested input and label text' do
|
|
69
75
|
::Post.all.each do |post|
|
|
70
|
-
output_buffer.
|
|
71
|
-
output_buffer.
|
|
76
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
|
|
77
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
|
|
72
78
|
end
|
|
73
79
|
end
|
|
74
80
|
|
|
75
81
|
it 'should use values as li.class when value_as_class is true' do
|
|
76
82
|
::Post.all.each do |post|
|
|
77
|
-
output_buffer.
|
|
83
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li.post_#{post.id} label")
|
|
78
84
|
end
|
|
79
85
|
end
|
|
80
|
-
|
|
86
|
+
|
|
81
87
|
it 'should have a checkbox input but no hidden field for each post' do
|
|
82
88
|
::Post.all.each do |post|
|
|
83
|
-
output_buffer.
|
|
84
|
-
output_buffer.
|
|
89
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
|
90
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
|
|
85
91
|
end
|
|
86
92
|
end
|
|
87
93
|
|
|
88
94
|
it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
|
|
89
|
-
output_buffer.
|
|
95
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
|
|
90
96
|
end
|
|
91
97
|
|
|
92
98
|
it 'the hidden field with an empty array value should be followed by the ol' do
|
|
93
|
-
output_buffer.
|
|
99
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
|
|
94
100
|
end
|
|
95
101
|
|
|
96
102
|
it 'should not have a hidden field with an empty string value for the collection' do
|
|
97
|
-
output_buffer.
|
|
103
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
|
|
98
104
|
end
|
|
99
105
|
|
|
100
106
|
it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
|
|
101
|
-
output_buffer.
|
|
107
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
102
108
|
|
|
103
109
|
concat(semantic_form_for(@fred) do |builder|
|
|
104
110
|
concat(builder.input(:posts, :as => :check_boxes, :hidden_fields => true, :value_as_class => true))
|
|
105
111
|
end)
|
|
106
112
|
|
|
107
113
|
::Post.all.each do |post|
|
|
108
|
-
output_buffer.
|
|
109
|
-
output_buffer.
|
|
110
|
-
output_buffer.
|
|
114
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
|
115
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
|
|
116
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
|
|
111
117
|
end
|
|
112
118
|
|
|
113
119
|
end
|
|
114
120
|
|
|
115
121
|
it "should mark input as checked if it's the the existing choice" do
|
|
116
|
-
::Post.all.include?(@fred.posts.first).
|
|
117
|
-
output_buffer.
|
|
122
|
+
expect(::Post.all.include?(@fred.posts.first)).to be_truthy
|
|
123
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
|
|
118
124
|
end
|
|
119
125
|
end
|
|
120
126
|
|
|
121
127
|
describe 'and no object is given' do
|
|
122
|
-
before(:
|
|
123
|
-
output_buffer.
|
|
128
|
+
before(:example) do
|
|
129
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
124
130
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
125
131
|
concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.all))
|
|
126
132
|
end)
|
|
127
133
|
end
|
|
128
134
|
|
|
129
135
|
it 'should generate a fieldset with legend' do
|
|
130
|
-
output_buffer.
|
|
136
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend', :text => /Author/)
|
|
131
137
|
end
|
|
132
138
|
|
|
133
139
|
it 'shold generate an li tag for each item in the collection' do
|
|
134
|
-
output_buffer.
|
|
140
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
|
|
135
141
|
end
|
|
136
142
|
|
|
137
143
|
it 'should generate labels for each item' do
|
|
138
144
|
::Author.all.each do |author|
|
|
139
|
-
output_buffer.
|
|
140
|
-
output_buffer.
|
|
145
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
|
|
146
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
|
|
141
147
|
end
|
|
142
148
|
end
|
|
143
149
|
|
|
144
150
|
it 'should generate inputs for each item' do
|
|
145
151
|
::Author.all.each do |author|
|
|
146
|
-
output_buffer.
|
|
147
|
-
output_buffer.
|
|
148
|
-
output_buffer.
|
|
149
|
-
output_buffer.
|
|
152
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
|
|
153
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@type='checkbox']")
|
|
154
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
|
155
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
|
|
150
156
|
end
|
|
151
157
|
end
|
|
152
158
|
|
|
@@ -155,15 +161,16 @@ describe 'check_boxes input' do
|
|
|
155
161
|
concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
|
|
156
162
|
end)
|
|
157
163
|
|
|
158
|
-
output_buffer.
|
|
159
|
-
label.
|
|
164
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2) do |label|
|
|
165
|
+
expect(label).to have_text('<b>Item 1</b>', count: 1)
|
|
166
|
+
expect(label).to have_text('<b>Item 2</b>', count: 1)
|
|
160
167
|
end
|
|
161
168
|
end
|
|
162
169
|
end
|
|
163
170
|
|
|
164
171
|
describe 'when :hidden_fields is set to false' do
|
|
165
172
|
before do
|
|
166
|
-
@output_buffer = ''
|
|
173
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
167
174
|
mock_everything
|
|
168
175
|
|
|
169
176
|
concat(semantic_form_for(@fred) do |builder|
|
|
@@ -173,29 +180,29 @@ describe 'check_boxes input' do
|
|
|
173
180
|
|
|
174
181
|
it 'should have a checkbox input for each post' do
|
|
175
182
|
::Post.all.each do |post|
|
|
176
|
-
output_buffer.
|
|
177
|
-
output_buffer.
|
|
183
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
|
184
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
|
|
178
185
|
end
|
|
179
186
|
end
|
|
180
187
|
|
|
181
188
|
it "should mark input as checked if it's the the existing choice" do
|
|
182
|
-
::Post.all.include?(@fred.posts.first).
|
|
183
|
-
output_buffer.
|
|
189
|
+
expect(::Post.all.include?(@fred.posts.first)).to be_truthy
|
|
190
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
|
|
184
191
|
end
|
|
185
192
|
|
|
186
193
|
it 'should not generate empty hidden inputs' do
|
|
187
|
-
output_buffer.
|
|
194
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
|
|
188
195
|
end
|
|
189
196
|
end
|
|
190
197
|
|
|
191
198
|
describe 'when :disabled is set' do
|
|
192
199
|
before do
|
|
193
|
-
@output_buffer = ''
|
|
200
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
194
201
|
end
|
|
195
202
|
|
|
196
203
|
describe "no disabled items" do
|
|
197
204
|
before do
|
|
198
|
-
@new_post.
|
|
205
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
199
206
|
|
|
200
207
|
concat(semantic_form_for(@new_post) do |builder|
|
|
201
208
|
concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
|
|
@@ -203,13 +210,13 @@ describe 'check_boxes input' do
|
|
|
203
210
|
end
|
|
204
211
|
|
|
205
212
|
it 'should not have any disabled item(s)' do
|
|
206
|
-
output_buffer.
|
|
213
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@disabled='disabled']")
|
|
207
214
|
end
|
|
208
215
|
end
|
|
209
216
|
|
|
210
217
|
describe "single disabled item" do
|
|
211
218
|
before do
|
|
212
|
-
@new_post.
|
|
219
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
213
220
|
|
|
214
221
|
concat(semantic_form_for(@new_post) do |builder|
|
|
215
222
|
concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
|
|
@@ -217,15 +224,15 @@ describe 'check_boxes input' do
|
|
|
217
224
|
end
|
|
218
225
|
|
|
219
226
|
it "should have one item disabled; the specified one" do
|
|
220
|
-
output_buffer.
|
|
221
|
-
output_buffer.
|
|
222
|
-
output_buffer.
|
|
227
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
|
|
228
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
|
|
229
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
|
223
230
|
end
|
|
224
231
|
end
|
|
225
232
|
|
|
226
233
|
describe "multiple disabled items" do
|
|
227
234
|
before do
|
|
228
|
-
@new_post.
|
|
235
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
229
236
|
|
|
230
237
|
concat(semantic_form_for(@new_post) do |builder|
|
|
231
238
|
concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
|
|
@@ -233,11 +240,11 @@ describe 'check_boxes input' do
|
|
|
233
240
|
end
|
|
234
241
|
|
|
235
242
|
it "should have multiple items disabled; the specified ones" do
|
|
236
|
-
output_buffer.
|
|
237
|
-
output_buffer.
|
|
238
|
-
output_buffer.
|
|
239
|
-
output_buffer.
|
|
240
|
-
output_buffer.
|
|
243
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
|
|
244
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", :text => /bob/i)
|
|
245
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
|
|
246
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
|
|
247
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
|
241
248
|
end
|
|
242
249
|
end
|
|
243
250
|
|
|
@@ -248,7 +255,7 @@ describe 'check_boxes input' do
|
|
|
248
255
|
before do
|
|
249
256
|
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
|
250
257
|
with_config :i18n_lookups_by_default, true do
|
|
251
|
-
@new_post.
|
|
258
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
252
259
|
concat(semantic_form_for(@new_post) do |builder|
|
|
253
260
|
concat(builder.input(:authors, :as => :check_boxes))
|
|
254
261
|
end)
|
|
@@ -260,62 +267,78 @@ describe 'check_boxes input' do
|
|
|
260
267
|
end
|
|
261
268
|
|
|
262
269
|
it "should do foo" do
|
|
263
|
-
output_buffer.
|
|
270
|
+
expect(output_buffer.to_str).to have_tag("legend.label label", :text => /Translated/)
|
|
264
271
|
end
|
|
265
272
|
|
|
266
273
|
end
|
|
267
274
|
|
|
268
275
|
describe "when :label option is set" do
|
|
269
276
|
before do
|
|
270
|
-
@new_post.
|
|
277
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
271
278
|
concat(semantic_form_for(@new_post) do |builder|
|
|
272
279
|
concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
|
|
273
280
|
end)
|
|
274
281
|
end
|
|
275
282
|
|
|
276
283
|
it "should output the correct label title" do
|
|
277
|
-
output_buffer.
|
|
284
|
+
expect(output_buffer.to_str).to have_tag("legend.label label", :text => /The authors/)
|
|
278
285
|
end
|
|
279
286
|
end
|
|
280
287
|
|
|
281
288
|
describe "when :label option is false" do
|
|
282
289
|
before do
|
|
283
|
-
@output_buffer = ''
|
|
284
|
-
@new_post.
|
|
290
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
291
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
285
292
|
concat(semantic_form_for(@new_post) do |builder|
|
|
286
293
|
concat(builder.input(:authors, :as => :check_boxes, :label => false))
|
|
287
294
|
end)
|
|
288
295
|
end
|
|
289
296
|
|
|
290
297
|
it "should not output the legend" do
|
|
291
|
-
output_buffer.
|
|
298
|
+
expect(output_buffer.to_str).not_to have_tag("legend.label")
|
|
292
299
|
end
|
|
293
|
-
|
|
300
|
+
|
|
294
301
|
it "should not cause escaped HTML" do
|
|
295
|
-
output_buffer.
|
|
302
|
+
expect(output_buffer.to_str).not_to include(">")
|
|
296
303
|
end
|
|
297
|
-
|
|
304
|
+
|
|
298
305
|
end
|
|
299
306
|
|
|
300
307
|
describe "when :required option is true" do
|
|
301
308
|
before do
|
|
302
|
-
@new_post.
|
|
309
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
303
310
|
concat(semantic_form_for(@new_post) do |builder|
|
|
304
311
|
concat(builder.input(:authors, :as => :check_boxes, :required => true))
|
|
305
312
|
end)
|
|
306
313
|
end
|
|
307
314
|
|
|
308
315
|
it "should output the correct label title" do
|
|
309
|
-
output_buffer.
|
|
316
|
+
expect(output_buffer.to_str).to have_tag("legend.label label abbr")
|
|
310
317
|
end
|
|
311
318
|
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
describe 'for a enum column' do
|
|
322
|
+
before do
|
|
323
|
+
allow(@new_post).to receive(:status) { 'inactive' }
|
|
324
|
+
statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
|
|
325
|
+
allow(@new_post.class).to receive(:statuses) { statuses }
|
|
326
|
+
allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
|
|
327
|
+
end
|
|
312
328
|
|
|
329
|
+
it 'should have a select inside the wrapper' do
|
|
330
|
+
expect {
|
|
331
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
332
|
+
concat(builder.input(:status, :as => :check_boxes))
|
|
333
|
+
end)
|
|
334
|
+
}.to raise_error(Formtastic::UnsupportedEnumCollection)
|
|
335
|
+
end
|
|
313
336
|
end
|
|
314
337
|
|
|
315
338
|
describe 'for a has_and_belongs_to_many association' do
|
|
316
339
|
|
|
317
340
|
before do
|
|
318
|
-
@output_buffer = ''
|
|
341
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
319
342
|
mock_everything
|
|
320
343
|
|
|
321
344
|
concat(semantic_form_for(@freds_post) do |builder|
|
|
@@ -325,14 +348,39 @@ describe 'check_boxes input' do
|
|
|
325
348
|
|
|
326
349
|
it 'should render checkboxes' do
|
|
327
350
|
# I'm aware these two lines test the same thing
|
|
328
|
-
output_buffer.
|
|
329
|
-
output_buffer.
|
|
351
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => 2)
|
|
352
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
|
|
330
353
|
end
|
|
331
354
|
|
|
332
355
|
it 'should only select checkboxes that are present in the association' do
|
|
333
356
|
# I'm aware these two lines test the same thing
|
|
334
|
-
output_buffer.
|
|
335
|
-
output_buffer.
|
|
357
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => 1)
|
|
358
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
describe ':collection for a has_and_belongs_to_many association' do
|
|
364
|
+
|
|
365
|
+
before do
|
|
366
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
367
|
+
mock_everything
|
|
368
|
+
|
|
369
|
+
concat(semantic_form_for(@freds_post) do |builder|
|
|
370
|
+
concat(builder.input(:authors, as: :check_boxes, collection: Author.all))
|
|
371
|
+
end)
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
it 'should render checkboxes' do
|
|
375
|
+
# I'm aware these two lines test the same thing
|
|
376
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => 2)
|
|
377
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
it 'should only select checkboxes that are present in the association' do
|
|
381
|
+
# I'm aware these two lines test the same thing
|
|
382
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => 1)
|
|
383
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
|
|
336
384
|
end
|
|
337
385
|
|
|
338
386
|
end
|
|
@@ -340,85 +388,85 @@ describe 'check_boxes input' do
|
|
|
340
388
|
describe 'for an association when a :collection is provided' do
|
|
341
389
|
describe 'it should use the specified :member_value option' do
|
|
342
390
|
before do
|
|
343
|
-
@output_buffer = ''
|
|
391
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
344
392
|
mock_everything
|
|
345
393
|
end
|
|
346
394
|
|
|
347
395
|
it 'to set the right input value' do
|
|
348
396
|
item = double('item')
|
|
349
|
-
item.
|
|
350
|
-
item.
|
|
351
|
-
item.
|
|
352
|
-
@new_post.author.
|
|
353
|
-
|
|
397
|
+
expect(item).not_to receive(:id)
|
|
398
|
+
allow(item).to receive(:custom_value).and_return('custom_value')
|
|
399
|
+
expect(item).to receive(:custom_value).exactly(3).times
|
|
400
|
+
expect(@new_post.author).to receive(:custom_value).exactly(1).times
|
|
401
|
+
|
|
354
402
|
with_deprecation_silenced do
|
|
355
403
|
concat(semantic_form_for(@new_post) do |builder|
|
|
356
404
|
concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
|
|
357
405
|
end)
|
|
358
406
|
end
|
|
359
|
-
output_buffer.
|
|
407
|
+
expect(output_buffer.to_str).to have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
|
|
360
408
|
end
|
|
361
409
|
end
|
|
362
410
|
end
|
|
363
|
-
|
|
411
|
+
|
|
364
412
|
describe 'when :collection is provided as an array of arrays' do
|
|
365
413
|
before do
|
|
366
|
-
@output_buffer = ''
|
|
414
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
367
415
|
mock_everything
|
|
368
|
-
@fred.
|
|
369
|
-
|
|
416
|
+
allow(@fred).to receive(:genres) { ['fiction', 'biography'] }
|
|
417
|
+
|
|
370
418
|
concat(semantic_form_for(@fred) do |builder|
|
|
371
419
|
concat(builder.input(:genres, :as => :check_boxes, :collection => [['Fiction', 'fiction'], ['Non-fiction', 'non_fiction'], ['Biography', 'biography']]))
|
|
372
420
|
end)
|
|
373
421
|
end
|
|
374
|
-
|
|
422
|
+
|
|
375
423
|
it 'should check the correct checkboxes' do
|
|
376
|
-
output_buffer.
|
|
377
|
-
output_buffer.
|
|
424
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
|
|
425
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
|
|
378
426
|
end
|
|
379
427
|
end
|
|
380
|
-
|
|
428
|
+
|
|
381
429
|
describe 'when :collection is a set' do
|
|
382
430
|
before do
|
|
383
|
-
@output_buffer = ''
|
|
431
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
384
432
|
mock_everything
|
|
385
|
-
@fred.
|
|
386
|
-
|
|
433
|
+
allow(@fred).to receive(:roles) { Set.new([:reviewer, :admin]) }
|
|
434
|
+
|
|
387
435
|
concat(semantic_form_for(@fred) do |builder|
|
|
388
436
|
concat(builder.input(:roles, :as => :check_boxes, :collection => [['User', :user], ['Reviewer', :reviewer], ['Administrator', :admin]]))
|
|
389
437
|
end)
|
|
390
438
|
end
|
|
391
|
-
|
|
439
|
+
|
|
392
440
|
it 'should check the correct checkboxes' do
|
|
393
|
-
output_buffer.
|
|
394
|
-
output_buffer.
|
|
395
|
-
output_buffer.
|
|
441
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='user']")
|
|
442
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
|
|
443
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
|
|
396
444
|
end
|
|
397
445
|
end
|
|
398
446
|
|
|
399
447
|
describe "when namespace is provided" do
|
|
400
448
|
|
|
401
449
|
before do
|
|
402
|
-
@output_buffer = ''
|
|
450
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
403
451
|
mock_everything
|
|
404
452
|
|
|
405
453
|
concat(semantic_form_for(@fred, :namespace => "context2") do |builder|
|
|
406
454
|
concat(builder.input(:posts, :as => :check_boxes))
|
|
407
455
|
end)
|
|
408
456
|
end
|
|
409
|
-
|
|
457
|
+
|
|
410
458
|
it "should have a label for #context2_author_post_ids_19" do
|
|
411
|
-
output_buffer.
|
|
459
|
+
expect(output_buffer.to_str).to have_tag("form li label[@for='context2_author_post_ids_19']")
|
|
412
460
|
end
|
|
413
461
|
|
|
414
462
|
it_should_have_input_with_id('context2_author_post_ids_19')
|
|
415
463
|
it_should_have_input_wrapper_with_id("context2_author_posts_input")
|
|
416
464
|
end
|
|
417
|
-
|
|
465
|
+
|
|
418
466
|
describe "when index is provided" do
|
|
419
467
|
|
|
420
468
|
before do
|
|
421
|
-
@output_buffer = ''
|
|
469
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
422
470
|
mock_everything
|
|
423
471
|
|
|
424
472
|
concat(semantic_form_for(@fred) do |builder|
|
|
@@ -427,25 +475,25 @@ describe 'check_boxes input' do
|
|
|
427
475
|
end)
|
|
428
476
|
end)
|
|
429
477
|
end
|
|
430
|
-
|
|
478
|
+
|
|
431
479
|
it 'should index the id of the wrapper' do
|
|
432
|
-
output_buffer.
|
|
480
|
+
expect(output_buffer.to_str).to have_tag("li#author_post_3_authors_input")
|
|
433
481
|
end
|
|
434
|
-
|
|
482
|
+
|
|
435
483
|
it 'should index the id of the input tag' do
|
|
436
|
-
output_buffer.
|
|
484
|
+
expect(output_buffer.to_str).to have_tag("input#author_post_3_author_ids_42")
|
|
437
485
|
end
|
|
438
486
|
|
|
439
487
|
it 'should index the name of the checkbox input' do
|
|
440
|
-
output_buffer.
|
|
488
|
+
expect(output_buffer.to_str).to have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
|
|
441
489
|
end
|
|
442
|
-
|
|
490
|
+
|
|
443
491
|
end
|
|
444
|
-
|
|
492
|
+
|
|
445
493
|
|
|
446
494
|
describe "when collection is an array" do
|
|
447
495
|
before do
|
|
448
|
-
@output_buffer = ''
|
|
496
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
449
497
|
@_collection = [["First", 1], ["Second", 2]]
|
|
450
498
|
mock_everything
|
|
451
499
|
|
|
@@ -456,18 +504,18 @@ describe 'check_boxes input' do
|
|
|
456
504
|
|
|
457
505
|
it "should use array items for labels and values" do
|
|
458
506
|
@_collection.each do |post|
|
|
459
|
-
output_buffer.
|
|
460
|
-
output_buffer.
|
|
507
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.first}/)
|
|
508
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
|
|
461
509
|
end
|
|
462
510
|
end
|
|
463
511
|
|
|
464
512
|
it "should not check any items" do
|
|
465
|
-
output_buffer.
|
|
513
|
+
expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 0)
|
|
466
514
|
end
|
|
467
515
|
|
|
468
516
|
describe "and the attribute has values" do
|
|
469
517
|
before do
|
|
470
|
-
@fred.
|
|
518
|
+
allow(@fred).to receive(:posts) { [1] }
|
|
471
519
|
|
|
472
520
|
concat(semantic_form_for(@fred) do |builder|
|
|
473
521
|
concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
|
|
@@ -475,7 +523,7 @@ describe 'check_boxes input' do
|
|
|
475
523
|
end
|
|
476
524
|
|
|
477
525
|
it "should check the appropriate items" do
|
|
478
|
-
output_buffer.
|
|
526
|
+
expect(output_buffer.to_str).to have_tag("form li input[@value='1'][@checked]")
|
|
479
527
|
end
|
|
480
528
|
end
|
|
481
529
|
|
|
@@ -490,11 +538,11 @@ describe 'check_boxes input' do
|
|
|
490
538
|
|
|
491
539
|
it "should have injected the html attributes" do
|
|
492
540
|
@_collection.each do |v|
|
|
493
|
-
output_buffer.
|
|
541
|
+
expect(output_buffer.to_str).to have_tag("form li input[@value='#{v[1]}'][@#{v[2].keys[0]}='#{v[2].values[0]}']")
|
|
494
542
|
end
|
|
495
543
|
end
|
|
496
544
|
end
|
|
497
545
|
end
|
|
498
|
-
|
|
546
|
+
|
|
499
547
|
end
|
|
500
548
|
|