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,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
class MyCustomFormBuilder < Formtastic::FormBuilder
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# TODO should be a separate spec for custom inputs
|
|
12
|
+
class Formtastic::Inputs::AwesomeInput
|
|
13
|
+
include Formtastic::Inputs::Base
|
|
14
|
+
def to_html
|
|
15
|
+
"Awesome!"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
before do
|
|
20
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
21
|
+
mock_everything
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'is the Formtastic::FormBuilder by default' do
|
|
25
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(Formtastic::FormBuilder)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'can be configured to use your own custom form builder' do
|
|
29
|
+
# Set it to a custom builder class
|
|
30
|
+
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
|
31
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(MyCustomFormBuilder)
|
|
32
|
+
|
|
33
|
+
# Reset it to the default
|
|
34
|
+
Formtastic::Helpers::FormHelper.builder = Formtastic::FormBuilder
|
|
35
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(Formtastic::FormBuilder)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should allow custom settings per form builder subclass' do
|
|
39
|
+
with_config(:all_fields_required_by_default, true) do
|
|
40
|
+
MyCustomFormBuilder.all_fields_required_by_default = false
|
|
41
|
+
|
|
42
|
+
expect(MyCustomFormBuilder.all_fields_required_by_default).to be_falsey
|
|
43
|
+
expect(Formtastic::FormBuilder.all_fields_required_by_default).to be_truthy
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "when using a custom builder" do
|
|
48
|
+
|
|
49
|
+
before do
|
|
50
|
+
allow(@new_post).to receive(:title)
|
|
51
|
+
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
after do
|
|
55
|
+
Formtastic::Helpers::FormHelper.builder = Formtastic::FormBuilder
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "semantic_form_for" do
|
|
59
|
+
|
|
60
|
+
it "should yield an instance of the custom builder" do
|
|
61
|
+
semantic_form_for(@new_post) do |builder|
|
|
62
|
+
expect(builder.class).to be(MyCustomFormBuilder)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# TODO should be a separate spec for custom inputs
|
|
67
|
+
it "should allow me to call my custom input" do
|
|
68
|
+
semantic_form_for(@new_post) do |builder|
|
|
69
|
+
concat(builder.input(:title, :as => :awesome))
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# See: https://github.com/formtastic/formtastic/issues/657
|
|
74
|
+
it "should not conflict with navigasmic" do
|
|
75
|
+
allow_any_instance_of(self.class).to receive(:builder).and_return('navigasmic')
|
|
76
|
+
|
|
77
|
+
expect { semantic_form_for(@new_post) { |f| } }.not_to raise_error
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should use the custom builder's skipped_columns config for inputs" do
|
|
81
|
+
class AnotherCustomFormBuilder < Formtastic::FormBuilder
|
|
82
|
+
configure :skipped_columns, [:title, :created_at]
|
|
83
|
+
end
|
|
84
|
+
#AnotherCustomFormBuilder.skipped_columns = [:title, :created_at]
|
|
85
|
+
|
|
86
|
+
concat(semantic_form_for(@new_post, builder: AnotherCustomFormBuilder) do |builder|
|
|
87
|
+
concat(builder.inputs)
|
|
88
|
+
end)
|
|
89
|
+
|
|
90
|
+
expect(output_buffer.to_str).to_not have_tag('input#post_title')
|
|
91
|
+
expect(output_buffer.to_str).to_not have_tag('li#post_created_at_input')
|
|
92
|
+
expect(output_buffer.to_str).to have_tag('textarea#post_body')
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe "fields_for" do
|
|
97
|
+
|
|
98
|
+
it "should yield an instance of the parent form builder" do
|
|
99
|
+
allow(@new_post).to receive(:comment).and_return([@fred])
|
|
100
|
+
allow(@new_post).to receive(:comment_attributes=)
|
|
101
|
+
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
|
102
|
+
expect(builder.class).to be(MyCustomFormBuilder)
|
|
103
|
+
|
|
104
|
+
builder.fields_for(:comment) do |nested_builder|
|
|
105
|
+
expect(nested_builder.class).to be(MyCustomFormBuilder)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe "when using a builder passed to form options" do
|
|
117
|
+
|
|
118
|
+
describe "fields_for" do
|
|
119
|
+
|
|
120
|
+
it "should yield an instance of the parent form builder" do
|
|
121
|
+
allow(@new_post).to receive(:author_attributes=)
|
|
122
|
+
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
|
123
|
+
builder.fields_for(:author) do |nested_builder|
|
|
124
|
+
expect(nested_builder.class).to be(MyCustomFormBuilder)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Rails field_error_proc' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should not be overridden globally for all form builders" do
|
|
14
|
+
current_field_error_proc = ::ActionView::Base.field_error_proc
|
|
15
|
+
|
|
16
|
+
semantic_form_for(@new_post) do |builder|
|
|
17
|
+
expect(::ActionView::Base.field_error_proc).not_to eq(current_field_error_proc)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
expect(::ActionView::Base.field_error_proc).to eq(current_field_error_proc)
|
|
21
|
+
|
|
22
|
+
form_for(@new_post) do |builder|
|
|
23
|
+
expect(::ActionView::Base.field_error_proc).to eq(current_field_error_proc)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Formtastic::FormBuilder#fields_for' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
allow(@new_post).to receive(:author).and_return(::Author.new)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'outside a form_for block' do
|
|
15
|
+
it 'yields an instance of FormHelper.builder' do
|
|
16
|
+
semantic_fields_for(@new_post) do |nested_builder|
|
|
17
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
|
18
|
+
end
|
|
19
|
+
semantic_fields_for(@new_post.author) do |nested_builder|
|
|
20
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
|
21
|
+
end
|
|
22
|
+
semantic_fields_for(:author, @new_post.author) do |nested_builder|
|
|
23
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
|
24
|
+
end
|
|
25
|
+
semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
|
|
26
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'should respond to input' do
|
|
31
|
+
semantic_fields_for(@new_post) do |nested_builder|
|
|
32
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
|
33
|
+
end
|
|
34
|
+
semantic_fields_for(@new_post.author) do |nested_builder|
|
|
35
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
|
36
|
+
end
|
|
37
|
+
semantic_fields_for(:author, @new_post.author) do |nested_builder|
|
|
38
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
|
39
|
+
end
|
|
40
|
+
semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
|
|
41
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'within a form_for block' do
|
|
47
|
+
it 'yields an instance of FormHelper.builder' do
|
|
48
|
+
semantic_form_for(@new_post) do |builder|
|
|
49
|
+
builder.semantic_fields_for(:author) do |nested_builder|
|
|
50
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'yields an instance of FormHelper.builder with hash-like model' do
|
|
56
|
+
semantic_form_for(:user) do |builder|
|
|
57
|
+
builder.semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
|
|
58
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'nests the object name' do
|
|
64
|
+
semantic_form_for(@new_post) do |builder|
|
|
65
|
+
builder.semantic_fields_for(@bob) do |nested_builder|
|
|
66
|
+
expect(nested_builder.object_name).to eq('post[author]')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'supports passing collection as second parameter' do
|
|
72
|
+
semantic_form_for(@new_post) do |builder|
|
|
73
|
+
builder.semantic_fields_for(:author, [@fred,@bob]) do |nested_builder|
|
|
74
|
+
expect(nested_builder.object_name).to match(/post\[author_attributes\]\[\d+\]/)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'should sanitize html id for li tag' do
|
|
80
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
81
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
82
|
+
concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
|
|
83
|
+
concat(nested_builder.inputs(:login))
|
|
84
|
+
end)
|
|
85
|
+
end)
|
|
86
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.inputs #post_author_1_login_input')
|
|
87
|
+
# Not valid selector, so using good ol' regex
|
|
88
|
+
expect(output_buffer.to_str).not_to match(/id="post\[author\]_1_login_input"/)
|
|
89
|
+
# <=> output_buffer.should_not have_tag('form fieldset.inputs #post[author]_1_login_input')
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should use namespace provided in nested fields' do
|
|
93
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
94
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
95
|
+
concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
|
|
96
|
+
concat(nested_builder.inputs(:login))
|
|
97
|
+
end)
|
|
98
|
+
end)
|
|
99
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.inputs #context2_post_author_1_login_input')
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'should render errors on the nested inputs' do
|
|
103
|
+
@errors = double('errors')
|
|
104
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
|
|
105
|
+
allow(@bob).to receive(:errors).and_return(@errors)
|
|
106
|
+
|
|
107
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
108
|
+
concat(builder.semantic_fields_for(@bob) do |nested_builder|
|
|
109
|
+
concat(nested_builder.inputs(:login))
|
|
110
|
+
end)
|
|
111
|
+
end)
|
|
112
|
+
expect(output_buffer.to_str).to match(/oh noes/)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
context "when I rendered my own hidden id input" do
|
|
117
|
+
|
|
118
|
+
before do
|
|
119
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
120
|
+
|
|
121
|
+
expect(@fred.posts.size).to eq(1)
|
|
122
|
+
allow(@fred.posts.first).to receive(:persisted?).and_return(true)
|
|
123
|
+
allow(@fred).to receive(:posts_attributes=)
|
|
124
|
+
concat(semantic_form_for(@fred) do |builder|
|
|
125
|
+
concat(builder.semantic_fields_for(:posts) do |nested_builder|
|
|
126
|
+
concat(nested_builder.input(:id, :as => :hidden))
|
|
127
|
+
concat(nested_builder.input(:title))
|
|
128
|
+
end)
|
|
129
|
+
end)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should only render one hidden input (my one)" do
|
|
133
|
+
expect(output_buffer.to_str).to have_tag 'input#author_posts_attributes_0_id', :count => 1
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should render the hidden input inside an li.hidden" do
|
|
137
|
+
expect(output_buffer.to_str).to have_tag 'li.hidden input#author_posts_attributes_0_id'
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
context "when FormBuilder.semantic_errors_link_to_inputs is true" do
|
|
142
|
+
before do
|
|
143
|
+
Formtastic::FormBuilder.semantic_errors_link_to_inputs = true
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
after do
|
|
147
|
+
Formtastic::FormBuilder.semantic_errors_link_to_inputs = false
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context "when there are errors" do
|
|
151
|
+
before do
|
|
152
|
+
@errors = double('errors')
|
|
153
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
|
|
154
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:name)).and_return([])
|
|
155
|
+
allow(@bob).to receive(:errors).and_return(@errors)
|
|
156
|
+
|
|
157
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
158
|
+
concat(builder.semantic_fields_for(@bob) do |nested_builder|
|
|
159
|
+
concat(nested_builder.inputs(:login, :name))
|
|
160
|
+
end)
|
|
161
|
+
end)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'should render errors on the nested inputs with default aria attributes' do
|
|
165
|
+
expect(output_buffer.to_str).to include('aria-invalid="true"')
|
|
166
|
+
expect(output_buffer.to_str).to \
|
|
167
|
+
have_tag 'input#context2_post_author_login[aria-describedby="login_error"]', \
|
|
168
|
+
count: 1
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'should preserve developer-set aria attributes' do
|
|
172
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
173
|
+
concat(builder.semantic_fields_for(@bob) do |nested_builder|
|
|
174
|
+
concat(nested_builder.input(:login, input_html: { 'aria-describedby': 'hint_for_email_field', 'aria-invalid': 'false' } ))
|
|
175
|
+
end)
|
|
176
|
+
end)
|
|
177
|
+
|
|
178
|
+
expect(output_buffer.to_str).to \
|
|
179
|
+
have_tag 'input#context2_post_author_login[aria-describedby="hint_for_email_field login_error"]', \
|
|
180
|
+
count: 1
|
|
181
|
+
expect(output_buffer.to_str).to \
|
|
182
|
+
have_tag 'input#context2_post_author_login[aria-invalid="false"]', \
|
|
183
|
+
count: 1
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
context "when there are no errors" do
|
|
188
|
+
before do
|
|
189
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
190
|
+
concat(builder.semantic_fields_for(@bob) do |nested_builder|
|
|
191
|
+
concat(nested_builder.input(:login))
|
|
192
|
+
end)
|
|
193
|
+
end)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it 'should not aria attributes on nested inputs' do
|
|
197
|
+
expect(output_buffer.to_str).not_to include('aria-invalid')
|
|
198
|
+
expect(output_buffer.to_str).not_to include('aria-describedby')
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'should render aria attributes I set' do
|
|
202
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
203
|
+
concat(builder.semantic_fields_for(@bob) do |nested_builder|
|
|
204
|
+
concat(nested_builder.input(:login, input_html: { 'aria-describedby': 'hint_for_email_field', 'aria-invalid': 'false' } ))
|
|
205
|
+
end)
|
|
206
|
+
end)
|
|
207
|
+
|
|
208
|
+
expect(output_buffer.to_str).to include('aria-describedby="hint_for_email_field"')
|
|
209
|
+
expect(output_buffer.to_str).to include('aria-invalid="false"')
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
$LOAD_PATH << 'lib/formtastic'
|
|
3
|
+
require 'active_support/all'
|
|
4
|
+
require 'localized_string'
|
|
5
|
+
require 'inputs'
|
|
6
|
+
require 'helpers'
|
|
7
|
+
|
|
8
|
+
class MyInput
|
|
9
|
+
include Formtastic::Inputs::Base
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
# Generators are not automatically loaded by Rails
|
|
5
|
+
require 'generators/formtastic/form/form_generator'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Formtastic::FormGenerator do
|
|
8
|
+
|
|
9
|
+
include FormtasticSpecHelper
|
|
10
|
+
|
|
11
|
+
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
12
|
+
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
16
|
+
prepare_destination
|
|
17
|
+
mock_everything
|
|
18
|
+
allow(::Post).to receive(:reflect_on_all_associations).with(:belongs_to).and_return([
|
|
19
|
+
double('reflection', :name => :author, :options => {}, :klass => ::Author, :macro => :belongs_to),
|
|
20
|
+
double('reflection', :name => :reviewer, :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to),
|
|
21
|
+
double('reflection', :name => :main_post, :options => {}, :klass => ::Post, :macro => :belongs_to),
|
|
22
|
+
double('reflection', :name => :attachment, :options => {:polymorphic => true}, :macro => :belongs_to),
|
|
23
|
+
])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
after do
|
|
27
|
+
FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe 'without model' do
|
|
31
|
+
it 'should raise Thor::RequiredArgumentMissingError' do
|
|
32
|
+
expect { run_generator }.to raise_error(Thor::RequiredArgumentMissingError)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe 'with existing model' do
|
|
37
|
+
it 'should not raise an exception' do
|
|
38
|
+
expect { run_generator %w(Post) }.not_to raise_error
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe 'with attributes' do
|
|
43
|
+
before { run_generator %w(Post title:string author:references) }
|
|
44
|
+
|
|
45
|
+
describe 'render only the specified attributes' do
|
|
46
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
47
|
+
it { is_expected.to exist }
|
|
48
|
+
it { is_expected.to contain "<%= f.input :title %>" }
|
|
49
|
+
it { is_expected.to contain "<%= f.input :author %>" }
|
|
50
|
+
it { is_expected.not_to contain "<%= f.input :main_post %>" }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe 'without attributes' do
|
|
55
|
+
before { run_generator %w(Post) }
|
|
56
|
+
|
|
57
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
58
|
+
|
|
59
|
+
describe 'content_columns' do
|
|
60
|
+
it { is_expected.to contain "<%= f.input :title %>" }
|
|
61
|
+
it { is_expected.to contain "<%= f.input :body %>" }
|
|
62
|
+
it { is_expected.not_to contain "<%= f.input :created_at %>" }
|
|
63
|
+
it { is_expected.not_to contain "<%= f.input :updated_at %>" }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe 'reflection_on_association' do
|
|
67
|
+
it { is_expected.to contain "<%= f.input :author %>" }
|
|
68
|
+
it { is_expected.to contain "<%= f.input :reviewer %>" }
|
|
69
|
+
it { is_expected.to contain "<%= f.input :main_post %>" }
|
|
70
|
+
it { is_expected.not_to contain "<%= f.input :attachment %>" }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe 'with template engine option' do
|
|
75
|
+
describe 'erb' do
|
|
76
|
+
before { run_generator %w(Post --template-engine erb) }
|
|
77
|
+
|
|
78
|
+
describe 'app/views/posts/_form.html.erb' do
|
|
79
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
80
|
+
it { is_expected.to exist }
|
|
81
|
+
it { is_expected.to contain "<%= semantic_form_for @post do |f| %>" }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe 'haml' do
|
|
86
|
+
|
|
87
|
+
describe 'app/views/posts/_form.html.haml' do
|
|
88
|
+
before { run_generator %w(Post --template-engine haml) }
|
|
89
|
+
subject { file('app/views/posts/_form.html.haml') }
|
|
90
|
+
it { is_expected.to exist }
|
|
91
|
+
it { is_expected.to contain "= semantic_form_for @post do |f|" }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context 'with copy option' do
|
|
95
|
+
describe 'app/views/posts/_form.html.haml' do
|
|
96
|
+
before { run_generator %w(Post --copy --template-engine haml) }
|
|
97
|
+
subject { file('app/views/posts/_form.html.haml') }
|
|
98
|
+
it { is_expected.not_to exist }
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe 'slim' do
|
|
105
|
+
before { run_generator %w(Post --template-engine slim) }
|
|
106
|
+
|
|
107
|
+
describe 'app/views/posts/_form.html.slim' do
|
|
108
|
+
subject { file('app/views/posts/_form.html.slim') }
|
|
109
|
+
it { is_expected.to exist }
|
|
110
|
+
it { is_expected.to contain "= semantic_form_for @post do |f|" }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe 'with copy option' do
|
|
116
|
+
before { run_generator %w(Post --copy) }
|
|
117
|
+
|
|
118
|
+
describe 'app/views/posts/_form.html.erb' do
|
|
119
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
120
|
+
it { is_expected.not_to exist }
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe 'with controller option' do
|
|
125
|
+
before { run_generator %w(Post --controller admin/posts) }
|
|
126
|
+
|
|
127
|
+
describe 'app/views/admin/posts/_form.html.erb' do
|
|
128
|
+
subject { file('app/views/admin/posts/_form.html.erb') }
|
|
129
|
+
it { is_expected.to exist }
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
require 'generators/formtastic/input/input_generator'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Formtastic::InputGenerator do
|
|
7
|
+
include FormtasticSpecHelper
|
|
8
|
+
|
|
9
|
+
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
prepare_destination
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after do
|
|
16
|
+
FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'without file name' do
|
|
20
|
+
it 'should raise Thor::RequiredArgumentMissingError' do
|
|
21
|
+
expect { run_generator }.to raise_error(Thor::RequiredArgumentMissingError)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "input generator with underscore definition" do
|
|
26
|
+
before { run_generator %w(hat_size)}
|
|
27
|
+
|
|
28
|
+
describe 'generate an input in its respective folder' do
|
|
29
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
30
|
+
it { is_expected.to exist}
|
|
31
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
32
|
+
it { is_expected.to contain "def to_html"}
|
|
33
|
+
it { is_expected.to contain "include Formtastic::Inputs::Base"}
|
|
34
|
+
it { is_expected.not_to contain "super"}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "input generator with camelcase definition" do
|
|
39
|
+
before { run_generator %w(HatSize)}
|
|
40
|
+
|
|
41
|
+
describe 'generate an input in its respective folder' do
|
|
42
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
43
|
+
it { is_expected.to exist}
|
|
44
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "input generator with camelcase Input name sufixed" do
|
|
49
|
+
before { run_generator %w(HatSizeInput)}
|
|
50
|
+
|
|
51
|
+
describe 'generate an input in its respective folder' do
|
|
52
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
53
|
+
it { is_expected.to exist}
|
|
54
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "input generator with underscore _input name sufixed" do
|
|
59
|
+
before { run_generator %w(hat_size_input)}
|
|
60
|
+
|
|
61
|
+
describe 'generate an input in its respective folder' do
|
|
62
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
63
|
+
it { is_expected.to exist}
|
|
64
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "input generator with underscore input name sufixed" do
|
|
69
|
+
before { run_generator %w(hat_sizeinput)}
|
|
70
|
+
|
|
71
|
+
describe 'generate an input in its respective folder' do
|
|
72
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
73
|
+
it { is_expected.to exist}
|
|
74
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe "override an existing input using extend" do
|
|
79
|
+
before { run_generator %w(string --extend)}
|
|
80
|
+
|
|
81
|
+
describe 'app/inputs/string_input.rb' do
|
|
82
|
+
subject{ file('app/inputs/string_input.rb')}
|
|
83
|
+
it { is_expected.to exist }
|
|
84
|
+
it { is_expected.to contain "class StringInput < Formtastic::Inputs::StringInput" }
|
|
85
|
+
it { is_expected.to contain "def to_html" }
|
|
86
|
+
it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
|
|
87
|
+
it { is_expected.to contain "super" }
|
|
88
|
+
it { is_expected.not_to contain "def input_html_options" }
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe "extend an existing input" do
|
|
93
|
+
before { run_generator %w(FlexibleText --extend string)}
|
|
94
|
+
|
|
95
|
+
describe 'app/inputs/flexible_text_input.rb' do
|
|
96
|
+
subject{ file('app/inputs/flexible_text_input.rb')}
|
|
97
|
+
it { is_expected.to contain "class FlexibleTextInput < Formtastic::Inputs::StringInput" }
|
|
98
|
+
it { is_expected.to contain "def input_html_options" }
|
|
99
|
+
it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
|
|
100
|
+
it { is_expected.not_to contain "def to_html" }
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe "provide a slashed namespace" do
|
|
105
|
+
before { run_generator %w(stuff/foo)}
|
|
106
|
+
|
|
107
|
+
describe 'app/inputs/stuff/foo_input.rb' do
|
|
108
|
+
subject{ file('app/inputs/stuff/foo_input.rb')}
|
|
109
|
+
it {is_expected.to exist}
|
|
110
|
+
it { is_expected.to contain "class Stuff::FooInput" }
|
|
111
|
+
it { is_expected.to contain "include Formtastic::Inputs::Base" }
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe "provide a camelized namespace" do
|
|
116
|
+
before { run_generator %w(Stuff::Foo)}
|
|
117
|
+
|
|
118
|
+
describe 'app/inputs/stuff/foo_input.rb' do
|
|
119
|
+
subject{ file('app/inputs/stuff/foo_input.rb')}
|
|
120
|
+
it {is_expected.to exist}
|
|
121
|
+
it { is_expected.to contain "class Stuff::FooInput" }
|
|
122
|
+
it { is_expected.to contain "include Formtastic::Inputs::Base" }
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
# Generators are not automatically loaded by Rails
|
|
5
|
+
require 'generators/formtastic/install/install_generator'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Formtastic::InstallGenerator do
|
|
8
|
+
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
9
|
+
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
10
|
+
|
|
11
|
+
before { prepare_destination }
|
|
12
|
+
|
|
13
|
+
describe 'no arguments' do
|
|
14
|
+
before { run_generator }
|
|
15
|
+
|
|
16
|
+
describe 'config/initializers/formtastic.rb' do
|
|
17
|
+
subject { file('config/initializers/formtastic.rb') }
|
|
18
|
+
it { is_expected.to exist }
|
|
19
|
+
it { is_expected.to contain "#" }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe 'lib/templates/erb/scaffold/_form.html.erb' do
|
|
23
|
+
subject { file('lib/templates/erb/scaffold/_form.html.erb') }
|
|
24
|
+
it { is_expected.to exist }
|
|
25
|
+
it { is_expected.to contain "<%%= semantic_form_for @<%= singular_name %> do |f| %>" }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe 'haml' do
|
|
30
|
+
before { run_generator %w(--template-engine haml) }
|
|
31
|
+
|
|
32
|
+
describe 'lib/templates/erb/scaffold/_form.html.haml' do
|
|
33
|
+
subject { file('lib/templates/haml/scaffold/_form.html.haml') }
|
|
34
|
+
it { is_expected.to exist }
|
|
35
|
+
it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe 'slim' do
|
|
40
|
+
before { run_generator %w(--template-engine slim) }
|
|
41
|
+
|
|
42
|
+
describe 'lib/templates/erb/scaffold/_form.html.slim' do
|
|
43
|
+
subject { file('lib/templates/slim/scaffold/_form.html.slim') }
|
|
44
|
+
it { is_expected.to exist }
|
|
45
|
+
it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|