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,669 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Formtastic::FormBuilder#inputs' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe 'with a block (block forms syntax)' do
|
|
14
|
+
|
|
15
|
+
describe 'when no options are provided' do
|
|
16
|
+
before do
|
|
17
|
+
@output_buffer = ActionView::OutputBuffer.new 'before_builder' # replace the output buffer and with one set to before_builder
|
|
18
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
19
|
+
@inputs_output = builder.inputs do
|
|
20
|
+
concat('hello')
|
|
21
|
+
end
|
|
22
|
+
end)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should output just the content wrapped in inputs, not the whole template' do
|
|
26
|
+
expect(output_buffer.to_str).to match(/before_builder/)
|
|
27
|
+
expect(@inputs_output).not_to match(/before_builder/)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
|
31
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'should render an ol inside the fieldset' do
|
|
35
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs ol")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should render the contents of the block inside the ol' do
|
|
39
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs ol", :text => /hello/)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should not render a legend inside the fieldset' do
|
|
43
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs legend")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'should render a fieldset even if no object is given' do
|
|
47
|
+
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
|
48
|
+
@inputs_output = builder.inputs do
|
|
49
|
+
concat('bye')
|
|
50
|
+
end
|
|
51
|
+
end)
|
|
52
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs ol", :text => /bye/)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe 'when a :for option is provided' do
|
|
57
|
+
|
|
58
|
+
before do
|
|
59
|
+
allow(@new_post).to receive(:respond_to?).and_return(true, true)
|
|
60
|
+
allow(@new_post).to receive(:respond_to?).with(:empty?).and_return(false)
|
|
61
|
+
allow(@new_post).to receive(:author).and_return(@bob)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'should render nested inputs' do
|
|
65
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
66
|
+
|
|
67
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
68
|
+
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
|
|
69
|
+
concat(bob_builder.input(:login))
|
|
70
|
+
end
|
|
71
|
+
concat(inputs)
|
|
72
|
+
end)
|
|
73
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #post_author_attributes_login")
|
|
74
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #author_login")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should concat rendered nested inputs to the template' do
|
|
78
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
79
|
+
|
|
80
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
81
|
+
builder.inputs :for => [:author, @bob] do |bob_builder|
|
|
82
|
+
concat(bob_builder.input(:login))
|
|
83
|
+
end
|
|
84
|
+
end)
|
|
85
|
+
|
|
86
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #post_author_attributes_login")
|
|
87
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #author_login")
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "as a symbol representing the association name" do
|
|
92
|
+
|
|
93
|
+
it 'should nest the inputs with an _attributes suffix on the association name' do
|
|
94
|
+
concat(semantic_form_for(@new_post) do |post|
|
|
95
|
+
inputs = post.inputs :for => :author do |author|
|
|
96
|
+
concat(author.input(:login))
|
|
97
|
+
end
|
|
98
|
+
concat(inputs)
|
|
99
|
+
end)
|
|
100
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[author_attributes][login]']")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "as a symbol representing a has_many association name" do
|
|
106
|
+
before do
|
|
107
|
+
allow(@new_post).to receive(:authors).and_return([@bob, @fred])
|
|
108
|
+
allow(@new_post).to receive(:authors_attributes=)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'should nest the inputs with a fieldset, legend and :name input for each item' do
|
|
112
|
+
concat(semantic_form_for(@new_post) do |post|
|
|
113
|
+
post.inputs :for => :authors, :name => '%i' do |author|
|
|
114
|
+
concat(author.input(:login))
|
|
115
|
+
end
|
|
116
|
+
end)
|
|
117
|
+
|
|
118
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs", :count => 2)
|
|
119
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs legend", :count => 2)
|
|
120
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs legend", :text => "1", :count => 1)
|
|
121
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs legend", :text => "2")
|
|
122
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[authors_attributes][0][login]']")
|
|
123
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[authors_attributes][1][login]']")
|
|
124
|
+
expect(output_buffer.to_str).not_to have_tag('form fieldset[@name]')
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'should include an indexed :label input for each item' do
|
|
128
|
+
concat(semantic_form_for(@new_post) do |post|
|
|
129
|
+
post.inputs :for => :authors do |author, index|
|
|
130
|
+
concat(author.input(:login, :label => "#{index}", :required => false))
|
|
131
|
+
end
|
|
132
|
+
end)
|
|
133
|
+
|
|
134
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs label", :text => "1", :count => 1)
|
|
135
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs label", :text => "2", :count => 1)
|
|
136
|
+
expect(output_buffer.to_str).not_to have_tag('form fieldset legend')
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe 'as an array containing the a symbol for the association name and the associated object' do
|
|
141
|
+
|
|
142
|
+
it 'should nest the inputs with an _attributes suffix on the association name' do
|
|
143
|
+
concat(semantic_form_for(@new_post) do |post|
|
|
144
|
+
inputs = post.inputs :for => [:author, @new_post.author] do |author|
|
|
145
|
+
concat(author.input(:login))
|
|
146
|
+
end
|
|
147
|
+
concat(inputs)
|
|
148
|
+
end)
|
|
149
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[author_attributes][login]']")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe 'as an associated object' do
|
|
155
|
+
|
|
156
|
+
it 'should not nest the inputs with an _attributes suffix' do
|
|
157
|
+
concat(semantic_form_for(@new_post) do |post|
|
|
158
|
+
inputs = post.inputs :for => @new_post.author do |author|
|
|
159
|
+
concat(author.input(:login))
|
|
160
|
+
end
|
|
161
|
+
concat(inputs)
|
|
162
|
+
end)
|
|
163
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[author][login]']")
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'should raise an error if :for and block with no argument is given' do
|
|
169
|
+
semantic_form_for(@new_post) do |builder|
|
|
170
|
+
expect {
|
|
171
|
+
builder.inputs(:for => [:author, @bob]) do
|
|
172
|
+
#
|
|
173
|
+
end
|
|
174
|
+
}.to raise_error(ArgumentError, 'You gave :for option with a block to inputs method, but the block does not accept any argument.')
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it 'should pass options down to semantic_fields_for' do
|
|
179
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
180
|
+
|
|
181
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
182
|
+
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
|
183
|
+
concat(bob_builder.input(:login))
|
|
184
|
+
end
|
|
185
|
+
concat(inputs)
|
|
186
|
+
end)
|
|
187
|
+
|
|
188
|
+
expect(output_buffer.to_str).to have_tag('form fieldset ol li #post_author_attributes_10_login')
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it 'should not add builder as a fieldset attribute tag' do
|
|
192
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
193
|
+
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
|
194
|
+
concat('input')
|
|
195
|
+
end
|
|
196
|
+
concat(inputs)
|
|
197
|
+
end)
|
|
198
|
+
|
|
199
|
+
expect(output_buffer.to_str).not_to have_tag('fieldset[@builder="Formtastic::Helpers::FormHelper"]')
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'should send parent_builder as an option to allow child index interpolation for legends' do
|
|
203
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
204
|
+
builder.instance_variable_set('@nested_child_index', 0)
|
|
205
|
+
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
|
206
|
+
concat('input')
|
|
207
|
+
end
|
|
208
|
+
concat(inputs)
|
|
209
|
+
end)
|
|
210
|
+
|
|
211
|
+
expect(output_buffer.to_str).to have_tag('fieldset legend', :text => 'Author #1')
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'should also provide child index interpolation for legends when nested child index is a hash' do
|
|
215
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
216
|
+
builder.instance_variable_set('@nested_child_index', :author => 10)
|
|
217
|
+
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
|
218
|
+
concat('input')
|
|
219
|
+
end
|
|
220
|
+
concat(inputs)
|
|
221
|
+
end)
|
|
222
|
+
|
|
223
|
+
expect(output_buffer.to_str).to have_tag('fieldset legend', :text => 'Author #11')
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it 'should send parent_builder as an option to allow child index interpolation for labels' do
|
|
227
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
228
|
+
builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 0)
|
|
229
|
+
inputs = builder.inputs :for => [:author, @bob] do |bob_builder, index|
|
|
230
|
+
concat(bob_builder.input(:name, :label => "Author ##{index}", :required => false))
|
|
231
|
+
end
|
|
232
|
+
concat(inputs)
|
|
233
|
+
end)
|
|
234
|
+
|
|
235
|
+
expect(output_buffer.to_str).to have_tag('fieldset label', :text => 'Author #1')
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it 'should also provide child index interpolation for labels when nested child index is a hash' do
|
|
239
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
240
|
+
builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 10)
|
|
241
|
+
inputs = builder.inputs :for => [:author, @bob] do |bob_builder, index|
|
|
242
|
+
concat(bob_builder.input(:name, :label => "Author ##{index}", :required => false))
|
|
243
|
+
end
|
|
244
|
+
concat(inputs)
|
|
245
|
+
end)
|
|
246
|
+
|
|
247
|
+
expect(output_buffer.to_str).to have_tag('fieldset label', :text => 'Author #11')
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
describe 'when a :name or :title option is provided' do
|
|
252
|
+
describe 'and is a string' do
|
|
253
|
+
before do
|
|
254
|
+
@legend_text = "Advanced options"
|
|
255
|
+
@legend_text_using_name = "Advanced options 2"
|
|
256
|
+
@legend_text_using_title = "Advanced options 3"
|
|
257
|
+
@nested_forms_legend_text = "This is a nested form title"
|
|
258
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
259
|
+
inputs = builder.inputs @legend_text do
|
|
260
|
+
end
|
|
261
|
+
concat(inputs)
|
|
262
|
+
inputs = builder.inputs :name => @legend_text_using_name do
|
|
263
|
+
end
|
|
264
|
+
concat(inputs)
|
|
265
|
+
inputs = builder.inputs :title => @legend_text_using_title do
|
|
266
|
+
end
|
|
267
|
+
concat(inputs)
|
|
268
|
+
inputs = builder.inputs @nested_forms_legend_text, :for => :authors do |nf|
|
|
269
|
+
end
|
|
270
|
+
concat(inputs)
|
|
271
|
+
end)
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# TODO: looks like the block isn't being called for the last assertion here
|
|
275
|
+
it 'should render a fieldset with a legend inside the form' do
|
|
276
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@legend_text}$/)
|
|
277
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@legend_text_using_name}$/)
|
|
278
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@legend_text_using_title}$/)
|
|
279
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@nested_forms_legend_text}$/)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
describe 'and is a symbol' do
|
|
284
|
+
before do
|
|
285
|
+
@localized_legend_text = "Localized advanced options"
|
|
286
|
+
@localized_legend_text_using_name = "Localized advanced options 2"
|
|
287
|
+
@localized_legend_text_using_title = "Localized advanced options 3"
|
|
288
|
+
@localized_nested_forms_legend_text = "This is a localized nested form title"
|
|
289
|
+
::I18n.backend.store_translations :en, :formtastic => {
|
|
290
|
+
:titles => {
|
|
291
|
+
:post => {
|
|
292
|
+
:advanced_options => @localized_legend_text,
|
|
293
|
+
:advanced_options_using_name => @localized_legend_text_using_name,
|
|
294
|
+
:advanced_options_using_title => @localized_legend_text_using_title,
|
|
295
|
+
:nested_forms_title => @localized_nested_forms_legend_text
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
300
|
+
concat(builder.inputs(:advanced_options) do
|
|
301
|
+
end)
|
|
302
|
+
concat(builder.inputs(:name => :advanced_options_using_name) do
|
|
303
|
+
end)
|
|
304
|
+
concat(builder.inputs(:title => :advanced_options_using_title) do
|
|
305
|
+
end)
|
|
306
|
+
concat(builder.inputs(:nested_forms_title, :for => :authors) do |nf|
|
|
307
|
+
end)
|
|
308
|
+
end)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
# TODO: looks like the block isn't being called for the last assertion here
|
|
312
|
+
it 'should render a fieldset with a localized legend inside the form' do
|
|
313
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text}$/)
|
|
314
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text_using_name}$/)
|
|
315
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text_using_title}$/)
|
|
316
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_nested_forms_legend_text}$/)
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
describe 'when other options are provided' do
|
|
322
|
+
before do
|
|
323
|
+
@id_option = 'advanced'
|
|
324
|
+
@class_option = 'wide'
|
|
325
|
+
|
|
326
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
327
|
+
builder.inputs :id => @id_option, :class => @class_option do
|
|
328
|
+
end
|
|
329
|
+
end)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
it 'should pass the options into the fieldset tag as attributes' do
|
|
333
|
+
expect(output_buffer.to_str).to have_tag("form fieldset##{@id_option}")
|
|
334
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.#{@class_option}")
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
describe 'without a block' do
|
|
341
|
+
|
|
342
|
+
before do
|
|
343
|
+
allow(::Post).to receive(:reflections).and_return({:author => double('reflection', :options => {}, :macro => :belongs_to),
|
|
344
|
+
:comments => double('reflection', :options => {}, :macro => :has_many) })
|
|
345
|
+
|
|
346
|
+
allow(@new_post).to receive(:title)
|
|
347
|
+
allow(@new_post).to receive(:body)
|
|
348
|
+
allow(@new_post).to receive(:author_id)
|
|
349
|
+
|
|
350
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
|
|
351
|
+
allow(@new_post).to receive(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
|
|
352
|
+
allow(@new_post).to receive(:column_for_attribute).with(:created_at).and_return(double('column', :type => :datetime))
|
|
353
|
+
allow(@new_post).to receive(:column_for_attribute).with(:author).and_return(nil)
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
describe 'with no args (quick forms syntax)' do
|
|
357
|
+
before do
|
|
358
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
359
|
+
concat(builder.inputs)
|
|
360
|
+
end)
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
it 'should render a form' do
|
|
364
|
+
expect(output_buffer.to_str).to have_tag('form')
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
it 'should render a fieldset inside the form' do
|
|
368
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs')
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
it 'should not render a legend in the fieldset' do
|
|
372
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > legend')
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
it 'should render an ol in the fieldset' do
|
|
376
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol')
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
it 'should render a list item in the ol for each column and reflection' do
|
|
380
|
+
# Remove the :has_many macro and :created_at column
|
|
381
|
+
count = ::Post.content_columns.size + ::Post.reflections.size - 2
|
|
382
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => count)
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it 'should render a string list item for title' do
|
|
386
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string')
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
it 'should render a text list item for body' do
|
|
390
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.text')
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it 'should render a select list item for author_id' do
|
|
394
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
it 'should not render timestamps inputs by default' do
|
|
398
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > ol > li.datetime')
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
context "with non-standard foregin keys" do
|
|
402
|
+
before do
|
|
403
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
it 'should respect foreign key while rendering select' do
|
|
407
|
+
concat(semantic_form_for(LegacyPost.new, {:url => '/'}) do |builder|
|
|
408
|
+
concat(builder.inputs)
|
|
409
|
+
end)
|
|
410
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.select select#legacy_post_post_author', :count => 1)
|
|
411
|
+
expect(output_buffer.to_str).not_to have_tag('input#legacy_post_post_author')
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
context "with a polymorphic association" do
|
|
417
|
+
|
|
418
|
+
before do
|
|
419
|
+
allow(@new_post).to receive(:commentable)
|
|
420
|
+
allow(@new_post.class).to receive(:reflections).and_return({
|
|
421
|
+
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
|
422
|
+
})
|
|
423
|
+
allow(@new_post).to receive(:column_for_attribute).with(:commentable).and_return(
|
|
424
|
+
double('column', :type => :integer)
|
|
425
|
+
)
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
it 'should not render an input for the polymorphic association (the collection class cannot be guessed)' do
|
|
429
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
430
|
+
concat(builder.inputs)
|
|
431
|
+
end)
|
|
432
|
+
expect(output_buffer.to_str).not_to have_tag('li#post_commentable_input')
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
describe 'with column names as args (short hand forms syntax)' do
|
|
439
|
+
describe 'and an object is given' do
|
|
440
|
+
it 'should render a form with a fieldset containing two list items' do
|
|
441
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
442
|
+
concat(builder.inputs(:title, :body))
|
|
443
|
+
end)
|
|
444
|
+
|
|
445
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
|
446
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string')
|
|
447
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.text')
|
|
448
|
+
end
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
describe 'and no object is given' do
|
|
452
|
+
it 'should render a form with a fieldset containing two list items' do
|
|
453
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
454
|
+
concat(builder.inputs(:title, :body))
|
|
455
|
+
end)
|
|
456
|
+
|
|
457
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
context "with a polymorphic association" do
|
|
462
|
+
|
|
463
|
+
it 'should raise an error for polymorphic associations (the collection class cannot be guessed)' do
|
|
464
|
+
allow(@new_post).to receive(:commentable)
|
|
465
|
+
allow(@new_post.class).to receive(:reflections).and_return({
|
|
466
|
+
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
|
467
|
+
})
|
|
468
|
+
allow(@new_post).to receive(:column_for_attribute).with(:commentable).and_return(
|
|
469
|
+
double('column', :type => :integer)
|
|
470
|
+
)
|
|
471
|
+
allow(@new_post.class).to receive(:reflect_on_association).with(:commentable).and_return(
|
|
472
|
+
double('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
expect {
|
|
476
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
477
|
+
concat(builder.inputs :commentable)
|
|
478
|
+
end)
|
|
479
|
+
}.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
describe 'when a :for option is provided' do
|
|
487
|
+
describe 'and an object is given' do
|
|
488
|
+
it 'should render nested inputs' do
|
|
489
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
490
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
491
|
+
concat(builder.inputs(:login, :for => @bob))
|
|
492
|
+
end)
|
|
493
|
+
|
|
494
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #post_author_login")
|
|
495
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #author_login")
|
|
496
|
+
end
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
describe 'and no object is given' do
|
|
500
|
+
it 'should render nested inputs' do
|
|
501
|
+
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
|
502
|
+
concat(builder.inputs(:login, :for => @bob))
|
|
503
|
+
end)
|
|
504
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #project_author_login")
|
|
505
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #project_login")
|
|
506
|
+
end
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
describe 'with column names and an options hash as args' do
|
|
511
|
+
before do
|
|
512
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
513
|
+
@legend_text_using_option = "Legendary Legend Text"
|
|
514
|
+
@legend_text_using_arg = "Legendary Legend Text 2"
|
|
515
|
+
concat(builder.inputs(:title, :body, :name => @legend_text_using_option, :id => "my-id"))
|
|
516
|
+
concat(builder.inputs(@legend_text_using_arg, :title, :body, :id => "my-id-2"))
|
|
517
|
+
end)
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
it 'should render a form with a fieldset containing two list items' do
|
|
521
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 4)
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
it 'should pass the options down to the fieldset' do
|
|
525
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.inputs')
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
it 'should use the special :name option as a text for the legend tag' do
|
|
529
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.inputs > legend', :text => /^#{@legend_text_using_option}$/)
|
|
530
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id-2.inputs > legend', :text => /^#{@legend_text_using_arg}$/)
|
|
531
|
+
end
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
describe 'when a :except option is provided' do
|
|
535
|
+
describe 'and an object is given' do
|
|
536
|
+
it 'should render a form with a fieldset containing only string item' do
|
|
537
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
538
|
+
concat(builder.inputs :except => :body)
|
|
539
|
+
end)
|
|
540
|
+
|
|
541
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
|
542
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string')
|
|
543
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > ol > li.text')
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
it 'should render a form with a fieldset containing only text item' do
|
|
547
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
548
|
+
concat(builder.inputs :except => :title)
|
|
549
|
+
end)
|
|
550
|
+
|
|
551
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
|
552
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > ol > li.string')
|
|
553
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.text')
|
|
554
|
+
end
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
describe 'and no object is given' do
|
|
558
|
+
it 'should render a form with a fieldset containing two list items' do
|
|
559
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
560
|
+
concat(builder.inputs(:title, :body))
|
|
561
|
+
end)
|
|
562
|
+
|
|
563
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
|
564
|
+
end
|
|
565
|
+
end
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
describe 'nesting' do
|
|
570
|
+
|
|
571
|
+
context "when not nested" do
|
|
572
|
+
it "should not wrap the inputs in an li block" do
|
|
573
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
574
|
+
concat(builder.inputs do
|
|
575
|
+
end)
|
|
576
|
+
end)
|
|
577
|
+
expect(output_buffer.to_str).not_to have_tag('form > li')
|
|
578
|
+
end
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
context "when nested (with block)" do
|
|
582
|
+
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
583
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
584
|
+
concat(builder.inputs do
|
|
585
|
+
concat(builder.inputs do
|
|
586
|
+
end)
|
|
587
|
+
end)
|
|
588
|
+
end)
|
|
589
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
590
|
+
end
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
context "when nested (with block and :for)" do
|
|
594
|
+
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
595
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
596
|
+
concat(builder.inputs do
|
|
597
|
+
concat(builder.inputs(:for => :author) do |author_builder|
|
|
598
|
+
end)
|
|
599
|
+
end)
|
|
600
|
+
end)
|
|
601
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
context "when nested (without block)" do
|
|
606
|
+
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
607
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
608
|
+
concat(builder.inputs do
|
|
609
|
+
concat(builder.inputs(:title))
|
|
610
|
+
end)
|
|
611
|
+
end)
|
|
612
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
613
|
+
end
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
context "when nested (without block, with :for)" do
|
|
617
|
+
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
618
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
619
|
+
concat(builder.inputs do
|
|
620
|
+
concat(builder.inputs(:name, :for => :author))
|
|
621
|
+
end)
|
|
622
|
+
end)
|
|
623
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
624
|
+
end
|
|
625
|
+
end
|
|
626
|
+
|
|
627
|
+
context "when double nested" do
|
|
628
|
+
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
629
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
630
|
+
concat(builder.inputs do
|
|
631
|
+
concat(builder.inputs do
|
|
632
|
+
concat(builder.inputs do
|
|
633
|
+
end)
|
|
634
|
+
end)
|
|
635
|
+
end)
|
|
636
|
+
end)
|
|
637
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
638
|
+
end
|
|
639
|
+
end
|
|
640
|
+
|
|
641
|
+
context "when several are nested" do
|
|
642
|
+
it "should wrap each of the nested inputs in an li block to maintain HTML validity" do
|
|
643
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
644
|
+
concat(builder.inputs do
|
|
645
|
+
concat(builder.inputs do
|
|
646
|
+
end)
|
|
647
|
+
concat(builder.inputs do
|
|
648
|
+
end)
|
|
649
|
+
end)
|
|
650
|
+
end)
|
|
651
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol', :count => 2)
|
|
652
|
+
end
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
describe 'when using MongoMapper associations ' do
|
|
658
|
+
def generate_form
|
|
659
|
+
semantic_form_for(@new_mm_post) do |builder|
|
|
660
|
+
builder.inputs :title, :sub_posts
|
|
661
|
+
end
|
|
662
|
+
end
|
|
663
|
+
it "should throw PolymorphicInputWithoutCollectionError on sub_posts" do
|
|
664
|
+
expect(::MongoPost).to receive(:associations).at_least(3).times
|
|
665
|
+
expect { generate_form }.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
|
666
|
+
end
|
|
667
|
+
end
|
|
668
|
+
|
|
669
|
+
end
|