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,326 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'string input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "when object is provided" do
|
|
14
|
+
before do
|
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
16
|
+
concat(builder.input(:title, :as => :string))
|
|
17
|
+
concat(builder.input(:status, :as => :string))
|
|
18
|
+
end)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it_should_have_input_wrapper_with_class(:string)
|
|
22
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
23
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
|
24
|
+
it_should_have_input_wrapper_with_id("post_title_input")
|
|
25
|
+
it_should_have_label_with_text(/Title/)
|
|
26
|
+
it_should_have_label_for("post_title")
|
|
27
|
+
it_should_have_input_with_id("post_title")
|
|
28
|
+
it_should_have_input_with_type(:text)
|
|
29
|
+
it_should_have_input_with_name("post[title]")
|
|
30
|
+
it_should_have_maxlength_matching_string_column_limit
|
|
31
|
+
it_should_have_maxlength_matching_integer_column_limit
|
|
32
|
+
it_should_use_default_text_field_size_when_not_nil(:string)
|
|
33
|
+
it_should_not_use_default_text_field_size_when_nil(:string)
|
|
34
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
|
35
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
|
36
|
+
it_should_apply_error_logic_for_input_type(:string)
|
|
37
|
+
|
|
38
|
+
def input_field_for_method_should_have_maxlength(method, maxlength)
|
|
39
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
40
|
+
concat(builder.input(method))
|
|
41
|
+
end)
|
|
42
|
+
expect(output_buffer.to_str).to have_tag("form li input[@maxlength='#{maxlength}']")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe 'and its a ActiveModel' do
|
|
46
|
+
let(:default_maxlength) { 50 }
|
|
47
|
+
|
|
48
|
+
before do
|
|
49
|
+
allow(@new_post).to receive(:class).and_return(::PostModel)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
after do
|
|
53
|
+
allow(@new_post).to receive(:class).and_return(::Post)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe 'and validates_length_of was called for the method' do
|
|
57
|
+
def should_have_maxlength(maxlength, options)
|
|
58
|
+
expect(@new_post.class).to receive(:validators_on).with(:title).at_least(1).and_return([
|
|
59
|
+
active_model_length_validator([:title], options[:options])
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
63
|
+
concat(builder.input(:title))
|
|
64
|
+
end)
|
|
65
|
+
|
|
66
|
+
expect(output_buffer.to_str).to have_tag("form li input##{@new_post.class.name.underscore}_title[@maxlength='#{maxlength}']")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'should have maxlength if the optional :if or :unless options are not supplied' do
|
|
70
|
+
should_have_maxlength(42, :options => {:maximum => 42})
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'should have default maxlength if the optional :if condition is not satisifed' do
|
|
74
|
+
should_have_maxlength(default_maxlength, :options => {:maximum => 42, :if => false})
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should have default_maxlength if the optional :if proc evaluates to false' do
|
|
78
|
+
should_have_maxlength(default_maxlength, :options => {:maximum => 42, :if => proc { |record| false }})
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'should have maxlength if the optional :if proc evaluates to true' do
|
|
82
|
+
should_have_maxlength(42, :options => { :maximum => 42, :if => proc { |record| true } })
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'should have default maxlength if the optional :if with a method name evaluates to false' do
|
|
86
|
+
expect(@new_post).to receive(:specify_maxlength).at_least(1).and_return(false)
|
|
87
|
+
should_have_maxlength(default_maxlength, :options => { :maximum => 42, :if => :specify_maxlength })
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'should have maxlength if the optional :if with a method name evaluates to true' do
|
|
91
|
+
expect(@new_post).to receive(:specify_maxlength).at_least(1).and_return(true)
|
|
92
|
+
should_have_maxlength(42, :options => { :maximum => 42, :if => :specify_maxlength })
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'should have default maxlength if the optional :unless proc evaluates to true' do
|
|
96
|
+
should_have_maxlength(default_maxlength, :options => { :maximum => 42, :unless => proc { |record| true } })
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'should have maxlength if the optional :unless proc evaluates to false' do
|
|
100
|
+
should_have_maxlength(42, :options => { :maximum => 42, :unless => proc { |record| false } })
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'should have default maxlength if the optional :unless with a method name evaluates to true' do
|
|
104
|
+
expect(@new_post).to receive(:specify_maxlength).at_least(1).and_return(true)
|
|
105
|
+
should_have_maxlength(default_maxlength, :options => { :maximum => 42, :unless => :specify_maxlength })
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'should have maxlength if the optional :unless with a method name evaluates to false' do
|
|
109
|
+
expect(@new_post).to receive(:specify_maxlength).at_least(1).and_return(false)
|
|
110
|
+
should_have_maxlength(42, :options => { :maximum => 42, :unless => :specify_maxlength })
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe 'and validates_length_of was called with a proc for :maximum' do
|
|
115
|
+
before do
|
|
116
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
117
|
+
active_model_length_validator([:title], { :maximum => Proc.new { 128 } })
|
|
118
|
+
])
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'should use the proc result as maxlength' do
|
|
122
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
123
|
+
concat(builder.input(:title))
|
|
124
|
+
end)
|
|
125
|
+
expect(output_buffer.to_str).to have_tag("form li input##{@new_post.class.name.underscore}_title[@maxlength='128']")
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe 'and validates_length_of was called with a proc for :within' do
|
|
130
|
+
before do
|
|
131
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
132
|
+
active_model_length_validator([:title], { :within => Proc.new { 5..100 } })
|
|
133
|
+
])
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'should use the proc result maximum as maxlength' do
|
|
137
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
138
|
+
concat(builder.input(:title))
|
|
139
|
+
end)
|
|
140
|
+
expect(output_buffer.to_str).to have_tag("form li input##{@new_post.class.name.underscore}_title[@maxlength='100']")
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
describe 'and validates_length_of was called with a proc for :minimum' do
|
|
145
|
+
before do
|
|
146
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
147
|
+
active_model_length_validator([:title], { :minimum => Proc.new { 8 }, :allow_blank => false })
|
|
148
|
+
])
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'should use the proc result to determine required status' do
|
|
152
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
153
|
+
concat(builder.input(:title))
|
|
154
|
+
end)
|
|
155
|
+
expect(output_buffer.to_str).to have_tag("form li.required")
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
describe 'and validates_length_of was called with a callable object for :maximum' do
|
|
160
|
+
before do
|
|
161
|
+
callable = Object.new
|
|
162
|
+
def callable.call(record)
|
|
163
|
+
128
|
|
164
|
+
end
|
|
165
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
166
|
+
active_model_length_validator([:title], { :maximum => callable })
|
|
167
|
+
])
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'should use the callable result as maxlength' do
|
|
171
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
172
|
+
concat(builder.input(:title))
|
|
173
|
+
end)
|
|
174
|
+
expect(output_buffer.to_str).to have_tag("form li input##{@new_post.class.name.underscore}_title[@maxlength='128']")
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
describe 'any conditional validation' do
|
|
179
|
+
describe 'proc that calls an instance method' do
|
|
180
|
+
it 'calls the method on the object' do
|
|
181
|
+
expect(@new_post).to receive(:something?)
|
|
182
|
+
expect(@new_post.class).to receive(:validators_on).with(:title).at_least(1).and_return([
|
|
183
|
+
active_model_presence_validator([:title], { :unless => -> { something? } })
|
|
184
|
+
])
|
|
185
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
186
|
+
concat(builder.input(:title))
|
|
187
|
+
end)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
describe 'proc with arity that calls an instance method' do
|
|
192
|
+
it 'calls the method on the object' do
|
|
193
|
+
expect(@new_post).to receive(:something?)
|
|
194
|
+
expect(@new_post.class).to receive(:validators_on).with(:title).at_least(1).and_return([
|
|
195
|
+
active_model_presence_validator([:title], { :unless => ->(user) { user.something? } })
|
|
196
|
+
])
|
|
197
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
198
|
+
concat(builder.input(:title))
|
|
199
|
+
end)
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
describe 'symbol method name' do
|
|
204
|
+
it 'calls the method on the object if the method exists' do
|
|
205
|
+
expect(@new_post).to receive(:something?)
|
|
206
|
+
expect(@new_post.class).to receive(:validators_on).with(:title).at_least(1).and_return([
|
|
207
|
+
active_model_presence_validator([:title], { :unless => :something? })
|
|
208
|
+
])
|
|
209
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
210
|
+
concat(builder.input(:title))
|
|
211
|
+
end)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
describe 'any other conditional' do
|
|
216
|
+
it 'does not raise an error' do
|
|
217
|
+
@conditional = double()
|
|
218
|
+
expect(@new_post.class).to receive(:validators_on).with(:title).at_least(1).and_return([
|
|
219
|
+
active_model_presence_validator([:title], { :unless => @conditional })
|
|
220
|
+
])
|
|
221
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
222
|
+
concat(builder.input(:title))
|
|
223
|
+
end)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
describe "when namespace is provided" do
|
|
233
|
+
|
|
234
|
+
before do
|
|
235
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
236
|
+
concat(builder.input(:title, :as => :string))
|
|
237
|
+
end)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it_should_have_input_wrapper_with_id("context2_post_title_input")
|
|
241
|
+
it_should_have_label_and_input_with_id("context2_post_title")
|
|
242
|
+
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
describe "when index is provided" do
|
|
246
|
+
|
|
247
|
+
before do
|
|
248
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
249
|
+
mock_everything
|
|
250
|
+
|
|
251
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
252
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
253
|
+
concat(author.input(:name, :as => :string))
|
|
254
|
+
end)
|
|
255
|
+
end)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
it 'should index the id of the wrapper' do
|
|
259
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
it 'should index the id of the select tag' do
|
|
263
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
it 'should index the name of the select tag' do
|
|
267
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
describe "when no object is provided" do
|
|
274
|
+
before do
|
|
275
|
+
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
|
276
|
+
concat(builder.input(:title, :as => :string))
|
|
277
|
+
end)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it_should_have_label_with_text(/Title/)
|
|
281
|
+
it_should_have_label_for("project_title")
|
|
282
|
+
it_should_have_input_with_id("project_title")
|
|
283
|
+
it_should_have_input_with_type(:text)
|
|
284
|
+
it_should_have_input_with_name("project[title]")
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
describe "when size is nil" do
|
|
288
|
+
before do
|
|
289
|
+
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
|
290
|
+
concat(builder.input(:title, :as => :string, :input_html => {:size => nil}))
|
|
291
|
+
end)
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
it "should have no size attribute" do
|
|
295
|
+
expect(output_buffer.to_str).not_to have_tag("input[@size]")
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
describe "when required" do
|
|
300
|
+
|
|
301
|
+
context "and configured to use HTML5 attribute" do
|
|
302
|
+
it "should add the required attribute to the input's html options" do
|
|
303
|
+
with_config :use_required_attribute, true do
|
|
304
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
305
|
+
concat(builder.input(:title, :as => :string, :required => true))
|
|
306
|
+
end)
|
|
307
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
context "and configured to not use HTML5 attribute" do
|
|
313
|
+
it "should add the required attribute to the input's html options" do
|
|
314
|
+
with_config :use_required_attribute, false do
|
|
315
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
316
|
+
concat(builder.input(:title, :as => :string, :required => true))
|
|
317
|
+
end)
|
|
318
|
+
expect(output_buffer.to_str).not_to have_tag("input[@required]")
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
end
|
|
326
|
+
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'text input' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
|
|
12
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
13
|
+
concat(builder.input(:body, :as => :text))
|
|
14
|
+
end)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it_should_have_input_wrapper_with_class("text")
|
|
18
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
19
|
+
it_should_have_input_wrapper_with_id("post_body_input")
|
|
20
|
+
it_should_have_label_with_text(/Body/)
|
|
21
|
+
it_should_have_label_for("post_body")
|
|
22
|
+
it_should_have_textarea_with_id("post_body")
|
|
23
|
+
it_should_have_textarea_with_name("post[body]")
|
|
24
|
+
it_should_apply_error_logic_for_input_type(:number)
|
|
25
|
+
|
|
26
|
+
it 'should use input_html to style inputs' do
|
|
27
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
28
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
29
|
+
concat(builder.input(:title, :as => :text, :input_html => { :class => 'myclass' }))
|
|
30
|
+
end)
|
|
31
|
+
expect(output_buffer.to_str).to have_tag("form li textarea.myclass")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should have a cols attribute when :cols is a number in :input_html" do
|
|
35
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
36
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
37
|
+
concat(builder.input(:title, :as => :text, :input_html => { :cols => 42 }))
|
|
38
|
+
end)
|
|
39
|
+
expect(output_buffer.to_str).to have_tag("form li textarea[@cols='42']")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should not have a cols attribute when :cols is nil in :input_html" do
|
|
43
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
44
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
45
|
+
concat(builder.input(:title, :as => :text, :input_html => { :cols => nil }))
|
|
46
|
+
end)
|
|
47
|
+
expect(output_buffer.to_str).not_to have_tag("form li textarea[@cols]")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should have a rows attribute when :rows is a number in :input_html" do
|
|
51
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
52
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
53
|
+
concat(builder.input(:title, :as => :text, :input_html => { :rows => 42 }))
|
|
54
|
+
end)
|
|
55
|
+
expect(output_buffer.to_str).to have_tag("form li textarea[@rows='42']")
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should not have a rows attribute when :rows is nil in :input_html" do
|
|
60
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
61
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
62
|
+
concat(builder.input(:title, :as => :text, :input_html => { :rows => nil }))
|
|
63
|
+
end)
|
|
64
|
+
expect(output_buffer.to_str).not_to have_tag("form li textarea[@rows]")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe "when namespace is provided" do
|
|
68
|
+
|
|
69
|
+
before do
|
|
70
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
71
|
+
mock_everything
|
|
72
|
+
|
|
73
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
74
|
+
concat(builder.input(:body, :as => :text))
|
|
75
|
+
end)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it_should_have_input_wrapper_with_id("context2_post_body_input")
|
|
79
|
+
it_should_have_textarea_with_id("context2_post_body")
|
|
80
|
+
it_should_have_label_for("context2_post_body")
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "when index is provided" do
|
|
85
|
+
|
|
86
|
+
before do
|
|
87
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
88
|
+
mock_everything
|
|
89
|
+
|
|
90
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
91
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
92
|
+
concat(author.input(:name, :as => :text))
|
|
93
|
+
end)
|
|
94
|
+
end)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'should index the id of the wrapper' do
|
|
98
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should index the id of the select tag' do
|
|
102
|
+
expect(output_buffer.to_str).to have_tag("textarea#post_author_attributes_3_name")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'should index the name of the select tag' do
|
|
106
|
+
expect(output_buffer.to_str).to have_tag("textarea[@name='post[author_attributes][3][name]']")
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
context "when required" do
|
|
112
|
+
it "should add the required attribute to the input's html options" do
|
|
113
|
+
with_config :use_required_attribute, true do
|
|
114
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
115
|
+
concat(builder.input(:title, :as => :text, :required => true))
|
|
116
|
+
end)
|
|
117
|
+
expect(output_buffer.to_str).to have_tag("textarea[@required]")
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context "when :autofocus is provided in :input_html" do
|
|
123
|
+
before(:example) do
|
|
124
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
125
|
+
concat(builder.input(:title, :input_html => {:autofocus => true}))
|
|
126
|
+
end)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it_should_have_input_wrapper_with_class("autofocus")
|
|
130
|
+
|
|
131
|
+
it "should add the autofocus attribute to the input's html options" do
|
|
132
|
+
expect(output_buffer.to_str).to have_tag("input[@autofocus]")
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
context "when :rows is missing in :input_html" do
|
|
137
|
+
before do
|
|
138
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "should have a rows attribute matching default_text_area_height if numeric" do
|
|
142
|
+
with_config :default_text_area_height, 12 do
|
|
143
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
144
|
+
concat(builder.input(:title, :as => :text))
|
|
145
|
+
end)
|
|
146
|
+
expect(output_buffer.to_str).to have_tag("form li textarea[@rows='12']")
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "should not have a rows attribute if default_text_area_height is nil" do
|
|
151
|
+
with_config :default_text_area_height, nil do
|
|
152
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
153
|
+
concat(builder.input(:title, :as => :text))
|
|
154
|
+
end)
|
|
155
|
+
expect(output_buffer.to_str).not_to have_tag("form li textarea[@rows]")
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context "when :cols is missing in :input_html" do
|
|
162
|
+
before do
|
|
163
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "should have a cols attribute matching default_text_area_width if numeric" do
|
|
167
|
+
with_config :default_text_area_width, 10 do
|
|
168
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
169
|
+
concat(builder.input(:title, :as => :text))
|
|
170
|
+
end)
|
|
171
|
+
expect(output_buffer.to_str).to have_tag("form li textarea[@cols='10']")
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "should not have a cols attribute if default_text_area_width is nil" do
|
|
176
|
+
with_config :default_text_area_width, nil do
|
|
177
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
178
|
+
concat(builder.input(:title, :as => :text))
|
|
179
|
+
end)
|
|
180
|
+
expect(output_buffer.to_str).not_to have_tag("form li textarea[@cols]")
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
end
|
|
187
|
+
|