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,547 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'check_boxes 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 a has_many association' do
|
|
14
|
+
before do
|
|
15
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
16
|
+
mock_everything
|
|
17
|
+
|
|
18
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
19
|
+
concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :required => true))
|
|
20
|
+
end)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it_should_have_input_wrapper_with_class("check_boxes")
|
|
24
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
25
|
+
it_should_have_input_wrapper_with_id("author_posts_input")
|
|
26
|
+
it_should_have_a_nested_fieldset
|
|
27
|
+
it_should_have_a_nested_fieldset_with_class('choices')
|
|
28
|
+
it_should_have_a_nested_ordered_list_with_class('choices-group')
|
|
29
|
+
it_should_apply_error_logic_for_input_type(:check_boxes)
|
|
30
|
+
it_should_call_find_on_association_class_when_no_collection_is_provided(:check_boxes)
|
|
31
|
+
it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
|
|
32
|
+
|
|
33
|
+
it 'should generate a legend containing a label with text for the input' do
|
|
34
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label')
|
|
35
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label', :text => /Posts/)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should not link the label within the legend to any input' do
|
|
39
|
+
expect(output_buffer.to_str).not_to have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should generate an ordered list with an li.choice for each choice' do
|
|
43
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol')
|
|
44
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'should have one option with a "checked" attribute' do
|
|
48
|
+
expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 1)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'should not generate hidden inputs with default value blank' do
|
|
52
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'should not render hidden inputs inside the ol' do
|
|
56
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li input[@type='hidden']")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'should render one hidden input for each choice outside the ol' do
|
|
60
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type='hidden']", :count => 1)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "each choice" do
|
|
64
|
+
|
|
65
|
+
it 'should not give the choice label the .label class' do
|
|
66
|
+
expect(output_buffer.to_str).not_to have_tag('li.choice label.label')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'should not be marked as required' do
|
|
70
|
+
expect(output_buffer.to_str).not_to have_tag('li.choice input[@required]')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'should contain a label for the radio input with a nested input and label text' do
|
|
74
|
+
::Post.all.each do |post|
|
|
75
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
|
|
76
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'should use values as li.class when value_as_class is true' do
|
|
81
|
+
::Post.all.each do |post|
|
|
82
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li.post_#{post.id} label")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'should have a checkbox input but no hidden field for each post' do
|
|
87
|
+
::Post.all.each do |post|
|
|
88
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
|
89
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
|
|
94
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'the hidden field with an empty array value should be followed by the ol' do
|
|
98
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should not have a hidden field with an empty string value for the collection' do
|
|
102
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
|
|
106
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
107
|
+
|
|
108
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
109
|
+
concat(builder.input(:posts, :as => :check_boxes, :hidden_fields => true, :value_as_class => true))
|
|
110
|
+
end)
|
|
111
|
+
|
|
112
|
+
::Post.all.each do |post|
|
|
113
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
|
114
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
|
|
115
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "should mark input as checked if it's the the existing choice" do
|
|
121
|
+
expect(::Post.all.include?(@fred.posts.first)).to be_truthy
|
|
122
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe 'and no object is given' do
|
|
127
|
+
before(:example) do
|
|
128
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
129
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
130
|
+
concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.all))
|
|
131
|
+
end)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'should generate a fieldset with legend' do
|
|
135
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset legend', :text => /Author/)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'shold generate an li tag for each item in the collection' do
|
|
139
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'should generate labels 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', :text => /#{author.to_label}/)
|
|
145
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'should generate inputs for each item' do
|
|
150
|
+
::Author.all.each do |author|
|
|
151
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
|
|
152
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@type='checkbox']")
|
|
153
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
|
154
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'should html escape the label string' do
|
|
159
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
160
|
+
concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
|
|
161
|
+
end)
|
|
162
|
+
|
|
163
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2) do |label|
|
|
164
|
+
expect(label).to have_text('<b>Item 1</b>', count: 1)
|
|
165
|
+
expect(label).to have_text('<b>Item 2</b>', count: 1)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
describe 'when :hidden_fields is set to false' do
|
|
171
|
+
before do
|
|
172
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
173
|
+
mock_everything
|
|
174
|
+
|
|
175
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
176
|
+
concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :hidden_fields => false))
|
|
177
|
+
end)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'should have a checkbox input for each post' do
|
|
181
|
+
::Post.all.each do |post|
|
|
182
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
|
183
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "should mark input as checked if it's the the existing choice" do
|
|
188
|
+
expect(::Post.all.include?(@fred.posts.first)).to be_truthy
|
|
189
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'should not generate empty hidden inputs' do
|
|
193
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
describe 'when :disabled is set' do
|
|
198
|
+
before do
|
|
199
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
describe "no disabled items" do
|
|
203
|
+
before do
|
|
204
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
205
|
+
|
|
206
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
207
|
+
concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
|
|
208
|
+
end)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'should not have any disabled item(s)' do
|
|
212
|
+
expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@disabled='disabled']")
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
describe "single disabled item" do
|
|
217
|
+
before do
|
|
218
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
219
|
+
|
|
220
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
221
|
+
concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
|
|
222
|
+
end)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "should have one item disabled; the specified one" do
|
|
226
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
|
|
227
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
|
|
228
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
describe "multiple disabled items" do
|
|
233
|
+
before do
|
|
234
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
235
|
+
|
|
236
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
237
|
+
concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
|
|
238
|
+
end)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it "should have multiple items disabled; the specified ones" do
|
|
242
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
|
|
243
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", :text => /bob/i)
|
|
244
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
|
|
245
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
|
|
246
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
describe "with i18n of the legend label" do
|
|
253
|
+
|
|
254
|
+
before do
|
|
255
|
+
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
|
256
|
+
with_config :i18n_lookups_by_default, true do
|
|
257
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
258
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
259
|
+
concat(builder.input(:authors, :as => :check_boxes))
|
|
260
|
+
end)
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
after do
|
|
265
|
+
::I18n.backend.reload!
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it "should do foo" do
|
|
269
|
+
expect(output_buffer.to_str).to have_tag("legend.label label", :text => /Translated/)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
describe "when :label option is set" do
|
|
275
|
+
before do
|
|
276
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
277
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
278
|
+
concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
|
|
279
|
+
end)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
it "should output the correct label title" do
|
|
283
|
+
expect(output_buffer.to_str).to have_tag("legend.label label", :text => /The authors/)
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
describe "when :label option is false" do
|
|
288
|
+
before do
|
|
289
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
290
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
291
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
292
|
+
concat(builder.input(:authors, :as => :check_boxes, :label => false))
|
|
293
|
+
end)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it "should not output the legend" do
|
|
297
|
+
expect(output_buffer.to_str).not_to have_tag("legend.label")
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it "should not cause escaped HTML" do
|
|
301
|
+
expect(output_buffer.to_str).not_to include(">")
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
describe "when :required option is true" do
|
|
307
|
+
before do
|
|
308
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
|
309
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
310
|
+
concat(builder.input(:authors, :as => :check_boxes, :required => true))
|
|
311
|
+
end)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
it "should output the correct label title" do
|
|
315
|
+
expect(output_buffer.to_str).to have_tag("legend.label label abbr")
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
describe 'for a enum column' do
|
|
321
|
+
before do
|
|
322
|
+
allow(@new_post).to receive(:status) { 'inactive' }
|
|
323
|
+
statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
|
|
324
|
+
allow(@new_post.class).to receive(:statuses) { statuses }
|
|
325
|
+
allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
it 'should have a select inside the wrapper' do
|
|
329
|
+
expect {
|
|
330
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
331
|
+
concat(builder.input(:status, :as => :check_boxes))
|
|
332
|
+
end)
|
|
333
|
+
}.to raise_error(Formtastic::UnsupportedEnumCollection)
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
describe 'for a has_and_belongs_to_many association' do
|
|
338
|
+
|
|
339
|
+
before do
|
|
340
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
341
|
+
mock_everything
|
|
342
|
+
|
|
343
|
+
concat(semantic_form_for(@freds_post) do |builder|
|
|
344
|
+
concat(builder.input(:authors, :as => :check_boxes))
|
|
345
|
+
end)
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
it 'should render checkboxes' do
|
|
349
|
+
# I'm aware these two lines test the same thing
|
|
350
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => 2)
|
|
351
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
it 'should only select checkboxes that are present in the association' do
|
|
355
|
+
# I'm aware these two lines test the same thing
|
|
356
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => 1)
|
|
357
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
describe ':collection for a has_and_belongs_to_many association' do
|
|
363
|
+
|
|
364
|
+
before do
|
|
365
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
366
|
+
mock_everything
|
|
367
|
+
|
|
368
|
+
concat(semantic_form_for(@freds_post) do |builder|
|
|
369
|
+
concat(builder.input(:authors, as: :check_boxes, collection: Author.all))
|
|
370
|
+
end)
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
it 'should render checkboxes' do
|
|
374
|
+
# I'm aware these two lines test the same thing
|
|
375
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => 2)
|
|
376
|
+
expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
it 'should only select checkboxes that are present in the association' do
|
|
380
|
+
# I'm aware these two lines test the same thing
|
|
381
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => 1)
|
|
382
|
+
expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
describe 'for an association when a :collection is provided' do
|
|
388
|
+
describe 'it should use the specified :member_value option' do
|
|
389
|
+
before do
|
|
390
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
391
|
+
mock_everything
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
it 'to set the right input value' do
|
|
395
|
+
item = double('item')
|
|
396
|
+
expect(item).not_to receive(:id)
|
|
397
|
+
allow(item).to receive(:custom_value).and_return('custom_value')
|
|
398
|
+
expect(item).to receive(:custom_value).exactly(3).times
|
|
399
|
+
expect(@new_post.author).to receive(:custom_value).exactly(1).times
|
|
400
|
+
|
|
401
|
+
with_deprecation_silenced do
|
|
402
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
403
|
+
concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
|
|
404
|
+
end)
|
|
405
|
+
end
|
|
406
|
+
expect(output_buffer.to_str).to have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
describe 'when :collection is provided as an array of arrays' do
|
|
412
|
+
before do
|
|
413
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
414
|
+
mock_everything
|
|
415
|
+
allow(@fred).to receive(:genres) { ['fiction', 'biography'] }
|
|
416
|
+
|
|
417
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
418
|
+
concat(builder.input(:genres, :as => :check_boxes, :collection => [['Fiction', 'fiction'], ['Non-fiction', 'non_fiction'], ['Biography', 'biography']]))
|
|
419
|
+
end)
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
it 'should check the correct checkboxes' do
|
|
423
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
|
|
424
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
describe 'when :collection is a set' do
|
|
429
|
+
before do
|
|
430
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
431
|
+
mock_everything
|
|
432
|
+
allow(@fred).to receive(:roles) { Set.new([:reviewer, :admin]) }
|
|
433
|
+
|
|
434
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
435
|
+
concat(builder.input(:roles, :as => :check_boxes, :collection => [['User', :user], ['Reviewer', :reviewer], ['Administrator', :admin]]))
|
|
436
|
+
end)
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
it 'should check the correct checkboxes' do
|
|
440
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='user']")
|
|
441
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
|
|
442
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
describe "when namespace is provided" do
|
|
447
|
+
|
|
448
|
+
before do
|
|
449
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
450
|
+
mock_everything
|
|
451
|
+
|
|
452
|
+
concat(semantic_form_for(@fred, :namespace => "context2") do |builder|
|
|
453
|
+
concat(builder.input(:posts, :as => :check_boxes))
|
|
454
|
+
end)
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
it "should have a label for #context2_author_post_ids_19" do
|
|
458
|
+
expect(output_buffer.to_str).to have_tag("form li label[@for='context2_author_post_ids_19']")
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
it_should_have_input_with_id('context2_author_post_ids_19')
|
|
462
|
+
it_should_have_input_wrapper_with_id("context2_author_posts_input")
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
describe "when index is provided" do
|
|
466
|
+
|
|
467
|
+
before do
|
|
468
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
469
|
+
mock_everything
|
|
470
|
+
|
|
471
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
472
|
+
concat(builder.fields_for(@fred.posts.first, :index => 3) do |author|
|
|
473
|
+
concat(author.input(:authors, :as => :check_boxes))
|
|
474
|
+
end)
|
|
475
|
+
end)
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
it 'should index the id of the wrapper' do
|
|
479
|
+
expect(output_buffer.to_str).to have_tag("li#author_post_3_authors_input")
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
it 'should index the id of the input tag' do
|
|
483
|
+
expect(output_buffer.to_str).to have_tag("input#author_post_3_author_ids_42")
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
it 'should index the name of the checkbox input' do
|
|
487
|
+
expect(output_buffer.to_str).to have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
describe "when collection is an array" do
|
|
494
|
+
before do
|
|
495
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
496
|
+
@_collection = [["First", 1], ["Second", 2]]
|
|
497
|
+
mock_everything
|
|
498
|
+
|
|
499
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
500
|
+
concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
|
|
501
|
+
end)
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
it "should use array items for labels and values" do
|
|
505
|
+
@_collection.each do |post|
|
|
506
|
+
expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.first}/)
|
|
507
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
|
|
508
|
+
end
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
it "should not check any items" do
|
|
512
|
+
expect(output_buffer.to_str).not_to have_tag('form li input[@checked]')
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
describe "and the attribute has values" do
|
|
516
|
+
before do
|
|
517
|
+
allow(@fred).to receive(:posts) { [1] }
|
|
518
|
+
|
|
519
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
520
|
+
concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
|
|
521
|
+
end)
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
it "should check the appropriate items" do
|
|
525
|
+
expect(output_buffer.to_str).to have_tag("form li input[@value='1'][@checked]")
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
describe "and the collection includes html options" do
|
|
530
|
+
before do
|
|
531
|
+
@_collection = [["First", 1, {'data-test' => 'test-data'}], ["Second", 2, {'data-test2' => 'test-data2'}]]
|
|
532
|
+
|
|
533
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
534
|
+
concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
|
|
535
|
+
end)
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
it "should have injected the html attributes" do
|
|
539
|
+
@_collection.each do |v|
|
|
540
|
+
expect(output_buffer.to_str).to have_tag("form li input[@value='#{v[1]}'][@#{v[2].keys[0]}='#{v[2].values[0]}']")
|
|
541
|
+
end
|
|
542
|
+
end
|
|
543
|
+
end
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
end
|
|
547
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'color 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(:color))
|
|
17
|
+
end)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it_should_have_input_wrapper_with_class(:color)
|
|
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_color_input")
|
|
24
|
+
it_should_have_label_with_text(/Color/)
|
|
25
|
+
it_should_have_label_for("post_color")
|
|
26
|
+
it_should_have_input_with_id("post_color")
|
|
27
|
+
it_should_have_input_with_type(:color)
|
|
28
|
+
it_should_have_input_with_name("post[color]")
|
|
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(:color))
|
|
37
|
+
end)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it_should_have_input_wrapper_with_id("context2_post_color_input")
|
|
41
|
+
it_should_have_label_and_input_with_id("context2_post_color")
|
|
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 => :color))
|
|
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 => :color, :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
|
+
|