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,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Formtastic::Helpers::Reflection' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class ReflectionTester
|
|
14
|
+
include Formtastic::Helpers::Reflection
|
|
15
|
+
def initialize(model_object)
|
|
16
|
+
@object = model_object
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'with an ActiveRecord object' do
|
|
21
|
+
it "should return association details on an ActiveRecord association" do
|
|
22
|
+
@reflection_tester = ReflectionTester.new(@new_post)
|
|
23
|
+
expect(@reflection_tester.reflection_for(:sub_posts)).not_to be_nil
|
|
24
|
+
end
|
|
25
|
+
it "should return association details on a MongoMapper association" do
|
|
26
|
+
@reflection_tester = ReflectionTester.new(@new_mm_post)
|
|
27
|
+
expect(@reflection_tester.reflection_for(:sub_posts)).not_to be_nil
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
|
+
mock_everything
|
|
11
|
+
@title_errors = ['must not be blank', 'must be awesome']
|
|
12
|
+
@base_errors = ['base error message', 'nasty error']
|
|
13
|
+
@base_error = ['one base error']
|
|
14
|
+
@errors = double('errors')
|
|
15
|
+
allow(@new_post).to receive(:errors).and_return(@errors)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe 'when there is only one error on base' do
|
|
19
|
+
before do
|
|
20
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should render an unordered list' do
|
|
24
|
+
semantic_form_for(@new_post) do |builder|
|
|
25
|
+
expect(builder.semantic_errors).to have_tag('ul.errors li', text: 'one base error')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe 'when there is more than one error on base' do
|
|
31
|
+
before do
|
|
32
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_errors)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should render an unordered list' do
|
|
36
|
+
semantic_form_for(@new_post) do |builder|
|
|
37
|
+
expect(builder.semantic_errors).to have_tag('ul.errors')
|
|
38
|
+
@base_errors.each do |error|
|
|
39
|
+
expect(builder.semantic_errors).to have_tag('ul.errors li', :text => error)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe 'when there are errors on title' do
|
|
46
|
+
before do
|
|
47
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
|
|
48
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'should render an unordered list' do
|
|
52
|
+
semantic_form_for(@new_post) do |builder|
|
|
53
|
+
title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
|
|
54
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', :text => title_name << " " << @title_errors.to_sentence)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe 'when there are errors on title and base' do
|
|
60
|
+
before do
|
|
61
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
|
|
62
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'should render an unordered list' do
|
|
66
|
+
semantic_form_for(@new_post) do |builder|
|
|
67
|
+
title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
|
|
68
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', :text => title_name << " " << @title_errors.to_sentence)
|
|
69
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', text: 'one base error')
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe 'when there are no errors' do
|
|
75
|
+
before do
|
|
76
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return([])
|
|
77
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'should return nil' do
|
|
81
|
+
semantic_form_for(@new_post) do |builder|
|
|
82
|
+
expect(builder.semantic_errors(:title)).to be_nil
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe 'when there is one error on base and options with class is passed' do
|
|
88
|
+
before do
|
|
89
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should render an unordered list with given class' do
|
|
93
|
+
semantic_form_for(@new_post) do |builder|
|
|
94
|
+
expect(builder.semantic_errors(:class => "awesome")).to have_tag('ul.awesome li', text: 'one base error')
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe 'when :base is passed in as an argument' do
|
|
100
|
+
before do
|
|
101
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'should ignore :base and only render base errors once' do
|
|
105
|
+
semantic_form_for(@new_post) do |builder|
|
|
106
|
+
expect(builder.semantic_errors(:base)).to have_tag('ul li', :count => 1)
|
|
107
|
+
expect(builder.semantic_errors(:base)).not_to have_tag('ul li', :text => "Base #{@base_error}")
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
context 'when configure FormBuilder.semantic_errors_link_to_inputs is true' do
|
|
113
|
+
before do
|
|
114
|
+
Formtastic::FormBuilder.semantic_errors_link_to_inputs = true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
after do
|
|
118
|
+
Formtastic::FormBuilder.semantic_errors_link_to_inputs = false
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
describe 'when there is only one error on base' do
|
|
123
|
+
before do
|
|
124
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'should render an unordered list' do
|
|
128
|
+
semantic_form_for(@new_post) do |builder|
|
|
129
|
+
expect(builder.semantic_errors).to have_tag('ul.errors li', text: 'one base error')
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
describe 'when there is more than one error on base' do
|
|
135
|
+
before do
|
|
136
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_errors)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'should render an unordered list' do
|
|
140
|
+
semantic_form_for(@new_post) do |builder|
|
|
141
|
+
expect(builder.semantic_errors).to have_tag('ul.errors')
|
|
142
|
+
@base_errors.each do |error|
|
|
143
|
+
expect(builder.semantic_errors).to have_tag('ul.errors li', :text => error)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe 'when there are errors on title' do
|
|
150
|
+
before do
|
|
151
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
|
|
152
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'should render an unordered list' do
|
|
156
|
+
semantic_form_for(@new_post) do |builder|
|
|
157
|
+
title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
|
|
158
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li a', :text => title_name << " " << @title_errors.to_sentence)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
describe 'when there are errors on title and base' do
|
|
164
|
+
before do
|
|
165
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
|
|
166
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'should render an unordered list where base has no link, and title error attribute links to title input field' do
|
|
170
|
+
semantic_form_for(@new_post) do |builder|
|
|
171
|
+
title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
|
|
172
|
+
expect(builder.semantic_errors(:title)).to \
|
|
173
|
+
have_tag('ul.errors li a',
|
|
174
|
+
with: { href: "##{@new_post.model_name}_title" },
|
|
175
|
+
text: title_name << " " << @title_errors.to_sentence
|
|
176
|
+
)
|
|
177
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', text: 'one base error')
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
describe 'when there are no errors' do
|
|
183
|
+
before do
|
|
184
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return([])
|
|
185
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it 'should return nil' do
|
|
189
|
+
semantic_form_for(@new_post) do |builder|
|
|
190
|
+
expect(builder.semantic_errors(:title)).to be_nil
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
describe 'when there is one error on base and options with class is passed' do
|
|
196
|
+
before do
|
|
197
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it 'should render an unordered list with given class' do
|
|
201
|
+
semantic_form_for(@new_post) do |builder|
|
|
202
|
+
expect(builder.semantic_errors(class: "awesome")).to have_tag('ul.awesome li', text: 'one base error')
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
describe 'when :base is passed in as an argument' do
|
|
208
|
+
before do
|
|
209
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it 'should ignore :base and only render base errors once' do
|
|
213
|
+
semantic_form_for(@new_post) do |builder|
|
|
214
|
+
expect(builder.semantic_errors(:base)).to have_tag('ul li', count: 1)
|
|
215
|
+
expect(builder.semantic_errors(:base)).not_to have_tag('ul li', text: "Base #{@base_error}")
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end # context 'when semantic_errors_link_to_inputs is true'
|
|
220
|
+
end
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'Formtastic::I18n' do
|
|
5
|
+
|
|
6
|
+
FORMTASTIC_KEYS = [:required, :yes, :no, :create, :update].freeze
|
|
7
|
+
|
|
8
|
+
it "should be defined" do
|
|
9
|
+
expect { Formtastic::I18n }.not_to raise_error
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "default translations" do
|
|
13
|
+
it "should be defined" do
|
|
14
|
+
expect { Formtastic::I18n::DEFAULT_VALUES }.not_to raise_error
|
|
15
|
+
expect(Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash)).to eq(true)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should exists for the core I18n lookup keys" do
|
|
19
|
+
expect((Formtastic::I18n::DEFAULT_VALUES.keys & FORMTASTIC_KEYS).size).to eq(FORMTASTIC_KEYS.size)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "when I18n locales are available" do
|
|
24
|
+
|
|
25
|
+
before do
|
|
26
|
+
@formtastic_strings = {
|
|
27
|
+
:yes => 'Default Yes',
|
|
28
|
+
:no => 'Default No',
|
|
29
|
+
:create => 'Default Create %{model}',
|
|
30
|
+
:update => 'Default Update %{model}',
|
|
31
|
+
:custom_scope => {
|
|
32
|
+
:duck => 'Duck',
|
|
33
|
+
:duck_pond => '%{ducks} ducks in a pond'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
::I18n.backend.store_translations :en, :formtastic => @formtastic_strings
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
after do
|
|
40
|
+
::I18n.backend.reload!
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should translate core strings correctly" do
|
|
44
|
+
::I18n.backend.store_translations :en, {:formtastic => {:required => 'Default Required'}}
|
|
45
|
+
expect(Formtastic::I18n.t(:required)).to eq("Default Required")
|
|
46
|
+
expect(Formtastic::I18n.t(:yes)).to eq("Default Yes")
|
|
47
|
+
expect(Formtastic::I18n.t(:no)).to eq("Default No")
|
|
48
|
+
expect(Formtastic::I18n.t(:create, :model => 'Post')).to eq("Default Create Post")
|
|
49
|
+
expect(Formtastic::I18n.t(:update, :model => 'Post')).to eq("Default Update Post")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should all belong to scope 'formtastic'" do
|
|
53
|
+
expect(Formtastic::I18n.t(:duck, :scope => [:custom_scope])).to eq('Duck')
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should override default I18n lookup args if these are specified" do
|
|
57
|
+
expect(Formtastic::I18n.t(:duck_pond, :scope => [:custom_scope], :ducks => 15)).to eq('15 ducks in a pond')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should be possible to override default values" do
|
|
61
|
+
expect(Formtastic::I18n.t(:required, :default => 'Nothing found!')).to eq('Nothing found!')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "when no I18n locales are available" do
|
|
67
|
+
|
|
68
|
+
before do
|
|
69
|
+
::I18n.backend.reload!
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should use default strings" do
|
|
73
|
+
(Formtastic::I18n::DEFAULT_VALUES.keys).each do |key|
|
|
74
|
+
expect(Formtastic::I18n.t(key, :model => '%{model}')).to eq(Formtastic::I18n::DEFAULT_VALUES[key])
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "I18n string lookups" do
|
|
81
|
+
|
|
82
|
+
include FormtasticSpecHelper
|
|
83
|
+
|
|
84
|
+
before do
|
|
85
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
86
|
+
mock_everything
|
|
87
|
+
|
|
88
|
+
::I18n.backend.store_translations :en, {:formtastic => {
|
|
89
|
+
:labels => {
|
|
90
|
+
:author => { :name => "Top author name translation" },
|
|
91
|
+
:post => {:title => "Hello post!", :author => {:name => "Hello author name!"}},
|
|
92
|
+
:project => {:title => "Hello project!"},
|
|
93
|
+
}
|
|
94
|
+
}, :helpers => {
|
|
95
|
+
:label => {
|
|
96
|
+
:post => {:body => "Elaborate..." },
|
|
97
|
+
:author => { :login => "Hello login" }
|
|
98
|
+
}
|
|
99
|
+
}}
|
|
100
|
+
|
|
101
|
+
allow(@new_post).to receive(:title)
|
|
102
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
after do
|
|
106
|
+
::I18n.backend.reload!
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "lookup scopes should be defined" do
|
|
110
|
+
with_config :i18n_lookups_by_default, true do
|
|
111
|
+
expect { Formtastic::I18n::SCOPES }.not_to raise_error
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should be able to translate with namespaced object" do
|
|
116
|
+
with_config :i18n_lookups_by_default, true do
|
|
117
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
118
|
+
concat(builder.input(:title))
|
|
119
|
+
end)
|
|
120
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello post!/)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "should be able to translate without form-object" do
|
|
125
|
+
with_config :i18n_lookups_by_default, true do
|
|
126
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
127
|
+
concat(builder.input(:title))
|
|
128
|
+
end)
|
|
129
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello project!/)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "should be able to translate when method name is same as model" do
|
|
134
|
+
with_config :i18n_lookups_by_default, true do
|
|
135
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
136
|
+
concat(builder.input(:author))
|
|
137
|
+
end)
|
|
138
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Author/)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'should be able to translate nested objects with nested translations' do
|
|
143
|
+
with_config :i18n_lookups_by_default, true do
|
|
144
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
145
|
+
concat(builder.semantic_fields_for(:author) do |f|
|
|
146
|
+
concat(f.input(:name))
|
|
147
|
+
end)
|
|
148
|
+
end)
|
|
149
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'should be able to translate nested objects with top level translations' do
|
|
154
|
+
with_config :i18n_lookups_by_default, true do
|
|
155
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
156
|
+
builder.semantic_fields_for(:author) do |f|
|
|
157
|
+
concat(f.input(:name))
|
|
158
|
+
end
|
|
159
|
+
end)
|
|
160
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'should be able to translate nested objects with nested object translations' do
|
|
165
|
+
with_config :i18n_lookups_by_default, true do
|
|
166
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
167
|
+
builder.semantic_fields_for(:project) do |f|
|
|
168
|
+
concat(f.input(:title))
|
|
169
|
+
end
|
|
170
|
+
end)
|
|
171
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello project!/)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'should be able to translate nested forms with top level translations' do
|
|
176
|
+
with_config :i18n_lookups_by_default, true do
|
|
177
|
+
concat(semantic_form_for(:post) do |builder|
|
|
178
|
+
builder.semantic_fields_for(:author) do |f|
|
|
179
|
+
concat(f.input(:name))
|
|
180
|
+
end
|
|
181
|
+
end)
|
|
182
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it 'should be able to translate helper label as Rails does' do
|
|
187
|
+
with_config :i18n_lookups_by_default, true do
|
|
188
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
189
|
+
concat(builder.input(:body))
|
|
190
|
+
end)
|
|
191
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Elaborate/)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it 'should be able to translate nested helper label as Rails does' do
|
|
196
|
+
with_config :i18n_lookups_by_default, true do
|
|
197
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
198
|
+
concat(builder.inputs(:for => :author) do |f|
|
|
199
|
+
concat(f.input(:login))
|
|
200
|
+
end)
|
|
201
|
+
end)
|
|
202
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello login/)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# TODO: Add spec for namespaced models?
|
|
207
|
+
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'formtastic/input_class_finder'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Formtastic::InputClassFinder do
|
|
6
|
+
it_behaves_like 'Specialized Class Finder' do
|
|
7
|
+
let(:default) { Formtastic::Inputs }
|
|
8
|
+
let(:namespaces_setting) { :input_namespaces }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'fast_spec_helper'
|
|
3
|
+
require 'inputs/base/collections'
|
|
4
|
+
|
|
5
|
+
class MyInput
|
|
6
|
+
include Formtastic::Inputs::Base::Collections
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
RSpec.describe MyInput do
|
|
10
|
+
let(:builder) { double }
|
|
11
|
+
let(:template) { double }
|
|
12
|
+
let(:model_class) { double }
|
|
13
|
+
let(:model) { double(:class => model_class) }
|
|
14
|
+
let(:model_name) { "post" }
|
|
15
|
+
let(:method) { double }
|
|
16
|
+
let(:options) { Hash.new }
|
|
17
|
+
|
|
18
|
+
let(:instance) { MyInput.new(builder, template, model, model_name, method, options) }
|
|
19
|
+
|
|
20
|
+
# class Whatever < ActiveRecord::Base
|
|
21
|
+
# enum :status => [:active, :archived]
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# Whatever.statuses
|
|
25
|
+
#
|
|
26
|
+
# Whatever.new.status
|
|
27
|
+
#
|
|
28
|
+
# f.input :status
|
|
29
|
+
describe "#collection_from_enum" do
|
|
30
|
+
|
|
31
|
+
let(:method) { :status }
|
|
32
|
+
|
|
33
|
+
context "when an enum is defined for the method" do
|
|
34
|
+
before do
|
|
35
|
+
statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
|
|
36
|
+
allow(model_class).to receive(:statuses) { statuses }
|
|
37
|
+
allow(model).to receive(:defined_enums) { {"status" => statuses } }
|
|
38
|
+
allow(model).to receive(:model_name).and_return(double(i18n_key: model_name))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context 'no translations available' do
|
|
42
|
+
it 'returns an Array of EnumOption objects based on the enum options hash' do
|
|
43
|
+
expect(instance.collection_from_enum).to eq [["Active", "active"],["Inactive", "inactive"]]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'with translations' do
|
|
48
|
+
before do
|
|
49
|
+
::I18n.backend.store_translations :en, :activerecord => {
|
|
50
|
+
:attributes => {
|
|
51
|
+
:post => {
|
|
52
|
+
:statuses => {
|
|
53
|
+
:active => "I am active",
|
|
54
|
+
:inactive => "I am inactive"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
it 'returns an Array of EnumOption objects based on the enum options hash' do
|
|
61
|
+
expect(instance.collection_from_enum).to eq [["I am active", "active"],["I am inactive", "inactive"]]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
after do
|
|
65
|
+
::I18n.backend.store_translations :en, {}
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "when an enum is not defined" do
|
|
71
|
+
it 'returns nil' do
|
|
72
|
+
expect(instance.collection_from_enum).to eq nil
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe '#collection' do
|
|
78
|
+
context 'when the raw collection is a string' do
|
|
79
|
+
it 'returns the string' do
|
|
80
|
+
allow(instance).to receive(:raw_collection).and_return("one_status_only")
|
|
81
|
+
expect(instance.collection).to eq "one_status_only"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'when the raw collection is an array of strings' do
|
|
86
|
+
it 'returns the array of symbols' do
|
|
87
|
+
allow(instance).to receive(:raw_collection).and_return(["active", "inactive", "pending"])
|
|
88
|
+
expect(instance.collection).to be_an(Array)
|
|
89
|
+
expect(instance.collection).to eq ["active", "inactive", "pending"]
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context 'when the raw collection is an array of arrays' do
|
|
94
|
+
it 'returns the array of arrays' do
|
|
95
|
+
allow(instance).to receive(:raw_collection).and_return([["inactive", "0"], ["active", "1"], ["pending", "2"]])
|
|
96
|
+
expect(instance.collection).to be_an(Array)
|
|
97
|
+
expect(instance.collection).to eq [["inactive", "0"], ["active", "1"], ["pending", "2"]]
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
context 'when the raw collection is an array of symbols' do
|
|
102
|
+
it 'returns the array of symbols' do
|
|
103
|
+
allow(instance).to receive(:raw_collection).and_return([:active, :inactive, :pending])
|
|
104
|
+
expect(instance.collection).to be_an(Array)
|
|
105
|
+
expect(instance.collection).to eq [:active, :inactive, :pending]
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context 'when the raw collection is a hash' do
|
|
110
|
+
it 'will be mapped into array form' do
|
|
111
|
+
allow(instance).to receive(:raw_collection).and_return({ inactive: 0, active: 1, pending: 2 })
|
|
112
|
+
expect(instance.collection).to be_an(Array)
|
|
113
|
+
expect(instance.collection).to eq [[:inactive, 0], [:active, 1], [:pending, 2]]
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|