formtastic 3.1.1 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.gitignore +3 -2
- data/.travis.yml +29 -24
- data/CHANGELOG.md +49 -0
- data/DEPRECATIONS +4 -1
- data/Gemfile.lock +104 -0
- data/{README.textile → README.md} +178 -166
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +9 -15
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +9 -11
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +1 -38
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +11 -24
- data/lib/formtastic/helpers.rb +1 -1
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
- data/lib/formtastic/helpers/form_helper.rb +1 -1
- data/lib/formtastic/helpers/input_helper.rb +23 -77
- data/lib/formtastic/helpers/inputs_helper.rb +27 -22
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/choices.rb +1 -1
- data/lib/formtastic/inputs/base/collections.rb +43 -10
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/html.rb +7 -6
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/options.rb +2 -3
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +38 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/country_input.rb +3 -1
- data/lib/formtastic/inputs/radio_input.rb +20 -0
- data/lib/formtastic/inputs/select_input.rb +29 -1
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/localizer.rb +20 -22
- data/lib/formtastic/namespaced_class_finder.rb +1 -1
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/form/form_generator.rb +1 -1
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/templates/formtastic.rb +14 -13
- data/lib/generators/templates/input.rb +19 -0
- data/script/integration-template.rb +71 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +1 -1
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +60 -60
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +36 -20
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +328 -10
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +37 -37
- data/spec/helpers/input_helper_spec.rb +975 -2
- data/spec/helpers/inputs_helper_spec.rb +120 -105
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +1 -1
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +480 -0
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +155 -108
- data/spec/inputs/color_input_spec.rb +51 -63
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +2 -6
- data/spec/inputs/datalist_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +42 -42
- data/spec/inputs/date_select_input_spec.rb +51 -37
- data/spec/inputs/datetime_picker_input_spec.rb +46 -46
- data/spec/inputs/datetime_select_input_spec.rb +53 -37
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +18 -18
- data/spec/inputs/include_blank_spec.rb +8 -8
- data/spec/inputs/label_spec.rb +20 -20
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +5 -5
- data/spec/inputs/radio_input_spec.rb +84 -58
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +149 -93
- data/spec/inputs/string_input_spec.rb +23 -23
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +43 -43
- data/spec/inputs/time_select_input_spec.rb +67 -54
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +17 -17
- data/spec/namespaced_class_finder_spec.rb +2 -2
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +165 -253
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1232
- data/spec/support/test_environment.rb +23 -9
- metadata +67 -174
- data/Appraisals +0 -29
- data/CHANGELOG +0 -31
- 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.2.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/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -66
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'InputAction', 'when submitting' do
|
4
|
+
RSpec.describe 'InputAction', 'when submitting' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -15,12 +15,12 @@ describe 'InputAction', 'when submitting' do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should render a submit type of input' do
|
18
|
-
output_buffer.
|
18
|
+
expect(output_buffer).to have_tag('li.action.input_action input[@type="submit"]')
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
describe 'InputAction', 'when resetting' do
|
23
|
+
RSpec.describe 'InputAction', 'when resetting' do
|
24
24
|
|
25
25
|
include FormtasticSpecHelper
|
26
26
|
|
@@ -34,12 +34,12 @@ describe 'InputAction', 'when resetting' do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should render a reset type of input' do
|
37
|
-
output_buffer.
|
37
|
+
expect(output_buffer).to have_tag('li.action.input_action input[@type="reset"]')
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
-
describe 'InputAction', 'when cancelling' do
|
42
|
+
RSpec.describe 'InputAction', 'when cancelling' do
|
43
43
|
|
44
44
|
include FormtasticSpecHelper
|
45
45
|
|
@@ -49,11 +49,11 @@ describe 'InputAction', 'when cancelling' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should raise an error' do
|
52
|
-
|
52
|
+
expect {
|
53
53
|
concat(semantic_form_for(@new_post) do |builder|
|
54
54
|
concat(builder.action(:cancel, :as => :input))
|
55
55
|
end)
|
56
|
-
}.
|
56
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'LinkAction', 'when cancelling' do
|
4
|
+
RSpec.describe 'LinkAction', 'when cancelling' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -18,7 +18,7 @@ describe 'LinkAction', 'when cancelling' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should render a submit type of input' do
|
21
|
-
output_buffer.
|
21
|
+
expect(output_buffer).to have_tag('li.action.link_action a[@href="javascript:history.back()"]')
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -32,7 +32,7 @@ describe 'LinkAction', 'when cancelling' do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should render a submit type of input' do
|
35
|
-
output_buffer.
|
35
|
+
expect(output_buffer).to have_tag('li.action.link_action a[@href="http://foo.bah/baz"]')
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -46,14 +46,14 @@ describe 'LinkAction', 'when cancelling' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should render a submit type of input' do
|
49
|
-
output_buffer.
|
49
|
+
expect(output_buffer).to have_tag('li.action.link_action a[@href="/mock/path"]')
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
|
-
describe 'LinkAction', 'when submitting' do
|
56
|
+
RSpec.describe 'LinkAction', 'when submitting' do
|
57
57
|
|
58
58
|
include FormtasticSpecHelper
|
59
59
|
|
@@ -63,16 +63,16 @@ describe 'LinkAction', 'when submitting' do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'should raise an error' do
|
66
|
-
|
66
|
+
expect {
|
67
67
|
concat(semantic_form_for(@new_post) do |builder|
|
68
68
|
concat(builder.action(:submit, :as => :link))
|
69
69
|
end)
|
70
|
-
}.
|
70
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
74
74
|
|
75
|
-
describe 'LinkAction', 'when submitting' do
|
75
|
+
RSpec.describe 'LinkAction', 'when submitting' do
|
76
76
|
|
77
77
|
include FormtasticSpecHelper
|
78
78
|
|
@@ -82,11 +82,11 @@ describe 'LinkAction', 'when submitting' do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'should raise an error' do
|
85
|
-
|
85
|
+
expect {
|
86
86
|
concat(semantic_form_for(@new_post) do |builder|
|
87
87
|
concat(builder.action(:reset, :as => :link))
|
88
88
|
end)
|
89
|
-
}.
|
89
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
90
90
|
end
|
91
91
|
|
92
92
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'Formtastic::Helpers::FormHelper.builder' do
|
4
|
+
RSpec.describe 'Formtastic::Helpers::FormHelper.builder' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
class MyCustomFormBuilder < Formtastic::FormBuilder
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
# TODO should be a separate spec for custom inputs
|
12
12
|
class Formtastic::Inputs::AwesomeInput
|
13
13
|
include Formtastic::Inputs::Base
|
@@ -22,32 +22,32 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'is the Formtastic::FormBuilder by default' do
|
25
|
-
Formtastic::Helpers::FormHelper.builder.
|
25
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(Formtastic::FormBuilder)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'can be configured to use your own custom form builder' do
|
29
29
|
# Set it to a custom builder class
|
30
30
|
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
31
|
-
Formtastic::Helpers::FormHelper.builder.
|
31
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(MyCustomFormBuilder)
|
32
32
|
|
33
33
|
# Reset it to the default
|
34
34
|
Formtastic::Helpers::FormHelper.builder = Formtastic::FormBuilder
|
35
|
-
Formtastic::Helpers::FormHelper.builder.
|
35
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(Formtastic::FormBuilder)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should allow custom settings per form builder subclass' do
|
39
39
|
with_config(:all_fields_required_by_default, true) do
|
40
40
|
MyCustomFormBuilder.all_fields_required_by_default = false
|
41
41
|
|
42
|
-
MyCustomFormBuilder.all_fields_required_by_default.
|
43
|
-
Formtastic::FormBuilder.all_fields_required_by_default.
|
42
|
+
expect(MyCustomFormBuilder.all_fields_required_by_default).to be_falsey
|
43
|
+
expect(Formtastic::FormBuilder.all_fields_required_by_default).to be_truthy
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "when using a custom builder" do
|
48
48
|
|
49
49
|
before do
|
50
|
-
@new_post.
|
50
|
+
allow(@new_post).to receive(:title)
|
51
51
|
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
52
52
|
end
|
53
53
|
|
@@ -59,10 +59,10 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
59
59
|
|
60
60
|
it "should yield an instance of the custom builder" do
|
61
61
|
semantic_form_for(@new_post) do |builder|
|
62
|
-
builder.class.
|
62
|
+
expect(builder.class).to be(MyCustomFormBuilder)
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
# TODO should be a separate spec for custom inputs
|
67
67
|
it "should allow me to call my custom input" do
|
68
68
|
semantic_form_for(@new_post) do |builder|
|
@@ -72,29 +72,45 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
72
72
|
|
73
73
|
# See: https://github.com/justinfrench/formtastic/issues/657
|
74
74
|
it "should not conflict with navigasmic" do
|
75
|
-
self.class.
|
76
|
-
|
77
|
-
|
75
|
+
allow_any_instance_of(self.class).to receive(:builder).and_return('navigasmic')
|
76
|
+
|
77
|
+
expect { semantic_form_for(@new_post) { |f| } }.not_to raise_error
|
78
78
|
end
|
79
79
|
|
80
|
+
it "should use the custom builder's skipped_columns config for inputs" do
|
81
|
+
class AnotherCustomFormBuilder < Formtastic::FormBuilder
|
82
|
+
configure :skipped_columns, [:title, :created_at]
|
83
|
+
end
|
84
|
+
#AnotherCustomFormBuilder.skipped_columns = [:title, :created_at]
|
85
|
+
|
86
|
+
concat(semantic_form_for(@new_post, builder: AnotherCustomFormBuilder) do |builder|
|
87
|
+
concat(builder.inputs)
|
88
|
+
end)
|
89
|
+
|
90
|
+
expect(output_buffer).to_not have_tag('input#post_title')
|
91
|
+
expect(output_buffer).to_not have_tag('li#post_created_at_input')
|
92
|
+
expect(output_buffer).to have_tag('textarea#post_body')
|
93
|
+
end
|
80
94
|
end
|
81
95
|
|
82
96
|
describe "fields_for" do
|
83
97
|
|
84
98
|
it "should yield an instance of the parent form builder" do
|
85
|
-
@new_post.
|
86
|
-
@new_post.
|
99
|
+
allow(@new_post).to receive(:comment).and_return([@fred])
|
100
|
+
allow(@new_post).to receive(:comment_attributes=)
|
87
101
|
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
88
|
-
builder.class.
|
89
|
-
|
102
|
+
expect(builder.class).to be(MyCustomFormBuilder)
|
103
|
+
|
90
104
|
builder.fields_for(:comment) do |nested_builder|
|
91
|
-
nested_builder.class.
|
105
|
+
expect(nested_builder.class).to be(MyCustomFormBuilder)
|
92
106
|
end
|
93
107
|
end
|
94
108
|
end
|
95
109
|
|
96
110
|
end
|
97
111
|
|
112
|
+
|
113
|
+
|
98
114
|
end
|
99
115
|
|
100
116
|
describe "when using a builder passed to form options" do
|
@@ -102,10 +118,10 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
102
118
|
describe "fields_for" do
|
103
119
|
|
104
120
|
it "should yield an instance of the parent form builder" do
|
105
|
-
@new_post.
|
121
|
+
allow(@new_post).to receive(:author_attributes=)
|
106
122
|
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
107
123
|
builder.fields_for(:author) do |nested_builder|
|
108
|
-
nested_builder.class.
|
124
|
+
expect(nested_builder.class).to be(MyCustomFormBuilder)
|
109
125
|
end
|
110
126
|
end
|
111
127
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'Rails field_error_proc' do
|
4
|
+
RSpec.describe 'Rails field_error_proc' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -14,13 +14,13 @@ describe 'Rails field_error_proc' do
|
|
14
14
|
current_field_error_proc = ::ActionView::Base.field_error_proc
|
15
15
|
|
16
16
|
semantic_form_for(@new_post) do |builder|
|
17
|
-
::ActionView::Base.field_error_proc.
|
17
|
+
expect(::ActionView::Base.field_error_proc).not_to eq(current_field_error_proc)
|
18
18
|
end
|
19
19
|
|
20
|
-
::ActionView::Base.field_error_proc.
|
20
|
+
expect(::ActionView::Base.field_error_proc).to eq(current_field_error_proc)
|
21
21
|
|
22
22
|
form_for(@new_post) do |builder|
|
23
|
-
::ActionView::Base.field_error_proc.
|
23
|
+
expect(::ActionView::Base.field_error_proc).to eq(current_field_error_proc)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -1,44 +1,44 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'Formtastic::FormBuilder#fields_for' do
|
4
|
+
RSpec.describe 'Formtastic::FormBuilder#fields_for' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
@new_post.
|
11
|
+
allow(@new_post).to receive(:author).and_return(::Author.new)
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'outside a form_for block' do
|
15
15
|
it 'yields an instance of FormHelper.builder' do
|
16
16
|
semantic_fields_for(@new_post) do |nested_builder|
|
17
|
-
nested_builder.class.
|
17
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
18
18
|
end
|
19
19
|
semantic_fields_for(@new_post.author) do |nested_builder|
|
20
|
-
nested_builder.class.
|
20
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
21
21
|
end
|
22
22
|
semantic_fields_for(:author, @new_post.author) do |nested_builder|
|
23
|
-
nested_builder.class.
|
23
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
24
24
|
end
|
25
25
|
semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
|
26
|
-
nested_builder.class.
|
26
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should respond to input' do
|
31
31
|
semantic_fields_for(@new_post) do |nested_builder|
|
32
|
-
nested_builder.respond_to?(:input).
|
32
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
33
33
|
end
|
34
34
|
semantic_fields_for(@new_post.author) do |nested_builder|
|
35
|
-
nested_builder.respond_to?(:input).
|
35
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
36
36
|
end
|
37
37
|
semantic_fields_for(:author, @new_post.author) do |nested_builder|
|
38
|
-
nested_builder.respond_to?(:input).
|
38
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
39
39
|
end
|
40
40
|
semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
|
41
|
-
nested_builder.respond_to?(:input).
|
41
|
+
expect(nested_builder.respond_to?(:input)).to be_truthy
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -47,7 +47,7 @@ describe 'Formtastic::FormBuilder#fields_for' do
|
|
47
47
|
it 'yields an instance of FormHelper.builder' do
|
48
48
|
semantic_form_for(@new_post) do |builder|
|
49
49
|
builder.semantic_fields_for(:author) do |nested_builder|
|
50
|
-
nested_builder.class.
|
50
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -55,7 +55,7 @@ describe 'Formtastic::FormBuilder#fields_for' do
|
|
55
55
|
it 'yields an instance of FormHelper.builder with hash-like model' do
|
56
56
|
semantic_form_for(:user) do |builder|
|
57
57
|
builder.semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
|
58
|
-
nested_builder.class.
|
58
|
+
expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -63,7 +63,7 @@ describe 'Formtastic::FormBuilder#fields_for' do
|
|
63
63
|
it 'nests the object name' do
|
64
64
|
semantic_form_for(@new_post) do |builder|
|
65
65
|
builder.semantic_fields_for(@bob) do |nested_builder|
|
66
|
-
nested_builder.object_name.
|
66
|
+
expect(nested_builder.object_name).to eq('post[author]')
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -71,45 +71,45 @@ describe 'Formtastic::FormBuilder#fields_for' do
|
|
71
71
|
it 'supports passing collection as second parameter' do
|
72
72
|
semantic_form_for(@new_post) do |builder|
|
73
73
|
builder.semantic_fields_for(:author, [@fred,@bob]) do |nested_builder|
|
74
|
-
nested_builder.object_name.
|
74
|
+
expect(nested_builder.object_name).to match(/post\[author_attributes\]\[\d+\]/)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'should sanitize html id for li tag' do
|
80
|
-
@bob.
|
80
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
81
81
|
concat(semantic_form_for(@new_post) do |builder|
|
82
82
|
concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
|
83
83
|
concat(nested_builder.inputs(:login))
|
84
84
|
end)
|
85
85
|
end)
|
86
|
-
output_buffer.
|
86
|
+
expect(output_buffer).to have_tag('form fieldset.inputs #post_author_1_login_input')
|
87
87
|
# Not valid selector, so using good ol' regex
|
88
|
-
output_buffer.
|
88
|
+
expect(output_buffer).not_to match(/id="post\[author\]_1_login_input"/)
|
89
89
|
# <=> output_buffer.should_not have_tag('form fieldset.inputs #post[author]_1_login_input')
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should use namespace provided in nested fields' do
|
93
|
-
@bob.
|
93
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
94
94
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
95
95
|
concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
|
96
96
|
concat(nested_builder.inputs(:login))
|
97
97
|
end)
|
98
98
|
end)
|
99
|
-
output_buffer.
|
99
|
+
expect(output_buffer).to have_tag('form fieldset.inputs #context2_post_author_1_login_input')
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'should render errors on the nested inputs' do
|
103
103
|
@errors = double('errors')
|
104
|
-
@errors.
|
105
|
-
@bob.
|
104
|
+
allow(@errors).to receive(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
|
105
|
+
allow(@bob).to receive(:errors).and_return(@errors)
|
106
106
|
|
107
107
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
108
108
|
concat(builder.semantic_fields_for(@bob) do |nested_builder|
|
109
109
|
concat(nested_builder.inputs(:login))
|
110
110
|
end)
|
111
111
|
end)
|
112
|
-
output_buffer.
|
112
|
+
expect(output_buffer).to match(/oh noes/)
|
113
113
|
end
|
114
114
|
|
115
115
|
end
|
@@ -119,9 +119,9 @@ describe 'Formtastic::FormBuilder#fields_for' do
|
|
119
119
|
before do
|
120
120
|
output_buffer.replace ''
|
121
121
|
|
122
|
-
@fred.posts.size.
|
123
|
-
@fred.posts.first.
|
124
|
-
@fred.
|
122
|
+
expect(@fred.posts.size).to eq(1)
|
123
|
+
allow(@fred.posts.first).to receive(:persisted?).and_return(true)
|
124
|
+
allow(@fred).to receive(:posts_attributes=)
|
125
125
|
concat(semantic_form_for(@fred) do |builder|
|
126
126
|
concat(builder.semantic_fields_for(:posts) do |nested_builder|
|
127
127
|
concat(nested_builder.input(:id, :as => :hidden))
|
@@ -131,11 +131,11 @@ describe 'Formtastic::FormBuilder#fields_for' do
|
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should only render one hidden input (my one)" do
|
134
|
-
output_buffer.
|
134
|
+
expect(output_buffer).to have_tag 'input#author_posts_attributes_0_id', :count => 1
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should render the hidden input inside an li.hidden" do
|
138
|
-
output_buffer.
|
138
|
+
expect(output_buffer).to have_tag 'li.hidden input#author_posts_attributes_0_id'
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH << 'lib/formtastic'
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'localized_string'
|
5
|
+
require 'inputs'
|
6
|
+
require 'helpers'
|
7
|
+
|
8
|
+
class MyInput
|
9
|
+
include Formtastic::Inputs::Base
|
10
|
+
end
|
11
|
+
|
12
|
+
I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales)
|