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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
require 'generators/formtastic/input/input_generator'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Formtastic::InputGenerator do
|
|
7
|
+
include FormtasticSpecHelper
|
|
8
|
+
|
|
9
|
+
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
prepare_destination
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after do
|
|
16
|
+
FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'without file name' do
|
|
20
|
+
it 'should raise Thor::RequiredArgumentMissingError' do
|
|
21
|
+
expect { run_generator }.to raise_error(Thor::RequiredArgumentMissingError)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "input generator with underscore definition" do
|
|
26
|
+
before { run_generator %w(hat_size)}
|
|
27
|
+
|
|
28
|
+
describe 'generate an input in its respective folder' do
|
|
29
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
30
|
+
it { is_expected.to exist}
|
|
31
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
32
|
+
it { is_expected.to contain "def to_html"}
|
|
33
|
+
it { is_expected.to contain "include Formtastic::Inputs::Base"}
|
|
34
|
+
it { is_expected.not_to contain "super"}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "input generator with camelcase definition" do
|
|
39
|
+
before { run_generator %w(HatSize)}
|
|
40
|
+
|
|
41
|
+
describe 'generate an input in its respective folder' do
|
|
42
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
43
|
+
it { is_expected.to exist}
|
|
44
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "input generator with camelcase Input name sufixed" do
|
|
49
|
+
before { run_generator %w(HatSizeInput)}
|
|
50
|
+
|
|
51
|
+
describe 'generate an input in its respective folder' do
|
|
52
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
53
|
+
it { is_expected.to exist}
|
|
54
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "input generator with underscore _input name sufixed" do
|
|
59
|
+
before { run_generator %w(hat_size_input)}
|
|
60
|
+
|
|
61
|
+
describe 'generate an input in its respective folder' do
|
|
62
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
63
|
+
it { is_expected.to exist}
|
|
64
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "input generator with underscore input name sufixed" do
|
|
69
|
+
before { run_generator %w(hat_sizeinput)}
|
|
70
|
+
|
|
71
|
+
describe 'generate an input in its respective folder' do
|
|
72
|
+
subject{ file('app/inputs/hat_size_input.rb')}
|
|
73
|
+
it { is_expected.to exist}
|
|
74
|
+
it { is_expected.to contain "class HatSizeInput"}
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe "override an existing input using extend" do
|
|
79
|
+
before { run_generator %w(string --extend)}
|
|
80
|
+
|
|
81
|
+
describe 'app/inputs/string_input.rb' do
|
|
82
|
+
subject{ file('app/inputs/string_input.rb')}
|
|
83
|
+
it { is_expected.to exist }
|
|
84
|
+
it { is_expected.to contain "class StringInput < Formtastic::Inputs::StringInput" }
|
|
85
|
+
it { is_expected.to contain "def to_html" }
|
|
86
|
+
it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
|
|
87
|
+
it { is_expected.to contain "super" }
|
|
88
|
+
it { is_expected.not_to contain "def input_html_options" }
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe "extend an existing input" do
|
|
93
|
+
before { run_generator %w(FlexibleText --extend string)}
|
|
94
|
+
|
|
95
|
+
describe 'app/inputs/flexible_text_input.rb' do
|
|
96
|
+
subject{ file('app/inputs/flexible_text_input.rb')}
|
|
97
|
+
it { is_expected.to contain "class FlexibleTextInput < Formtastic::Inputs::StringInput" }
|
|
98
|
+
it { is_expected.to contain "def input_html_options" }
|
|
99
|
+
it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
|
|
100
|
+
it { is_expected.not_to contain "def to_html" }
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe "provide a slashed namespace" do
|
|
105
|
+
before { run_generator %w(stuff/foo)}
|
|
106
|
+
|
|
107
|
+
describe 'app/inputs/stuff/foo_input.rb' do
|
|
108
|
+
subject{ file('app/inputs/stuff/foo_input.rb')}
|
|
109
|
+
it {is_expected.to exist}
|
|
110
|
+
it { is_expected.to contain "class Stuff::FooInput" }
|
|
111
|
+
it { is_expected.to contain "include Formtastic::Inputs::Base" }
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe "provide a camelized namespace" do
|
|
116
|
+
before { run_generator %w(Stuff::Foo)}
|
|
117
|
+
|
|
118
|
+
describe 'app/inputs/stuff/foo_input.rb' do
|
|
119
|
+
subject{ file('app/inputs/stuff/foo_input.rb')}
|
|
120
|
+
it {is_expected.to exist}
|
|
121
|
+
it { is_expected.to contain "class Stuff::FooInput" }
|
|
122
|
+
it { is_expected.to contain "include Formtastic::Inputs::Base" }
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
# Generators are not automatically loaded by Rails
|
|
4
5
|
require 'generators/formtastic/install/install_generator'
|
|
5
6
|
|
|
6
|
-
describe Formtastic::InstallGenerator do
|
|
7
|
+
RSpec.describe Formtastic::InstallGenerator do
|
|
7
8
|
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
8
9
|
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
9
10
|
|
|
@@ -14,14 +15,14 @@ describe Formtastic::InstallGenerator do
|
|
|
14
15
|
|
|
15
16
|
describe 'config/initializers/formtastic.rb' do
|
|
16
17
|
subject { file('config/initializers/formtastic.rb') }
|
|
17
|
-
it {
|
|
18
|
-
it {
|
|
18
|
+
it { is_expected.to exist }
|
|
19
|
+
it { is_expected.to contain "#" }
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
describe 'lib/templates/erb/scaffold/_form.html.erb' do
|
|
22
23
|
subject { file('lib/templates/erb/scaffold/_form.html.erb') }
|
|
23
|
-
it {
|
|
24
|
-
it {
|
|
24
|
+
it { is_expected.to exist }
|
|
25
|
+
it { is_expected.to contain "<%%= semantic_form_for @<%= singular_name %> do |f| %>" }
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -30,8 +31,8 @@ describe Formtastic::InstallGenerator do
|
|
|
30
31
|
|
|
31
32
|
describe 'lib/templates/erb/scaffold/_form.html.haml' do
|
|
32
33
|
subject { file('lib/templates/haml/scaffold/_form.html.haml') }
|
|
33
|
-
it {
|
|
34
|
-
it {
|
|
34
|
+
it { is_expected.to exist }
|
|
35
|
+
it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
|
|
35
36
|
end
|
|
36
37
|
end
|
|
37
38
|
|
|
@@ -40,8 +41,8 @@ describe Formtastic::InstallGenerator do
|
|
|
40
41
|
|
|
41
42
|
describe 'lib/templates/erb/scaffold/_form.html.slim' do
|
|
42
43
|
subject { file('lib/templates/slim/scaffold/_form.html.slim') }
|
|
43
|
-
it {
|
|
44
|
-
it {
|
|
44
|
+
it { is_expected.to exist }
|
|
45
|
+
it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
48
|
end
|
|
@@ -1,72 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe '
|
|
5
|
-
|
|
6
|
-
include FormtasticSpecHelper
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
-
mock_everything
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
after do
|
|
14
|
-
::I18n.backend.reload!
|
|
15
|
-
end
|
|
4
|
+
RSpec.describe 'with action class finder' do
|
|
5
|
+
include_context 'form builder'
|
|
16
6
|
|
|
17
7
|
describe 'arguments and options' do
|
|
18
8
|
|
|
19
9
|
it 'should require the first argument (the action method)' do
|
|
20
|
-
|
|
10
|
+
expect {
|
|
21
11
|
concat(semantic_form_for(@new_post) do |builder|
|
|
22
12
|
concat(builder.action()) # no args passed in at all
|
|
23
13
|
end)
|
|
24
|
-
}.
|
|
14
|
+
}.to raise_error(ArgumentError)
|
|
25
15
|
end
|
|
26
16
|
|
|
27
17
|
describe ':as option' do
|
|
28
|
-
|
|
18
|
+
|
|
29
19
|
describe 'when not provided' do
|
|
30
|
-
|
|
20
|
+
|
|
31
21
|
it 'should default to a commit for commit' do
|
|
32
22
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
33
23
|
concat(builder.action(:submit))
|
|
34
24
|
end)
|
|
35
|
-
output_buffer.
|
|
25
|
+
expect(output_buffer.to_str).to have_tag('form li.action.input_action', :count => 1)
|
|
36
26
|
end
|
|
37
|
-
|
|
27
|
+
|
|
38
28
|
it 'should default to a button for reset' do
|
|
39
29
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
40
30
|
concat(builder.action(:reset))
|
|
41
31
|
end)
|
|
42
|
-
output_buffer.
|
|
32
|
+
expect(output_buffer.to_str).to have_tag('form li.action.input_action', :count => 1)
|
|
43
33
|
end
|
|
44
34
|
|
|
45
35
|
it 'should default to a link for cancel' do
|
|
46
36
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
47
37
|
concat(builder.action(:cancel))
|
|
48
38
|
end)
|
|
49
|
-
output_buffer.
|
|
39
|
+
expect(output_buffer.to_str).to have_tag('form li.action.link_action', :count => 1)
|
|
50
40
|
end
|
|
51
41
|
end
|
|
52
|
-
|
|
42
|
+
|
|
53
43
|
it 'should call the corresponding action class with .to_html' do
|
|
54
44
|
[:input, :button, :link].each do |action_style|
|
|
55
45
|
semantic_form_for(:project, :url => "http://test.host") do |builder|
|
|
56
46
|
action_instance = double('Action instance')
|
|
57
47
|
action_class = "#{action_style.to_s}_action".classify
|
|
58
48
|
action_constant = "Formtastic::Actions::#{action_class}".constantize
|
|
59
|
-
|
|
60
|
-
action_constant.
|
|
61
|
-
action_instance.
|
|
62
|
-
|
|
49
|
+
|
|
50
|
+
expect(action_constant).to receive(:new).and_return(action_instance)
|
|
51
|
+
expect(action_instance).to receive(:to_html).and_return("some HTML")
|
|
52
|
+
|
|
63
53
|
concat(builder.action(:submit, :as => action_style))
|
|
64
54
|
end
|
|
65
55
|
end
|
|
66
56
|
end
|
|
67
|
-
|
|
57
|
+
|
|
68
58
|
end
|
|
69
|
-
|
|
59
|
+
|
|
70
60
|
#describe ':label option' do
|
|
71
61
|
#
|
|
72
62
|
# describe 'when provided' do
|
|
@@ -207,159 +197,142 @@ describe 'Formtastic::FormBuilder#action' do
|
|
|
207
197
|
#end
|
|
208
198
|
#
|
|
209
199
|
describe ':wrapper_html option' do
|
|
210
|
-
|
|
200
|
+
|
|
211
201
|
describe 'when provided' do
|
|
212
202
|
it 'should be passed down to the li tag' do
|
|
213
203
|
concat(semantic_form_for(@new_post) do |builder|
|
|
214
204
|
concat(builder.action(:submit, :wrapper_html => {:id => :another_id}))
|
|
215
205
|
end)
|
|
216
|
-
output_buffer.
|
|
206
|
+
expect(output_buffer.to_str).to have_tag("form li#another_id")
|
|
217
207
|
end
|
|
218
|
-
|
|
208
|
+
|
|
219
209
|
it 'should append given classes to li default classes' do
|
|
220
210
|
concat(semantic_form_for(@new_post) do |builder|
|
|
221
211
|
concat(builder.action(:submit, :wrapper_html => {:class => :another_class}))
|
|
222
212
|
end)
|
|
223
|
-
output_buffer.
|
|
224
|
-
output_buffer.
|
|
225
|
-
output_buffer.
|
|
213
|
+
expect(output_buffer.to_str).to have_tag("form li.action")
|
|
214
|
+
expect(output_buffer.to_str).to have_tag("form li.input_action")
|
|
215
|
+
expect(output_buffer.to_str).to have_tag("form li.another_class")
|
|
226
216
|
end
|
|
227
|
-
|
|
217
|
+
|
|
228
218
|
it 'should allow classes to be an array' do
|
|
229
219
|
concat(semantic_form_for(@new_post) do |builder|
|
|
230
220
|
concat(builder.action(:submit, :wrapper_html => {:class => [ :my_class, :another_class ]}))
|
|
231
221
|
end)
|
|
232
|
-
output_buffer.
|
|
233
|
-
output_buffer.
|
|
234
|
-
output_buffer.
|
|
235
|
-
output_buffer.
|
|
222
|
+
expect(output_buffer.to_str).to have_tag("form li.action")
|
|
223
|
+
expect(output_buffer.to_str).to have_tag("form li.input_action")
|
|
224
|
+
expect(output_buffer.to_str).to have_tag("form li.my_class")
|
|
225
|
+
expect(output_buffer.to_str).to have_tag("form li.another_class")
|
|
236
226
|
end
|
|
237
227
|
end
|
|
238
|
-
|
|
228
|
+
|
|
239
229
|
describe 'when not provided' do
|
|
240
230
|
it 'should use default id and class' do
|
|
241
231
|
concat(semantic_form_for(@new_post) do |builder|
|
|
242
232
|
concat(builder.action(:submit))
|
|
243
233
|
end)
|
|
244
|
-
output_buffer.
|
|
245
|
-
output_buffer.
|
|
246
|
-
output_buffer.
|
|
234
|
+
expect(output_buffer.to_str).to have_tag("form li#post_submit_action")
|
|
235
|
+
expect(output_buffer.to_str).to have_tag("form li.action")
|
|
236
|
+
expect(output_buffer.to_str).to have_tag("form li.input_action")
|
|
247
237
|
end
|
|
248
238
|
end
|
|
249
|
-
|
|
239
|
+
|
|
250
240
|
end
|
|
251
|
-
|
|
241
|
+
|
|
252
242
|
end
|
|
253
243
|
|
|
254
244
|
describe 'instantiating an action class' do
|
|
255
|
-
|
|
256
245
|
context 'when a class does not exist' do
|
|
257
246
|
it "should raise an error" do
|
|
258
|
-
|
|
247
|
+
expect {
|
|
259
248
|
concat(semantic_form_for(@new_post) do |builder|
|
|
260
249
|
builder.action(:submit, :as => :non_existant)
|
|
261
250
|
end)
|
|
262
|
-
}.
|
|
251
|
+
}.to raise_error(Formtastic::UnknownActionError)
|
|
263
252
|
end
|
|
264
253
|
end
|
|
265
|
-
|
|
254
|
+
|
|
266
255
|
context 'when a customized top-level class does not exist' do
|
|
267
|
-
|
|
268
256
|
it 'should instantiate the Formtastic action' do
|
|
269
257
|
action = double('action', :to_html => 'some HTML')
|
|
270
|
-
Formtastic::Actions::ButtonAction.
|
|
258
|
+
expect(Formtastic::Actions::ButtonAction).to receive(:new).and_return(action)
|
|
271
259
|
concat(semantic_form_for(@new_post) do |builder|
|
|
272
260
|
builder.action(:commit, :as => :button)
|
|
273
261
|
end)
|
|
274
262
|
end
|
|
275
|
-
|
|
276
263
|
end
|
|
277
|
-
|
|
264
|
+
|
|
278
265
|
describe 'when a top-level (custom) action class exists' do
|
|
279
266
|
it "should instantiate the top-level action instead of the Formtastic one" do
|
|
280
267
|
class ::ButtonAction < Formtastic::Actions::ButtonAction
|
|
281
268
|
end
|
|
282
|
-
|
|
269
|
+
|
|
283
270
|
action = double('action', :to_html => 'some HTML')
|
|
284
|
-
Formtastic::Actions::ButtonAction.
|
|
285
|
-
::ButtonAction.
|
|
286
|
-
|
|
271
|
+
expect(Formtastic::Actions::ButtonAction).not_to receive(:new)
|
|
272
|
+
expect(::ButtonAction).to receive(:new).and_return(action)
|
|
273
|
+
|
|
287
274
|
concat(semantic_form_for(@new_post) do |builder|
|
|
288
275
|
builder.action(:commit, :as => :button)
|
|
289
276
|
end)
|
|
290
277
|
end
|
|
291
278
|
end
|
|
292
|
-
|
|
293
|
-
describe 'when instantiated multiple times with the same action type' do
|
|
294
|
-
|
|
295
|
-
it "should be cached (not calling the internal methods)" do
|
|
296
|
-
# TODO this is really tied to the underlying implementation
|
|
297
|
-
concat(semantic_form_for(@new_post) do |builder|
|
|
298
|
-
builder.should_receive(:custom_action_class_name).with(:button).once.and_return(::Formtastic::Actions::ButtonAction)
|
|
299
|
-
builder.action(:submit, :as => :button)
|
|
300
|
-
builder.action(:submit, :as => :button)
|
|
301
|
-
end)
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
end
|
|
305
|
-
|
|
279
|
+
|
|
306
280
|
describe 'support for :as on each action' do
|
|
307
|
-
|
|
281
|
+
|
|
308
282
|
it "should raise an error when the action does not support the :as" do
|
|
309
|
-
|
|
283
|
+
expect {
|
|
310
284
|
concat(semantic_form_for(@new_post) do |builder|
|
|
311
285
|
concat(builder.action(:submit, :as => :link))
|
|
312
286
|
end)
|
|
313
|
-
}.
|
|
314
|
-
|
|
315
|
-
|
|
287
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
288
|
+
|
|
289
|
+
expect {
|
|
316
290
|
concat(semantic_form_for(@new_post) do |builder|
|
|
317
291
|
concat(builder.action(:cancel, :as => :input))
|
|
318
292
|
end)
|
|
319
|
-
}.
|
|
320
|
-
|
|
321
|
-
|
|
293
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
294
|
+
|
|
295
|
+
expect {
|
|
322
296
|
concat(semantic_form_for(@new_post) do |builder|
|
|
323
297
|
concat(builder.action(:cancel, :as => :button))
|
|
324
298
|
end)
|
|
325
|
-
}.
|
|
299
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
326
300
|
end
|
|
327
|
-
|
|
301
|
+
|
|
328
302
|
it "should not raise an error when the action does not support the :as" do
|
|
329
|
-
|
|
303
|
+
expect {
|
|
330
304
|
concat(semantic_form_for(@new_post) do |builder|
|
|
331
305
|
concat(builder.action(:cancel, :as => :link))
|
|
332
306
|
end)
|
|
333
|
-
}.
|
|
334
|
-
|
|
335
|
-
|
|
307
|
+
}.not_to raise_error
|
|
308
|
+
|
|
309
|
+
expect {
|
|
336
310
|
concat(semantic_form_for(@new_post) do |builder|
|
|
337
311
|
concat(builder.action(:submit, :as => :input))
|
|
338
312
|
end)
|
|
339
|
-
}.
|
|
313
|
+
}.not_to raise_error
|
|
340
314
|
|
|
341
|
-
|
|
315
|
+
expect {
|
|
342
316
|
concat(semantic_form_for(@new_post) do |builder|
|
|
343
317
|
concat(builder.action(:submit, :as => :button))
|
|
344
318
|
end)
|
|
345
|
-
}.
|
|
346
|
-
|
|
347
|
-
|
|
319
|
+
}.not_to raise_error
|
|
320
|
+
|
|
321
|
+
expect {
|
|
348
322
|
concat(semantic_form_for(@new_post) do |builder|
|
|
349
323
|
concat(builder.action(:reset, :as => :input))
|
|
350
324
|
end)
|
|
351
|
-
}.
|
|
352
|
-
|
|
353
|
-
|
|
325
|
+
}.not_to raise_error
|
|
326
|
+
|
|
327
|
+
expect {
|
|
354
328
|
concat(semantic_form_for(@new_post) do |builder|
|
|
355
329
|
concat(builder.action(:reset, :as => :button))
|
|
356
330
|
end)
|
|
357
|
-
}.
|
|
331
|
+
}.not_to raise_error
|
|
358
332
|
end
|
|
359
|
-
|
|
333
|
+
|
|
360
334
|
end
|
|
361
|
-
|
|
335
|
+
|
|
362
336
|
end
|
|
363
337
|
|
|
364
338
|
end
|
|
365
|
-
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'Formtastic::FormBuilder#actions' do
|
|
5
|
+
RSpec.describe 'Formtastic::FormBuilder#actions' 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
|
|
|
@@ -21,123 +22,123 @@ describe 'Formtastic::FormBuilder#actions' do
|
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
it 'should render a fieldset inside the form, with a class of "actions"' do
|
|
24
|
-
output_buffer.
|
|
25
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions")
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
it 'should render an ol inside the fieldset' do
|
|
28
|
-
output_buffer.
|
|
29
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions ol")
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
it 'should render the contents of the block inside the ol' do
|
|
32
|
-
output_buffer.
|
|
33
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions ol", :text => /hello/)
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
it 'should not render a legend inside the fieldset' do
|
|
36
|
-
output_buffer.
|
|
37
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.actions legend")
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
describe 'when a :name option is provided' do
|
|
41
42
|
before do
|
|
42
43
|
@legend_text = "Advanced options"
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
concat(semantic_form_for(@new_post) do |builder|
|
|
45
46
|
builder.actions :name => @legend_text do
|
|
46
47
|
end
|
|
47
48
|
end)
|
|
48
49
|
end
|
|
49
50
|
it 'should render a fieldset inside the form' do
|
|
50
|
-
output_buffer.
|
|
51
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions legend", :text => /#{@legend_text}/)
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
|
-
|
|
54
|
+
|
|
54
55
|
describe 'when other options are provided' do
|
|
55
56
|
before do
|
|
56
57
|
@id_option = 'advanced'
|
|
57
58
|
@class_option = 'wide'
|
|
58
|
-
|
|
59
|
+
|
|
59
60
|
concat(semantic_form_for(@new_post) do |builder|
|
|
60
61
|
builder.actions :id => @id_option, :class => @class_option do
|
|
61
62
|
end
|
|
62
63
|
end)
|
|
63
64
|
end
|
|
64
65
|
it 'should pass the options into the fieldset tag as attributes' do
|
|
65
|
-
output_buffer.
|
|
66
|
-
output_buffer.
|
|
66
|
+
expect(output_buffer.to_str).to have_tag("form fieldset##{@id_option}")
|
|
67
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.#{@class_option}")
|
|
67
68
|
end
|
|
68
69
|
end
|
|
69
|
-
|
|
70
|
+
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
describe 'without a block' do
|
|
73
|
-
|
|
74
|
+
|
|
74
75
|
describe 'with no args (default buttons)' do
|
|
75
|
-
|
|
76
|
+
|
|
76
77
|
before do
|
|
77
78
|
concat(semantic_form_for(@new_post) do |builder|
|
|
78
79
|
concat(builder.actions)
|
|
79
80
|
end)
|
|
80
81
|
end
|
|
81
|
-
|
|
82
|
+
|
|
82
83
|
it 'should render a form' do
|
|
83
|
-
output_buffer.
|
|
84
|
+
expect(output_buffer.to_str).to have_tag('form')
|
|
84
85
|
end
|
|
85
|
-
|
|
86
|
+
|
|
86
87
|
it 'should render an actions fieldset inside the form' do
|
|
87
|
-
output_buffer.
|
|
88
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions')
|
|
88
89
|
end
|
|
89
|
-
|
|
90
|
+
|
|
90
91
|
it 'should not render a legend in the fieldset' do
|
|
91
|
-
output_buffer.
|
|
92
|
+
expect(output_buffer.to_str).not_to have_tag('form fieldset.actions legend')
|
|
92
93
|
end
|
|
93
|
-
|
|
94
|
+
|
|
94
95
|
it 'should render an ol in the fieldset' do
|
|
95
|
-
output_buffer.
|
|
96
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions ol')
|
|
96
97
|
end
|
|
97
|
-
|
|
98
|
+
|
|
98
99
|
it 'should render a list item in the ol for each default action' do
|
|
99
|
-
output_buffer.
|
|
100
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
|
|
100
101
|
end
|
|
101
|
-
|
|
102
|
+
|
|
102
103
|
end
|
|
103
|
-
|
|
104
|
+
|
|
104
105
|
describe 'with button names as args' do
|
|
105
|
-
|
|
106
|
+
|
|
106
107
|
before do
|
|
107
108
|
concat(semantic_form_for(@new_post) do |builder|
|
|
108
109
|
concat(builder.actions(:submit, :cancel, :reset))
|
|
109
110
|
end)
|
|
110
111
|
end
|
|
111
|
-
|
|
112
|
+
|
|
112
113
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
113
|
-
output_buffer.
|
|
114
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
114
115
|
end
|
|
115
|
-
|
|
116
|
+
|
|
116
117
|
end
|
|
117
|
-
|
|
118
|
+
|
|
118
119
|
describe 'with button names as args and an options hash' do
|
|
119
|
-
|
|
120
|
+
|
|
120
121
|
before do
|
|
121
122
|
concat(semantic_form_for(@new_post) do |builder|
|
|
122
123
|
concat(builder.actions(:submit, :cancel, :reset, :name => "Now click a button", :id => "my-id"))
|
|
123
124
|
end)
|
|
124
125
|
end
|
|
125
|
-
|
|
126
|
+
|
|
126
127
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
127
|
-
output_buffer.
|
|
128
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
128
129
|
end
|
|
129
|
-
|
|
130
|
+
|
|
130
131
|
it 'should pass the options down to the fieldset' do
|
|
131
|
-
output_buffer.
|
|
132
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions')
|
|
132
133
|
end
|
|
133
|
-
|
|
134
|
+
|
|
134
135
|
it 'should use the special :name option as a text for the legend tag' do
|
|
135
|
-
output_buffer.
|
|
136
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions > legend', :text => /Now click a button/)
|
|
136
137
|
end
|
|
137
|
-
|
|
138
|
+
|
|
138
139
|
end
|
|
139
|
-
|
|
140
|
+
|
|
140
141
|
end
|
|
141
|
-
|
|
142
|
+
|
|
142
143
|
end
|
|
143
144
|
|