mega-safe-tool 0.0.1

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.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/formtastic-6.0.0/Appraisals +23 -0
  3. data/formtastic-6.0.0/CONTRIBUTING.md +27 -0
  4. data/formtastic-6.0.0/Gemfile +8 -0
  5. data/formtastic-6.0.0/MIT-LICENSE +20 -0
  6. data/formtastic-6.0.0/README.md +600 -0
  7. data/formtastic-6.0.0/RELEASE_PROCESS +7 -0
  8. data/formtastic-6.0.0/Rakefile +54 -0
  9. data/formtastic-6.0.0/bin/appraisal +8 -0
  10. data/formtastic-6.0.0/formtastic.gemspec +45 -0
  11. data/formtastic-6.0.0/gemfiles/rails_72.gemfile +9 -0
  12. data/formtastic-6.0.0/gemfiles/rails_80.gemfile +9 -0
  13. data/formtastic-6.0.0/gemfiles/rails_81.gemfile +9 -0
  14. data/formtastic-6.0.0/gemfiles/rails_edge.gemfile +9 -0
  15. data/formtastic-6.0.0/lib/formtastic/action_class_finder.rb +19 -0
  16. data/formtastic-6.0.0/lib/formtastic/actions/base.rb +157 -0
  17. data/formtastic-6.0.0/lib/formtastic/actions/button_action.rb +68 -0
  18. data/formtastic-6.0.0/lib/formtastic/actions/buttonish.rb +18 -0
  19. data/formtastic-6.0.0/lib/formtastic/actions/input_action.rb +71 -0
  20. data/formtastic-6.0.0/lib/formtastic/actions/link_action.rb +89 -0
  21. data/formtastic-6.0.0/lib/formtastic/actions.rb +15 -0
  22. data/formtastic-6.0.0/lib/formtastic/deprecation.rb +6 -0
  23. data/formtastic-6.0.0/lib/formtastic/form_builder.rb +109 -0
  24. data/formtastic-6.0.0/lib/formtastic/helpers/action_helper.rb +115 -0
  25. data/formtastic-6.0.0/lib/formtastic/helpers/actions_helper.rb +169 -0
  26. data/formtastic-6.0.0/lib/formtastic/helpers/enum.rb +14 -0
  27. data/formtastic-6.0.0/lib/formtastic/helpers/errors_helper.rb +139 -0
  28. data/formtastic-6.0.0/lib/formtastic/helpers/fieldset_wrapper.rb +85 -0
  29. data/formtastic-6.0.0/lib/formtastic/helpers/file_column_detection.rb +17 -0
  30. data/formtastic-6.0.0/lib/formtastic/helpers/form_helper.rb +204 -0
  31. data/formtastic-6.0.0/lib/formtastic/helpers/input_helper.rb +349 -0
  32. data/formtastic-6.0.0/lib/formtastic/helpers/inputs_helper.rb +421 -0
  33. data/formtastic-6.0.0/lib/formtastic/helpers/reflection.rb +38 -0
  34. data/formtastic-6.0.0/lib/formtastic/helpers.rb +16 -0
  35. data/formtastic-6.0.0/lib/formtastic/html_attributes.rb +33 -0
  36. data/formtastic-6.0.0/lib/formtastic/i18n.rb +33 -0
  37. data/formtastic-6.0.0/lib/formtastic/input_class_finder.rb +19 -0
  38. data/formtastic-6.0.0/lib/formtastic/inputs/base/aria.rb +26 -0
  39. data/formtastic-6.0.0/lib/formtastic/inputs/base/associations.rb +32 -0
  40. data/formtastic-6.0.0/lib/formtastic/inputs/base/choices.rb +109 -0
  41. data/formtastic-6.0.0/lib/formtastic/inputs/base/collections.rb +158 -0
  42. data/formtastic-6.0.0/lib/formtastic/inputs/base/database.rb +20 -0
  43. data/formtastic-6.0.0/lib/formtastic/inputs/base/datetime_pickerish.rb +86 -0
  44. data/formtastic-6.0.0/lib/formtastic/inputs/base/errors.rb +59 -0
  45. data/formtastic-6.0.0/lib/formtastic/inputs/base/fileish.rb +24 -0
  46. data/formtastic-6.0.0/lib/formtastic/inputs/base/hints.rb +32 -0
  47. data/formtastic-6.0.0/lib/formtastic/inputs/base/html.rb +54 -0
  48. data/formtastic-6.0.0/lib/formtastic/inputs/base/labelling.rb +53 -0
  49. data/formtastic-6.0.0/lib/formtastic/inputs/base/naming.rb +43 -0
  50. data/formtastic-6.0.0/lib/formtastic/inputs/base/numeric.rb +51 -0
  51. data/formtastic-6.0.0/lib/formtastic/inputs/base/options.rb +18 -0
  52. data/formtastic-6.0.0/lib/formtastic/inputs/base/placeholder.rb +18 -0
  53. data/formtastic-6.0.0/lib/formtastic/inputs/base/stringish.rb +39 -0
  54. data/formtastic-6.0.0/lib/formtastic/inputs/base/timeish.rb +246 -0
  55. data/formtastic-6.0.0/lib/formtastic/inputs/base/validations.rb +250 -0
  56. data/formtastic-6.0.0/lib/formtastic/inputs/base/wrapping.rb +51 -0
  57. data/formtastic-6.0.0/lib/formtastic/inputs/base.rb +79 -0
  58. data/formtastic-6.0.0/lib/formtastic/inputs/boolean_input.rb +119 -0
  59. data/formtastic-6.0.0/lib/formtastic/inputs/check_boxes_input.rb +198 -0
  60. data/formtastic-6.0.0/lib/formtastic/inputs/color_input.rb +42 -0
  61. data/formtastic-6.0.0/lib/formtastic/inputs/country_input.rb +90 -0
  62. data/formtastic-6.0.0/lib/formtastic/inputs/datalist_input.rb +42 -0
  63. data/formtastic-6.0.0/lib/formtastic/inputs/date_picker_input.rb +94 -0
  64. data/formtastic-6.0.0/lib/formtastic/inputs/date_select_input.rb +35 -0
  65. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_picker_input.rb +104 -0
  66. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_select_input.rb +13 -0
  67. data/formtastic-6.0.0/lib/formtastic/inputs/email_input.rb +42 -0
  68. data/formtastic-6.0.0/lib/formtastic/inputs/file_input.rb +43 -0
  69. data/formtastic-6.0.0/lib/formtastic/inputs/hidden_input.rb +63 -0
  70. data/formtastic-6.0.0/lib/formtastic/inputs/number_input.rb +89 -0
  71. data/formtastic-6.0.0/lib/formtastic/inputs/password_input.rb +42 -0
  72. data/formtastic-6.0.0/lib/formtastic/inputs/phone_input.rb +43 -0
  73. data/formtastic-6.0.0/lib/formtastic/inputs/radio_input.rb +164 -0
  74. data/formtastic-6.0.0/lib/formtastic/inputs/range_input.rb +96 -0
  75. data/formtastic-6.0.0/lib/formtastic/inputs/search_input.rb +42 -0
  76. data/formtastic-6.0.0/lib/formtastic/inputs/select_input.rb +236 -0
  77. data/formtastic-6.0.0/lib/formtastic/inputs/string_input.rb +37 -0
  78. data/formtastic-6.0.0/lib/formtastic/inputs/text_input.rb +49 -0
  79. data/formtastic-6.0.0/lib/formtastic/inputs/time_picker_input.rb +100 -0
  80. data/formtastic-6.0.0/lib/formtastic/inputs/time_select_input.rb +39 -0
  81. data/formtastic-6.0.0/lib/formtastic/inputs/time_zone_input.rb +59 -0
  82. data/formtastic-6.0.0/lib/formtastic/inputs/url_input.rb +42 -0
  83. data/formtastic-6.0.0/lib/formtastic/inputs.rb +43 -0
  84. data/formtastic-6.0.0/lib/formtastic/localized_string.rb +18 -0
  85. data/formtastic-6.0.0/lib/formtastic/localizer.rb +151 -0
  86. data/formtastic-6.0.0/lib/formtastic/namespaced_class_finder.rb +98 -0
  87. data/formtastic-6.0.0/lib/formtastic/version.rb +4 -0
  88. data/formtastic-6.0.0/lib/formtastic.rb +48 -0
  89. data/formtastic-6.0.0/lib/generators/formtastic/form/form_generator.rb +111 -0
  90. data/formtastic-6.0.0/lib/generators/formtastic/input/input_generator.rb +47 -0
  91. data/formtastic-6.0.0/lib/generators/formtastic/install/install_generator.rb +23 -0
  92. data/formtastic-6.0.0/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
  93. data/formtastic-6.0.0/lib/generators/templates/_form.html.erb +11 -0
  94. data/formtastic-6.0.0/lib/generators/templates/_form.html.haml +8 -0
  95. data/formtastic-6.0.0/lib/generators/templates/_form.html.slim +8 -0
  96. data/formtastic-6.0.0/lib/generators/templates/formtastic.css +289 -0
  97. data/formtastic-6.0.0/lib/generators/templates/formtastic.rb +118 -0
  98. data/formtastic-6.0.0/lib/generators/templates/input.rb +19 -0
  99. data/formtastic-6.0.0/lib/locale/en.yml +10 -0
  100. data/formtastic-6.0.0/sample/basic_inputs.html +224 -0
  101. data/formtastic-6.0.0/sample/config.ru +69 -0
  102. data/formtastic-6.0.0/sample/index.html +14 -0
  103. data/formtastic-6.0.0/script/integration-template.rb +76 -0
  104. data/formtastic-6.0.0/script/integration.sh +32 -0
  105. data/formtastic-6.0.0/spec/action_class_finder_spec.rb +12 -0
  106. data/formtastic-6.0.0/spec/actions/button_action_spec.rb +63 -0
  107. data/formtastic-6.0.0/spec/actions/generic_action_spec.rb +521 -0
  108. data/formtastic-6.0.0/spec/actions/input_action_spec.rb +59 -0
  109. data/formtastic-6.0.0/spec/actions/link_action_spec.rb +92 -0
  110. data/formtastic-6.0.0/spec/builder/custom_builder_spec.rb +132 -0
  111. data/formtastic-6.0.0/spec/builder/error_proc_spec.rb +27 -0
  112. data/formtastic-6.0.0/spec/builder/semantic_fields_for_spec.rb +213 -0
  113. data/formtastic-6.0.0/spec/fast_spec_helper.rb +12 -0
  114. data/formtastic-6.0.0/spec/generators/formtastic/form/form_generator_spec.rb +132 -0
  115. data/formtastic-6.0.0/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
  116. data/formtastic-6.0.0/spec/generators/formtastic/install/install_generator_spec.rb +48 -0
  117. data/formtastic-6.0.0/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
  118. data/formtastic-6.0.0/spec/helpers/action_helper_spec.rb +338 -0
  119. data/formtastic-6.0.0/spec/helpers/actions_helper_spec.rb +143 -0
  120. data/formtastic-6.0.0/spec/helpers/form_helper_spec.rb +224 -0
  121. data/formtastic-6.0.0/spec/helpers/input_helper_spec.rb +991 -0
  122. data/formtastic-6.0.0/spec/helpers/inputs_helper_spec.rb +669 -0
  123. data/formtastic-6.0.0/spec/helpers/reflection_helper_spec.rb +32 -0
  124. data/formtastic-6.0.0/spec/helpers/semantic_errors_helper_spec.rb +220 -0
  125. data/formtastic-6.0.0/spec/i18n_spec.rb +210 -0
  126. data/formtastic-6.0.0/spec/input_class_finder_spec.rb +10 -0
  127. data/formtastic-6.0.0/spec/inputs/base/collections_spec.rb +119 -0
  128. data/formtastic-6.0.0/spec/inputs/base/validations_spec.rb +481 -0
  129. data/formtastic-6.0.0/spec/inputs/boolean_input_spec.rb +254 -0
  130. data/formtastic-6.0.0/spec/inputs/check_boxes_input_spec.rb +547 -0
  131. data/formtastic-6.0.0/spec/inputs/color_input_spec.rb +85 -0
  132. data/formtastic-6.0.0/spec/inputs/country_input_spec.rb +133 -0
  133. data/formtastic-6.0.0/spec/inputs/custom_input_spec.rb +51 -0
  134. data/formtastic-6.0.0/spec/inputs/datalist_input_spec.rb +61 -0
  135. data/formtastic-6.0.0/spec/inputs/date_picker_input_spec.rb +449 -0
  136. data/formtastic-6.0.0/spec/inputs/date_select_input_spec.rb +249 -0
  137. data/formtastic-6.0.0/spec/inputs/datetime_picker_input_spec.rb +490 -0
  138. data/formtastic-6.0.0/spec/inputs/datetime_select_input_spec.rb +209 -0
  139. data/formtastic-6.0.0/spec/inputs/email_input_spec.rb +85 -0
  140. data/formtastic-6.0.0/spec/inputs/file_input_spec.rb +89 -0
  141. data/formtastic-6.0.0/spec/inputs/hidden_input_spec.rb +135 -0
  142. data/formtastic-6.0.0/spec/inputs/include_blank_spec.rb +78 -0
  143. data/formtastic-6.0.0/spec/inputs/label_spec.rb +181 -0
  144. data/formtastic-6.0.0/spec/inputs/number_input_spec.rb +815 -0
  145. data/formtastic-6.0.0/spec/inputs/password_input_spec.rb +99 -0
  146. data/formtastic-6.0.0/spec/inputs/phone_input_spec.rb +85 -0
  147. data/formtastic-6.0.0/spec/inputs/placeholder_spec.rb +71 -0
  148. data/formtastic-6.0.0/spec/inputs/radio_input_spec.rb +326 -0
  149. data/formtastic-6.0.0/spec/inputs/range_input_spec.rb +505 -0
  150. data/formtastic-6.0.0/spec/inputs/readonly_spec.rb +50 -0
  151. data/formtastic-6.0.0/spec/inputs/search_input_spec.rb +84 -0
  152. data/formtastic-6.0.0/spec/inputs/select_input_spec.rb +661 -0
  153. data/formtastic-6.0.0/spec/inputs/string_input_spec.rb +326 -0
  154. data/formtastic-6.0.0/spec/inputs/text_input_spec.rb +187 -0
  155. data/formtastic-6.0.0/spec/inputs/time_picker_input_spec.rb +455 -0
  156. data/formtastic-6.0.0/spec/inputs/time_select_input_spec.rb +261 -0
  157. data/formtastic-6.0.0/spec/inputs/time_zone_input_spec.rb +143 -0
  158. data/formtastic-6.0.0/spec/inputs/url_input_spec.rb +85 -0
  159. data/formtastic-6.0.0/spec/inputs/with_options_spec.rb +43 -0
  160. data/formtastic-6.0.0/spec/localizer_spec.rb +130 -0
  161. data/formtastic-6.0.0/spec/namespaced_class_finder_spec.rb +90 -0
  162. data/formtastic-6.0.0/spec/schema.rb +22 -0
  163. data/formtastic-6.0.0/spec/spec.opts +2 -0
  164. data/formtastic-6.0.0/spec/spec_helper.rb +466 -0
  165. data/formtastic-6.0.0/spec/support/custom_macros.rb +570 -0
  166. data/formtastic-6.0.0/spec/support/deprecation.rb +7 -0
  167. data/formtastic-6.0.0/spec/support/shared_examples.rb +13 -0
  168. data/formtastic-6.0.0/spec/support/specialized_class_finder_shared_example.rb +27 -0
  169. data/formtastic-6.0.0/spec/support/test_environment.rb +46 -0
  170. data/mega-safe-tool.gemspec +11 -0
  171. metadata +209 -0
@@ -0,0 +1,521 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'InputAction::Base' do
5
+
6
+ # Most basic Action class to test Base
7
+ class ::GenericAction
8
+ include ::Formtastic::Actions::Base
9
+
10
+ def supported_methods
11
+ [:submit, :reset, :cancel]
12
+ end
13
+
14
+ def to_html
15
+ wrapper do
16
+ builder.submit(text, button_html)
17
+ end
18
+ end
19
+ end
20
+
21
+ include FormtasticSpecHelper
22
+
23
+ before do
24
+ @output_buffer = ActionView::OutputBuffer.new ''
25
+ mock_everything
26
+ end
27
+
28
+ describe 'wrapping HTML' do
29
+
30
+ before do
31
+ concat(semantic_form_for(@new_post) do |builder|
32
+ concat(builder.action(:submit, :as => :generic,
33
+ :wrapper_html => { :foo => 'bah' }
34
+ ))
35
+ end)
36
+ end
37
+
38
+ it 'should add the #foo id to the li' do
39
+ expect(output_buffer.to_str).to have_tag('li#post_submit_action')
40
+ end
41
+
42
+ it 'should add the .action and .generic_action classes to the li' do
43
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action')
44
+ end
45
+
46
+ it 'should pass :wrapper_html HTML attributes to the wrapper' do
47
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action[@foo="bah"]')
48
+ end
49
+
50
+ context "when a custom :id is provided" do
51
+
52
+ before do
53
+ concat(semantic_form_for(@new_post) do |builder|
54
+ concat(builder.action(:submit, :as => :generic,
55
+ :wrapper_html => { :id => 'foo_bah_bing' }
56
+ ))
57
+ end)
58
+ end
59
+
60
+ it "should use the custom id" do
61
+ expect(output_buffer.to_str).to have_tag('li#foo_bah_bing')
62
+ end
63
+
64
+ end
65
+
66
+ context "when a custom class is provided as a string" do
67
+
68
+ before do
69
+ concat(semantic_form_for(@new_post) do |builder|
70
+ concat(builder.action(:submit, :as => :generic,
71
+ :wrapper_html => { :class => 'foo_bah_bing' }
72
+ ))
73
+ end)
74
+ end
75
+
76
+ it "should add the custom class string to the existing classes" do
77
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing')
78
+ end
79
+
80
+ end
81
+
82
+ context "when a custom class is provided as an array" do
83
+
84
+ before do
85
+ concat(semantic_form_for(@new_post) do |builder|
86
+ concat(builder.action(:submit, :as => :generic,
87
+ :wrapper_html => { :class => ['foo_bah_bing', 'zing_boo'] }
88
+ ))
89
+ end)
90
+ end
91
+
92
+ it "should add the custom class string to the existing classes" do
93
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
100
+ describe 'button HTML' do
101
+
102
+ before do
103
+ concat(semantic_form_for(@new_post) do |builder|
104
+ concat(builder.action(:submit, :as => :generic,
105
+ :button_html => { :foo => 'bah' }
106
+ ))
107
+ end)
108
+ end
109
+
110
+ it 'should pass :button_html HTML attributes to the button' do
111
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action input[@foo="bah"]')
112
+ end
113
+
114
+ it 'should respect a default_commit_button_accesskey configuration with nil' do
115
+ with_config :default_commit_button_accesskey, nil do
116
+ concat(semantic_form_for(@new_post) do |builder|
117
+ concat(builder.action(:submit, :as => :generic))
118
+ end)
119
+ expect(output_buffer.to_str).not_to have_tag('li.action input[@accesskey]')
120
+ end
121
+ end
122
+
123
+ it 'should respect a default_commit_button_accesskey configuration with a String' do
124
+ with_config :default_commit_button_accesskey, 's' do
125
+ concat(semantic_form_for(@new_post) do |builder|
126
+ concat(builder.action(:submit, :as => :generic))
127
+ end)
128
+ expect(output_buffer.to_str).to have_tag('li.action input[@accesskey="s"]')
129
+ end
130
+ end
131
+
132
+ it 'should respect an accesskey through options over configration' do
133
+ with_config :default_commit_button_accesskey, 's' do
134
+ concat(semantic_form_for(@new_post) do |builder|
135
+ concat(builder.action(:submit, :as => :generic, :accesskey => 'o'))
136
+ end)
137
+ expect(output_buffer.to_str).not_to have_tag('li.action input[@accesskey="s"]')
138
+ expect(output_buffer.to_str).to have_tag('li.action input[@accesskey="o"]')
139
+ end
140
+ end
141
+
142
+ end
143
+
144
+ describe 'labelling' do
145
+
146
+ describe 'when used without object' do
147
+
148
+ describe 'when explicit label is provided' do
149
+ it 'should render an input with the explicitly specified label' do
150
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
151
+ concat(builder.action(:submit, :as => :generic, :label => "Click!"))
152
+ concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
153
+ concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
154
+ end)
155
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
156
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
157
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
158
+ end
159
+ end
160
+
161
+ describe 'when no explicit label is provided' do
162
+ describe 'when no I18n-localized label is provided' do
163
+ before do
164
+ ::I18n.backend.store_translations :en, :formtastic => {
165
+ :submit => 'Submit %{model}',
166
+ :reset => 'Reset %{model}',
167
+ :cancel => 'Cancel %{model}',
168
+ :actions => {
169
+ :message => {
170
+ :submit => 'Submit message',
171
+ :reset => 'Reset message',
172
+ :cancel => 'Cancel message'
173
+ }
174
+ }
175
+ }
176
+ end
177
+
178
+ after do
179
+ ::I18n.backend.reload!
180
+ end
181
+
182
+ it 'should render an input with default I18n-localized label (fallback)' do
183
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
184
+ concat(builder.action(:submit, :as => :generic))
185
+ concat(builder.action(:reset, :as => :generic))
186
+ concat(builder.action(:cancel, :as => :generic))
187
+ end)
188
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit Post"]')
189
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
190
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
191
+ end
192
+
193
+ it 'should render an input with custom resource name localized label' do
194
+ concat(semantic_form_for(:post, :as => :message, :url => 'http://example.com') do |builder|
195
+ concat(builder.action(:submit, :as => :generic))
196
+ concat(builder.action(:reset, :as => :generic))
197
+ concat(builder.action(:cancel, :as => :generic))
198
+ end)
199
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit message"]')
200
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel message"]')
201
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset message"]')
202
+ end
203
+ end
204
+
205
+ describe 'when I18n-localized label is provided' do
206
+
207
+ before do
208
+ ::I18n.backend.store_translations :en,
209
+ :formtastic => {
210
+ :actions => {
211
+ :submit => 'Custom Submit',
212
+ :reset => 'Custom Reset',
213
+ :cancel => 'Custom Cancel'
214
+ }
215
+ }
216
+ end
217
+
218
+ after do
219
+ ::I18n.backend.reload!
220
+ end
221
+
222
+ it 'should render an input with localized label (I18n)' do
223
+ with_config :i18n_lookups_by_default, true do
224
+ ::I18n.backend.store_translations :en,
225
+ :formtastic => {
226
+ :actions => {
227
+ :post => {
228
+ :submit => 'Custom Submit %{model}',
229
+ :reset => 'Custom Reset %{model}',
230
+ :cancel => 'Custom Cancel %{model}'
231
+ }
232
+ }
233
+ }
234
+
235
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
236
+ concat(builder.action(:submit, :as => :generic))
237
+ concat(builder.action(:reset, :as => :generic))
238
+ concat(builder.action(:cancel, :as => :generic))
239
+ end)
240
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Submit Post"]})
241
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
242
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
243
+ end
244
+ end
245
+
246
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
247
+ with_config :i18n_lookups_by_default, true do
248
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
249
+ concat(builder.action(:submit, :as => :generic))
250
+ concat(builder.action(:reset, :as => :generic))
251
+ concat(builder.action(:cancel, :as => :generic))
252
+ end)
253
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Submit"]})
254
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
255
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
256
+ end
257
+ end
258
+
259
+ end
260
+ end
261
+ end
262
+
263
+ describe 'when used on a new record' do
264
+ before do
265
+ allow(@new_post).to receive(:new_record?).and_return(true)
266
+ end
267
+
268
+ describe 'when explicit label is provided' do
269
+ it 'should render an input with the explicitly specified label' do
270
+ concat(semantic_form_for(@new_post) do |builder|
271
+ concat(builder.action(:submit, :as => :generic, :label => "Click!"))
272
+ concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
273
+ concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
274
+ end)
275
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
276
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
277
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
278
+ end
279
+ end
280
+
281
+ describe 'when no explicit label is provided' do
282
+ describe 'when no I18n-localized label is provided' do
283
+ before do
284
+ ::I18n.backend.store_translations :en, :formtastic => {
285
+ :create => 'Create %{model}',
286
+ :reset => 'Reset %{model}',
287
+ :cancel => 'Cancel %{model}'
288
+ }
289
+ end
290
+
291
+ after do
292
+ ::I18n.backend.reload!
293
+ end
294
+
295
+ it 'should render an input with default I18n-localized label (fallback)' do
296
+ concat(semantic_form_for(@new_post) do |builder|
297
+ concat(builder.action(:submit, :as => :generic))
298
+ concat(builder.action(:reset, :as => :generic))
299
+ concat(builder.action(:cancel, :as => :generic))
300
+ end)
301
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Create Post"]')
302
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
303
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
304
+ end
305
+ end
306
+
307
+ describe 'when I18n-localized label is provided' do
308
+ before do
309
+ ::I18n.backend.store_translations :en,
310
+ :formtastic => {
311
+ :actions => {
312
+ :create => 'Custom Create',
313
+ :reset => 'Custom Reset',
314
+ :cancel => 'Custom Cancel'
315
+ }
316
+ }
317
+ end
318
+
319
+ after do
320
+ ::I18n.backend.reload!
321
+ end
322
+
323
+ it 'should render an input with localized label (I18n)' do
324
+ with_config :i18n_lookups_by_default, true do
325
+ ::I18n.backend.store_translations :en,
326
+ :formtastic => {
327
+ :actions => {
328
+ :post => {
329
+ :create => 'Custom Create %{model}',
330
+ :reset => 'Custom Reset %{model}',
331
+ :cancel => 'Custom Cancel %{model}'
332
+ }
333
+ }
334
+ }
335
+ concat(semantic_form_for(@new_post) do |builder|
336
+ concat(builder.action(:submit, :as => :generic))
337
+ concat(builder.action(:reset, :as => :generic))
338
+ concat(builder.action(:cancel, :as => :generic))
339
+ end)
340
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Create Post"]})
341
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
342
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
343
+ end
344
+ end
345
+
346
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
347
+ with_config :i18n_lookups_by_default, true do
348
+ concat(semantic_form_for(@new_post) do |builder|
349
+ concat(builder.action(:submit, :as => :generic))
350
+ concat(builder.action(:reset, :as => :generic))
351
+ concat(builder.action(:cancel, :as => :generic))
352
+ end)
353
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Create"]})
354
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
355
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
356
+ end
357
+ end
358
+
359
+ end
360
+ end
361
+ end
362
+
363
+ describe 'when used on an existing record' do
364
+ before do
365
+ allow(@new_post).to receive(:persisted?).and_return(true)
366
+ end
367
+
368
+ describe 'when explicit label is provided' do
369
+ it 'should render an input with the explicitly specified label' do
370
+ concat(semantic_form_for(@new_post) do |builder|
371
+ concat(builder.action(:submit, :as => :generic, :label => "Click!"))
372
+ concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
373
+ concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
374
+ end)
375
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
376
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
377
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
378
+ end
379
+ end
380
+
381
+ describe 'when no explicit label is provided' do
382
+ describe 'when no I18n-localized label is provided' do
383
+ before do
384
+ ::I18n.backend.store_translations :en, :formtastic => {
385
+ :update => 'Save %{model}',
386
+ :reset => 'Reset %{model}',
387
+ :cancel => 'Cancel %{model}',
388
+ :actions => {
389
+ :message => {
390
+ :submit => 'Submit message',
391
+ :reset => 'Reset message',
392
+ :cancel => 'Cancel message'
393
+ }
394
+ }
395
+ }
396
+ end
397
+
398
+ after do
399
+ ::I18n.backend.reload!
400
+ end
401
+
402
+ it 'should render an input with default I18n-localized label (fallback)' do
403
+ concat(semantic_form_for(@new_post) do |builder|
404
+ concat(builder.action(:submit, :as => :generic))
405
+ concat(builder.action(:reset, :as => :generic))
406
+ concat(builder.action(:cancel, :as => :generic))
407
+ end)
408
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Save Post"]')
409
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
410
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
411
+ end
412
+
413
+ it 'should render an input with custom resource name localized label' do
414
+ concat(semantic_form_for(:post, :as => :message, :url => 'http://example.com') do |builder|
415
+ concat(builder.action(:submit, :as => :generic))
416
+ concat(builder.action(:reset, :as => :generic))
417
+ concat(builder.action(:cancel, :as => :generic))
418
+ end)
419
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit message"]')
420
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel message"]')
421
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset message"]')
422
+ end
423
+ end
424
+
425
+ describe 'when I18n-localized label is provided' do
426
+ before do
427
+ ::I18n.backend.reload!
428
+ ::I18n.backend.store_translations :en,
429
+ :formtastic => {
430
+ :actions => {
431
+ :update => 'Custom Save',
432
+ :reset => 'Custom Reset',
433
+ :cancel => 'Custom Cancel'
434
+ }
435
+ }
436
+ end
437
+
438
+ after do
439
+ ::I18n.backend.reload!
440
+ end
441
+
442
+ it 'should render an input with localized label (I18n)' do
443
+ with_config :i18n_lookups_by_default, true do
444
+ ::I18n.backend.store_translations :en,
445
+ :formtastic => {
446
+ :actions => {
447
+ :post => {
448
+ :update => 'Custom Save %{model}',
449
+ :reset => 'Custom Reset %{model}',
450
+ :cancel => 'Custom Cancel %{model}'
451
+ }
452
+ }
453
+ }
454
+ concat(semantic_form_for(@new_post) do |builder|
455
+ concat(builder.action(:submit, :as => :generic))
456
+ concat(builder.action(:reset, :as => :generic))
457
+ concat(builder.action(:cancel, :as => :generic))
458
+ end)
459
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Save Post"]})
460
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
461
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
462
+ end
463
+ end
464
+
465
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
466
+ with_config :i18n_lookups_by_default, true do
467
+ concat(semantic_form_for(@new_post) do |builder|
468
+ concat(builder.action(:submit, :as => :generic))
469
+ concat(builder.action(:reset, :as => :generic))
470
+ concat(builder.action(:cancel, :as => :generic))
471
+ end)
472
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Save"]})
473
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
474
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
475
+ ::I18n.backend.store_translations :en, :formtastic => {}
476
+ end
477
+ end
478
+
479
+ end
480
+ end
481
+ end
482
+ end
483
+
484
+ describe 'when the model is two words' do
485
+
486
+ before do
487
+ output_buffer = ActionView::OutputBuffer.new ''
488
+ class ::UserPost
489
+ extend ActiveModel::Naming if defined?(ActiveModel::Naming)
490
+ include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
491
+
492
+ def id
493
+ end
494
+
495
+ def persisted?
496
+ end
497
+
498
+ # Rails does crappy human_name
499
+ def self.human_name
500
+ "User post"
501
+ end
502
+ end
503
+ @new_user_post = ::UserPost.new
504
+
505
+ allow(@new_user_post).to receive(:new_record?).and_return(true)
506
+ concat(semantic_form_for(@new_user_post, :url => '') do |builder|
507
+ concat(builder.action(:submit, :as => :generic))
508
+ concat(builder.action(:reset, :as => :generic))
509
+ concat(builder.action(:cancel, :as => :generic))
510
+ end)
511
+ end
512
+
513
+ it "should render the string as the value of the button" do
514
+ expect(output_buffer.to_str).to have_tag('li input[@value="Create User post"]')
515
+ expect(output_buffer.to_str).to have_tag('li input[@value="Reset User post"]')
516
+ expect(output_buffer.to_str).to have_tag('li input[@value="Cancel User post"]')
517
+ end
518
+
519
+ end
520
+
521
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'InputAction', 'when submitting' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+
12
+ concat(semantic_form_for(@new_post) do |builder|
13
+ concat(builder.action(:submit, :as => :input))
14
+ end)
15
+ end
16
+
17
+ it 'should render a submit type of input' do
18
+ expect(output_buffer.to_str).to have_tag('li.action.input_action input[@type="submit"]')
19
+ end
20
+
21
+ end
22
+
23
+ RSpec.describe 'InputAction', 'when resetting' do
24
+
25
+ include FormtasticSpecHelper
26
+
27
+ before do
28
+ @output_buffer = ActionView::OutputBuffer.new ''
29
+ mock_everything
30
+
31
+ concat(semantic_form_for(@new_post) do |builder|
32
+ concat(builder.action(:reset, :as => :input))
33
+ end)
34
+ end
35
+
36
+ it 'should render a reset type of input' do
37
+ expect(output_buffer.to_str).to have_tag('li.action.input_action input[@type="reset"]')
38
+ end
39
+
40
+ end
41
+
42
+ RSpec.describe 'InputAction', 'when cancelling' do
43
+
44
+ include FormtasticSpecHelper
45
+
46
+ before do
47
+ @output_buffer = ActionView::OutputBuffer.new ''
48
+ mock_everything
49
+ end
50
+
51
+ it 'should raise an error' do
52
+ expect {
53
+ concat(semantic_form_for(@new_post) do |builder|
54
+ concat(builder.action(:cancel, :as => :input))
55
+ end)
56
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
57
+ end
58
+
59
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'LinkAction', 'when cancelling' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ context 'without a :url' do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.action(:cancel, :as => :link))
17
+ end)
18
+ end
19
+
20
+ it 'should render a submit type of input' do
21
+ expect(output_buffer.to_str).to have_tag('li.action.link_action a[@href="javascript:history.back()"]')
22
+ end
23
+
24
+ end
25
+
26
+ context 'with a :url as String' do
27
+
28
+ before do
29
+ concat(semantic_form_for(@new_post) do |builder|
30
+ concat(builder.action(:cancel, :as => :link, :url => "http://foo.bah/baz"))
31
+ end)
32
+ end
33
+
34
+ it 'should render a submit type of input' do
35
+ expect(output_buffer.to_str).to have_tag('li.action.link_action a[@href="http://foo.bah/baz"]')
36
+ end
37
+
38
+ end
39
+
40
+ context 'with a :url as Hash' do
41
+
42
+ before do
43
+ concat(semantic_form_for(@new_post) do |builder|
44
+ concat(builder.action(:cancel, :as => :link, :url => { :action => "foo" }))
45
+ end)
46
+ end
47
+
48
+ it 'should render a submit type of input' do
49
+ expect(output_buffer.to_str).to have_tag('li.action.link_action a[@href="/mock/path"]')
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ RSpec.describe 'LinkAction', 'when submitting' do
57
+
58
+ include FormtasticSpecHelper
59
+
60
+ before do
61
+ @output_buffer = ActionView::OutputBuffer.new ''
62
+ mock_everything
63
+ end
64
+
65
+ it 'should raise an error' do
66
+ expect {
67
+ concat(semantic_form_for(@new_post) do |builder|
68
+ concat(builder.action(:submit, :as => :link))
69
+ end)
70
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
71
+ end
72
+
73
+ end
74
+
75
+ RSpec.describe 'LinkAction', 'when submitting' do
76
+
77
+ include FormtasticSpecHelper
78
+
79
+ before do
80
+ @output_buffer = ActionView::OutputBuffer.new ''
81
+ mock_everything
82
+ end
83
+
84
+ it 'should raise an error' do
85
+ expect {
86
+ concat(semantic_form_for(@new_post) do |builder|
87
+ concat(builder.action(:reset, :as => :link))
88
+ end)
89
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
90
+ end
91
+
92
+ end