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,99 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'password 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(:title, :as => :password))
14
+ end)
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class(:password)
18
+ it_should_have_input_wrapper_with_class(:input)
19
+ it_should_have_input_wrapper_with_class(:stringish)
20
+ it_should_have_input_wrapper_with_id("post_title_input")
21
+ it_should_have_label_with_text(/Title/)
22
+ it_should_have_label_for("post_title")
23
+ it_should_have_input_with_id("post_title")
24
+ it_should_have_input_with_type(:password)
25
+ it_should_have_input_with_name("post[title]")
26
+ it_should_have_maxlength_matching_string_column_limit
27
+ it_should_use_default_text_field_size_when_not_nil(:string)
28
+ it_should_not_use_default_text_field_size_when_nil(:string)
29
+ it_should_apply_custom_input_attributes_when_input_html_provided(:string)
30
+ it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
31
+ it_should_apply_error_logic_for_input_type(:password)
32
+
33
+ describe "when no object is provided" do
34
+ before do
35
+ concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
36
+ concat(builder.input(:title, :as => :password))
37
+ end)
38
+ end
39
+
40
+ it_should_have_label_with_text(/Title/)
41
+ it_should_have_label_for("project_title")
42
+ it_should_have_input_with_id("project_title")
43
+ it_should_have_input_with_type(:password)
44
+ it_should_have_input_with_name("project[title]")
45
+ end
46
+
47
+ describe "when namespace is provided" do
48
+
49
+ before do
50
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
51
+ concat(builder.input(:title, :as => :password))
52
+ end)
53
+ end
54
+
55
+ it_should_have_input_wrapper_with_id("context2_post_title_input")
56
+ it_should_have_label_and_input_with_id("context2_post_title")
57
+
58
+ end
59
+
60
+ describe "when index is provided" do
61
+
62
+ before do
63
+ @output_buffer = ActionView::OutputBuffer.new ''
64
+ mock_everything
65
+
66
+ concat(semantic_form_for(@new_post) do |builder|
67
+ concat(builder.fields_for(:author, :index => 3) do |author|
68
+ concat(author.input(:name, :as => :password))
69
+ end)
70
+ end)
71
+ end
72
+
73
+ it 'should index the id of the wrapper' do
74
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
75
+ end
76
+
77
+ it 'should index the id of the select tag' do
78
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
79
+ end
80
+
81
+ it 'should index the name of the select tag' do
82
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
83
+ end
84
+
85
+ end
86
+
87
+
88
+ describe "when required" do
89
+ it "should add the required attribute to the input's html options" do
90
+ with_config :use_required_attribute, true do
91
+ concat(semantic_form_for(@new_post) do |builder|
92
+ concat(builder.input(:title, :as => :password, :required => true))
93
+ end)
94
+ expect(output_buffer.to_str).to have_tag("input[@required]")
95
+ end
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'phone 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(:phone))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:phone)
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_phone_input")
24
+ it_should_have_label_with_text(/Phone/)
25
+ it_should_have_label_for("post_phone")
26
+ it_should_have_input_with_id("post_phone")
27
+ it_should_have_input_with_type(:tel)
28
+ it_should_have_input_with_name("post[phone]")
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(:phone))
37
+ end)
38
+ end
39
+
40
+ it_should_have_input_wrapper_with_id("context2_post_phone_input")
41
+ it_should_have_label_and_input_with_id("context2_post_phone")
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 => :phone))
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 => :phone, :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,71 @@
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
+ after do
14
+ ::I18n.backend.reload!
15
+ end
16
+
17
+ describe "placeholder text" do
18
+
19
+ [:email, :number, :password, :phone, :search, :string, :url, :text, :date_picker, :time_picker, :datetime_picker].each do |type|
20
+
21
+ describe "for #{type} inputs" do
22
+
23
+ describe "when found in i18n" do
24
+ it "should have a placeholder containing i18n text" do
25
+ with_config :i18n_lookups_by_default, true do
26
+ ::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
27
+ concat(semantic_form_for(@new_post) do |builder|
28
+ concat(builder.input(:title, :as => type))
29
+ end)
30
+ expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="War and Peace"]')
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "when not found in i18n" do
36
+ it "should not have placeholder" do
37
+ concat(semantic_form_for(@new_post) do |builder|
38
+ concat(builder.input(:title, :as => type))
39
+ end)
40
+ expect(output_buffer.to_str).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder]')
41
+ end
42
+ end
43
+
44
+ describe "when found in i18n and :input_html" do
45
+ it "should favor :input_html" do
46
+ with_config :i18n_lookups_by_default, true do
47
+ ::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
48
+ concat(semantic_form_for(@new_post) do |builder|
49
+ concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Foo" }))
50
+ end)
51
+ expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Foo"]')
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "when found in :input_html" do
57
+ it "should use the :input_html placeholder" do
58
+ concat(semantic_form_for(@new_post) do |builder|
59
+ concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Untitled" }))
60
+ end)
61
+ expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Untitled"]')
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,326 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'radio input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ describe 'for belongs_to association' do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:author, :as => :radio, :value_as_class => true, :required => true))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class("radio")
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_id("post_author_input")
23
+ it_should_have_a_nested_fieldset
24
+ it_should_have_a_nested_fieldset_with_class('choices')
25
+ it_should_have_a_nested_ordered_list_with_class('choices-group')
26
+ it_should_apply_error_logic_for_input_type(:radio)
27
+ it_should_use_the_collection_when_provided(:radio, 'input')
28
+
29
+ it 'should generate a legend containing a label with text for the input' do
30
+ expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label')
31
+ expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label', :text => /Author/)
32
+ end
33
+
34
+ it 'should not link the label within the legend to any input' do
35
+ expect(output_buffer.to_str).not_to have_tag('form li fieldset legend label[@for]')
36
+ end
37
+
38
+ it 'should generate an ordered list with a list item for each choice' do
39
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol')
40
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li.choice', :count => ::Author.all.size)
41
+ end
42
+
43
+ it 'should have one option with a "checked" attribute' do
44
+ expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 1)
45
+ end
46
+
47
+ describe "each choice" do
48
+
49
+ it 'should not give the choice label the .label class' do
50
+ expect(output_buffer.to_str).not_to have_tag('li.choice label.label')
51
+ end
52
+
53
+ it 'should not add the required attribute to each input' do
54
+ expect(output_buffer.to_str).not_to have_tag('li.choice input[@required]')
55
+ end
56
+
57
+
58
+ it 'should contain a label for the radio input with a nested input and label text' do
59
+ ::Author.all.each do |author|
60
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', /#{author.to_label}/)
61
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
62
+ end
63
+ end
64
+
65
+ it 'should use values as li.class when value_as_class is true' do
66
+ ::Author.all.each do |author|
67
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li.author_#{author.id} label")
68
+ end
69
+ end
70
+
71
+ it "should have a radio input" do
72
+ ::Author.all.each do |author|
73
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
74
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@type='radio']")
75
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
76
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='post[author_id]']")
77
+ end
78
+ end
79
+
80
+ it "should mark input as checked if it's the the existing choice" do
81
+ expect(@new_post.author_id).to eq(@bob.id)
82
+ expect(@new_post.author.id).to eq(@bob.id)
83
+ expect(@new_post.author).to eq(@bob)
84
+
85
+ concat(semantic_form_for(@new_post) do |builder|
86
+ concat(builder.input(:author, :as => :radio))
87
+ end)
88
+
89
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
90
+ end
91
+
92
+ it "should mark the input as disabled if options attached for disabling" do
93
+ concat(semantic_form_for(@new_post) do |builder|
94
+ concat(builder.input(:author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]))
95
+ end)
96
+
97
+ expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@value='test'][@disabled='disabled']")
98
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='try'][@disabled='disabled']")
99
+ end
100
+
101
+ it "should not contain invalid HTML attributes" do
102
+
103
+ concat(semantic_form_for(@new_post) do |builder|
104
+ concat(builder.input(:author, :as => :radio))
105
+ end)
106
+
107
+ expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li input[@find_options]")
108
+ end
109
+
110
+ end
111
+
112
+ describe 'and no object is given' do
113
+ before(:example) do
114
+ @output_buffer = ActionView::OutputBuffer.new ''
115
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
116
+ concat(builder.input(:author_id, :as => :radio, :collection => ::Author.all))
117
+ end)
118
+ end
119
+
120
+ it 'should generate a fieldset with legend' do
121
+ expect(output_buffer.to_str).to have_tag('form li fieldset legend', :text => /Author/)
122
+ end
123
+
124
+ it 'should generate an li tag for each item in the collection' do
125
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li', :count => ::Author.all.size)
126
+ end
127
+
128
+ it 'should generate labels for each item' do
129
+ ::Author.all.each do |author|
130
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
131
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
132
+ end
133
+ end
134
+
135
+ it 'should html escape the label string' do
136
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
137
+ concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
138
+ end)
139
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2)
140
+ end
141
+
142
+ it 'should generate inputs for each item' do
143
+ ::Author.all.each do |author|
144
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
145
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@type='radio']")
146
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
147
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='project[author_id]']")
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ describe 'for a enum column' do
154
+ before do
155
+ allow(@new_post).to receive(:status) { 'inactive' }
156
+ statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
157
+ allow(@new_post.class).to receive(:statuses) { statuses }
158
+ allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
159
+ end
160
+
161
+ before do
162
+ concat(semantic_form_for(@new_post) do |builder|
163
+ concat(builder.input(:status, :as => :radio))
164
+ end)
165
+ end
166
+
167
+ it 'should have a radio input for each defined enum status' do
168
+ expect(output_buffer.to_str).to have_tag("form li input[@name='post[status]'][@type='radio']", :count => @new_post.class.statuses.count)
169
+ @new_post.class.statuses.each do |label, value|
170
+ expect(output_buffer.to_str).to have_tag("form li input[@value='#{label}']")
171
+ expect(output_buffer.to_str).to have_tag("form li label", :text => /#{label.humanize}/)
172
+ end
173
+ end
174
+
175
+ it 'should have one radio input with a "checked" attribute' do
176
+ expect(output_buffer.to_str).to have_tag("form li input[@name='post[status]'][@checked]", :count => 1)
177
+ end
178
+ end
179
+
180
+
181
+ describe "with i18n of the legend label" do
182
+
183
+ before do
184
+ ::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
185
+
186
+ with_config :i18n_lookups_by_default, true do
187
+ allow(@new_post).to receive(:author_ids).and_return(nil)
188
+ concat(semantic_form_for(@new_post) do |builder|
189
+ concat(builder.input(:authors, :as => :radio))
190
+ end)
191
+ end
192
+ end
193
+
194
+ after do
195
+ ::I18n.backend.reload!
196
+ end
197
+
198
+ it "should do foo" do
199
+ expect(output_buffer.to_str).to have_tag("legend.label label", :text => /Translated/)
200
+ end
201
+
202
+ end
203
+
204
+ describe "when :label option is set" do
205
+ before do
206
+ allow(@new_post).to receive(:author_ids).and_return(nil)
207
+ concat(semantic_form_for(@new_post) do |builder|
208
+ concat(builder.input(:authors, :as => :radio, :label => 'The authors'))
209
+ end)
210
+ end
211
+
212
+ it "should output the correct label title" do
213
+ expect(output_buffer.to_str).to have_tag("legend.label label", :text => /The authors/)
214
+ end
215
+ end
216
+
217
+ describe "when :label option is false" do
218
+ before do
219
+ @output_buffer = ActionView::OutputBuffer.new ''
220
+ allow(@new_post).to receive(:author_ids).and_return(nil)
221
+ concat(semantic_form_for(@new_post) do |builder|
222
+ concat(builder.input(:authors, :as => :radio, :label => false))
223
+ end)
224
+ end
225
+
226
+ it "should not output the legend" do
227
+ expect(output_buffer.to_str).not_to have_tag("legend.label")
228
+ expect(output_buffer.to_str).not_to include("&gt;")
229
+ end
230
+
231
+ it "should not cause escaped HTML" do
232
+ expect(output_buffer.to_str).not_to include("&gt;")
233
+ end
234
+ end
235
+
236
+ describe "when :required option is true" do
237
+ before do
238
+ allow(@new_post).to receive(:author_ids).and_return(nil)
239
+ concat(semantic_form_for(@new_post) do |builder|
240
+ concat(builder.input(:authors, :as => :radio, :required => true))
241
+ end)
242
+ end
243
+
244
+ it "should output the correct label title" do
245
+ expect(output_buffer.to_str).to have_tag("legend.label label abbr")
246
+ end
247
+ end
248
+
249
+ describe "when :namespace is given on form" do
250
+ before do
251
+ @output_buffer = ActionView::OutputBuffer.new ''
252
+ allow(@new_post).to receive(:author_ids).and_return(nil)
253
+ concat(semantic_form_for(@new_post, :namespace => "custom_prefix") do |builder|
254
+ concat(builder.input(:authors, :as => :radio, :label => ''))
255
+ end)
256
+
257
+ expect(output_buffer.to_str).to match(/for="custom_prefix_post_author_ids_(\d+)"/)
258
+ expect(output_buffer.to_str).to match(/id="custom_prefix_post_author_ids_(\d+)"/)
259
+ end
260
+ it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
261
+ end
262
+
263
+ describe "when index is provided" do
264
+
265
+ before do
266
+ @output_buffer = ActionView::OutputBuffer.new ''
267
+ mock_everything
268
+
269
+ concat(semantic_form_for(@new_post) do |builder|
270
+ concat(builder.fields_for(:author, :index => 3) do |author|
271
+ concat(author.input(:name, :as => :radio))
272
+ end)
273
+ end)
274
+ end
275
+
276
+ it 'should index the id of the wrapper' do
277
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
278
+ end
279
+
280
+ it 'should index the id of the select tag' do
281
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name_true")
282
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name_false")
283
+ end
284
+
285
+ it 'should index the name of the select tag' do
286
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
287
+ end
288
+
289
+ end
290
+
291
+ describe "when collection contains integers" do
292
+ before do
293
+ @output_buffer = ActionView::OutputBuffer.new ''
294
+ mock_everything
295
+
296
+ concat(semantic_form_for(:project) do |builder|
297
+ concat(builder.input(:author_id, :as => :radio, :collection => [1, 2, 3]))
298
+ end)
299
+ end
300
+
301
+ it 'should output the correct labels' do
302
+ expect(output_buffer.to_str).to have_tag("li.choice label", :text => /1/)
303
+ expect(output_buffer.to_str).to have_tag("li.choice label", :text => /2/)
304
+ expect(output_buffer.to_str).to have_tag("li.choice label", :text => /3/)
305
+ end
306
+ end
307
+
308
+ describe "when collection contains symbols" do
309
+ before do
310
+ @output_buffer = ActionView::OutputBuffer.new ''
311
+ mock_everything
312
+
313
+ concat(semantic_form_for(:project) do |builder|
314
+ concat(builder.input(:author_id, :as => :radio, :collection => Set.new([["A", :a], ["B", :b], ["C", :c]])))
315
+ end)
316
+ end
317
+
318
+ it 'should output the correct labels' do
319
+ expect(output_buffer.to_str).to have_tag("li.choice label", :text => /A/)
320
+ expect(output_buffer.to_str).to have_tag("li.choice label", :text => /B/)
321
+ expect(output_buffer.to_str).to have_tag("li.choice label", :text => /C/)
322
+ end
323
+ end
324
+
325
+
326
+ end