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,85 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'email 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(:email))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:email)
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_email_input")
24
+ it_should_have_label_with_text(/Email/)
25
+ it_should_have_label_for("post_email")
26
+ it_should_have_input_with_id("post_email")
27
+ it_should_have_input_with_type(:email)
28
+ it_should_have_input_with_name("post[email]")
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(:email))
37
+ end)
38
+ end
39
+
40
+ it_should_have_input_wrapper_with_id("context2_post_email_input")
41
+ it_should_have_label_and_input_with_id("context2_post_email")
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 => :email))
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 => :email, :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,89 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'file 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(:body, :as => :file))
14
+ end)
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class("file")
18
+ it_should_have_input_wrapper_with_class(:input)
19
+ it_should_have_input_wrapper_with_id("post_body_input")
20
+ it_should_have_label_with_text(/Body/)
21
+ it_should_have_label_for("post_body")
22
+ it_should_have_input_with_id("post_body")
23
+ it_should_have_input_with_name("post[body]")
24
+ it_should_apply_error_logic_for_input_type(:file)
25
+
26
+ it 'should use input_html to style inputs' do
27
+ concat(semantic_form_for(@new_post) do |builder|
28
+ concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
29
+ end)
30
+ expect(output_buffer.to_str).to have_tag("form li input.myclass")
31
+ end
32
+
33
+ describe "when namespace is provided" do
34
+
35
+ before do
36
+ @output_buffer = ActionView::OutputBuffer.new ''
37
+ mock_everything
38
+
39
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
40
+ concat(builder.input(:body, :as => :file))
41
+ end)
42
+ end
43
+
44
+ it_should_have_input_wrapper_with_id("context2_post_body_input")
45
+ it_should_have_label_and_input_with_id("context2_post_body")
46
+
47
+ end
48
+
49
+ describe "when index is provided" do
50
+
51
+ before do
52
+ @output_buffer = ActionView::OutputBuffer.new ''
53
+ mock_everything
54
+
55
+ concat(semantic_form_for(@new_post) do |builder|
56
+ concat(builder.fields_for(:author, :index => 3) do |author|
57
+ concat(author.input(:name, :as => :file))
58
+ end)
59
+ end)
60
+ end
61
+
62
+ it 'should index the id of the wrapper' do
63
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
64
+ end
65
+
66
+ it 'should index the id of the select tag' do
67
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
68
+ end
69
+
70
+ it 'should index the name of the select tag' do
71
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
72
+ end
73
+
74
+ end
75
+
76
+
77
+ context "when required" do
78
+ it "should add the required attribute to the input's html options" do
79
+ with_config :use_required_attribute, true do
80
+ concat(semantic_form_for(@new_post) do |builder|
81
+ concat(builder.input(:title, :as => :file, :required => true))
82
+ end)
83
+ expect(output_buffer.to_str).to have_tag("input[@required]")
84
+ end
85
+ end
86
+ end
87
+
88
+ end
89
+
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'hidden 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(:secret, :as => :hidden))
14
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
15
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
16
+ end)
17
+ end
18
+
19
+ it_should_have_input_wrapper_with_class("hidden")
20
+ it_should_have_input_wrapper_with_class(:input)
21
+ it_should_have_input_wrapper_with_id("post_secret_input")
22
+ it_should_not_have_a_label
23
+
24
+ it "should generate a input field" do
25
+ expect(output_buffer.to_str).to have_tag("form li input#post_secret")
26
+ expect(output_buffer.to_str).to have_tag("form li input#post_secret[@type=\"hidden\"]")
27
+ expect(output_buffer.to_str).to have_tag("form li input#post_secret[@name=\"post[secret]\"]")
28
+ end
29
+
30
+ it "should get value from the object" do
31
+ expect(output_buffer.to_str).to have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
32
+ end
33
+
34
+ it "should pass any explicitly specified value - using :input_html options" do
35
+ expect(output_buffer.to_str).to have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
36
+ end
37
+
38
+ it "should pass any option specified using :input_html" do
39
+ expect(output_buffer.to_str).to have_tag("form li input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
40
+ end
41
+
42
+ it "should not render inline errors" do
43
+ @errors = double('errors')
44
+ allow(@errors).to receive(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
45
+ allow(@new_post).to receive(:errors).and_return(@errors)
46
+
47
+ concat(semantic_form_for(@new_post) do |builder|
48
+ concat(builder.input(:secret, :as => :hidden))
49
+ end)
50
+
51
+ expect(output_buffer.to_str).not_to have_tag("form li p.inline-errors")
52
+ expect(output_buffer.to_str).not_to have_tag("form li ul.errors")
53
+ end
54
+
55
+ it "should not render inline hints" do
56
+ concat(semantic_form_for(@new_post) do |builder|
57
+ concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
58
+ end)
59
+
60
+ expect(output_buffer.to_str).not_to have_tag("form li p.inline-hints")
61
+ expect(output_buffer.to_str).not_to have_tag("form li ul.hints")
62
+ end
63
+
64
+ describe "when namespace is provided" do
65
+
66
+ before do
67
+ @output_buffer = ActionView::OutputBuffer.new ''
68
+ mock_everything
69
+
70
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
71
+ concat(builder.input(:secret, :as => :hidden))
72
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
73
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
74
+ end)
75
+ end
76
+
77
+ attributes_to_check = [:secret, :published, :reviewer]
78
+ attributes_to_check.each do |a|
79
+ it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
80
+ end
81
+
82
+ (attributes_to_check - [:reviewer]).each do |a|
83
+ it_should_have_input_with_id("context2_post_#{a}")
84
+ end
85
+
86
+ end
87
+
88
+ describe "when index is provided" do
89
+
90
+ before do
91
+ @output_buffer = ActionView::OutputBuffer.new ''
92
+ mock_everything
93
+
94
+ concat(semantic_form_for(@new_post) do |builder|
95
+ concat(builder.fields_for(:author, :index => 3) do |author|
96
+ concat(author.input(:name, :as => :hidden))
97
+ end)
98
+ end)
99
+ end
100
+
101
+ it 'should index the id of the wrapper' do
102
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
103
+ end
104
+
105
+ it 'should index the id of the select tag' do
106
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
107
+ end
108
+
109
+ it 'should index the name of the select tag' do
110
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
111
+ end
112
+
113
+ end
114
+
115
+
116
+ context "when required" do
117
+ it "should not add the required attribute to the input's html options" do
118
+ concat(semantic_form_for(@new_post) do |builder|
119
+ concat(builder.input(:title, :as => :hidden, :required => true))
120
+ end)
121
+ expect(output_buffer.to_str).not_to have_tag("input[@required]")
122
+ end
123
+ end
124
+
125
+ context "when :autofocus is provided in :input_html" do
126
+ it "should not add the autofocus attribute to the input's html options" do
127
+ concat(semantic_form_for(@new_post) do |builder|
128
+ concat(builder.input(:title, :as => :hidden, :input_html => {:autofocus => true}))
129
+ end)
130
+ expect(output_buffer.to_str).not_to have_tag("input[@autofocus]")
131
+ end
132
+ end
133
+
134
+ end
135
+
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe "*select: options[:include_blank]" do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+
12
+ allow(@new_post).to receive(:author_id).and_return(nil)
13
+ allow(@new_post).to receive(:publish_at).and_return(nil)
14
+ end
15
+
16
+ SELECT_INPUT_TYPES = {
17
+ :select => :author,
18
+ :datetime_select => :publish_at,
19
+ :date_select => :publish_at,
20
+ :time_select => :publish_at
21
+ }
22
+
23
+ SELECT_INPUT_TYPES.each do |as, attribute|
24
+ describe "for #{as} input" do
25
+
26
+ describe 'when :include_blank is not set' do
27
+ it 'blank value should be included if the default value specified in config is true' do
28
+ Formtastic::FormBuilder.include_blank_for_select_by_default = true
29
+ concat(semantic_form_for(@new_post) do |builder|
30
+ concat(builder.input(attribute, :as => as))
31
+ end)
32
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']", "")
33
+ end
34
+
35
+ it 'blank value should not be included if the default value specified in config is false' do
36
+ Formtastic::FormBuilder.include_blank_for_select_by_default = false
37
+ concat(semantic_form_for(@new_post) do |builder|
38
+ concat(builder.input(attribute, :as => as))
39
+ end)
40
+ expect(output_buffer.to_str).not_to have_tag("form li select option[@value='']", "")
41
+ end
42
+
43
+ after do
44
+ Formtastic::FormBuilder.include_blank_for_select_by_default = true
45
+ end
46
+ end
47
+
48
+ describe 'when :include_blank is set to false' do
49
+ it 'should not have a blank option' do
50
+ concat(semantic_form_for(@new_post) do |builder|
51
+ concat(builder.input(attribute, :as => as, :include_blank => false))
52
+ end)
53
+ expect(output_buffer.to_str).not_to have_tag("form li select option[@value='']", "")
54
+ end
55
+ end
56
+
57
+ describe 'when :include_blank is set to true' do
58
+ it 'should have a blank select option' do
59
+ concat(semantic_form_for(@new_post) do |builder|
60
+ concat(builder.input(attribute, :as => as, :include_blank => true))
61
+ end)
62
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']", "")
63
+ end
64
+ end
65
+
66
+ if as == :select
67
+ describe 'when :include_blank is set to a string' do
68
+ it 'should have a select option with blank value but that string as text' do
69
+ concat(semantic_form_for(@new_post) do |builder|
70
+ concat(builder.input(attribute, :as => as, :include_blank => 'string'))
71
+ end)
72
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']", "string")
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'Formtastic::FormBuilder#label' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ it 'should add "required string" only once with caching enabled' do
14
+ with_config :i18n_cache_lookups, true do
15
+ ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => "I18n title" } } } }
16
+ required_string = "[req_string]"
17
+ default_required_str = Formtastic::FormBuilder.required_string
18
+ Formtastic::FormBuilder.required_string = required_string
19
+
20
+ concat(semantic_form_for(@new_post) do |builder|
21
+ builder.input(:title, :required => true, :label => true)
22
+ end)
23
+ @output_buffer = ActionView::OutputBuffer.new ''
24
+ concat(semantic_form_for(@new_post) do |builder|
25
+ builder.input(:title, :required => true, :label => true)
26
+ end)
27
+
28
+ ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
29
+ Formtastic::FormBuilder.required_string = default_required_str
30
+
31
+ expect(output_buffer.to_s.scan(required_string).count).to eq(1)
32
+ end
33
+ end
34
+
35
+ it 'should humanize the given attribute' do
36
+ concat(semantic_form_for(@new_post) do |builder|
37
+ builder.input(:title)
38
+ end)
39
+ expect(output_buffer.to_str).to have_tag('label', :text => /Title/)
40
+ end
41
+
42
+ it 'should apply a "for" attribute to the label' do
43
+ concat(semantic_form_for(@new_post) do |builder|
44
+ builder.input(:title)
45
+ end)
46
+ expect(output_buffer.to_str).to have_tag('label[for=post_title]')
47
+ end
48
+
49
+ it 'should apply a "label" class to the label' do
50
+ concat(semantic_form_for(@new_post) do |builder|
51
+ builder.input(:title)
52
+ end)
53
+ expect(output_buffer.to_str).to have_tag('label.label')
54
+ end
55
+
56
+ it 'should use i18n instead of the method name when method given as a String' do
57
+ with_config :i18n_cache_lookups, true do
58
+ ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => "I18n title" } } } }
59
+ concat(semantic_form_for(@new_post) do |builder|
60
+ builder.input("title")
61
+ end)
62
+ ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
63
+ expect(output_buffer.to_str).to have_tag('label', :text => /I18n title/)
64
+ end
65
+ end
66
+
67
+ it 'should humanize the given attribute for date fields' do
68
+ concat(semantic_form_for(@new_post) do |builder|
69
+ builder.input(:publish_at)
70
+ end)
71
+ expect(output_buffer.to_str).to have_tag('label', :text => /Publish at/)
72
+ end
73
+
74
+ describe 'when required is given' do
75
+ it 'should append a required note' do
76
+ concat(semantic_form_for(@new_post) do |builder|
77
+ builder.input(:title, :required => true)
78
+ end)
79
+ expect(output_buffer.to_str).to have_tag('label abbr', '*')
80
+ end
81
+ end
82
+
83
+ describe "when label_html is given" do
84
+ it "should allow label_html to override the class" do
85
+ concat(semantic_form_for(@new_post) do |builder|
86
+ builder.input(:title, :label_html => { :class => 'my_class' } )
87
+ end)
88
+ expect(output_buffer.to_str).to have_tag('label.my_class', /Title/)
89
+ end
90
+
91
+ it "should allow label_html to add custom attributes" do
92
+ concat(semantic_form_for(@new_post) do |builder|
93
+ builder.input(:title, :label_html => { :data => { :tooltip => 'Great Tooltip' } } )
94
+ end)
95
+ aggregate_failures do
96
+ expect(output_buffer.to_str).to have_tag('label[data-tooltip="Great Tooltip"]')
97
+ end
98
+ end
99
+ end
100
+
101
+ describe 'when a collection is given' do
102
+ it 'should use a supplied label_method for simple collections' do
103
+ with_deprecation_silenced do
104
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
105
+ concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => :to_s, :member_label => proc {|f| ('Label_%s' % [f])}))
106
+ end)
107
+ end
108
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /Label_[abc]/, :count => 3)
109
+ end
110
+
111
+ it 'should use a supplied value_method for simple collections' do
112
+ with_deprecation_silenced do
113
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
114
+ concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => proc {|f| ('Value_%s' % [f.to_s])}))
115
+ end)
116
+ end
117
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label input[value="Value_a"]')
118
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label input[value="Value_b"]')
119
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label input[value="Value_c"]')
120
+ end
121
+ end
122
+
123
+ describe 'when label is given' do
124
+ it 'should allow the text to be given as label option' do
125
+ concat(semantic_form_for(@new_post) do |builder|
126
+ builder.input(:title, :label => 'My label')
127
+ end)
128
+ expect(output_buffer.to_str).to have_tag('label', :text => /My label/)
129
+ end
130
+
131
+ it 'should allow the text to be given as label option for date fields' do
132
+ concat(semantic_form_for(@new_post) do |builder|
133
+ builder.input(:publish_at, :label => 'My other label')
134
+ end)
135
+ expect(output_buffer.to_str).to have_tag('label', :text => /My other label/)
136
+ end
137
+
138
+ it 'should return nil if label is false' do
139
+ concat(semantic_form_for(@new_post) do |builder|
140
+ builder.input(:title, :label => false)
141
+ end)
142
+ expect(output_buffer.to_str).not_to have_tag('label')
143
+ expect(output_buffer.to_str).not_to include(">")
144
+ end
145
+
146
+ it 'should return nil if label is false for timeish fragments' do
147
+ concat(semantic_form_for(@new_post) do |builder|
148
+ builder.input(:title, :as => :time_select, :label => false)
149
+ end)
150
+ expect(output_buffer.to_str).not_to have_tag('li.time > label')
151
+ expect(output_buffer.to_str).not_to include(">")
152
+ end
153
+
154
+ it 'should html escape the label string by default' do
155
+ concat(semantic_form_for(@new_post) do |builder|
156
+ builder.input(:title, :label => '<b>My label</b>')
157
+ end)
158
+ expect(output_buffer.to_str).to include('&lt;b&gt;')
159
+ expect(output_buffer.to_str).not_to include('<b>')
160
+ end
161
+
162
+ it 'should not html escape the label if configured that way' do
163
+ Formtastic::FormBuilder.escape_html_entities_in_hints_and_labels = false
164
+ concat(semantic_form_for(@new_post) do |builder|
165
+ builder.input(:title, :label => '<b>My label</b>')
166
+ end)
167
+ expect(output_buffer.to_str).to have_tag("label b", :text => "My label")
168
+ end
169
+
170
+ it 'should not html escape the label string for html_safe strings' do
171
+ Formtastic::FormBuilder.escape_html_entities_in_hints_and_labels = true
172
+ concat(semantic_form_for(@new_post) do |builder|
173
+ builder.input(:title, :label => '<b>My label</b>'.html_safe)
174
+ end)
175
+ expect(output_buffer.to_str).to have_tag('label b')
176
+ end
177
+
178
+ end
179
+
180
+ end
181
+