formtastic 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +13 -13
- data/CHANGELOG.md +10 -1
- data/Gemfile.lock +99 -64
- data/README.md +7 -2
- data/formtastic.gemspec +5 -3
- data/gemfiles/{rails_5.2 → rails_7.0}/Gemfile +1 -1
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +1 -1
- 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 +1 -0
- data/lib/formtastic/deprecation.rb +2 -1
- data/lib/formtastic/engine.rb +1 -0
- data/lib/formtastic/form_builder.rb +1 -0
- data/lib/formtastic/helpers/action_helper.rb +1 -0
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +1 -0
- data/lib/formtastic/helpers/errors_helper.rb +1 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +1 -0
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +1 -0
- data/lib/formtastic/helpers/input_helper.rb +2 -4
- data/lib/formtastic/helpers/inputs_helper.rb +2 -1
- data/lib/formtastic/helpers/reflection.rb +1 -0
- data/lib/formtastic/helpers.rb +1 -1
- data/lib/formtastic/html_attributes.rb +1 -0
- data/lib/formtastic/i18n.rb +1 -0
- 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 +2 -1
- data/lib/formtastic/inputs/base/collections.rb +4 -1
- 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 +3 -2
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +1 -0
- data/lib/formtastic/inputs/base/html.rb +2 -1
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +1 -0
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +1 -0
- 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 +4 -3
- data/lib/formtastic/inputs/base/validations.rb +2 -1
- 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 +2 -1
- data/lib/formtastic/inputs/color_input.rb +1 -0
- data/lib/formtastic/inputs/country_input.rb +1 -0
- 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 +1 -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 +1 -0
- 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 +1 -0
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +1 -0
- data/lib/formtastic/localized_string.rb +1 -0
- data/lib/formtastic/localizer.rb +1 -0
- data/lib/formtastic/namespaced_class_finder.rb +7 -8
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +1 -0
- data/lib/generators/formtastic/form/form_generator.rb +1 -0
- data/lib/generators/formtastic/input/input_generator.rb +1 -0
- data/lib/generators/formtastic/install/install_generator.rb +1 -0
- data/lib/generators/templates/formtastic.rb +1 -0
- data/script/integration-template.rb +2 -3
- data/spec/action_class_finder_spec.rb +1 -0
- data/spec/actions/button_action_spec.rb +17 -16
- data/spec/actions/generic_action_spec.rb +130 -129
- data/spec/actions/input_action_spec.rb +16 -15
- data/spec/actions/link_action_spec.rb +25 -24
- data/spec/builder/custom_builder_spec.rb +5 -4
- data/spec/builder/error_proc_spec.rb +2 -1
- data/spec/builder/semantic_fields_for_spec.rb +26 -25
- data/spec/fast_spec_helper.rb +1 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +8 -7
- data/spec/generators/formtastic/input/input_generator_spec.rb +1 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +1 -0
- data/spec/helpers/action_helper_spec.rb +15 -14
- data/spec/helpers/actions_helper_spec.rb +42 -41
- data/spec/helpers/form_helper_spec.rb +26 -19
- data/spec/helpers/input_helper_spec.rb +70 -69
- data/spec/helpers/inputs_helper_spec.rb +179 -179
- data/spec/helpers/reflection_helper_spec.rb +4 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +4 -3
- data/spec/i18n_spec.rb +13 -12
- data/spec/input_class_finder_spec.rb +1 -0
- data/spec/inputs/base/collections_spec.rb +2 -0
- data/spec/inputs/base/validations_spec.rb +1 -0
- data/spec/inputs/boolean_input_spec.rb +66 -65
- data/spec/inputs/check_boxes_input_spec.rb +89 -88
- data/spec/inputs/color_input_spec.rb +7 -6
- data/spec/inputs/country_input_spec.rb +10 -9
- data/spec/inputs/custom_input_spec.rb +1 -0
- data/spec/inputs/datalist_input_spec.rb +2 -1
- data/spec/inputs/date_picker_input_spec.rb +109 -108
- data/spec/inputs/date_select_input_spec.rb +63 -62
- data/spec/inputs/datetime_picker_input_spec.rb +118 -117
- data/spec/inputs/datetime_select_input_spec.rb +72 -71
- data/spec/inputs/email_input_spec.rb +16 -15
- data/spec/inputs/file_input_spec.rb +17 -16
- data/spec/inputs/hidden_input_spec.rb +29 -28
- data/spec/inputs/include_blank_spec.rb +7 -6
- data/spec/inputs/label_spec.rb +25 -24
- data/spec/inputs/number_input_spec.rb +159 -158
- data/spec/inputs/password_input_spec.rb +16 -15
- data/spec/inputs/phone_input_spec.rb +16 -15
- data/spec/inputs/placeholder_spec.rb +17 -16
- data/spec/inputs/radio_input_spec.rb +58 -57
- data/spec/inputs/range_input_spec.rb +108 -107
- data/spec/inputs/readonly_spec.rb +5 -4
- data/spec/inputs/search_input_spec.rb +15 -14
- data/spec/inputs/select_input_spec.rb +144 -93
- data/spec/inputs/string_input_spec.rb +36 -35
- data/spec/inputs/text_input_spec.rb +32 -31
- data/spec/inputs/time_picker_input_spec.rb +110 -109
- data/spec/inputs/time_select_input_spec.rb +71 -70
- data/spec/inputs/time_zone_input_spec.rb +21 -20
- data/spec/inputs/url_input_spec.rb +16 -15
- data/spec/inputs/with_options_spec.rb +8 -7
- data/spec/localizer_spec.rb +1 -0
- data/spec/namespaced_class_finder_spec.rb +17 -5
- data/spec/schema.rb +1 -0
- data/spec/spec_helper.rb +8 -8
- data/spec/support/custom_macros.rb +64 -63
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +2 -1
- data/spec/support/specialized_class_finder_shared_example.rb +1 -0
- data/spec/support/test_environment.rb +1 -0
- metadata +29 -14
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe 'time select input' do
|
@@ -6,14 +7,14 @@ RSpec.describe 'time select input' do
|
|
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 "general" do
|
14
15
|
before do
|
15
16
|
::I18n.backend.reload!
|
16
|
-
output_buffer.
|
17
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
17
18
|
end
|
18
19
|
|
19
20
|
describe "with :ignore_date => true" do
|
@@ -24,18 +25,18 @@ RSpec.describe 'time select input' do
|
|
24
25
|
end
|
25
26
|
|
26
27
|
it 'should not have hidden inputs for day, month and year' do
|
27
|
-
expect(output_buffer).not_to have_tag('input#post_publish_at_1i')
|
28
|
-
expect(output_buffer).not_to have_tag('input#post_publish_at_2i')
|
29
|
-
expect(output_buffer).not_to have_tag('input#post_publish_at_3i')
|
28
|
+
expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_1i')
|
29
|
+
expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_2i')
|
30
|
+
expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_3i')
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'should have an input for hour and minute' do
|
33
|
-
expect(output_buffer).to have_tag('select#post_publish_at_4i')
|
34
|
-
expect(output_buffer).to have_tag('select#post_publish_at_5i')
|
34
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
|
35
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
|
35
36
|
end
|
36
37
|
|
37
38
|
end
|
38
|
-
|
39
|
+
|
39
40
|
describe "with :ignore_date => false" do
|
40
41
|
before do
|
41
42
|
allow(@new_post).to receive(:publish_at).and_return(Time.parse('2010-11-07'))
|
@@ -45,21 +46,21 @@ RSpec.describe 'time select input' do
|
|
45
46
|
end
|
46
47
|
|
47
48
|
it 'should have a hidden input for day, month and year' do
|
48
|
-
expect(output_buffer).to have_tag('input#post_publish_at_1i')
|
49
|
-
expect(output_buffer).to have_tag('input#post_publish_at_2i')
|
50
|
-
expect(output_buffer).to have_tag('input#post_publish_at_3i')
|
51
|
-
expect(output_buffer).to have_tag('input#post_publish_at_1i[@value="2010"]')
|
52
|
-
expect(output_buffer).to have_tag('input#post_publish_at_2i[@value="11"]')
|
53
|
-
expect(output_buffer).to have_tag('input#post_publish_at_3i[@value="7"]')
|
49
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i')
|
50
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i')
|
51
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i')
|
52
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i[@value="2010"]')
|
53
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i[@value="11"]')
|
54
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i[@value="7"]')
|
54
55
|
end
|
55
56
|
|
56
57
|
it 'should have an select for hour and minute' do
|
57
|
-
expect(output_buffer).to have_tag('select#post_publish_at_4i')
|
58
|
-
expect(output_buffer).to have_tag('select#post_publish_at_5i')
|
58
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
|
59
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
|
59
60
|
end
|
60
61
|
|
61
62
|
it 'should associate the legend label with the hour select' do
|
62
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
63
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
63
64
|
end
|
64
65
|
|
65
66
|
end
|
@@ -80,26 +81,26 @@ RSpec.describe 'time select input' do
|
|
80
81
|
it_should_apply_error_logic_for_input_type(:time_select)
|
81
82
|
|
82
83
|
it 'should have a legend and label with the label text inside the fieldset' do
|
83
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset legend.label label', :text => /Publish at/)
|
84
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label', :text => /Publish at/)
|
84
85
|
end
|
85
86
|
|
86
87
|
it 'should associate the legend label with the first select' do
|
87
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
88
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
88
89
|
end
|
89
90
|
|
90
91
|
it 'should have an ordered list of two items inside the fieldset' do
|
91
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol.fragments-group')
|
92
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
|
92
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol.fragments-group')
|
93
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
|
93
94
|
end
|
94
95
|
|
95
96
|
it 'should have five labels for hour and minute' do
|
96
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => 2)
|
97
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
|
98
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
|
97
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 2)
|
98
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
|
99
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
|
99
100
|
end
|
100
101
|
|
101
102
|
it 'should have two selects for hour and minute' do
|
102
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li', :count => 2)
|
103
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 2)
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
@@ -111,20 +112,20 @@ RSpec.describe 'time select input' do
|
|
111
112
|
end
|
112
113
|
|
113
114
|
it 'should have five labels for hour and minute' do
|
114
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => 3)
|
115
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
|
116
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
|
117
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /second/i)
|
115
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 3)
|
116
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
|
117
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
|
118
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /second/i)
|
118
119
|
end
|
119
120
|
|
120
121
|
it 'should have three selects for hour, minute and seconds' do
|
121
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li', :count => 3)
|
122
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 3)
|
122
123
|
end
|
123
124
|
|
124
125
|
it 'should generate a sanitized label and matching ids for attribute' do
|
125
126
|
4.upto(6) do |i|
|
126
|
-
expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
|
127
|
-
expect(output_buffer).to have_tag("form li fieldset ol li #post_publish_at_#{i}i")
|
127
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
|
128
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li #post_publish_at_#{i}i")
|
128
129
|
end
|
129
130
|
end
|
130
131
|
end
|
@@ -134,54 +135,54 @@ RSpec.describe 'time select input' do
|
|
134
135
|
fields = [:hour, :minute, :second]
|
135
136
|
fields.each do |field|
|
136
137
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
137
|
-
output_buffer.
|
138
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
138
139
|
concat(semantic_form_for(@new_post) do |builder|
|
139
140
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
|
140
141
|
end)
|
141
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => fields.length)
|
142
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length)
|
142
143
|
fields.each do |f|
|
143
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => f == field ? /another #{f} label/i : /#{f}/i)
|
144
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => f == field ? /another #{f} label/i : /#{f}/i)
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
147
148
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
148
|
-
output_buffer.
|
149
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
149
150
|
concat(semantic_form_for(@new_post) do |builder|
|
150
151
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
|
151
152
|
end)
|
152
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
153
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
153
154
|
fields.each do |f|
|
154
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
155
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
155
156
|
end
|
156
157
|
end
|
157
|
-
|
158
|
-
it "should not render the label when :labels[:#{field}] is false" do
|
159
|
-
output_buffer.
|
158
|
+
|
159
|
+
it "should not render the label when :labels[:#{field}] is false" do
|
160
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
160
161
|
concat(semantic_form_for(@new_post) do |builder|
|
161
162
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
|
162
163
|
end)
|
163
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
164
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
164
165
|
fields.each do |f|
|
165
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
166
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
169
|
-
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
170
|
-
output_buffer.
|
170
|
+
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
171
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
171
172
|
concat(semantic_form_for(@new_post) do |builder|
|
172
173
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
|
173
174
|
end)
|
174
|
-
expect(output_buffer).not_to include(">")
|
175
|
+
expect(output_buffer.to_str).not_to include(">")
|
175
176
|
end
|
176
|
-
|
177
|
+
|
177
178
|
end
|
178
179
|
|
179
180
|
it "should not render labels when :labels is falsy" do
|
180
|
-
output_buffer.
|
181
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
181
182
|
concat(semantic_form_for(@new_post) do |builder|
|
182
183
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
|
183
184
|
end)
|
184
|
-
expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => 0)
|
185
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 0)
|
185
186
|
end
|
186
187
|
end
|
187
188
|
|
@@ -193,8 +194,8 @@ RSpec.describe 'time select input' do
|
|
193
194
|
end
|
194
195
|
)
|
195
196
|
|
196
|
-
expect(output_buffer).to have_tag "option[value='12'][selected='selected']"
|
197
|
-
expect(output_buffer).to have_tag "option[value='00'][selected='selected']"
|
197
|
+
expect(output_buffer.to_str).to have_tag "option[value='12'][selected='selected']"
|
198
|
+
expect(output_buffer.to_str).to have_tag "option[value='00'][selected='selected']"
|
198
199
|
end
|
199
200
|
end
|
200
201
|
|
@@ -206,23 +207,23 @@ RSpec.describe 'time select input' do
|
|
206
207
|
end
|
207
208
|
|
208
209
|
it 'should have a tag matching the namespace' do
|
209
|
-
expect(output_buffer).to have_tag('#form2_post_publish_at_input')
|
210
|
-
expect(output_buffer).to have_tag('#form2_post_publish_at_4i')
|
211
|
-
expect(output_buffer).to have_tag('#form2_post_publish_at_5i')
|
210
|
+
expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_input')
|
211
|
+
expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_4i')
|
212
|
+
expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_5i')
|
212
213
|
end
|
213
214
|
end
|
214
|
-
|
215
|
+
|
215
216
|
describe "when required" do
|
216
217
|
it "should add the required attribute to the input's html options" do
|
217
|
-
with_config :use_required_attribute, true do
|
218
|
+
with_config :use_required_attribute, true do
|
218
219
|
concat(semantic_form_for(@new_post) do |builder|
|
219
220
|
concat(builder.input(:title, :as => :time_select, :required => true))
|
220
221
|
end)
|
221
|
-
expect(output_buffer).to have_tag("select[@required]", :count => 2)
|
222
|
+
expect(output_buffer.to_str).to have_tag("select[@required]", :count => 2)
|
222
223
|
end
|
223
224
|
end
|
224
225
|
end
|
225
|
-
|
226
|
+
|
226
227
|
describe "when index is provided" do
|
227
228
|
|
228
229
|
before do
|
@@ -234,27 +235,27 @@ RSpec.describe 'time select input' do
|
|
234
235
|
end
|
235
236
|
|
236
237
|
it 'should index the id of the wrapper' do
|
237
|
-
expect(output_buffer).to have_tag("li#post_author_attributes_3_created_at_input")
|
238
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_created_at_input")
|
238
239
|
end
|
239
240
|
|
240
241
|
it 'should index the id of the select tag' do
|
241
|
-
expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at_1i")
|
242
|
-
expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at_2i")
|
243
|
-
expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at_3i")
|
244
|
-
expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_4i")
|
245
|
-
expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_5i")
|
242
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_1i")
|
243
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_2i")
|
244
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_3i")
|
245
|
+
expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_4i")
|
246
|
+
expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_5i")
|
246
247
|
end
|
247
248
|
|
248
249
|
it 'should index the name of the select tag' do
|
249
|
-
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at(1i)]']")
|
250
|
-
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at(2i)]']")
|
251
|
-
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at(3i)]']")
|
252
|
-
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
|
253
|
-
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
|
250
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(1i)]']")
|
251
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(2i)]']")
|
252
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(3i)]']")
|
253
|
+
expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
|
254
|
+
expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
|
254
255
|
end
|
255
256
|
|
256
257
|
end
|
257
|
-
|
258
|
+
|
258
259
|
end
|
259
260
|
|
260
261
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe 'time_zone input' do
|
@@ -6,7 +7,7 @@ RSpec.describe 'time_zone input' do
|
|
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|
|
@@ -20,28 +21,28 @@ RSpec.describe 'time_zone input' do
|
|
20
21
|
it_should_apply_error_logic_for_input_type(:time_zone)
|
21
22
|
|
22
23
|
it 'should generate a label for the input' do
|
23
|
-
expect(output_buffer).to have_tag('form li label')
|
24
|
-
expect(output_buffer).to have_tag('form li label[@for="post_time_zone"]')
|
25
|
-
expect(output_buffer).to have_tag('form li label', :text => /Time zone/)
|
24
|
+
expect(output_buffer.to_str).to have_tag('form li label')
|
25
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="post_time_zone"]')
|
26
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should generate a select" do
|
29
|
-
expect(output_buffer).to have_tag("form li select")
|
30
|
-
expect(output_buffer).to have_tag("form li select#post_time_zone")
|
31
|
-
expect(output_buffer).to have_tag("form li select[@name=\"post[time_zone]\"]")
|
30
|
+
expect(output_buffer.to_str).to have_tag("form li select")
|
31
|
+
expect(output_buffer.to_str).to have_tag("form li select#post_time_zone")
|
32
|
+
expect(output_buffer.to_str).to have_tag("form li select[@name=\"post[time_zone]\"]")
|
32
33
|
end
|
33
34
|
|
34
35
|
it 'should use input_html to style inputs' do
|
35
36
|
concat(semantic_form_for(@new_post) do |builder|
|
36
37
|
concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
|
37
38
|
end)
|
38
|
-
expect(output_buffer).to have_tag("form li select.myclass")
|
39
|
+
expect(output_buffer.to_str).to have_tag("form li select.myclass")
|
39
40
|
end
|
40
41
|
|
41
42
|
describe "when namespace is provided" do
|
42
43
|
|
43
44
|
before do
|
44
|
-
@output_buffer = ''
|
45
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
45
46
|
mock_everything
|
46
47
|
|
47
48
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
@@ -58,7 +59,7 @@ RSpec.describe 'time_zone input' do
|
|
58
59
|
describe "when index is provided" do
|
59
60
|
|
60
61
|
before do
|
61
|
-
@output_buffer = ''
|
62
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
62
63
|
mock_everything
|
63
64
|
|
64
65
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -69,15 +70,15 @@ RSpec.describe 'time_zone input' do
|
|
69
70
|
end
|
70
71
|
|
71
72
|
it 'should index the id of the wrapper' do
|
72
|
-
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
73
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
73
74
|
end
|
74
75
|
|
75
76
|
it 'should index the id of the select tag' do
|
76
|
-
expect(output_buffer).to have_tag("select#post_author_attributes_3_name")
|
77
|
+
expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_name")
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'should index the name of the select tag' do
|
80
|
-
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][name]']")
|
81
|
+
expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][name]']")
|
81
82
|
end
|
82
83
|
|
83
84
|
end
|
@@ -91,15 +92,15 @@ RSpec.describe 'time_zone input' do
|
|
91
92
|
end
|
92
93
|
|
93
94
|
it 'should generate labels' do
|
94
|
-
expect(output_buffer).to have_tag('form li label')
|
95
|
-
expect(output_buffer).to have_tag('form li label[@for="project_time_zone"]')
|
96
|
-
expect(output_buffer).to have_tag('form li label', :text => /Time zone/)
|
95
|
+
expect(output_buffer.to_str).to have_tag('form li label')
|
96
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="project_time_zone"]')
|
97
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
|
97
98
|
end
|
98
99
|
|
99
100
|
it 'should generate select inputs' do
|
100
|
-
expect(output_buffer).to have_tag("form li select")
|
101
|
-
expect(output_buffer).to have_tag("form li select#project_time_zone")
|
102
|
-
expect(output_buffer).to have_tag("form li select[@name=\"project[time_zone]\"]")
|
101
|
+
expect(output_buffer.to_str).to have_tag("form li select")
|
102
|
+
expect(output_buffer.to_str).to have_tag("form li select#project_time_zone")
|
103
|
+
expect(output_buffer.to_str).to have_tag("form li select[@name=\"project[time_zone]\"]")
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
@@ -109,7 +110,7 @@ RSpec.describe 'time_zone input' do
|
|
109
110
|
concat(semantic_form_for(@new_post) do |builder|
|
110
111
|
concat(builder.input(:title, :as => :time_zone, :required => true))
|
111
112
|
end)
|
112
|
-
expect(output_buffer).to have_tag("select[@required]")
|
113
|
+
expect(output_buffer.to_str).to have_tag("select[@required]")
|
113
114
|
end
|
114
115
|
end
|
115
116
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe 'url input' do
|
@@ -6,7 +7,7 @@ RSpec.describe 'url input' do
|
|
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 @@ RSpec.describe 'url input' do
|
|
41
42
|
it_should_have_label_and_input_with_id("context2_post_url")
|
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 @@ RSpec.describe 'url 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
|
-
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
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
|
-
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
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
|
-
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
|
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 => :url, :required => true))
|
78
79
|
end)
|
79
|
-
expect(output_buffer).to have_tag("input[@required]")
|
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,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe 'string input' do
|
@@ -6,7 +7,7 @@ RSpec.describe 'string input' do
|
|
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
|
|
@@ -21,23 +22,23 @@ RSpec.describe 'string input' do
|
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should have extra class on title" do
|
24
|
-
expect(output_buffer).to have_tag("form li#post_title_input.extra")
|
25
|
+
expect(output_buffer.to_str).to have_tag("form li#post_title_input.extra")
|
25
26
|
end
|
26
27
|
it "should have title as string" do
|
27
|
-
expect(output_buffer).to have_tag("form li#post_title_input.string")
|
28
|
+
expect(output_buffer.to_str).to have_tag("form li#post_title_input.string")
|
28
29
|
end
|
29
30
|
it "should not have title as radio" do
|
30
|
-
expect(output_buffer).not_to have_tag("form li#post_title_input.radio")
|
31
|
+
expect(output_buffer.to_str).not_to have_tag("form li#post_title_input.radio")
|
31
32
|
end
|
32
33
|
|
33
34
|
it "should have extra class on author" do
|
34
|
-
expect(output_buffer).to have_tag("form li#post_author_input.extra")
|
35
|
+
expect(output_buffer.to_str).to have_tag("form li#post_author_input.extra")
|
35
36
|
end
|
36
37
|
it "should not have author as string" do
|
37
|
-
expect(output_buffer).not_to have_tag("form li#post_author_input.string")
|
38
|
+
expect(output_buffer.to_str).not_to have_tag("form li#post_author_input.string")
|
38
39
|
end
|
39
40
|
it "should have author as radio" do
|
40
|
-
expect(output_buffer).to have_tag("form li#post_author_input.radio")
|
41
|
+
expect(output_buffer.to_str).to have_tag("form li#post_author_input.radio")
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
data/spec/localizer_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'formtastic/namespaced_class_finder'
|
4
5
|
|
@@ -54,16 +55,27 @@ RSpec.describe Formtastic::NamespacedClassFinder do
|
|
54
55
|
|
55
56
|
context '#finder' do
|
56
57
|
before do
|
57
|
-
allow(Rails.application.config).to receive(:
|
58
|
+
allow(Rails.application.config).to receive(:eager_load).and_return(eager_load)
|
58
59
|
end
|
59
60
|
|
60
|
-
context 'when
|
61
|
-
let(:
|
61
|
+
context 'when eager_load is on' do
|
62
|
+
let(:eager_load) { true }
|
63
|
+
|
64
|
+
it "finder_method is :find_with_const_defined" do
|
65
|
+
expect(described_class.finder_method).to eq(:find_with_const_defined)
|
66
|
+
end
|
67
|
+
|
62
68
|
it_behaves_like 'Namespaced Class Finder'
|
63
69
|
end
|
64
70
|
|
65
|
-
context 'when
|
66
|
-
let(:
|
71
|
+
context 'when eager_load is off' do
|
72
|
+
let(:eager_load) { false }
|
73
|
+
|
74
|
+
it "finder_method is :find_by_trying" do
|
75
|
+
described_class.instance_variable_set(:@finder_method, nil) # clear cache
|
76
|
+
expect(described_class.finder_method).to eq(:find_by_trying)
|
77
|
+
end
|
78
|
+
|
67
79
|
it_behaves_like 'Namespaced Class Finder'
|
68
80
|
end
|
69
81
|
end
|
data/spec/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'rubygems'
|
3
4
|
require 'bundler/setup'
|
4
5
|
require 'active_support'
|
@@ -251,7 +252,7 @@ module FormtasticSpecHelper
|
|
251
252
|
allow(::Author).to receive(:where).and_return(author_array_or_scope)
|
252
253
|
allow(::Author).to receive(:human_attribute_name) { |column_name| column_name.humanize }
|
253
254
|
allow(::Author).to receive(:human_name).and_return('::Author')
|
254
|
-
allow(::Author).to receive(:reflect_on_association) { |column_name| double('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
|
255
|
+
allow(::Author).to receive(:reflect_on_association) { |column_name| double('reflection', :scope => nil, :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
|
255
256
|
allow(::Author).to receive(:content_columns).and_return([double('column', :name => 'login'), double('column', :name => 'created_at')])
|
256
257
|
allow(::Author).to receive(:to_key).and_return(nil)
|
257
258
|
allow(::Author).to receive(:persisted?).and_return(nil)
|
@@ -304,21 +305,22 @@ module FormtasticSpecHelper
|
|
304
305
|
allow(::Post).to receive(:reflect_on_association) { |column_name|
|
305
306
|
case column_name
|
306
307
|
when :author, :author_status
|
307
|
-
mock = double('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
|
308
|
+
mock = double('reflection', :scope => nil, :options => {}, :klass => ::Author, :macro => :belongs_to)
|
308
309
|
allow(mock).to receive(:[]).with(:class_name).and_return("Author")
|
309
310
|
mock
|
310
311
|
when :reviewer
|
311
|
-
mock = double('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
|
312
|
+
mock = double('reflection', :scope => nil, :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
|
312
313
|
allow(mock).to receive(:[]).with(:class_name).and_return("Author")
|
313
314
|
mock
|
314
315
|
when :authors
|
315
|
-
double('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
|
316
|
+
double('reflection', :scope => nil, :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
|
316
317
|
when :sub_posts
|
317
|
-
double('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
|
318
|
+
double('reflection', :scope => nil, :options => {}, :klass => ::Post, :macro => :has_many)
|
318
319
|
when :main_post
|
319
|
-
double('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
|
320
|
+
double('reflection', :scope => nil, :options => {}, :klass => ::Post, :macro => :belongs_to)
|
320
321
|
when :mongoid_reviewer
|
321
322
|
::MongoidReflectionMock.new('reflection',
|
323
|
+
:scope => nil,
|
322
324
|
:options => Proc.new { raise NoMethodError, "Mongoid has no reflection.options" },
|
323
325
|
:klass => ::Author, :macro => :referenced_in, :foreign_key => "reviewer_id") # custom id
|
324
326
|
end
|
@@ -450,8 +452,6 @@ class ::ActionView::Base
|
|
450
452
|
include Formtastic::Helpers::FormHelper
|
451
453
|
end
|
452
454
|
|
453
|
-
::ActiveSupport::Deprecation.silenced = false
|
454
|
-
|
455
455
|
RSpec.configure do |config|
|
456
456
|
config.infer_spec_type_from_file_location!
|
457
457
|
|