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,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
# Generators are not automatically loaded by Rails
|
|
5
|
+
require 'generators/formtastic/stylesheets/stylesheets_generator'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Formtastic::StylesheetsGenerator 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 'app/assets/stylesheets/formtastic.css' do
|
|
17
|
+
subject { file('app/assets/stylesheets/formtastic.css') }
|
|
18
|
+
it { is_expected.to exist }
|
|
19
|
+
it { is_expected.to contain ".formtastic" }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'with action class finder' do
|
|
5
|
+
include_context 'form builder'
|
|
6
|
+
|
|
7
|
+
describe 'arguments and options' do
|
|
8
|
+
|
|
9
|
+
it 'should require the first argument (the action method)' do
|
|
10
|
+
expect {
|
|
11
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
12
|
+
concat(builder.action()) # no args passed in at all
|
|
13
|
+
end)
|
|
14
|
+
}.to raise_error(ArgumentError)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe ':as option' do
|
|
18
|
+
|
|
19
|
+
describe 'when not provided' do
|
|
20
|
+
|
|
21
|
+
it 'should default to a commit for commit' do
|
|
22
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
23
|
+
concat(builder.action(:submit))
|
|
24
|
+
end)
|
|
25
|
+
expect(output_buffer.to_str).to have_tag('form li.action.input_action', :count => 1)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should default to a button for reset' do
|
|
29
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
30
|
+
concat(builder.action(:reset))
|
|
31
|
+
end)
|
|
32
|
+
expect(output_buffer.to_str).to have_tag('form li.action.input_action', :count => 1)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should default to a link for cancel' do
|
|
36
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
37
|
+
concat(builder.action(:cancel))
|
|
38
|
+
end)
|
|
39
|
+
expect(output_buffer.to_str).to have_tag('form li.action.link_action', :count => 1)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'should call the corresponding action class with .to_html' do
|
|
44
|
+
[:input, :button, :link].each do |action_style|
|
|
45
|
+
semantic_form_for(:project, :url => "http://test.host") do |builder|
|
|
46
|
+
action_instance = double('Action instance')
|
|
47
|
+
action_class = "#{action_style.to_s}_action".classify
|
|
48
|
+
action_constant = "Formtastic::Actions::#{action_class}".constantize
|
|
49
|
+
|
|
50
|
+
expect(action_constant).to receive(:new).and_return(action_instance)
|
|
51
|
+
expect(action_instance).to receive(:to_html).and_return("some HTML")
|
|
52
|
+
|
|
53
|
+
concat(builder.action(:submit, :as => action_style))
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
#describe ':label option' do
|
|
61
|
+
#
|
|
62
|
+
# describe 'when provided' do
|
|
63
|
+
# it 'should be passed down to the label tag' do
|
|
64
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
65
|
+
# concat(builder.input(:title, :label => "Kustom"))
|
|
66
|
+
# end)
|
|
67
|
+
# output_buffer.should have_tag("form li label", /Kustom/)
|
|
68
|
+
# end
|
|
69
|
+
#
|
|
70
|
+
# it 'should not generate a label if false' do
|
|
71
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
72
|
+
# concat(builder.input(:title, :label => false))
|
|
73
|
+
# end)
|
|
74
|
+
# output_buffer.should_not have_tag("form li label")
|
|
75
|
+
# end
|
|
76
|
+
#
|
|
77
|
+
# it 'should be dupped if frozen' do
|
|
78
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
79
|
+
# concat(builder.input(:title, :label => "Kustom".freeze))
|
|
80
|
+
# end)
|
|
81
|
+
# output_buffer.should have_tag("form li label", /Kustom/)
|
|
82
|
+
# end
|
|
83
|
+
# end
|
|
84
|
+
#
|
|
85
|
+
# describe 'when not provided' do
|
|
86
|
+
# describe 'when localized label is provided' do
|
|
87
|
+
# describe 'and object is given' do
|
|
88
|
+
# describe 'and label_str_method not :humanize' do
|
|
89
|
+
# it 'should render a label with localized text and not apply the label_str_method' do
|
|
90
|
+
# with_config :label_str_method, :reverse do
|
|
91
|
+
# @localized_label_text = 'Localized title'
|
|
92
|
+
# @new_post.stub(:meta_description)
|
|
93
|
+
# ::I18n.backend.store_translations :en,
|
|
94
|
+
# :formtastic => {
|
|
95
|
+
# :labels => {
|
|
96
|
+
# :meta_description => @localized_label_text
|
|
97
|
+
# }
|
|
98
|
+
# }
|
|
99
|
+
#
|
|
100
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
101
|
+
# concat(builder.input(:meta_description))
|
|
102
|
+
# end)
|
|
103
|
+
# output_buffer.should have_tag('form li label', /Localized title/)
|
|
104
|
+
# end
|
|
105
|
+
# end
|
|
106
|
+
# end
|
|
107
|
+
# end
|
|
108
|
+
# end
|
|
109
|
+
#
|
|
110
|
+
# describe 'when localized label is NOT provided' do
|
|
111
|
+
# describe 'and object is not given' do
|
|
112
|
+
# it 'should default the humanized method name, passing it down to the label tag' do
|
|
113
|
+
# ::I18n.backend.store_translations :en, :formtastic => {}
|
|
114
|
+
# with_config :label_str_method, :humanize do
|
|
115
|
+
# concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
116
|
+
# concat(builder.input(:meta_description))
|
|
117
|
+
# end)
|
|
118
|
+
# output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
|
|
119
|
+
# end
|
|
120
|
+
# end
|
|
121
|
+
# end
|
|
122
|
+
#
|
|
123
|
+
# describe 'and object is given' do
|
|
124
|
+
# it 'should delegate the label logic to class human attribute name and pass it down to the label tag' do
|
|
125
|
+
# @new_post.stub(:meta_description) # a two word method name
|
|
126
|
+
# @new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
|
|
127
|
+
#
|
|
128
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
129
|
+
# concat(builder.input(:meta_description))
|
|
130
|
+
# end)
|
|
131
|
+
# output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
|
|
132
|
+
# end
|
|
133
|
+
# end
|
|
134
|
+
#
|
|
135
|
+
# describe 'and object is given with label_str_method set to :capitalize' do
|
|
136
|
+
# it 'should capitalize method name, passing it down to the label tag' do
|
|
137
|
+
# with_config :label_str_method, :capitalize do
|
|
138
|
+
# @new_post.stub(:meta_description)
|
|
139
|
+
#
|
|
140
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
141
|
+
# concat(builder.input(:meta_description))
|
|
142
|
+
# end)
|
|
143
|
+
# output_buffer.should have_tag("form li label", /#{'meta_description'.capitalize}/)
|
|
144
|
+
# end
|
|
145
|
+
# end
|
|
146
|
+
# end
|
|
147
|
+
# end
|
|
148
|
+
#
|
|
149
|
+
# describe 'when localized label is provided' do
|
|
150
|
+
# before do
|
|
151
|
+
# @localized_label_text = 'Localized title'
|
|
152
|
+
# @default_localized_label_text = 'Default localized title'
|
|
153
|
+
# ::I18n.backend.store_translations :en,
|
|
154
|
+
# :formtastic => {
|
|
155
|
+
# :labels => {
|
|
156
|
+
# :title => @default_localized_label_text,
|
|
157
|
+
# :published => @default_localized_label_text,
|
|
158
|
+
# :post => {
|
|
159
|
+
# :title => @localized_label_text,
|
|
160
|
+
# :published => @default_localized_label_text
|
|
161
|
+
# }
|
|
162
|
+
# }
|
|
163
|
+
# }
|
|
164
|
+
# end
|
|
165
|
+
#
|
|
166
|
+
# it 'should render a label with localized label (I18n)' do
|
|
167
|
+
# with_config :i18n_lookups_by_default, false do
|
|
168
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
169
|
+
# concat(builder.input(:title, :label => true))
|
|
170
|
+
# concat(builder.input(:published, :as => :boolean, :label => true))
|
|
171
|
+
# end)
|
|
172
|
+
# output_buffer.should have_tag('form li label', Regexp.new('^' + @localized_label_text))
|
|
173
|
+
# end
|
|
174
|
+
# end
|
|
175
|
+
#
|
|
176
|
+
# it 'should render a hint paragraph containing an optional localized label (I18n) if first is not set' do
|
|
177
|
+
# with_config :i18n_lookups_by_default, false do
|
|
178
|
+
# ::I18n.backend.store_translations :en,
|
|
179
|
+
# :formtastic => {
|
|
180
|
+
# :labels => {
|
|
181
|
+
# :post => {
|
|
182
|
+
# :title => nil,
|
|
183
|
+
# :published => nil
|
|
184
|
+
# }
|
|
185
|
+
# }
|
|
186
|
+
# }
|
|
187
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
|
188
|
+
# concat(builder.input(:title, :label => true))
|
|
189
|
+
# concat(builder.input(:published, :as => :boolean, :label => true))
|
|
190
|
+
# end)
|
|
191
|
+
# output_buffer.should have_tag('form li label', Regexp.new('^' + @default_localized_label_text))
|
|
192
|
+
# end
|
|
193
|
+
# end
|
|
194
|
+
# end
|
|
195
|
+
# end
|
|
196
|
+
#
|
|
197
|
+
#end
|
|
198
|
+
#
|
|
199
|
+
describe ':wrapper_html option' do
|
|
200
|
+
|
|
201
|
+
describe 'when provided' do
|
|
202
|
+
it 'should be passed down to the li tag' do
|
|
203
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
204
|
+
concat(builder.action(:submit, :wrapper_html => {:id => :another_id}))
|
|
205
|
+
end)
|
|
206
|
+
expect(output_buffer.to_str).to have_tag("form li#another_id")
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it 'should append given classes to li default classes' do
|
|
210
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
211
|
+
concat(builder.action(:submit, :wrapper_html => {:class => :another_class}))
|
|
212
|
+
end)
|
|
213
|
+
expect(output_buffer.to_str).to have_tag("form li.action")
|
|
214
|
+
expect(output_buffer.to_str).to have_tag("form li.input_action")
|
|
215
|
+
expect(output_buffer.to_str).to have_tag("form li.another_class")
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it 'should allow classes to be an array' do
|
|
219
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
220
|
+
concat(builder.action(:submit, :wrapper_html => {:class => [ :my_class, :another_class ]}))
|
|
221
|
+
end)
|
|
222
|
+
expect(output_buffer.to_str).to have_tag("form li.action")
|
|
223
|
+
expect(output_buffer.to_str).to have_tag("form li.input_action")
|
|
224
|
+
expect(output_buffer.to_str).to have_tag("form li.my_class")
|
|
225
|
+
expect(output_buffer.to_str).to have_tag("form li.another_class")
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
describe 'when not provided' do
|
|
230
|
+
it 'should use default id and class' do
|
|
231
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
232
|
+
concat(builder.action(:submit))
|
|
233
|
+
end)
|
|
234
|
+
expect(output_buffer.to_str).to have_tag("form li#post_submit_action")
|
|
235
|
+
expect(output_buffer.to_str).to have_tag("form li.action")
|
|
236
|
+
expect(output_buffer.to_str).to have_tag("form li.input_action")
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
describe 'instantiating an action class' do
|
|
245
|
+
context 'when a class does not exist' do
|
|
246
|
+
it "should raise an error" do
|
|
247
|
+
expect {
|
|
248
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
249
|
+
builder.action(:submit, :as => :non_existant)
|
|
250
|
+
end)
|
|
251
|
+
}.to raise_error(Formtastic::UnknownActionError)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
context 'when a customized top-level class does not exist' do
|
|
256
|
+
it 'should instantiate the Formtastic action' do
|
|
257
|
+
action = double('action', :to_html => 'some HTML')
|
|
258
|
+
expect(Formtastic::Actions::ButtonAction).to receive(:new).and_return(action)
|
|
259
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
260
|
+
builder.action(:commit, :as => :button)
|
|
261
|
+
end)
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
describe 'when a top-level (custom) action class exists' do
|
|
266
|
+
it "should instantiate the top-level action instead of the Formtastic one" do
|
|
267
|
+
class ::ButtonAction < Formtastic::Actions::ButtonAction
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
action = double('action', :to_html => 'some HTML')
|
|
271
|
+
expect(Formtastic::Actions::ButtonAction).not_to receive(:new)
|
|
272
|
+
expect(::ButtonAction).to receive(:new).and_return(action)
|
|
273
|
+
|
|
274
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
275
|
+
builder.action(:commit, :as => :button)
|
|
276
|
+
end)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
describe 'support for :as on each action' do
|
|
281
|
+
|
|
282
|
+
it "should raise an error when the action does not support the :as" do
|
|
283
|
+
expect {
|
|
284
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
285
|
+
concat(builder.action(:submit, :as => :link))
|
|
286
|
+
end)
|
|
287
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
288
|
+
|
|
289
|
+
expect {
|
|
290
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
291
|
+
concat(builder.action(:cancel, :as => :input))
|
|
292
|
+
end)
|
|
293
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
294
|
+
|
|
295
|
+
expect {
|
|
296
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
297
|
+
concat(builder.action(:cancel, :as => :button))
|
|
298
|
+
end)
|
|
299
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
it "should not raise an error when the action does not support the :as" do
|
|
303
|
+
expect {
|
|
304
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
305
|
+
concat(builder.action(:cancel, :as => :link))
|
|
306
|
+
end)
|
|
307
|
+
}.not_to raise_error
|
|
308
|
+
|
|
309
|
+
expect {
|
|
310
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
311
|
+
concat(builder.action(:submit, :as => :input))
|
|
312
|
+
end)
|
|
313
|
+
}.not_to raise_error
|
|
314
|
+
|
|
315
|
+
expect {
|
|
316
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
317
|
+
concat(builder.action(:submit, :as => :button))
|
|
318
|
+
end)
|
|
319
|
+
}.not_to raise_error
|
|
320
|
+
|
|
321
|
+
expect {
|
|
322
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
323
|
+
concat(builder.action(:reset, :as => :input))
|
|
324
|
+
end)
|
|
325
|
+
}.not_to raise_error
|
|
326
|
+
|
|
327
|
+
expect {
|
|
328
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
329
|
+
concat(builder.action(:reset, :as => :button))
|
|
330
|
+
end)
|
|
331
|
+
}.not_to raise_error
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Formtastic::FormBuilder#actions' 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' do
|
|
14
|
+
describe 'when no options are provided' do
|
|
15
|
+
before do
|
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
17
|
+
concat(builder.actions do
|
|
18
|
+
concat('hello')
|
|
19
|
+
end)
|
|
20
|
+
end)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should render a fieldset inside the form, with a class of "actions"' do
|
|
24
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should render an ol inside the fieldset' do
|
|
28
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions ol")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should render the contents of the block inside the ol' do
|
|
32
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions ol", :text => /hello/)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should not render a legend inside the fieldset' do
|
|
36
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.actions legend")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'when a :name option is provided' do
|
|
41
|
+
before do
|
|
42
|
+
@legend_text = "Advanced options"
|
|
43
|
+
|
|
44
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
45
|
+
builder.actions :name => @legend_text do
|
|
46
|
+
end
|
|
47
|
+
end)
|
|
48
|
+
end
|
|
49
|
+
it 'should render a fieldset inside the form' do
|
|
50
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions legend", :text => /#{@legend_text}/)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe 'when other options are provided' do
|
|
55
|
+
before do
|
|
56
|
+
@id_option = 'advanced'
|
|
57
|
+
@class_option = 'wide'
|
|
58
|
+
|
|
59
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
60
|
+
builder.actions :id => @id_option, :class => @class_option do
|
|
61
|
+
end
|
|
62
|
+
end)
|
|
63
|
+
end
|
|
64
|
+
it 'should pass the options into the fieldset tag as attributes' do
|
|
65
|
+
expect(output_buffer.to_str).to have_tag("form fieldset##{@id_option}")
|
|
66
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.#{@class_option}")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe 'without a block' do
|
|
73
|
+
|
|
74
|
+
describe 'with no args (default buttons)' do
|
|
75
|
+
|
|
76
|
+
before do
|
|
77
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
78
|
+
concat(builder.actions)
|
|
79
|
+
end)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'should render a form' do
|
|
83
|
+
expect(output_buffer.to_str).to have_tag('form')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'should render an actions fieldset inside the form' do
|
|
87
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'should not render a legend in the fieldset' do
|
|
91
|
+
expect(output_buffer.to_str).not_to have_tag('form fieldset.actions legend')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'should render an ol in the fieldset' do
|
|
95
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions ol')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'should render a list item in the ol for each default action' do
|
|
99
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe 'with button names as args' do
|
|
105
|
+
|
|
106
|
+
before do
|
|
107
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
108
|
+
concat(builder.actions(:submit, :cancel, :reset))
|
|
109
|
+
end)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
113
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe 'with button names as args and an options hash' do
|
|
119
|
+
|
|
120
|
+
before do
|
|
121
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
122
|
+
concat(builder.actions(:submit, :cancel, :reset, :name => "Now click a button", :id => "my-id"))
|
|
123
|
+
end)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
127
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'should pass the options down to the fieldset' do
|
|
131
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions')
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'should use the special :name option as a text for the legend tag' do
|
|
135
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions > legend', :text => /Now click a button/)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|