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,261 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'time select input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "general" do
14
+ before do
15
+ ::I18n.backend.reload!
16
+ @output_buffer = ActionView::OutputBuffer.new ''
17
+ end
18
+
19
+ describe "with :ignore_date => true" do
20
+ before do
21
+ concat(semantic_form_for(@new_post) do |builder|
22
+ concat(builder.input(:publish_at, :as => :time_select, :ignore_date => true))
23
+ end)
24
+ end
25
+
26
+ it 'should not have hidden inputs for day, month and year' do
27
+ expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_1i')
28
+ expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_2i')
29
+ expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_3i')
30
+ end
31
+
32
+ it 'should have an input for hour and minute' do
33
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
34
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
35
+ end
36
+
37
+ end
38
+
39
+ describe "with :ignore_date => false" do
40
+ before do
41
+ allow(@new_post).to receive(:publish_at).and_return(Time.parse('2010-11-07'))
42
+ concat(semantic_form_for(@new_post) do |builder|
43
+ concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
44
+ end)
45
+ end
46
+
47
+ it 'should have a hidden input for day, month and year' do
48
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i')
49
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i')
50
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i')
51
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i[@value="2010"]')
52
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i[@value="11"]')
53
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i[@value="7"]')
54
+ end
55
+
56
+ it 'should have an select for hour and minute' do
57
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
58
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
59
+ end
60
+
61
+ it 'should associate the legend label with the hour select' do
62
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
63
+ end
64
+
65
+ end
66
+
67
+ describe "without seconds" do
68
+ before do
69
+ concat(semantic_form_for(@new_post) do |builder|
70
+ concat(builder.input(:publish_at, :as => :time_select))
71
+ end)
72
+ end
73
+
74
+ it_should_have_input_wrapper_with_class("time_select")
75
+ it_should_have_input_wrapper_with_class(:input)
76
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
77
+ it_should_have_a_nested_fieldset
78
+ it_should_have_a_nested_fieldset_with_class('fragments')
79
+ it_should_have_a_nested_ordered_list_with_class('fragments-group')
80
+ it_should_apply_error_logic_for_input_type(:time_select)
81
+
82
+ it 'should have a legend and label with the label text inside the fieldset' do
83
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label', :text => /Publish at/)
84
+ end
85
+
86
+ it 'should associate the legend label with the first select' do
87
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
88
+ end
89
+
90
+ it 'should have an ordered list of two items inside the fieldset' do
91
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol.fragments-group')
92
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
93
+ end
94
+
95
+ it 'should have five labels for hour and minute' do
96
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 2)
97
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
98
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
99
+ end
100
+
101
+ it 'should have two selects for hour and minute' do
102
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 2)
103
+ end
104
+ end
105
+
106
+ describe "with seconds" do
107
+ before do
108
+ concat(semantic_form_for(@new_post) do |builder|
109
+ concat(builder.input(:publish_at, :as => :time_select, :include_seconds => true))
110
+ end)
111
+ end
112
+
113
+ it 'should have five labels for hour and minute' do
114
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 3)
115
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
116
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
117
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /second/i)
118
+ end
119
+
120
+ it 'should have three selects for hour, minute and seconds' do
121
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 3)
122
+ end
123
+
124
+ it 'should generate a sanitized label and matching ids for attribute' do
125
+ 4.upto(6) do |i|
126
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
127
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li #post_publish_at_#{i}i")
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ describe ':labels option' do
134
+ fields = [:hour, :minute, :second]
135
+ fields.each do |field|
136
+ it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
137
+ @output_buffer = ActionView::OutputBuffer.new ''
138
+ concat(semantic_form_for(@new_post) do |builder|
139
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
140
+ end)
141
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length)
142
+ fields.each do |f|
143
+ 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
+ end
145
+ end
146
+
147
+ it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
148
+ @output_buffer = ActionView::OutputBuffer.new ''
149
+ concat(semantic_form_for(@new_post) do |builder|
150
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
151
+ end)
152
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
153
+ fields.each do |f|
154
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
155
+ end
156
+ end
157
+
158
+ it "should not render the label when :labels[:#{field}] is false" do
159
+ @output_buffer = ActionView::OutputBuffer.new ''
160
+ concat(semantic_form_for(@new_post) do |builder|
161
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
162
+ end)
163
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
164
+ fields.each do |f|
165
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
166
+ end
167
+ end
168
+
169
+ it "should not render unsafe HTML when :labels[:#{field}] is false" do
170
+ @output_buffer = ActionView::OutputBuffer.new ''
171
+ concat(semantic_form_for(@new_post) do |builder|
172
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
173
+ end)
174
+ expect(output_buffer.to_str).not_to include(">")
175
+ end
176
+
177
+ end
178
+
179
+ it "should not render labels when :labels is falsy" do
180
+ @output_buffer = ActionView::OutputBuffer.new ''
181
+ concat(semantic_form_for(@new_post) do |builder|
182
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
183
+ end)
184
+ expect(output_buffer.to_str).not_to have_tag('form li.time_select fieldset ol li label')
185
+ end
186
+ end
187
+
188
+ describe ":selected option for setting a value" do
189
+ it "should set the selected value for the form" do
190
+ concat(
191
+ semantic_form_for(@new_post) do |f|
192
+ concat(f.input(:created_at, :as => :datetime_select, :selected => DateTime.new(2018, 10, 4, 12, 00)))
193
+ end
194
+ )
195
+
196
+ expect(output_buffer.to_str).to have_tag "option[value='12'][selected='selected']"
197
+ expect(output_buffer.to_str).to have_tag "option[value='00'][selected='selected']"
198
+ end
199
+ end
200
+
201
+ describe ':namespace option' do
202
+ before do
203
+ concat(semantic_form_for(@new_post, :namespace => 'form2') do |builder|
204
+ concat(builder.input(:publish_at, :as => :time_select))
205
+ end)
206
+ end
207
+
208
+ it 'should have a tag matching the namespace' do
209
+ expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_input')
210
+ expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_4i')
211
+ expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_5i')
212
+ end
213
+ end
214
+
215
+ describe "when required" do
216
+ it "should add the required attribute to the input's html options" do
217
+ with_config :use_required_attribute, true do
218
+ concat(semantic_form_for(@new_post) do |builder|
219
+ concat(builder.input(:title, :as => :time_select, :required => true))
220
+ end)
221
+ expect(output_buffer.to_str).to have_tag("select[@required]", :count => 2)
222
+ end
223
+ end
224
+ end
225
+
226
+ describe "when index is provided" do
227
+
228
+ before do
229
+ concat(semantic_form_for(@new_post) do |builder|
230
+ concat(builder.fields_for(:author, :index => 3) do |author|
231
+ concat(author.input(:created_at, :as => :time_select))
232
+ end)
233
+ end)
234
+ end
235
+
236
+ it 'should index the id of the wrapper' do
237
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_created_at_input")
238
+ end
239
+
240
+ it 'should index the id of the select tag' do
241
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_1i")
242
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_2i")
243
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_3i")
244
+ expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_4i")
245
+ expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_5i")
246
+ end
247
+
248
+ it 'should index the name of the select tag' do
249
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(1i)]']")
250
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(2i)]']")
251
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(3i)]']")
252
+ expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
253
+ expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
254
+ end
255
+
256
+ end
257
+
258
+ end
259
+
260
+
261
+
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'time_zone input' 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.input(:time_zone))
14
+ end)
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class("time_zone")
18
+ it_should_have_input_wrapper_with_class(:input)
19
+ it_should_have_input_wrapper_with_id("post_time_zone_input")
20
+ it_should_apply_error_logic_for_input_type(:time_zone)
21
+
22
+ it 'should generate a label for the input' do
23
+ expect(output_buffer.to_str).to have_tag('form li label')
24
+ expect(output_buffer.to_str).to have_tag('form li label[@for="post_time_zone"]')
25
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
26
+ end
27
+
28
+ it "should generate a select" do
29
+ expect(output_buffer.to_str).to have_tag("form li select")
30
+ expect(output_buffer.to_str).to have_tag("form li select#post_time_zone")
31
+ expect(output_buffer.to_str).to have_tag("form li select[@name=\"post[time_zone]\"]")
32
+ end
33
+
34
+ it 'should use input_html to style inputs' do
35
+ concat(semantic_form_for(@new_post) do |builder|
36
+ concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
37
+ end)
38
+ expect(output_buffer.to_str).to have_tag("form li select.myclass")
39
+ end
40
+
41
+ describe "when namespace is provided" do
42
+
43
+ before do
44
+ @output_buffer = ActionView::OutputBuffer.new ''
45
+ mock_everything
46
+
47
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
48
+ concat(builder.input(:time_zone))
49
+ end)
50
+ end
51
+
52
+ it_should_have_input_wrapper_with_id("context2_post_time_zone_input")
53
+ it_should_have_select_with_id("context2_post_time_zone")
54
+ it_should_have_label_for("context2_post_time_zone")
55
+
56
+ end
57
+
58
+ describe "when index is provided" do
59
+
60
+ before do
61
+ @output_buffer = ActionView::OutputBuffer.new ''
62
+ mock_everything
63
+
64
+ concat(semantic_form_for(@new_post) do |builder|
65
+ concat(builder.fields_for(:author, :index => 3) do |author|
66
+ concat(author.input(:name, :as => :time_zone))
67
+ end)
68
+ end)
69
+ end
70
+
71
+ it 'should index the id of the wrapper' do
72
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
73
+ end
74
+
75
+ it 'should index the id of the select tag' do
76
+ expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_name")
77
+ end
78
+
79
+ it 'should index the name of the select tag' do
80
+ expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][name]']")
81
+ end
82
+
83
+ end
84
+
85
+
86
+ describe 'when no object is given' do
87
+ before(:example) do
88
+ concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
89
+ concat(builder.input(:time_zone, :as => :time_zone))
90
+ end)
91
+ end
92
+
93
+ it 'should generate labels' do
94
+ expect(output_buffer.to_str).to have_tag('form li label')
95
+ expect(output_buffer.to_str).to have_tag('form li label[@for="project_time_zone"]')
96
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
97
+ end
98
+
99
+ it 'should generate select inputs' do
100
+ expect(output_buffer.to_str).to have_tag("form li select")
101
+ expect(output_buffer.to_str).to have_tag("form li select#project_time_zone")
102
+ expect(output_buffer.to_str).to have_tag("form li select[@name=\"project[time_zone]\"]")
103
+ end
104
+ end
105
+
106
+ context "when required" do
107
+ it "should add the required attribute to the input's html options" do
108
+ with_config :use_required_attribute, true do
109
+ concat(semantic_form_for(@new_post) do |builder|
110
+ concat(builder.input(:title, :as => :time_zone, :required => true))
111
+ end)
112
+ expect(output_buffer.to_str).to have_tag("select[@required]")
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "when priority time zone is provided" do
118
+ let(:time_zones) { [ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii']] }
119
+ let(:input_html_options) do
120
+ { id: "post_title", required: false, autofocus: false, readonly: false }
121
+ end
122
+
123
+ context "by priority_zone option" do
124
+ it "passes right time_zones" do
125
+ expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
126
+ semantic_form_for(@new_post) do |builder|
127
+ builder.input(:title, as: :time_zone, priority_zones: time_zones)
128
+ end
129
+ end
130
+ end
131
+
132
+ context "by configuration" do
133
+ it "passes right time_zones" do
134
+ expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
135
+ with_config :priority_time_zones, time_zones do
136
+ semantic_form_for(@new_post) do |builder|
137
+ builder.input(:title, as: :time_zone)
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'url input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "when object is provided" do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:url))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:url)
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_class(:stringish)
23
+ it_should_have_input_wrapper_with_id("post_url_input")
24
+ it_should_have_label_with_text(/Url/)
25
+ it_should_have_label_for("post_url")
26
+ it_should_have_input_with_id("post_url")
27
+ it_should_have_input_with_type(:url)
28
+ it_should_have_input_with_name("post[url]")
29
+
30
+ end
31
+
32
+ describe "when namespace is provided" do
33
+
34
+ before do
35
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
36
+ concat(builder.input(:url))
37
+ end)
38
+ end
39
+
40
+ it_should_have_input_wrapper_with_id("context2_post_url_input")
41
+ it_should_have_label_and_input_with_id("context2_post_url")
42
+
43
+ end
44
+
45
+ describe "when index is provided" do
46
+
47
+ before do
48
+ @output_buffer = ActionView::OutputBuffer.new ''
49
+ mock_everything
50
+
51
+ concat(semantic_form_for(@new_post) do |builder|
52
+ concat(builder.fields_for(:author, :index => 3) do |author|
53
+ concat(author.input(:name, :as => :url))
54
+ end)
55
+ end)
56
+ end
57
+
58
+ it 'should index the id of the wrapper' do
59
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
60
+ end
61
+
62
+ it 'should index the id of the select tag' do
63
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
64
+ end
65
+
66
+ it 'should index the name of the select tag' do
67
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
68
+ end
69
+
70
+ end
71
+
72
+
73
+ describe "when required" do
74
+ it "should add the required attribute to the input's html options" do
75
+ with_config :use_required_attribute, true do
76
+ concat(semantic_form_for(@new_post) do |builder|
77
+ concat(builder.input(:title, :as => :url, :required => true))
78
+ end)
79
+ expect(output_buffer.to_str).to have_tag("input[@required]")
80
+ end
81
+ end
82
+ end
83
+
84
+ end
85
+
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'string input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "with_options and :wrapper_html" do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ builder.with_options :wrapper_html => { :class => ['extra'] } do |opt_builder|
17
+ concat(opt_builder.input(:title, :as => :string))
18
+ concat(opt_builder.input(:author, :as => :radio))
19
+ end
20
+ end)
21
+ end
22
+
23
+ it "should have extra class on title" do
24
+ expect(output_buffer.to_str).to have_tag("form li#post_title_input.extra")
25
+ end
26
+ it "should have title as string" do
27
+ expect(output_buffer.to_str).to have_tag("form li#post_title_input.string")
28
+ end
29
+ it "should not have title as radio" do
30
+ expect(output_buffer.to_str).not_to have_tag("form li#post_title_input.radio")
31
+ end
32
+
33
+ it "should have extra class on author" do
34
+ expect(output_buffer.to_str).to have_tag("form li#post_author_input.extra")
35
+ end
36
+ it "should not have author as string" do
37
+ expect(output_buffer.to_str).not_to have_tag("form li#post_author_input.string")
38
+ end
39
+ it "should have author as radio" do
40
+ expect(output_buffer.to_str).to have_tag("form li#post_author_input.radio")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'Formtastic::Localizer' do
5
+ describe "Cache" do
6
+ before do
7
+ @cache = Formtastic::Localizer::Cache.new
8
+ @key = ['model', 'name']
9
+ @undefined_key = ['model', 'undefined']
10
+ @cache.set(@key, 'value')
11
+ end
12
+
13
+ it "should get value" do
14
+ expect(@cache.get(@key)).to eq('value')
15
+ expect(@cache.get(@undefined_key)).to be_nil
16
+ end
17
+
18
+ it "should check if key exists?" do
19
+ expect(@cache.has_key?(@key)).to be_truthy
20
+ expect(@cache.has_key?(@undefined_key)).to be_falsey
21
+ end
22
+
23
+ it "should set a key" do
24
+ @cache.set(['model', 'name2'], 'value2')
25
+ expect(@cache.get(['model', 'name2'])).to eq('value2')
26
+ end
27
+
28
+ it "should return hash" do
29
+ expect(@cache.cache).to be_an_instance_of(Hash)
30
+ end
31
+
32
+ it "should clear the cache" do
33
+ @cache.clear!
34
+ expect(@cache.get(@key)).to be_nil
35
+ end
36
+ end
37
+
38
+ describe "Localizer" do
39
+ include FormtasticSpecHelper
40
+
41
+ before do
42
+ mock_everything
43
+
44
+ with_config :i18n_lookups_by_default, true do
45
+ semantic_form_for(@new_post) do |builder|
46
+ @localizer = Formtastic::Localizer.new(builder)
47
+ end
48
+ end
49
+ end
50
+
51
+ after do
52
+ ::I18n.backend.reload!
53
+ end
54
+
55
+ it "should be defined" do
56
+ expect { Formtastic::Localizer }.not_to raise_error
57
+ end
58
+
59
+ it "should have a cache" do
60
+ expect(Formtastic::Localizer.cache).to be_an_instance_of(Formtastic::Localizer::Cache)
61
+ end
62
+
63
+ describe "localize" do
64
+ def store_post_translations(value)
65
+ ::I18n.backend.store_translations :en, {:formtastic => {
66
+ :labels => {
67
+ :post => { :name => value }
68
+ }
69
+ }
70
+ }
71
+ end
72
+
73
+ before do
74
+ store_post_translations('POST.NAME')
75
+ end
76
+
77
+ it "should translate key with i18n" do
78
+ expect(@localizer.localize(:name, :name, :label)).to eq('POST.NAME')
79
+ end
80
+
81
+ describe "with caching" do
82
+ it "should not update translation when stored translations change" do
83
+ with_config :i18n_cache_lookups, true do
84
+ expect(@localizer.localize(:name, :name, :label)).to eq('POST.NAME')
85
+ store_post_translations('POST.NEW_NAME')
86
+
87
+ expect(@localizer.localize(:name, :name, :label)).to eq('POST.NAME')
88
+
89
+ Formtastic::Localizer.cache.clear!
90
+ expect(@localizer.localize(:name, :name, :label)).to eq('POST.NEW_NAME')
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "without caching" do
96
+ it "should update translation when stored translations change" do
97
+ with_config :i18n_cache_lookups, false do
98
+ expect(@localizer.localize(:name, :name, :label)).to eq('POST.NAME')
99
+ store_post_translations('POST.NEW_NAME')
100
+ expect(@localizer.localize(:name, :name, :label)).to eq('POST.NEW_NAME')
101
+ end
102
+ end
103
+ end
104
+
105
+ describe "with custom resource name" do
106
+ before do
107
+ ::I18n.backend.store_translations :en, {:formtastic => {
108
+ :labels => {
109
+ :post => { :name => 'POST.NAME' },
110
+ :message => { :name => 'MESSAGE.NAME' }
111
+ }
112
+ }
113
+ }
114
+
115
+ with_config :i18n_lookups_by_default, true do
116
+ semantic_form_for(@new_post, :as => :message) do |builder|
117
+ @localizer = Formtastic::Localizer.new(builder)
118
+ end
119
+ end
120
+ end
121
+
122
+ it "should translate custom key with i18n" do
123
+ expect(@localizer.localize(:name, :name, :label)).to eq('MESSAGE.NAME')
124
+ end
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ end