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,32 +1,33 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
describe 'InputAction::Base' do
|
5
|
-
|
5
|
+
RSpec.describe 'InputAction::Base' do
|
6
|
+
|
6
7
|
# Most basic Action class to test Base
|
7
8
|
class ::GenericAction
|
8
9
|
include ::Formtastic::Actions::Base
|
9
|
-
|
10
|
+
|
10
11
|
def supported_methods
|
11
12
|
[:submit, :reset, :cancel]
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
def to_html
|
15
16
|
wrapper do
|
16
17
|
builder.submit(text, button_html)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
include FormtasticSpecHelper
|
22
23
|
|
23
24
|
before do
|
24
|
-
@output_buffer = ''
|
25
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
25
26
|
mock_everything
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
describe 'wrapping HTML' do
|
29
|
-
|
30
|
+
|
30
31
|
before do
|
31
32
|
concat(semantic_form_for(@new_post) do |builder|
|
32
33
|
concat(builder.action(:submit, :as => :generic,
|
@@ -34,117 +35,117 @@ describe 'InputAction::Base' do
|
|
34
35
|
))
|
35
36
|
end)
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
it 'should add the #foo id to the li' do
|
39
|
-
output_buffer.
|
40
|
+
expect(output_buffer.to_str).to have_tag('li#post_submit_action')
|
40
41
|
end
|
41
|
-
|
42
|
+
|
42
43
|
it 'should add the .action and .generic_action classes to the li' do
|
43
|
-
output_buffer.
|
44
|
+
expect(output_buffer.to_str).to have_tag('li.action.generic_action')
|
44
45
|
end
|
45
46
|
|
46
47
|
it 'should pass :wrapper_html HTML attributes to the wrapper' do
|
47
|
-
output_buffer.
|
48
|
+
expect(output_buffer.to_str).to have_tag('li.action.generic_action[@foo="bah"]')
|
48
49
|
end
|
49
|
-
|
50
|
+
|
50
51
|
context "when a custom :id is provided" do
|
51
|
-
|
52
|
+
|
52
53
|
before do
|
53
54
|
concat(semantic_form_for(@new_post) do |builder|
|
54
|
-
concat(builder.action(:submit, :as => :generic,
|
55
|
+
concat(builder.action(:submit, :as => :generic,
|
55
56
|
:wrapper_html => { :id => 'foo_bah_bing' }
|
56
57
|
))
|
57
58
|
end)
|
58
59
|
end
|
59
|
-
|
60
|
+
|
60
61
|
it "should use the custom id" do
|
61
|
-
output_buffer.
|
62
|
+
expect(output_buffer.to_str).to have_tag('li#foo_bah_bing')
|
62
63
|
end
|
63
|
-
|
64
|
+
|
64
65
|
end
|
65
|
-
|
66
|
-
context "when a custom class is provided as a string" do
|
67
|
-
|
66
|
+
|
67
|
+
context "when a custom class is provided as a string" do
|
68
|
+
|
68
69
|
before do
|
69
70
|
concat(semantic_form_for(@new_post) do |builder|
|
70
|
-
concat(builder.action(:submit, :as => :generic,
|
71
|
+
concat(builder.action(:submit, :as => :generic,
|
71
72
|
:wrapper_html => { :class => 'foo_bah_bing' }
|
72
73
|
))
|
73
74
|
end)
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
it "should add the custom class strng to the existing classes" do
|
77
|
-
output_buffer.
|
78
|
+
expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing')
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
end
|
81
|
-
|
82
|
-
context "when a custom class is provided as an array" do
|
83
|
-
|
82
|
+
|
83
|
+
context "when a custom class is provided as an array" do
|
84
|
+
|
84
85
|
before do
|
85
86
|
concat(semantic_form_for(@new_post) do |builder|
|
86
|
-
concat(builder.action(:submit, :as => :generic,
|
87
|
+
concat(builder.action(:submit, :as => :generic,
|
87
88
|
:wrapper_html => { :class => ['foo_bah_bing', 'zing_boo'] }
|
88
89
|
))
|
89
90
|
end)
|
90
91
|
end
|
91
|
-
|
92
|
+
|
92
93
|
it "should add the custom class strng to the existing classes" do
|
93
|
-
output_buffer.
|
94
|
+
expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
|
94
95
|
end
|
95
|
-
|
96
|
+
|
96
97
|
end
|
97
|
-
|
98
|
+
|
98
99
|
end
|
99
|
-
|
100
|
+
|
100
101
|
describe 'button HTML' do
|
101
|
-
|
102
|
+
|
102
103
|
before do
|
103
104
|
concat(semantic_form_for(@new_post) do |builder|
|
104
|
-
concat(builder.action(:submit, :as => :generic,
|
105
|
+
concat(builder.action(:submit, :as => :generic,
|
105
106
|
:button_html => { :foo => 'bah' }
|
106
107
|
))
|
107
108
|
end)
|
108
109
|
end
|
109
|
-
|
110
|
+
|
110
111
|
it 'should pass :button_html HTML attributes to the button' do
|
111
|
-
output_buffer.
|
112
|
+
expect(output_buffer.to_str).to have_tag('li.action.generic_action input[@foo="bah"]')
|
112
113
|
end
|
113
|
-
|
114
|
+
|
114
115
|
it 'should respect a default_commit_button_accesskey configuration with nil' do
|
115
116
|
with_config :default_commit_button_accesskey, nil do
|
116
117
|
concat(semantic_form_for(@new_post) do |builder|
|
117
118
|
concat(builder.action(:submit, :as => :generic))
|
118
119
|
end)
|
119
|
-
output_buffer.
|
120
|
+
expect(output_buffer.to_str).not_to have_tag('li.action input[@accesskey]')
|
120
121
|
end
|
121
122
|
end
|
122
|
-
|
123
|
+
|
123
124
|
it 'should respect a default_commit_button_accesskey configuration with a String' do
|
124
125
|
with_config :default_commit_button_accesskey, 's' do
|
125
126
|
concat(semantic_form_for(@new_post) do |builder|
|
126
127
|
concat(builder.action(:submit, :as => :generic))
|
127
128
|
end)
|
128
|
-
output_buffer.
|
129
|
+
expect(output_buffer.to_str).to have_tag('li.action input[@accesskey="s"]')
|
129
130
|
end
|
130
131
|
end
|
131
|
-
|
132
|
+
|
132
133
|
it 'should respect an accesskey through options over configration' do
|
133
134
|
with_config :default_commit_button_accesskey, 's' do
|
134
135
|
concat(semantic_form_for(@new_post) do |builder|
|
135
136
|
concat(builder.action(:submit, :as => :generic, :accesskey => 'o'))
|
136
137
|
end)
|
137
|
-
output_buffer.
|
138
|
-
output_buffer.
|
138
|
+
expect(output_buffer.to_str).not_to have_tag('li.action input[@accesskey="s"]')
|
139
|
+
expect(output_buffer.to_str).to have_tag('li.action input[@accesskey="o"]')
|
139
140
|
end
|
140
141
|
end
|
141
|
-
|
142
|
+
|
142
143
|
end
|
143
|
-
|
144
|
+
|
144
145
|
describe 'labelling' do
|
145
|
-
|
146
|
+
|
146
147
|
describe 'when used without object' do
|
147
|
-
|
148
|
+
|
148
149
|
describe 'when explicit label is provided' do
|
149
150
|
it 'should render an input with the explicitly specified label' do
|
150
151
|
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
@@ -152,12 +153,12 @@ describe 'InputAction::Base' do
|
|
152
153
|
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
153
154
|
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
154
155
|
end)
|
155
|
-
output_buffer.
|
156
|
-
output_buffer.
|
157
|
-
output_buffer.
|
156
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
|
157
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
|
158
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
|
158
159
|
end
|
159
160
|
end
|
160
|
-
|
161
|
+
|
161
162
|
describe 'when no explicit label is provided' do
|
162
163
|
describe 'when no I18n-localized label is provided' do
|
163
164
|
before do
|
@@ -174,20 +175,20 @@ describe 'InputAction::Base' do
|
|
174
175
|
}
|
175
176
|
}
|
176
177
|
end
|
177
|
-
|
178
|
+
|
178
179
|
after do
|
179
180
|
::I18n.backend.reload!
|
180
181
|
end
|
181
|
-
|
182
|
+
|
182
183
|
it 'should render an input with default I18n-localized label (fallback)' do
|
183
184
|
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
184
185
|
concat(builder.action(:submit, :as => :generic))
|
185
186
|
concat(builder.action(:reset, :as => :generic))
|
186
187
|
concat(builder.action(:cancel, :as => :generic))
|
187
188
|
end)
|
188
|
-
output_buffer.
|
189
|
-
output_buffer.
|
190
|
-
output_buffer.
|
189
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit Post"]')
|
190
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
|
191
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
|
191
192
|
end
|
192
193
|
|
193
194
|
it 'should render an input with custom resource name localized label' do
|
@@ -196,14 +197,14 @@ describe 'InputAction::Base' do
|
|
196
197
|
concat(builder.action(:reset, :as => :generic))
|
197
198
|
concat(builder.action(:cancel, :as => :generic))
|
198
199
|
end)
|
199
|
-
output_buffer.
|
200
|
-
output_buffer.
|
201
|
-
output_buffer.
|
200
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit message"]')
|
201
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel message"]')
|
202
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset message"]')
|
202
203
|
end
|
203
204
|
end
|
204
|
-
|
205
|
+
|
205
206
|
describe 'when I18n-localized label is provided' do
|
206
|
-
|
207
|
+
|
207
208
|
before do
|
208
209
|
::I18n.backend.store_translations :en,
|
209
210
|
:formtastic => {
|
@@ -214,11 +215,11 @@ describe 'InputAction::Base' do
|
|
214
215
|
}
|
215
216
|
}
|
216
217
|
end
|
217
|
-
|
218
|
+
|
218
219
|
after do
|
219
220
|
::I18n.backend.reload!
|
220
221
|
end
|
221
|
-
|
222
|
+
|
222
223
|
it 'should render an input with localized label (I18n)' do
|
223
224
|
with_config :i18n_lookups_by_default, true do
|
224
225
|
::I18n.backend.store_translations :en,
|
@@ -237,12 +238,12 @@ describe 'InputAction::Base' do
|
|
237
238
|
concat(builder.action(:reset, :as => :generic))
|
238
239
|
concat(builder.action(:cancel, :as => :generic))
|
239
240
|
end)
|
240
|
-
output_buffer.
|
241
|
-
output_buffer.
|
242
|
-
output_buffer.
|
241
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Submit Post"]})
|
242
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
243
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
243
244
|
end
|
244
245
|
end
|
245
|
-
|
246
|
+
|
246
247
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
247
248
|
with_config :i18n_lookups_by_default, true do
|
248
249
|
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
@@ -250,21 +251,21 @@ describe 'InputAction::Base' do
|
|
250
251
|
concat(builder.action(:reset, :as => :generic))
|
251
252
|
concat(builder.action(:cancel, :as => :generic))
|
252
253
|
end)
|
253
|
-
output_buffer.
|
254
|
-
output_buffer.
|
255
|
-
output_buffer.
|
254
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Submit"]})
|
255
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
256
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
256
257
|
end
|
257
258
|
end
|
258
|
-
|
259
|
+
|
259
260
|
end
|
260
261
|
end
|
261
262
|
end
|
262
|
-
|
263
|
+
|
263
264
|
describe 'when used on a new record' do
|
264
265
|
before do
|
265
|
-
@new_post.
|
266
|
+
allow(@new_post).to receive(:new_record?).and_return(true)
|
266
267
|
end
|
267
|
-
|
268
|
+
|
268
269
|
describe 'when explicit label is provided' do
|
269
270
|
it 'should render an input with the explicitly specified label' do
|
270
271
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -272,12 +273,12 @@ describe 'InputAction::Base' do
|
|
272
273
|
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
273
274
|
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
274
275
|
end)
|
275
|
-
output_buffer.
|
276
|
-
output_buffer.
|
277
|
-
output_buffer.
|
276
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
|
277
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
|
278
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
|
278
279
|
end
|
279
280
|
end
|
280
|
-
|
281
|
+
|
281
282
|
describe 'when no explicit label is provided' do
|
282
283
|
describe 'when no I18n-localized label is provided' do
|
283
284
|
before do
|
@@ -287,23 +288,23 @@ describe 'InputAction::Base' do
|
|
287
288
|
:cancel => 'Cancel %{model}'
|
288
289
|
}
|
289
290
|
end
|
290
|
-
|
291
|
+
|
291
292
|
after do
|
292
293
|
::I18n.backend.reload!
|
293
294
|
end
|
294
|
-
|
295
|
+
|
295
296
|
it 'should render an input with default I18n-localized label (fallback)' do
|
296
297
|
concat(semantic_form_for(@new_post) do |builder|
|
297
298
|
concat(builder.action(:submit, :as => :generic))
|
298
299
|
concat(builder.action(:reset, :as => :generic))
|
299
300
|
concat(builder.action(:cancel, :as => :generic))
|
300
301
|
end)
|
301
|
-
output_buffer.
|
302
|
-
output_buffer.
|
303
|
-
output_buffer.
|
302
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Create Post"]')
|
303
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
|
304
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
|
304
305
|
end
|
305
306
|
end
|
306
|
-
|
307
|
+
|
307
308
|
describe 'when I18n-localized label is provided' do
|
308
309
|
before do
|
309
310
|
::I18n.backend.store_translations :en,
|
@@ -315,11 +316,11 @@ describe 'InputAction::Base' do
|
|
315
316
|
}
|
316
317
|
}
|
317
318
|
end
|
318
|
-
|
319
|
+
|
319
320
|
after do
|
320
321
|
::I18n.backend.reload!
|
321
322
|
end
|
322
|
-
|
323
|
+
|
323
324
|
it 'should render an input with localized label (I18n)' do
|
324
325
|
with_config :i18n_lookups_by_default, true do
|
325
326
|
::I18n.backend.store_translations :en,
|
@@ -337,12 +338,12 @@ describe 'InputAction::Base' do
|
|
337
338
|
concat(builder.action(:reset, :as => :generic))
|
338
339
|
concat(builder.action(:cancel, :as => :generic))
|
339
340
|
end)
|
340
|
-
output_buffer.
|
341
|
-
output_buffer.
|
342
|
-
output_buffer.
|
341
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Create Post"]})
|
342
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
343
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
343
344
|
end
|
344
345
|
end
|
345
|
-
|
346
|
+
|
346
347
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
347
348
|
with_config :i18n_lookups_by_default, true do
|
348
349
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -350,21 +351,21 @@ describe 'InputAction::Base' do
|
|
350
351
|
concat(builder.action(:reset, :as => :generic))
|
351
352
|
concat(builder.action(:cancel, :as => :generic))
|
352
353
|
end)
|
353
|
-
output_buffer.
|
354
|
-
output_buffer.
|
355
|
-
output_buffer.
|
354
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Create"]})
|
355
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
356
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
356
357
|
end
|
357
358
|
end
|
358
|
-
|
359
|
+
|
359
360
|
end
|
360
361
|
end
|
361
362
|
end
|
362
|
-
|
363
|
+
|
363
364
|
describe 'when used on an existing record' do
|
364
365
|
before do
|
365
|
-
@new_post.
|
366
|
+
allow(@new_post).to receive(:persisted?).and_return(true)
|
366
367
|
end
|
367
|
-
|
368
|
+
|
368
369
|
describe 'when explicit label is provided' do
|
369
370
|
it 'should render an input with the explicitly specified label' do
|
370
371
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -372,12 +373,12 @@ describe 'InputAction::Base' do
|
|
372
373
|
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
373
374
|
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
374
375
|
end)
|
375
|
-
output_buffer.
|
376
|
-
output_buffer.
|
377
|
-
output_buffer.
|
376
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
|
377
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
|
378
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
|
378
379
|
end
|
379
380
|
end
|
380
|
-
|
381
|
+
|
381
382
|
describe 'when no explicit label is provided' do
|
382
383
|
describe 'when no I18n-localized label is provided' do
|
383
384
|
before do
|
@@ -394,20 +395,20 @@ describe 'InputAction::Base' do
|
|
394
395
|
}
|
395
396
|
}
|
396
397
|
end
|
397
|
-
|
398
|
+
|
398
399
|
after do
|
399
400
|
::I18n.backend.reload!
|
400
401
|
end
|
401
|
-
|
402
|
+
|
402
403
|
it 'should render an input with default I18n-localized label (fallback)' do
|
403
404
|
concat(semantic_form_for(@new_post) do |builder|
|
404
405
|
concat(builder.action(:submit, :as => :generic))
|
405
406
|
concat(builder.action(:reset, :as => :generic))
|
406
407
|
concat(builder.action(:cancel, :as => :generic))
|
407
408
|
end)
|
408
|
-
output_buffer.
|
409
|
-
output_buffer.
|
410
|
-
output_buffer.
|
409
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Save Post"]')
|
410
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
|
411
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
|
411
412
|
end
|
412
413
|
|
413
414
|
it 'should render an input with custom resource name localized label' do
|
@@ -416,12 +417,12 @@ describe 'InputAction::Base' do
|
|
416
417
|
concat(builder.action(:reset, :as => :generic))
|
417
418
|
concat(builder.action(:cancel, :as => :generic))
|
418
419
|
end)
|
419
|
-
output_buffer.
|
420
|
-
output_buffer.
|
421
|
-
output_buffer.
|
420
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit message"]')
|
421
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel message"]')
|
422
|
+
expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset message"]')
|
422
423
|
end
|
423
424
|
end
|
424
|
-
|
425
|
+
|
425
426
|
describe 'when I18n-localized label is provided' do
|
426
427
|
before do
|
427
428
|
::I18n.backend.reload!
|
@@ -434,11 +435,11 @@ describe 'InputAction::Base' do
|
|
434
435
|
}
|
435
436
|
}
|
436
437
|
end
|
437
|
-
|
438
|
+
|
438
439
|
after do
|
439
440
|
::I18n.backend.reload!
|
440
441
|
end
|
441
|
-
|
442
|
+
|
442
443
|
it 'should render an input with localized label (I18n)' do
|
443
444
|
with_config :i18n_lookups_by_default, true do
|
444
445
|
::I18n.backend.store_translations :en,
|
@@ -456,12 +457,12 @@ describe 'InputAction::Base' do
|
|
456
457
|
concat(builder.action(:reset, :as => :generic))
|
457
458
|
concat(builder.action(:cancel, :as => :generic))
|
458
459
|
end)
|
459
|
-
output_buffer.
|
460
|
-
output_buffer.
|
461
|
-
output_buffer.
|
460
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Save Post"]})
|
461
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
462
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
462
463
|
end
|
463
464
|
end
|
464
|
-
|
465
|
+
|
465
466
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
466
467
|
with_config :i18n_lookups_by_default, true do
|
467
468
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -469,13 +470,13 @@ describe 'InputAction::Base' do
|
|
469
470
|
concat(builder.action(:reset, :as => :generic))
|
470
471
|
concat(builder.action(:cancel, :as => :generic))
|
471
472
|
end)
|
472
|
-
output_buffer.
|
473
|
-
output_buffer.
|
474
|
-
output_buffer.
|
473
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Save"]})
|
474
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
475
|
+
expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
475
476
|
::I18n.backend.store_translations :en, :formtastic => {}
|
476
477
|
end
|
477
478
|
end
|
478
|
-
|
479
|
+
|
479
480
|
end
|
480
481
|
end
|
481
482
|
end
|
@@ -484,36 +485,36 @@ describe 'InputAction::Base' do
|
|
484
485
|
describe 'when the model is two words' do
|
485
486
|
|
486
487
|
before do
|
487
|
-
output_buffer = ''
|
488
|
+
output_buffer = ActionView::OutputBuffer.new ''
|
488
489
|
class ::UserPost
|
489
490
|
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
490
491
|
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
491
|
-
|
492
|
+
|
492
493
|
def id
|
493
494
|
end
|
494
|
-
|
495
|
+
|
495
496
|
def persisted?
|
496
497
|
end
|
497
|
-
|
498
|
+
|
498
499
|
# Rails does crappy human_name
|
499
500
|
def self.human_name
|
500
501
|
"User post"
|
501
502
|
end
|
502
503
|
end
|
503
504
|
@new_user_post = ::UserPost.new
|
504
|
-
|
505
|
-
@new_user_post.
|
505
|
+
|
506
|
+
allow(@new_user_post).to receive(:new_record?).and_return(true)
|
506
507
|
concat(semantic_form_for(@new_user_post, :url => '') do |builder|
|
507
508
|
concat(builder.action(:submit, :as => :generic))
|
508
509
|
concat(builder.action(:reset, :as => :generic))
|
509
510
|
concat(builder.action(:cancel, :as => :generic))
|
510
511
|
end)
|
511
512
|
end
|
512
|
-
|
513
|
+
|
513
514
|
it "should render the string as the value of the button" do
|
514
|
-
output_buffer.
|
515
|
-
output_buffer.
|
516
|
-
output_buffer.
|
515
|
+
expect(output_buffer.to_str).to have_tag('li input[@value="Create User post"]')
|
516
|
+
expect(output_buffer.to_str).to have_tag('li input[@value="Reset User post"]')
|
517
|
+
expect(output_buffer.to_str).to have_tag('li input[@value="Cancel User post"]')
|
517
518
|
end
|
518
519
|
|
519
520
|
end
|
@@ -1,59 +1,60 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
describe 'InputAction', 'when submitting' do
|
5
|
+
RSpec.describe 'InputAction', 'when submitting' do
|
5
6
|
|
6
7
|
include FormtasticSpecHelper
|
7
8
|
|
8
9
|
before do
|
9
|
-
@output_buffer = ''
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
10
11
|
mock_everything
|
11
|
-
|
12
|
+
|
12
13
|
concat(semantic_form_for(@new_post) do |builder|
|
13
14
|
concat(builder.action(:submit, :as => :input))
|
14
15
|
end)
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
it 'should render a submit type of input' do
|
18
|
-
output_buffer.
|
19
|
+
expect(output_buffer.to_str).to have_tag('li.action.input_action input[@type="submit"]')
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
22
23
|
|
23
|
-
describe 'InputAction', 'when resetting' do
|
24
|
+
RSpec.describe 'InputAction', 'when resetting' do
|
24
25
|
|
25
26
|
include FormtasticSpecHelper
|
26
|
-
|
27
|
+
|
27
28
|
before do
|
28
|
-
@output_buffer = ''
|
29
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
29
30
|
mock_everything
|
30
|
-
|
31
|
+
|
31
32
|
concat(semantic_form_for(@new_post) do |builder|
|
32
33
|
concat(builder.action(:reset, :as => :input))
|
33
34
|
end)
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
it 'should render a reset type of input' do
|
37
|
-
output_buffer.
|
38
|
+
expect(output_buffer.to_str).to have_tag('li.action.input_action input[@type="reset"]')
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
end
|
41
42
|
|
42
|
-
describe 'InputAction', 'when cancelling' do
|
43
|
+
RSpec.describe 'InputAction', 'when cancelling' do
|
43
44
|
|
44
45
|
include FormtasticSpecHelper
|
45
|
-
|
46
|
+
|
46
47
|
before do
|
47
|
-
@output_buffer = ''
|
48
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
48
49
|
mock_everything
|
49
50
|
end
|
50
|
-
|
51
|
+
|
51
52
|
it 'should raise an error' do
|
52
|
-
|
53
|
+
expect {
|
53
54
|
concat(semantic_form_for(@new_post) do |builder|
|
54
55
|
concat(builder.action(:cancel, :as => :input))
|
55
56
|
end)
|
56
|
-
}.
|
57
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
57
58
|
end
|
58
|
-
|
59
|
+
|
59
60
|
end
|