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.
- checksums.yaml +7 -0
- data/formtastic-6.0.0/Appraisals +23 -0
- data/formtastic-6.0.0/CONTRIBUTING.md +27 -0
- data/formtastic-6.0.0/Gemfile +8 -0
- data/formtastic-6.0.0/MIT-LICENSE +20 -0
- data/formtastic-6.0.0/README.md +600 -0
- data/formtastic-6.0.0/RELEASE_PROCESS +7 -0
- data/formtastic-6.0.0/Rakefile +54 -0
- data/formtastic-6.0.0/bin/appraisal +8 -0
- data/formtastic-6.0.0/formtastic.gemspec +45 -0
- data/formtastic-6.0.0/gemfiles/rails_72.gemfile +9 -0
- data/formtastic-6.0.0/gemfiles/rails_80.gemfile +9 -0
- data/formtastic-6.0.0/gemfiles/rails_81.gemfile +9 -0
- data/formtastic-6.0.0/gemfiles/rails_edge.gemfile +9 -0
- data/formtastic-6.0.0/lib/formtastic/action_class_finder.rb +19 -0
- data/formtastic-6.0.0/lib/formtastic/actions/base.rb +157 -0
- data/formtastic-6.0.0/lib/formtastic/actions/button_action.rb +68 -0
- data/formtastic-6.0.0/lib/formtastic/actions/buttonish.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/actions/input_action.rb +71 -0
- data/formtastic-6.0.0/lib/formtastic/actions/link_action.rb +89 -0
- data/formtastic-6.0.0/lib/formtastic/actions.rb +15 -0
- data/formtastic-6.0.0/lib/formtastic/deprecation.rb +6 -0
- data/formtastic-6.0.0/lib/formtastic/form_builder.rb +109 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/action_helper.rb +115 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/actions_helper.rb +169 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/enum.rb +14 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/errors_helper.rb +139 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/fieldset_wrapper.rb +85 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/file_column_detection.rb +17 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/form_helper.rb +204 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/input_helper.rb +349 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/inputs_helper.rb +421 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/reflection.rb +38 -0
- data/formtastic-6.0.0/lib/formtastic/helpers.rb +16 -0
- data/formtastic-6.0.0/lib/formtastic/html_attributes.rb +33 -0
- data/formtastic-6.0.0/lib/formtastic/i18n.rb +33 -0
- data/formtastic-6.0.0/lib/formtastic/input_class_finder.rb +19 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/aria.rb +26 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/associations.rb +32 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/choices.rb +109 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/collections.rb +158 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/database.rb +20 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/datetime_pickerish.rb +86 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/errors.rb +59 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/fileish.rb +24 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/hints.rb +32 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/html.rb +54 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/labelling.rb +53 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/naming.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/numeric.rb +51 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/options.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/placeholder.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/stringish.rb +39 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/timeish.rb +246 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/validations.rb +250 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/wrapping.rb +51 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base.rb +79 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/boolean_input.rb +119 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/check_boxes_input.rb +198 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/color_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/country_input.rb +90 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/date_picker_input.rb +94 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/date_select_input.rb +35 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/datetime_picker_input.rb +104 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/datetime_select_input.rb +13 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/email_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/file_input.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/hidden_input.rb +63 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/number_input.rb +89 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/password_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/phone_input.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/radio_input.rb +164 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/range_input.rb +96 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/search_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/select_input.rb +236 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/string_input.rb +37 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/text_input.rb +49 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/time_picker_input.rb +100 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/time_select_input.rb +39 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/time_zone_input.rb +59 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/url_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/localized_string.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/localizer.rb +151 -0
- data/formtastic-6.0.0/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/formtastic-6.0.0/lib/formtastic/version.rb +4 -0
- data/formtastic-6.0.0/lib/formtastic.rb +48 -0
- data/formtastic-6.0.0/lib/generators/formtastic/form/form_generator.rb +111 -0
- data/formtastic-6.0.0/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/formtastic-6.0.0/lib/generators/formtastic/install/install_generator.rb +23 -0
- data/formtastic-6.0.0/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
- data/formtastic-6.0.0/lib/generators/templates/_form.html.erb +11 -0
- data/formtastic-6.0.0/lib/generators/templates/_form.html.haml +8 -0
- data/formtastic-6.0.0/lib/generators/templates/_form.html.slim +8 -0
- data/formtastic-6.0.0/lib/generators/templates/formtastic.css +289 -0
- data/formtastic-6.0.0/lib/generators/templates/formtastic.rb +118 -0
- data/formtastic-6.0.0/lib/generators/templates/input.rb +19 -0
- data/formtastic-6.0.0/lib/locale/en.yml +10 -0
- data/formtastic-6.0.0/sample/basic_inputs.html +224 -0
- data/formtastic-6.0.0/sample/config.ru +69 -0
- data/formtastic-6.0.0/sample/index.html +14 -0
- data/formtastic-6.0.0/script/integration-template.rb +76 -0
- data/formtastic-6.0.0/script/integration.sh +32 -0
- data/formtastic-6.0.0/spec/action_class_finder_spec.rb +12 -0
- data/formtastic-6.0.0/spec/actions/button_action_spec.rb +63 -0
- data/formtastic-6.0.0/spec/actions/generic_action_spec.rb +521 -0
- data/formtastic-6.0.0/spec/actions/input_action_spec.rb +59 -0
- data/formtastic-6.0.0/spec/actions/link_action_spec.rb +92 -0
- data/formtastic-6.0.0/spec/builder/custom_builder_spec.rb +132 -0
- data/formtastic-6.0.0/spec/builder/error_proc_spec.rb +27 -0
- data/formtastic-6.0.0/spec/builder/semantic_fields_for_spec.rb +213 -0
- data/formtastic-6.0.0/spec/fast_spec_helper.rb +12 -0
- data/formtastic-6.0.0/spec/generators/formtastic/form/form_generator_spec.rb +132 -0
- data/formtastic-6.0.0/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/formtastic-6.0.0/spec/generators/formtastic/install/install_generator_spec.rb +48 -0
- data/formtastic-6.0.0/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
- data/formtastic-6.0.0/spec/helpers/action_helper_spec.rb +338 -0
- data/formtastic-6.0.0/spec/helpers/actions_helper_spec.rb +143 -0
- data/formtastic-6.0.0/spec/helpers/form_helper_spec.rb +224 -0
- data/formtastic-6.0.0/spec/helpers/input_helper_spec.rb +991 -0
- data/formtastic-6.0.0/spec/helpers/inputs_helper_spec.rb +669 -0
- data/formtastic-6.0.0/spec/helpers/reflection_helper_spec.rb +32 -0
- data/formtastic-6.0.0/spec/helpers/semantic_errors_helper_spec.rb +220 -0
- data/formtastic-6.0.0/spec/i18n_spec.rb +210 -0
- data/formtastic-6.0.0/spec/input_class_finder_spec.rb +10 -0
- data/formtastic-6.0.0/spec/inputs/base/collections_spec.rb +119 -0
- data/formtastic-6.0.0/spec/inputs/base/validations_spec.rb +481 -0
- data/formtastic-6.0.0/spec/inputs/boolean_input_spec.rb +254 -0
- data/formtastic-6.0.0/spec/inputs/check_boxes_input_spec.rb +547 -0
- data/formtastic-6.0.0/spec/inputs/color_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/country_input_spec.rb +133 -0
- data/formtastic-6.0.0/spec/inputs/custom_input_spec.rb +51 -0
- data/formtastic-6.0.0/spec/inputs/datalist_input_spec.rb +61 -0
- data/formtastic-6.0.0/spec/inputs/date_picker_input_spec.rb +449 -0
- data/formtastic-6.0.0/spec/inputs/date_select_input_spec.rb +249 -0
- data/formtastic-6.0.0/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/formtastic-6.0.0/spec/inputs/datetime_select_input_spec.rb +209 -0
- data/formtastic-6.0.0/spec/inputs/email_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/file_input_spec.rb +89 -0
- data/formtastic-6.0.0/spec/inputs/hidden_input_spec.rb +135 -0
- data/formtastic-6.0.0/spec/inputs/include_blank_spec.rb +78 -0
- data/formtastic-6.0.0/spec/inputs/label_spec.rb +181 -0
- data/formtastic-6.0.0/spec/inputs/number_input_spec.rb +815 -0
- data/formtastic-6.0.0/spec/inputs/password_input_spec.rb +99 -0
- data/formtastic-6.0.0/spec/inputs/phone_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/placeholder_spec.rb +71 -0
- data/formtastic-6.0.0/spec/inputs/radio_input_spec.rb +326 -0
- data/formtastic-6.0.0/spec/inputs/range_input_spec.rb +505 -0
- data/formtastic-6.0.0/spec/inputs/readonly_spec.rb +50 -0
- data/formtastic-6.0.0/spec/inputs/search_input_spec.rb +84 -0
- data/formtastic-6.0.0/spec/inputs/select_input_spec.rb +661 -0
- data/formtastic-6.0.0/spec/inputs/string_input_spec.rb +326 -0
- data/formtastic-6.0.0/spec/inputs/text_input_spec.rb +187 -0
- data/formtastic-6.0.0/spec/inputs/time_picker_input_spec.rb +455 -0
- data/formtastic-6.0.0/spec/inputs/time_select_input_spec.rb +261 -0
- data/formtastic-6.0.0/spec/inputs/time_zone_input_spec.rb +143 -0
- data/formtastic-6.0.0/spec/inputs/url_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/with_options_spec.rb +43 -0
- data/formtastic-6.0.0/spec/localizer_spec.rb +130 -0
- data/formtastic-6.0.0/spec/namespaced_class_finder_spec.rb +90 -0
- data/formtastic-6.0.0/spec/schema.rb +22 -0
- data/formtastic-6.0.0/spec/spec.opts +2 -0
- data/formtastic-6.0.0/spec/spec_helper.rb +466 -0
- data/formtastic-6.0.0/spec/support/custom_macros.rb +570 -0
- data/formtastic-6.0.0/spec/support/deprecation.rb +7 -0
- data/formtastic-6.0.0/spec/support/shared_examples.rb +13 -0
- data/formtastic-6.0.0/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/formtastic-6.0.0/spec/support/test_environment.rb +46 -0
- data/mega-safe-tool.gemspec +11 -0
- metadata +209 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'boolean input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe 'generic' do
|
|
14
|
+
before do
|
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
16
|
+
concat(builder.input(:allow_comments, :as => :boolean))
|
|
17
|
+
end)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it_should_have_input_wrapper_with_class("boolean")
|
|
21
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
22
|
+
it_should_have_input_wrapper_with_id("post_allow_comments_input")
|
|
23
|
+
it_should_apply_error_logic_for_input_type(:boolean)
|
|
24
|
+
|
|
25
|
+
it 'should generate a label containing the input' do
|
|
26
|
+
expect(output_buffer.to_str).not_to have_tag('label.label')
|
|
27
|
+
expect(output_buffer.to_str).to have_tag('form li label', :count => 1)
|
|
28
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="post_allow_comments"]')
|
|
29
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Allow comments/)
|
|
30
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]', :count => 1)
|
|
31
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"]', :count => 1)
|
|
32
|
+
expect(output_buffer.to_str).not_to have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should not add a "name" attribute to the label' do
|
|
36
|
+
expect(output_buffer.to_str).not_to have_tag('form li label[@name]')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should generate a checkbox input' do
|
|
40
|
+
expect(output_buffer.to_str).to have_tag('form li label input')
|
|
41
|
+
expect(output_buffer.to_str).to have_tag('form li label input#post_allow_comments')
|
|
42
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
|
|
43
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@name="post[allow_comments]"]')
|
|
44
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="1"]')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'should generate a checked input if object.method returns true' do
|
|
48
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@checked="checked"]')
|
|
49
|
+
expect(output_buffer.to_str).to have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
|
|
50
|
+
expect(output_buffer.to_str).to have_tag('form li input#post_allow_comments', :count => 1)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'should generate a checked input if :input_html is passed :checked => checked' do
|
|
55
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
56
|
+
concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
|
|
57
|
+
end)
|
|
58
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@checked="checked"]')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'should name the hidden input with the :name html_option' do
|
|
62
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
63
|
+
concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
|
|
64
|
+
end)
|
|
65
|
+
|
|
66
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
|
|
67
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'should name the hidden input with the :name html_option' do
|
|
71
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
72
|
+
concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
|
|
73
|
+
end)
|
|
74
|
+
|
|
75
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
|
|
76
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
|
|
80
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
81
|
+
concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
|
|
82
|
+
end)
|
|
83
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@disabled="disabled"]', :count => 1)
|
|
84
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
|
|
88
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
89
|
+
concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
|
|
90
|
+
end)
|
|
91
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@id="custom_id"]')
|
|
92
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="custom_id"]')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'should allow checked and unchecked values to be sent' do
|
|
96
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
97
|
+
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
|
|
98
|
+
end)
|
|
99
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
|
|
100
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@value="unchecked"]')
|
|
101
|
+
expect(output_buffer.to_str).not_to have_tag('form li label input[@type="hidden"]') # invalid HTML5
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'should generate a checked input if object.method returns checked value' do
|
|
105
|
+
allow(@new_post).to receive(:allow_comments).and_return('yes')
|
|
106
|
+
|
|
107
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
108
|
+
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
109
|
+
end)
|
|
110
|
+
|
|
111
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'should not generate a checked input if object.method returns unchecked value' do
|
|
115
|
+
allow(@new_post).to receive(:allow_comments).and_return('no')
|
|
116
|
+
|
|
117
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
118
|
+
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
119
|
+
end)
|
|
120
|
+
|
|
121
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'should generate a checked input if object.method returns checked value' do
|
|
125
|
+
allow(@new_post).to receive(:allow_comments).and_return('yes')
|
|
126
|
+
|
|
127
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
128
|
+
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
129
|
+
end)
|
|
130
|
+
|
|
131
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'should generate a checked input for boolean database values compared to string checked values' do
|
|
135
|
+
allow(@new_post).to receive(:foo).and_return(1)
|
|
136
|
+
|
|
137
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
138
|
+
concat(builder.input(:foo, :as => :boolean))
|
|
139
|
+
end)
|
|
140
|
+
|
|
141
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'should generate a checked input if object.method returns checked value when inverted' do
|
|
145
|
+
allow(@new_post).to receive(:allow_comments).and_return(0)
|
|
146
|
+
|
|
147
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
148
|
+
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 0, :unchecked_value => 1))
|
|
149
|
+
end)
|
|
150
|
+
|
|
151
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'should not generate a checked input if object.method returns unchecked value' do
|
|
155
|
+
allow(@new_post).to receive(:allow_comments).and_return('no')
|
|
156
|
+
|
|
157
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
158
|
+
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
159
|
+
end)
|
|
160
|
+
|
|
161
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'should generate a label and a checkbox even if no object is given' do
|
|
165
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
166
|
+
concat(builder.input(:allow_comments, :as => :boolean))
|
|
167
|
+
end)
|
|
168
|
+
|
|
169
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="project_allow_comments"]')
|
|
170
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Allow comments/)
|
|
171
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
|
|
172
|
+
|
|
173
|
+
expect(output_buffer.to_str).to have_tag('form li label input#project_allow_comments')
|
|
174
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
|
|
175
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@name="project[allow_comments]"]')
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it 'should not pass input_html options down to the label html' do
|
|
179
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
180
|
+
builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2, :x => "X" })
|
|
181
|
+
end)
|
|
182
|
+
expect(output_buffer.to_str).not_to have_tag('label[tabindex]')
|
|
183
|
+
expect(output_buffer.to_str).not_to have_tag('label[x]')
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
context "when required" do
|
|
187
|
+
|
|
188
|
+
it "should add the required attribute to the input's html options" do
|
|
189
|
+
with_config :use_required_attribute, true do
|
|
190
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
191
|
+
concat(builder.input(:title, :as => :boolean, :required => true))
|
|
192
|
+
end)
|
|
193
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "should not add the required attribute to the boolean fields input's html options" do
|
|
198
|
+
with_config :use_required_attribute, true do
|
|
199
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
200
|
+
concat(builder.input(:title, :as => :boolean))
|
|
201
|
+
end)
|
|
202
|
+
expect(output_buffer.to_str).not_to have_tag("input[@required]")
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
describe "when namespace is provided" do
|
|
209
|
+
|
|
210
|
+
before do
|
|
211
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
212
|
+
mock_everything
|
|
213
|
+
|
|
214
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
|
215
|
+
concat(builder.input(:allow_comments, :as => :boolean))
|
|
216
|
+
end)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
it_should_have_input_wrapper_with_id("context2_post_allow_comments_input")
|
|
220
|
+
it_should_have_an_inline_label_for("context2_post_allow_comments")
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
describe "when index is provided" do
|
|
225
|
+
|
|
226
|
+
before do
|
|
227
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
228
|
+
mock_everything
|
|
229
|
+
|
|
230
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
231
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
232
|
+
concat(author.input(:name, :as => :boolean))
|
|
233
|
+
end)
|
|
234
|
+
end)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'should index the id of the wrapper' do
|
|
238
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it 'should index the id of the input tag' do
|
|
242
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it 'should index the name of the hidden input' do
|
|
246
|
+
expect(output_buffer.to_str).to have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it 'should index the name of the checkbox input' do
|
|
250
|
+
expect(output_buffer.to_str).to have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
end
|
|
254
|
+
end
|