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,133 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'country 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 country_select is not available as a helper from a plugin" do
14
+
15
+ it "should raise an error, suggesting the author installs a plugin" do
16
+ expect {
17
+ semantic_form_for(@new_post) do |builder|
18
+ concat(builder.input(:country, :as => :country))
19
+ end
20
+ }.to raise_error(Formtastic::Inputs::CountryInput::CountrySelectPluginMissing)
21
+ end
22
+
23
+ end
24
+
25
+ describe "when country_select is available as a helper (from a plugin)" do
26
+
27
+ before do
28
+ concat(semantic_form_for(@new_post) do |builder|
29
+ allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
30
+ concat(builder.input(:country, :as => :country))
31
+ end)
32
+ end
33
+
34
+ it_should_have_input_wrapper_with_class("country")
35
+ it_should_have_input_wrapper_with_class(:input)
36
+ it_should_have_input_wrapper_with_id("post_country_input")
37
+
38
+ # TODO -- needs stubbing inside the builder block, tricky!
39
+ #it_should_apply_error_logic_for_input_type(:country)
40
+
41
+ it 'should generate a label for the input' do
42
+ expect(output_buffer.to_str).to have_tag('form li label')
43
+ expect(output_buffer.to_str).to have_tag('form li label[@for="post_country"]')
44
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Country/)
45
+ end
46
+
47
+ it "should generate a select" do
48
+ expect(output_buffer.to_str).to have_tag("form li select")
49
+ end
50
+
51
+ end
52
+
53
+ describe ":priority_countries option" do
54
+
55
+ it "should be passed down to the country_select helper when provided" do
56
+ priority_countries = ["Foo", "Bah"]
57
+ semantic_form_for(@new_post) do |builder|
58
+ allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
59
+ expect(builder).to receive(:country_select).with(:country, { :priority_countries => priority_countries }, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
60
+
61
+ concat(builder.input(:country, :as => :country, :priority_countries => priority_countries))
62
+ end
63
+ end
64
+
65
+ it "should default to the @@priority_countries config when absent" do
66
+ priority_countries = Formtastic::FormBuilder.priority_countries
67
+ expect(priority_countries).not_to be_empty
68
+ expect(priority_countries).not_to be_nil
69
+
70
+ semantic_form_for(@new_post) do |builder|
71
+ allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
72
+ expect(builder).to receive(:country_select).with(:country, { :priority_countries => priority_countries }, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
73
+
74
+ concat(builder.input(:country, :as => :country))
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ describe "when namespace is provided" do
81
+
82
+ before do
83
+ @output_buffer = ActionView::OutputBuffer.new ''
84
+ mock_everything
85
+
86
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
87
+ allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
88
+ expect(builder).to receive(:country_select).with(:country, { :priority_countries => [] }, {:id => "context2_post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
89
+ concat(builder.input(:country, :priority_countries => []))
90
+ end)
91
+ end
92
+
93
+ it_should_have_input_wrapper_with_id("context2_post_country_input")
94
+ it_should_have_label_for("context2_post_country")
95
+
96
+ end
97
+
98
+ describe "matching" do
99
+
100
+ describe "when the attribute is 'country'" do
101
+
102
+ before do
103
+ concat(semantic_form_for(@new_post) do |builder|
104
+ allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
105
+ concat(builder.input(:country))
106
+ end)
107
+ end
108
+
109
+ it "should render a country input" do
110
+ expect(output_buffer.to_str).to have_tag "form li.country"
111
+ end
112
+ end
113
+
114
+ describe "when the attribute is 'country_something'" do
115
+
116
+ before do
117
+ concat(semantic_form_for(@new_post) do |builder|
118
+ concat(builder.input(:country_subdivision))
119
+ concat(builder.input(:country_code))
120
+ end)
121
+ end
122
+
123
+ it "should render a country input" do
124
+ expect(output_buffer.to_str).not_to have_tag "form li.country"
125
+ expect(output_buffer.to_str).to have_tag "form li.string", :count => 2
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+ end
133
+
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ # TODO extract out
5
+ module TestInputs
6
+
7
+ def input_args
8
+ @template = self
9
+ @object = ::Post.new
10
+ @object_name = 'post'
11
+ @method = :title
12
+ @options = {}
13
+ @proc = Proc.new {}
14
+ @builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options)
15
+ [@builder, @template, @object, @object_name, @method, @options]
16
+ end
17
+
18
+ class ::UnimplementedInput
19
+ include Formtastic::Inputs::Base
20
+ end
21
+
22
+ class ::ImplementedInput < UnimplementedInput
23
+ def to_html
24
+ "some HTML output"
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ RSpec.describe 'AnyCustomInput' do
31
+
32
+ include TestInputs
33
+
34
+ describe "#to_html" do
35
+
36
+ describe 'without an implementation' do
37
+ it "should raise a NotImplementedError exception" do
38
+ expect { ::UnimplementedInput.new(*input_args).to_html }.to raise_error(NotImplementedError)
39
+ end
40
+ end
41
+
42
+ describe 'with an implementation' do
43
+ it "should raise a NotImplementedError exception" do
44
+ expect { ::ImplementedInput.new(*input_args).to_html }.to_not raise_error
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe "datalist inputs" do
5
+ include FormtasticSpecHelper
6
+
7
+ before do
8
+ @output_buffer = ActionView::OutputBuffer.new ''
9
+ mock_everything
10
+ end
11
+
12
+ describe "renders correctly" do
13
+ lists_without_values =[
14
+ %w(a b c),
15
+ ["a", "b", "c"],
16
+ ("a".."c")
17
+ ]
18
+ lists_with_values = [
19
+ {a: 1, b: 2, c:3},
20
+ {"a" => 1, "b" => 2, "c" =>3},
21
+ [["a",1], ["b",2], ["c", 3]]
22
+ ]
23
+
24
+ def self.common_tests(list)
25
+ it_should_have_label_with_text(/Document/)
26
+ it_should_have_label_for("post_document")
27
+ it_should_have_input_wrapper_with_class(:datalist)
28
+ it_should_have_input_with(id: "post_document", type: :text, list:"post_document_datalist")
29
+ it_should_have_tag_with(:datalist, id: "post_document_datalist" )
30
+ it_should_have_many_tags(:option, list.count)
31
+ end
32
+
33
+ context "Rendering list of simple items" do
34
+ lists_without_values.each do |list|
35
+ describe "renders #{list.to_s} correctly" do
36
+ before do
37
+ concat(semantic_form_for(@new_post) do |builder|
38
+ concat(builder.input(:document, as: :datalist, collection: list))
39
+ end)
40
+ end
41
+ common_tests list
42
+ it_should_have_tag_with :option, value: list.first
43
+ end
44
+ end
45
+ end
46
+
47
+ context "Rendering list of complex items, key-value pairs and such" do
48
+ lists_with_values.each do |list|
49
+ describe "renders #{list.to_s} correctly" do
50
+ before do
51
+ concat(semantic_form_for(@new_post) do |builder|
52
+ concat(builder.input(:document, as: :datalist, collection: list))
53
+ end)
54
+ end
55
+ common_tests list
56
+ it_should_have_tag_with :option, value: list.first.last
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,449 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'date_picker input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ context "with an object" do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:publish_at, :as => :date_picker))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:date_picker)
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_publish_at_input")
24
+ it_should_have_label_with_text(/Publish at/)
25
+ it_should_have_label_for("post_publish_at")
26
+ it_should_have_input_with_id("post_publish_at")
27
+ it_should_have_input_with_type(:date)
28
+ it_should_have_input_with_name("post[publish_at]")
29
+ it_should_apply_custom_input_attributes_when_input_html_provided(:date_picker)
30
+ it_should_apply_custom_for_to_label_when_input_html_id_provided(:date_picker)
31
+ # TODO why does this blow-up it_should_apply_error_logic_for_input_type(:date_picker)
32
+
33
+ end
34
+
35
+ describe "size attribute" do
36
+
37
+ it "defaults to 10 chars (YYYY-YY-YY)" do
38
+ concat(
39
+ semantic_form_for(@new_post) do |f|
40
+ concat(f.input(:publish_at, :as => :date_picker))
41
+ end
42
+ )
43
+ expect(output_buffer.to_str).to have_tag "input[size='10']"
44
+ end
45
+
46
+ it "can be set from :input_html options" do
47
+ concat(
48
+ semantic_form_for(@new_post) do |f|
49
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :size => "11" }))
50
+ end
51
+ )
52
+ expect(output_buffer.to_str).to have_tag "input[size='11']"
53
+ end
54
+
55
+ it "can be set from options (ignoring input_html)" do
56
+ concat(
57
+ semantic_form_for(@new_post) do |f|
58
+ concat(f.input(:publish_at, :as => :date_picker, :size => '12', :input_html => { :size => "11" }))
59
+ end
60
+ )
61
+ expect(output_buffer.to_str).to have_tag "input[size='12']"
62
+ end
63
+
64
+ end
65
+
66
+ describe "maxlength attribute" do
67
+
68
+ it "defaults to 10 chars (YYYY-YY-YY)" do
69
+ concat(
70
+ semantic_form_for(@new_post) do |f|
71
+ concat(f.input(:publish_at, :as => :date_picker))
72
+ end
73
+ )
74
+ expect(output_buffer.to_str).to have_tag "input[maxlength='10']"
75
+ end
76
+
77
+ it "can be set from :input_html options" do
78
+ concat(
79
+ semantic_form_for(@new_post) do |f|
80
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :maxlength => "11" }))
81
+ end
82
+ )
83
+ expect(output_buffer.to_str).to have_tag "input[maxlength='11']"
84
+ end
85
+
86
+ it "can be set from options (ignoring input_html)" do
87
+ concat(
88
+ semantic_form_for(@new_post) do |f|
89
+ concat(f.input(:publish_at, :as => :date_picker, :maxlength => 12, :input_html => { :maxlength => "11" }))
90
+ end
91
+ )
92
+ expect(output_buffer.to_str).to have_tag "input[maxlength='12']"
93
+ end
94
+
95
+ end
96
+
97
+ describe "value attribute" do
98
+
99
+ context "when method returns nil" do
100
+
101
+ it "has no value" do
102
+ concat(
103
+ semantic_form_for(@new_post) do |f|
104
+ concat(f.input(:publish_at, :as => :date_picker ))
105
+ end
106
+ )
107
+ expect(output_buffer.to_str).not_to have_tag "li input[value]"
108
+ end
109
+
110
+ it "can be set from :input_html options" do
111
+ concat(
112
+ semantic_form_for(@new_post) do |f|
113
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
114
+ end
115
+ )
116
+ expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
117
+ end
118
+
119
+ end
120
+
121
+ context "when method returns a Date" do
122
+
123
+ before do
124
+ @date = Date.new(2000, 11, 11)
125
+ allow(@new_post).to receive(:publish_at).and_return(@date)
126
+ end
127
+
128
+ it "renders the date as YYYY-MM-DD" do
129
+ concat(
130
+ semantic_form_for(@new_post) do |f|
131
+ concat(f.input(:publish_at, :as => :date_picker ))
132
+ end
133
+ )
134
+ expect(output_buffer.to_str).to have_tag "input[value='#{@date.to_s}']"
135
+ end
136
+
137
+ it "can be set from :input_html options" do
138
+ concat(
139
+ semantic_form_for(@new_post) do |f|
140
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
141
+ end
142
+ )
143
+ expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
144
+ end
145
+
146
+ end
147
+
148
+ context "when method returns a Time" do
149
+
150
+ before do
151
+ @time = Time.utc(2000,11,11,11,11,11)
152
+ allow(@new_post).to receive(:publish_at).and_return(@time)
153
+ end
154
+
155
+ it "renders the time as a YYYY-MM-DD" do
156
+ concat(
157
+ semantic_form_for(@new_post) do |f|
158
+ concat(f.input(:publish_at, :as => :date_picker ))
159
+ end
160
+ )
161
+ expect(output_buffer.to_str).to have_tag "input[value='2000-11-11']"
162
+ end
163
+
164
+ it "can be set from :input_html options" do
165
+ concat(
166
+ semantic_form_for(@new_post) do |f|
167
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
168
+ end
169
+ )
170
+ expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
171
+ end
172
+
173
+ end
174
+
175
+ context "when method returns an empty String" do
176
+
177
+ before do
178
+ allow(@new_post).to receive(:publish_at).and_return("")
179
+ end
180
+
181
+ it "will be empty" do
182
+ concat(
183
+ semantic_form_for(@new_post) do |f|
184
+ concat(f.input(:publish_at, :as => :date_picker ))
185
+ end
186
+ )
187
+ expect(output_buffer.to_str).to have_tag "input[value='']"
188
+ end
189
+
190
+ it "can be set from :input_html options" do
191
+ concat(
192
+ semantic_form_for(@new_post) do |f|
193
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
194
+ end
195
+ )
196
+ expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
197
+ end
198
+
199
+ end
200
+
201
+ context "when method returns a String" do
202
+
203
+ before do
204
+ allow(@new_post).to receive(:publish_at).and_return("yeah")
205
+ end
206
+
207
+ it "will be the string" do
208
+ concat(
209
+ semantic_form_for(@new_post) do |f|
210
+ concat(f.input(:publish_at, :as => :date_picker ))
211
+ end
212
+ )
213
+ expect(output_buffer.to_str).to have_tag "input[value='yeah']"
214
+ end
215
+
216
+ it "can be set from :input_html options" do
217
+ concat(
218
+ semantic_form_for(@new_post) do |f|
219
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
220
+ end
221
+ )
222
+ expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
223
+ end
224
+
225
+ end
226
+
227
+ end
228
+
229
+ describe "min attribute" do
230
+
231
+ it "will be omitted by default" do
232
+ concat(
233
+ semantic_form_for(@new_post) do |f|
234
+ concat(f.input(:publish_at, :as => :date_picker))
235
+ end
236
+ )
237
+ expect(output_buffer.to_str).not_to have_tag "input[min]"
238
+ end
239
+
240
+ it "can be set from :input_html options" do
241
+ concat(
242
+ semantic_form_for(@new_post) do |f|
243
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :min => "1970-01-01" }))
244
+ end
245
+ )
246
+ expect(output_buffer.to_str).to have_tag "input[min='1970-01-01']"
247
+ end
248
+
249
+ end
250
+
251
+ describe "max attribute" do
252
+
253
+ it "will be omitted by default" do
254
+ concat(
255
+ semantic_form_for(@new_post) do |f|
256
+ concat(f.input(:publish_at, :as => :date_picker))
257
+ end
258
+ )
259
+ expect(output_buffer.to_str).not_to have_tag "input[max]"
260
+ end
261
+
262
+ it "can be set from :input_html options" do
263
+ concat(
264
+ semantic_form_for(@new_post) do |f|
265
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :max => "1970-01-01" }))
266
+ end
267
+ )
268
+ expect(output_buffer.to_str).to have_tag "input[max='1970-01-01']"
269
+ end
270
+
271
+ end
272
+
273
+ describe "step attribute" do
274
+
275
+ it "defaults to 1" do
276
+ concat(
277
+ semantic_form_for(@new_post) do |f|
278
+ concat(f.input(:publish_at, :as => :date_picker))
279
+ end
280
+ )
281
+ expect(output_buffer.to_str).to have_tag "input[step='1']"
282
+ end
283
+
284
+ it "can be set from :input_html options" do
285
+ concat(
286
+ semantic_form_for(@new_post) do |f|
287
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :step => "5" }))
288
+ end
289
+ )
290
+ expect(output_buffer.to_str).to have_tag "input[step='5']"
291
+ end
292
+
293
+ describe "macros" do
294
+
295
+ before do
296
+ concat(
297
+ semantic_form_for(@new_post) do |f|
298
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :step => step }))
299
+ end
300
+ )
301
+ end
302
+
303
+ context ":day" do
304
+ let(:step) { :day }
305
+ it "uses 1" do
306
+ expect(output_buffer.to_str).to have_tag "input[step='1']"
307
+ end
308
+ end
309
+
310
+ context ":seven_days" do
311
+ let(:step) { :seven_days }
312
+ it "uses 7" do
313
+ expect(output_buffer.to_str).to have_tag "input[step='7']"
314
+ end
315
+ end
316
+
317
+ context ":week" do
318
+ let(:step) { :week }
319
+ it "uses 7" do
320
+ expect(output_buffer.to_str).to have_tag "input[step='7']"
321
+ end
322
+ end
323
+
324
+ context ":fortnight" do
325
+ let(:step) { :fortnight }
326
+ it "uses 14" do
327
+ expect(output_buffer.to_str).to have_tag "input[step='14']"
328
+ end
329
+ end
330
+
331
+ context ":two_weeks" do
332
+ let(:step) { :two_weeks }
333
+ it "uses 14" do
334
+ expect(output_buffer.to_str).to have_tag "input[step='14']"
335
+ end
336
+ end
337
+
338
+ context ":four_weeks" do
339
+ let(:step) { :four_weeks }
340
+ it "uses 28" do
341
+ expect(output_buffer.to_str).to have_tag "input[step='28']"
342
+ end
343
+ end
344
+
345
+ context ":thirty_days" do
346
+ let(:step) { :thirty_days }
347
+ it "uses 30" do
348
+ expect(output_buffer.to_str).to have_tag "input[step='30']"
349
+ end
350
+ end
351
+
352
+ end
353
+
354
+ end
355
+
356
+ describe "placeholder attribute" do
357
+
358
+ it "will be omitted" do
359
+ concat(
360
+ semantic_form_for(@new_post) do |f|
361
+ concat(f.input(:publish_at, :as => :date_picker))
362
+ end
363
+ )
364
+ expect(output_buffer.to_str).not_to have_tag "input[placeholder]"
365
+ end
366
+
367
+ it "can be set from :input_html options" do
368
+ concat(
369
+ semantic_form_for(@new_post) do |f|
370
+ concat(f.input(:publish_at, :as => :date_picker, :input_html => { :placeholder => "1970-01-01" }))
371
+ end
372
+ )
373
+ expect(output_buffer.to_str).to have_tag "input[placeholder='1970-01-01']"
374
+ end
375
+
376
+ context "with i18n set" do
377
+ before do
378
+ ::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :publish_at => 'YYYY-MM-DD' }}
379
+ end
380
+
381
+ it "can be set with i18n" do
382
+ with_config :i18n_lookups_by_default, true do
383
+ concat(semantic_form_for(@new_post) do |builder|
384
+ concat(builder.input(:publish_at, :as => :date_picker))
385
+ end)
386
+ expect(output_buffer.to_str).to have_tag('input[@placeholder="YYYY-MM-DD"]')
387
+ end
388
+ end
389
+
390
+ it "can be set with input_html, trumping i18n" do
391
+ with_config :i18n_lookups_by_default, true do
392
+ concat(semantic_form_for(@new_post) do |builder|
393
+ concat(builder.input(:publish_at, :as => :date_picker, :input_html => { :placeholder => "Something" }))
394
+ end)
395
+ expect(output_buffer.to_str).to have_tag('input[@placeholder="Something"]')
396
+ end
397
+ end
398
+ end
399
+
400
+ end
401
+
402
+ describe "when namespace is provided" do
403
+ before do
404
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
405
+ concat(builder.input(:publish_at, :as => :date_picker))
406
+ end)
407
+ end
408
+
409
+ it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
410
+ it_should_have_label_and_input_with_id("context2_post_publish_at")
411
+ end
412
+
413
+ describe "when index is provided" do
414
+ before do
415
+ @output_buffer = ActionView::OutputBuffer.new ''
416
+ mock_everything
417
+
418
+ concat(semantic_form_for(@new_post) do |builder|
419
+ concat(builder.fields_for(:author, :index => 3) do |author|
420
+ concat(author.input(:created_at, :as => :date_picker))
421
+ end)
422
+ end)
423
+ end
424
+
425
+ it 'should index the id of the wrapper' do
426
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_created_at_input")
427
+ end
428
+
429
+ it 'should index the id of the select tag' do
430
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at")
431
+ end
432
+
433
+ it 'should index the name of the select tag' do
434
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at]']")
435
+ end
436
+ end
437
+
438
+ describe "when required" do
439
+ it "should add the required attribute to the input's html options" do
440
+ with_config :use_required_attribute, true do
441
+ concat(semantic_form_for(@new_post) do |builder|
442
+ concat(builder.input(:publish_at, :as => :date_picker, :required => true))
443
+ end)
444
+ expect(output_buffer.to_str).to have_tag("input[@required]")
445
+ end
446
+ end
447
+ end
448
+
449
+ end