formtastic 3.0.0 → 5.0.0
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 +5 -13
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +61 -0
- data/Gemfile.lock +140 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +191 -168
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +24 -8
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +13 -17
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_7.0/Gemfile +5 -0
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +19 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +56 -53
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +60 -57
- data/lib/formtastic/actions/link_action.rb +69 -67
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +6 -0
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +32 -25
- data/lib/formtastic/helpers/action_helper.rb +22 -31
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +14 -0
- data/lib/formtastic/helpers/errors_helper.rb +3 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -11
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +4 -3
- data/lib/formtastic/helpers/input_helper.rb +59 -80
- data/lib/formtastic/helpers/inputs_helper.rb +33 -27
- data/lib/formtastic/helpers/reflection.rb +5 -4
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +13 -1
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +19 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +4 -3
- data/lib/formtastic/inputs/base/collections.rb +47 -11
- data/lib/formtastic/inputs/base/database.rb +8 -5
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -6
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +2 -1
- data/lib/formtastic/inputs/base/html.rb +12 -10
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +5 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +3 -3
- data/lib/formtastic/inputs/base/placeholder.rb +1 -0
- data/lib/formtastic/inputs/base/stringish.rb +1 -0
- data/lib/formtastic/inputs/base/timeish.rb +9 -4
- data/lib/formtastic/inputs/base/validations.rb +39 -12
- data/lib/formtastic/inputs/base/wrapping.rb +2 -3
- data/lib/formtastic/inputs/base.rb +17 -12
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
- data/lib/formtastic/inputs/color_input.rb +1 -1
- data/lib/formtastic/inputs/country_input.rb +4 -1
- data/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/lib/formtastic/inputs/date_picker_input.rb +1 -0
- data/lib/formtastic/inputs/date_select_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
- data/lib/formtastic/inputs/email_input.rb +1 -0
- data/lib/formtastic/inputs/file_input.rb +3 -2
- data/lib/formtastic/inputs/hidden_input.rb +3 -2
- data/lib/formtastic/inputs/number_input.rb +1 -0
- data/lib/formtastic/inputs/password_input.rb +1 -0
- data/lib/formtastic/inputs/phone_input.rb +1 -0
- data/lib/formtastic/inputs/radio_input.rb +26 -21
- data/lib/formtastic/inputs/range_input.rb +1 -0
- data/lib/formtastic/inputs/search_input.rb +1 -0
- data/lib/formtastic/inputs/select_input.rb +32 -10
- data/lib/formtastic/inputs/string_input.rb +1 -0
- data/lib/formtastic/inputs/text_input.rb +1 -0
- data/lib/formtastic/inputs/time_picker_input.rb +1 -0
- data/lib/formtastic/inputs/time_select_input.rb +1 -0
- data/lib/formtastic/inputs/time_zone_input.rb +17 -6
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +33 -28
- data/lib/formtastic/localized_string.rb +2 -1
- data/lib/formtastic/localizer.rb +23 -24
- data/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +19 -14
- data/lib/generators/formtastic/form/form_generator.rb +8 -2
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +2 -0
- data/lib/generators/templates/formtastic.rb +29 -7
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +73 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +13 -0
- data/spec/actions/button_action_spec.rb +21 -20
- data/spec/actions/generic_action_spec.rb +134 -133
- data/spec/actions/input_action_spec.rb +20 -19
- data/spec/actions/link_action_spec.rb +30 -29
- data/spec/builder/custom_builder_spec.rb +39 -22
- data/spec/builder/error_proc_spec.rb +6 -5
- data/spec/builder/semantic_fields_for_spec.rb +46 -45
- data/spec/fast_spec_helper.rb +13 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
- data/spec/helpers/action_helper_spec.rb +70 -97
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +56 -39
- data/spec/helpers/input_helper_spec.rb +314 -255
- data/spec/helpers/inputs_helper_spec.rb +217 -202
- data/spec/helpers/reflection_helper_spec.rb +7 -6
- data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
- data/spec/i18n_spec.rb +30 -29
- data/spec/input_class_finder_spec.rb +11 -0
- data/spec/inputs/base/collections_spec.rb +78 -0
- data/spec/inputs/base/validations_spec.rb +481 -0
- data/spec/inputs/boolean_input_spec.rb +73 -72
- data/spec/inputs/check_boxes_input_spec.rb +174 -123
- data/spec/inputs/color_input_spec.rb +53 -64
- data/spec/inputs/country_input_spec.rb +23 -22
- data/spec/inputs/custom_input_spec.rb +3 -6
- data/spec/inputs/datalist_input_spec.rb +62 -0
- data/spec/inputs/date_picker_input_spec.rb +114 -113
- data/spec/inputs/date_select_input_spec.rb +76 -61
- data/spec/inputs/datetime_picker_input_spec.rb +123 -122
- data/spec/inputs/datetime_select_input_spec.rb +85 -68
- data/spec/inputs/email_input_spec.rb +17 -16
- data/spec/inputs/file_input_spec.rb +18 -17
- data/spec/inputs/hidden_input_spec.rb +32 -31
- data/spec/inputs/include_blank_spec.rb +10 -9
- data/spec/inputs/label_spec.rb +36 -31
- data/spec/inputs/number_input_spec.rb +212 -211
- data/spec/inputs/password_input_spec.rb +17 -16
- data/spec/inputs/phone_input_spec.rb +17 -16
- data/spec/inputs/placeholder_spec.rb +18 -17
- data/spec/inputs/radio_input_spec.rb +92 -65
- data/spec/inputs/range_input_spec.rb +136 -135
- data/spec/inputs/readonly_spec.rb +51 -0
- data/spec/inputs/search_input_spec.rb +16 -15
- data/spec/inputs/select_input_spec.rb +209 -102
- data/spec/inputs/string_input_spec.rb +51 -50
- data/spec/inputs/text_input_spec.rb +34 -33
- data/spec/inputs/time_picker_input_spec.rb +115 -114
- data/spec/inputs/time_select_input_spec.rb +84 -70
- data/spec/inputs/time_zone_input_spec.rb +58 -31
- data/spec/inputs/url_input_spec.rb +17 -16
- data/spec/inputs/with_options_spec.rb +9 -8
- data/spec/localizer_spec.rb +18 -17
- data/spec/namespaced_class_finder_spec.rb +91 -0
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +180 -249
- data/spec/support/custom_macros.rb +128 -98
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +13 -0
- data/spec/support/specialized_class_finder_shared_example.rb +28 -0
- data/spec/support/test_environment.rb +25 -10
- metadata +95 -136
- data/.travis.yml +0 -28
- data/Appraisals +0 -25
- data/CHANGELOG +0 -27
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -53
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -52
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'Formtastic::Helpers::Reflection' do
|
|
5
|
+
RSpec.describe 'Formtastic::Helpers::Reflection' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -20,13 +21,13 @@ describe 'Formtastic::Helpers::Reflection' do
|
|
|
20
21
|
context 'with an ActiveRecord object' do
|
|
21
22
|
it "should return association details on an ActiveRecord association" do
|
|
22
23
|
@reflection_tester = ReflectionTester.new(@new_post)
|
|
23
|
-
@reflection_tester.reflection_for(:sub_posts).
|
|
24
|
+
expect(@reflection_tester.reflection_for(:sub_posts)).not_to be_nil
|
|
24
25
|
end
|
|
25
26
|
it "should return association details on a MongoMapper association" do
|
|
26
27
|
@reflection_tester = ReflectionTester.new(@new_mm_post)
|
|
27
|
-
@reflection_tester.reflection_for(:sub_posts).
|
|
28
|
+
expect(@reflection_tester.reflection_for(:sub_posts)).not_to be_nil
|
|
28
29
|
end
|
|
29
30
|
end
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
|
|
32
33
|
end
|
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'Formtastic::FormBuilder#semantic_errors' do
|
|
5
|
+
RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
12
|
@title_errors = ['must not be blank', 'must be awesome']
|
|
12
13
|
@base_errors = ['base error message', 'nasty error']
|
|
13
14
|
@base_error = 'one base error'
|
|
14
15
|
@errors = double('errors')
|
|
15
|
-
@new_post.
|
|
16
|
+
allow(@new_post).to receive(:errors).and_return(@errors)
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
describe 'when there is only one error on base' do
|
|
19
20
|
before do
|
|
20
|
-
@errors.
|
|
21
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
it 'should render an unordered list' do
|
|
24
25
|
semantic_form_for(@new_post) do |builder|
|
|
25
|
-
builder.semantic_errors.
|
|
26
|
+
expect(builder.semantic_errors).to have_tag('ul.errors li', :text => @base_error)
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
describe 'when there is more than one error on base' do
|
|
31
32
|
before do
|
|
32
|
-
@errors.
|
|
33
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_errors)
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
it 'should render an unordered list' do
|
|
36
37
|
semantic_form_for(@new_post) do |builder|
|
|
37
|
-
builder.semantic_errors.
|
|
38
|
+
expect(builder.semantic_errors).to have_tag('ul.errors')
|
|
38
39
|
@base_errors.each do |error|
|
|
39
|
-
builder.semantic_errors.
|
|
40
|
+
expect(builder.semantic_errors).to have_tag('ul.errors li', :text => error)
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
end
|
|
@@ -44,69 +45,69 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
|
|
|
44
45
|
|
|
45
46
|
describe 'when there are errors on title' do
|
|
46
47
|
before do
|
|
47
|
-
@errors.
|
|
48
|
-
@errors.
|
|
48
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
|
|
49
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
it 'should render an unordered list' do
|
|
52
53
|
semantic_form_for(@new_post) do |builder|
|
|
53
54
|
title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
|
|
54
|
-
builder.semantic_errors(:title).
|
|
55
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', :text => title_name << " " << @title_errors.to_sentence)
|
|
55
56
|
end
|
|
56
57
|
end
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
describe 'when there are errors on title and base' do
|
|
60
61
|
before do
|
|
61
|
-
@errors.
|
|
62
|
-
@errors.
|
|
62
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
|
|
63
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
it 'should render an unordered list' do
|
|
66
67
|
semantic_form_for(@new_post) do |builder|
|
|
67
68
|
title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
|
|
68
|
-
builder.semantic_errors(:title).
|
|
69
|
-
builder.semantic_errors(:title).
|
|
69
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', :text => title_name << " " << @title_errors.to_sentence)
|
|
70
|
+
expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', :text => @base_error)
|
|
70
71
|
end
|
|
71
72
|
end
|
|
72
73
|
end
|
|
73
74
|
|
|
74
75
|
describe 'when there are no errors' do
|
|
75
76
|
before do
|
|
76
|
-
@errors.
|
|
77
|
-
@errors.
|
|
77
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(nil)
|
|
78
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(nil)
|
|
78
79
|
end
|
|
79
80
|
|
|
80
81
|
it 'should return nil' do
|
|
81
82
|
semantic_form_for(@new_post) do |builder|
|
|
82
|
-
builder.semantic_errors(:title).
|
|
83
|
+
expect(builder.semantic_errors(:title)).to be_nil
|
|
83
84
|
end
|
|
84
85
|
end
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
describe 'when there is one error on base and options with class is passed' do
|
|
88
89
|
before do
|
|
89
|
-
@errors.
|
|
90
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
90
91
|
end
|
|
91
92
|
|
|
92
93
|
it 'should render an unordered list with given class' do
|
|
93
94
|
semantic_form_for(@new_post) do |builder|
|
|
94
|
-
builder.semantic_errors(:class => "awesome").
|
|
95
|
+
expect(builder.semantic_errors(:class => "awesome")).to have_tag('ul.awesome li', :text => @base_error)
|
|
95
96
|
end
|
|
96
97
|
end
|
|
97
98
|
end
|
|
98
|
-
|
|
99
|
+
|
|
99
100
|
describe 'when :base is passed in as an argument' do
|
|
100
101
|
before do
|
|
101
|
-
@errors.
|
|
102
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
|
|
102
103
|
end
|
|
103
104
|
|
|
104
105
|
it 'should ignore :base and only render base errors once' do
|
|
105
106
|
semantic_form_for(@new_post) do |builder|
|
|
106
|
-
builder.semantic_errors(:base).
|
|
107
|
-
builder.semantic_errors(:base).
|
|
107
|
+
expect(builder.semantic_errors(:base)).to have_tag('ul li', :count => 1)
|
|
108
|
+
expect(builder.semantic_errors(:base)).not_to have_tag('ul li', :text => "Base #{@base_error}")
|
|
108
109
|
end
|
|
109
110
|
end
|
|
110
111
|
end
|
|
111
|
-
|
|
112
|
+
|
|
112
113
|
end
|
data/spec/i18n_spec.rb
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'Formtastic::I18n' do
|
|
5
|
+
RSpec.describe 'Formtastic::I18n' do
|
|
5
6
|
|
|
6
7
|
FORMTASTIC_KEYS = [:required, :yes, :no, :create, :update].freeze
|
|
7
8
|
|
|
8
9
|
it "should be defined" do
|
|
9
|
-
|
|
10
|
+
expect { Formtastic::I18n }.not_to raise_error
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
describe "default translations" do
|
|
13
14
|
it "should be defined" do
|
|
14
|
-
|
|
15
|
-
Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash).
|
|
15
|
+
expect { Formtastic::I18n::DEFAULT_VALUES }.not_to raise_error
|
|
16
|
+
expect(Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash)).to eq(true)
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
it "should exists for the core I18n lookup keys" do
|
|
19
|
-
(Formtastic::I18n::DEFAULT_VALUES.keys & FORMTASTIC_KEYS).size.
|
|
20
|
+
expect((Formtastic::I18n::DEFAULT_VALUES.keys & FORMTASTIC_KEYS).size).to eq(FORMTASTIC_KEYS.size)
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
|
|
@@ -42,23 +43,23 @@ describe 'Formtastic::I18n' do
|
|
|
42
43
|
|
|
43
44
|
it "should translate core strings correctly" do
|
|
44
45
|
::I18n.backend.store_translations :en, {:formtastic => {:required => 'Default Required'}}
|
|
45
|
-
Formtastic::I18n.t(:required).
|
|
46
|
-
Formtastic::I18n.t(:yes).
|
|
47
|
-
Formtastic::I18n.t(:no).
|
|
48
|
-
Formtastic::I18n.t(:create, :model => 'Post').
|
|
49
|
-
Formtastic::I18n.t(:update, :model => 'Post').
|
|
46
|
+
expect(Formtastic::I18n.t(:required)).to eq("Default Required")
|
|
47
|
+
expect(Formtastic::I18n.t(:yes)).to eq("Default Yes")
|
|
48
|
+
expect(Formtastic::I18n.t(:no)).to eq("Default No")
|
|
49
|
+
expect(Formtastic::I18n.t(:create, :model => 'Post')).to eq("Default Create Post")
|
|
50
|
+
expect(Formtastic::I18n.t(:update, :model => 'Post')).to eq("Default Update Post")
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
it "should all belong to scope 'formtastic'" do
|
|
53
|
-
Formtastic::I18n.t(:duck, :scope => [:custom_scope]).
|
|
54
|
+
expect(Formtastic::I18n.t(:duck, :scope => [:custom_scope])).to eq('Duck')
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
it "should override default I18n lookup args if these are specified" do
|
|
57
|
-
Formtastic::I18n.t(:duck_pond, :scope => [:custom_scope], :ducks => 15).
|
|
58
|
+
expect(Formtastic::I18n.t(:duck_pond, :scope => [:custom_scope], :ducks => 15)).to eq('15 ducks in a pond')
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
it "should be possible to override default values" do
|
|
61
|
-
Formtastic::I18n.t(:required, :default => 'Nothing found!').
|
|
62
|
+
expect(Formtastic::I18n.t(:required, :default => 'Nothing found!')).to eq('Nothing found!')
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
end
|
|
@@ -71,7 +72,7 @@ describe 'Formtastic::I18n' do
|
|
|
71
72
|
|
|
72
73
|
it "should use default strings" do
|
|
73
74
|
(Formtastic::I18n::DEFAULT_VALUES.keys).each do |key|
|
|
74
|
-
Formtastic::I18n.t(key, :model => '%{model}').
|
|
75
|
+
expect(Formtastic::I18n.t(key, :model => '%{model}')).to eq(Formtastic::I18n::DEFAULT_VALUES[key])
|
|
75
76
|
end
|
|
76
77
|
end
|
|
77
78
|
|
|
@@ -82,7 +83,7 @@ describe 'Formtastic::I18n' do
|
|
|
82
83
|
include FormtasticSpecHelper
|
|
83
84
|
|
|
84
85
|
before do
|
|
85
|
-
@output_buffer = ''
|
|
86
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
86
87
|
mock_everything
|
|
87
88
|
|
|
88
89
|
::I18n.backend.store_translations :en, {:formtastic => {
|
|
@@ -98,8 +99,8 @@ describe 'Formtastic::I18n' do
|
|
|
98
99
|
}
|
|
99
100
|
}}
|
|
100
101
|
|
|
101
|
-
@new_post.
|
|
102
|
-
@new_post.
|
|
102
|
+
allow(@new_post).to receive(:title)
|
|
103
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
|
|
103
104
|
end
|
|
104
105
|
|
|
105
106
|
after do
|
|
@@ -108,7 +109,7 @@ describe 'Formtastic::I18n' do
|
|
|
108
109
|
|
|
109
110
|
it "lookup scopes should be defined" do
|
|
110
111
|
with_config :i18n_lookups_by_default, true do
|
|
111
|
-
|
|
112
|
+
expect { Formtastic::I18n::SCOPES }.not_to raise_error
|
|
112
113
|
end
|
|
113
114
|
end
|
|
114
115
|
|
|
@@ -117,7 +118,7 @@ describe 'Formtastic::I18n' do
|
|
|
117
118
|
concat(semantic_form_for(@new_post) do |builder|
|
|
118
119
|
concat(builder.input(:title))
|
|
119
120
|
end)
|
|
120
|
-
output_buffer.
|
|
121
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello post!/)
|
|
121
122
|
end
|
|
122
123
|
end
|
|
123
124
|
|
|
@@ -126,7 +127,7 @@ describe 'Formtastic::I18n' do
|
|
|
126
127
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
127
128
|
concat(builder.input(:title))
|
|
128
129
|
end)
|
|
129
|
-
output_buffer.
|
|
130
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello project!/)
|
|
130
131
|
end
|
|
131
132
|
end
|
|
132
133
|
|
|
@@ -135,7 +136,7 @@ describe 'Formtastic::I18n' do
|
|
|
135
136
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
136
137
|
concat(builder.input(:author))
|
|
137
138
|
end)
|
|
138
|
-
output_buffer.
|
|
139
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Author/)
|
|
139
140
|
end
|
|
140
141
|
end
|
|
141
142
|
|
|
@@ -146,7 +147,7 @@ describe 'Formtastic::I18n' do
|
|
|
146
147
|
concat(f.input(:name))
|
|
147
148
|
end)
|
|
148
149
|
end)
|
|
149
|
-
output_buffer.
|
|
150
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
|
|
150
151
|
end
|
|
151
152
|
end
|
|
152
153
|
|
|
@@ -157,7 +158,7 @@ describe 'Formtastic::I18n' do
|
|
|
157
158
|
concat(f.input(:name))
|
|
158
159
|
end
|
|
159
160
|
end)
|
|
160
|
-
output_buffer.
|
|
161
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
|
|
161
162
|
end
|
|
162
163
|
end
|
|
163
164
|
|
|
@@ -168,10 +169,10 @@ describe 'Formtastic::I18n' do
|
|
|
168
169
|
concat(f.input(:title))
|
|
169
170
|
end
|
|
170
171
|
end)
|
|
171
|
-
output_buffer.
|
|
172
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello project!/)
|
|
172
173
|
end
|
|
173
174
|
end
|
|
174
|
-
|
|
175
|
+
|
|
175
176
|
it 'should be able to translate nested forms with top level translations' do
|
|
176
177
|
with_config :i18n_lookups_by_default, true do
|
|
177
178
|
concat(semantic_form_for(:post) do |builder|
|
|
@@ -179,7 +180,7 @@ describe 'Formtastic::I18n' do
|
|
|
179
180
|
concat(f.input(:name))
|
|
180
181
|
end
|
|
181
182
|
end)
|
|
182
|
-
output_buffer.
|
|
183
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
|
|
183
184
|
end
|
|
184
185
|
end
|
|
185
186
|
|
|
@@ -188,10 +189,10 @@ describe 'Formtastic::I18n' do
|
|
|
188
189
|
concat(semantic_form_for(@new_post) do |builder|
|
|
189
190
|
concat(builder.input(:body))
|
|
190
191
|
end)
|
|
191
|
-
output_buffer.
|
|
192
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Elaborate/)
|
|
192
193
|
end
|
|
193
194
|
end
|
|
194
|
-
|
|
195
|
+
|
|
195
196
|
it 'should be able to translate nested helper label as Rails does' do
|
|
196
197
|
with_config :i18n_lookups_by_default, true do
|
|
197
198
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -199,7 +200,7 @@ describe 'Formtastic::I18n' do
|
|
|
199
200
|
concat(f.input(:login))
|
|
200
201
|
end)
|
|
201
202
|
end)
|
|
202
|
-
output_buffer.
|
|
203
|
+
expect(output_buffer.to_str).to have_tag("form label", :text => /Hello login/)
|
|
203
204
|
end
|
|
204
205
|
end
|
|
205
206
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'formtastic/input_class_finder'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Formtastic::InputClassFinder do
|
|
7
|
+
it_behaves_like 'Specialized Class Finder' do
|
|
8
|
+
let(:default) { Formtastic::Inputs }
|
|
9
|
+
let(:namespaces_setting) { :input_namespaces }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
end
|
|
78
|
+
|