formtastic 2.0.2 → 2.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Appraisals +11 -0
- data/CHANGELOG +2 -2
- data/Gemfile +0 -2
- data/README.textile +183 -151
- data/Rakefile +9 -5
- data/app/assets/stylesheets/formtastic.css +16 -3
- data/formtastic.gemspec +6 -2
- data/gemfiles/rails-3.0.gemfile +7 -0
- data/gemfiles/rails-3.1.gemfile +7 -0
- data/gemfiles/rails-3.2.gemfile +7 -0
- data/lib/formtastic.rb +10 -2
- data/lib/formtastic/actions.rb +11 -0
- data/lib/formtastic/actions/base.rb +156 -0
- data/lib/formtastic/actions/button_action.rb +72 -0
- data/lib/formtastic/actions/buttonish.rb +17 -0
- data/lib/formtastic/actions/input_action.rb +68 -0
- data/lib/formtastic/actions/link_action.rb +87 -0
- data/lib/formtastic/engine.rb +5 -1
- data/lib/formtastic/form_builder.rb +3 -0
- data/lib/formtastic/helpers.rb +2 -1
- data/lib/formtastic/helpers/action_helper.rb +109 -0
- data/lib/formtastic/helpers/actions_helper.rb +168 -0
- data/lib/formtastic/helpers/buttons_helper.rb +22 -9
- data/lib/formtastic/helpers/errors_helper.rb +0 -54
- data/lib/formtastic/helpers/fieldset_wrapper.rb +10 -5
- data/lib/formtastic/helpers/form_helper.rb +2 -2
- data/lib/formtastic/helpers/input_helper.rb +1 -10
- data/lib/formtastic/helpers/inputs_helper.rb +6 -3
- data/lib/formtastic/i18n.rb +3 -2
- data/lib/formtastic/inputs/base.rb +11 -3
- data/lib/formtastic/inputs/base/choices.rb +6 -1
- data/lib/formtastic/inputs/base/collections.rb +36 -13
- data/lib/formtastic/inputs/base/grouped_collections.rb +1 -1
- data/lib/formtastic/inputs/base/numeric.rb +50 -0
- data/lib/formtastic/inputs/base/options.rb +1 -1
- data/lib/formtastic/inputs/base/placeholder.rb +17 -0
- data/lib/formtastic/inputs/base/stringish.rb +2 -7
- data/lib/formtastic/inputs/base/timeish.rb +21 -5
- data/lib/formtastic/inputs/base/validations.rb +1 -1
- data/lib/formtastic/inputs/base/wrapping.rb +10 -3
- data/lib/formtastic/inputs/boolean_input.rb +10 -2
- data/lib/formtastic/inputs/check_boxes_input.rb +18 -9
- data/lib/formtastic/inputs/country_input.rb +2 -2
- data/lib/formtastic/inputs/date_input.rb +19 -1
- data/lib/formtastic/inputs/datetime_input.rb +1 -1
- data/lib/formtastic/inputs/email_input.rb +2 -1
- data/lib/formtastic/inputs/file_input.rb +1 -1
- data/lib/formtastic/inputs/hidden_input.rb +1 -1
- data/lib/formtastic/inputs/number_input.rb +6 -36
- data/lib/formtastic/inputs/password_input.rb +2 -1
- data/lib/formtastic/inputs/phone_input.rb +3 -2
- data/lib/formtastic/inputs/radio_input.rb +1 -1
- data/lib/formtastic/inputs/range_input.rb +8 -32
- data/lib/formtastic/inputs/search_input.rb +2 -1
- data/lib/formtastic/inputs/select_input.rb +56 -28
- data/lib/formtastic/inputs/string_input.rb +3 -1
- data/lib/formtastic/inputs/text_input.rb +5 -4
- data/lib/formtastic/inputs/time_input.rb +4 -8
- data/lib/formtastic/inputs/time_zone_input.rb +1 -1
- data/lib/formtastic/inputs/url_input.rb +2 -1
- data/lib/formtastic/localized_string.rb +6 -94
- data/lib/formtastic/localizer.rb +110 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/form/form_generator.rb +105 -0
- data/lib/generators/templates/_form.html.erb +2 -2
- data/lib/generators/templates/_form.html.haml +4 -4
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +4 -0
- data/lib/locale/en.yml +2 -0
- data/sample/basic_inputs.html +22 -0
- data/spec/actions/button_action_spec.rb +63 -0
- data/spec/actions/generic_action_spec.rb +484 -0
- data/spec/actions/input_action_spec.rb +59 -0
- data/spec/actions/link_action_spec.rb +92 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +118 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
- data/spec/helpers/action_helper_spec.rb +365 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/buttons_helper_spec.rb +39 -23
- data/spec/helpers/commit_button_helper_spec.rb +153 -93
- data/spec/helpers/inputs_helper_spec.rb +14 -0
- data/spec/i18n_spec.rb +11 -0
- data/spec/inputs/boolean_input_spec.rb +31 -2
- data/spec/inputs/check_boxes_input_spec.rb +29 -1
- data/spec/inputs/date_input_spec.rb +95 -0
- data/spec/inputs/datetime_input_spec.rb +49 -0
- data/spec/inputs/email_input_spec.rb +28 -0
- data/spec/inputs/file_input_spec.rb +28 -0
- data/spec/inputs/hidden_input_spec.rb +28 -0
- data/spec/inputs/include_blank_spec.rb +53 -45
- data/spec/inputs/number_input_spec.rb +34 -4
- data/spec/inputs/password_input_spec.rb +28 -0
- data/spec/inputs/phone_input_spec.rb +28 -0
- data/spec/inputs/placeholder_spec.rb +10 -10
- data/spec/inputs/radio_input_spec.rb +51 -6
- data/spec/inputs/range_input_spec.rb +30 -2
- data/spec/inputs/search_input_spec.rb +27 -0
- data/spec/inputs/select_input_spec.rb +52 -6
- data/spec/inputs/string_input_spec.rb +28 -0
- data/spec/inputs/text_input_spec.rb +27 -0
- data/spec/inputs/time_input_spec.rb +67 -1
- data/spec/inputs/time_zone_input_spec.rb +28 -0
- data/spec/inputs/url_input_spec.rb +28 -0
- data/spec/inputs/with_options_spec.rb +43 -0
- data/spec/spec_helper.rb +22 -6
- data/spec/support/custom_macros.rb +6 -134
- data/spec/support/test_environment.rb +0 -1
- metadata +104 -17
- data/lib/formtastic/helpers/semantic_form_helper.rb +0 -11
- data/lib/formtastic/inputs/numeric_input.rb +0 -21
- data/lib/formtastic/railtie.rb +0 -12
- data/lib/formtastic/semantic_form_builder.rb +0 -11
- data/spec/builder/errors_spec.rb +0 -203
- data/spec/inputs/numeric_input_spec.rb +0 -41
@@ -0,0 +1,143 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Formtastic::FormBuilder#actions' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'with a block' do
|
14
|
+
describe 'when no options are provided' do
|
15
|
+
before do
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
17
|
+
concat(builder.actions do
|
18
|
+
concat('hello')
|
19
|
+
end)
|
20
|
+
end)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should render a fieldset inside the form, with a class of "actions"' do
|
24
|
+
output_buffer.should have_tag("form fieldset.actions")
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should render an ol inside the fieldset' do
|
28
|
+
output_buffer.should have_tag("form fieldset.actions ol")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should render the contents of the block inside the ol' do
|
32
|
+
output_buffer.should have_tag("form fieldset.actions ol", /hello/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should not render a legend inside the fieldset' do
|
36
|
+
output_buffer.should_not have_tag("form fieldset.actions legend")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'when a :name option is provided' do
|
41
|
+
before do
|
42
|
+
@legend_text = "Advanced options"
|
43
|
+
|
44
|
+
concat(semantic_form_for(@new_post) do |builder|
|
45
|
+
builder.actions :name => @legend_text do
|
46
|
+
end
|
47
|
+
end)
|
48
|
+
end
|
49
|
+
it 'should render a fieldset inside the form' do
|
50
|
+
output_buffer.should have_tag("form fieldset.actions legend", /#{@legend_text}/)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'when other options are provided' do
|
55
|
+
before do
|
56
|
+
@id_option = 'advanced'
|
57
|
+
@class_option = 'wide'
|
58
|
+
|
59
|
+
concat(semantic_form_for(@new_post) do |builder|
|
60
|
+
builder.actions :id => @id_option, :class => @class_option do
|
61
|
+
end
|
62
|
+
end)
|
63
|
+
end
|
64
|
+
it 'should pass the options into the fieldset tag as attributes' do
|
65
|
+
output_buffer.should have_tag("form fieldset##{@id_option}")
|
66
|
+
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'without a block' do
|
73
|
+
|
74
|
+
describe 'with no args (default buttons)' do
|
75
|
+
|
76
|
+
before do
|
77
|
+
concat(semantic_form_for(@new_post) do |builder|
|
78
|
+
concat(builder.actions)
|
79
|
+
end)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should render a form' do
|
83
|
+
output_buffer.should have_tag('form')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should render an actions fieldset inside the form' do
|
87
|
+
output_buffer.should have_tag('form fieldset.actions')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should not render a legend in the fieldset' do
|
91
|
+
output_buffer.should_not have_tag('form fieldset.actions legend')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should render an ol in the fieldset' do
|
95
|
+
output_buffer.should have_tag('form fieldset.actions ol')
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should render a list item in the ol for each default action' do
|
99
|
+
output_buffer.should have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'with button names as args' do
|
105
|
+
|
106
|
+
before do
|
107
|
+
concat(semantic_form_for(@new_post) do |builder|
|
108
|
+
concat(builder.actions(:submit, :cancel, :reset))
|
109
|
+
end)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should render a form with a fieldset containing a list item for each button arg' do
|
113
|
+
output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'with button names as args and an options hash' do
|
119
|
+
|
120
|
+
before do
|
121
|
+
concat(semantic_form_for(@new_post) do |builder|
|
122
|
+
concat(builder.actions(:submit, :cancel, :reset, :name => "Now click a button", :id => "my-id"))
|
123
|
+
end)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should render a form with a fieldset containing a list item for each button arg' do
|
127
|
+
output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should pass the options down to the fieldset' do
|
131
|
+
output_buffer.should have_tag('form > fieldset#my-id.actions')
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should use the special :name option as a text for the legend tag' do
|
135
|
+
output_buffer.should have_tag('form > fieldset#my-id.actions > legend', /Now click a button/)
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
@@ -13,12 +13,14 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
13
13
|
describe 'with a block' do
|
14
14
|
describe 'when no options are provided' do
|
15
15
|
before do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
with_deprecation_silenced do
|
17
|
+
concat(semantic_form_for(@new_post) do |builder|
|
18
|
+
buttons = builder.buttons do
|
19
|
+
concat('hello')
|
20
|
+
end
|
21
|
+
concat(buttons)
|
22
|
+
end)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
@@ -42,14 +44,18 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
42
44
|
before do
|
43
45
|
@legend_text = "Advanced options"
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
with_deprecation_silenced do
|
48
|
+
concat(semantic_form_for(@new_post) do |builder|
|
49
|
+
builder.buttons :name => @legend_text do
|
50
|
+
end
|
51
|
+
end)
|
52
|
+
end
|
49
53
|
end
|
54
|
+
|
50
55
|
it 'should render a fieldset inside the form' do
|
51
56
|
output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
|
52
57
|
end
|
58
|
+
|
53
59
|
end
|
54
60
|
|
55
61
|
describe 'when other options are provided' do
|
@@ -57,15 +63,19 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
57
63
|
@id_option = 'advanced'
|
58
64
|
@class_option = 'wide'
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
with_deprecation_silenced do
|
67
|
+
concat(semantic_form_for(@new_post) do |builder|
|
68
|
+
builder.buttons :id => @id_option, :class => @class_option do
|
69
|
+
end
|
70
|
+
end)
|
71
|
+
end
|
64
72
|
end
|
73
|
+
|
65
74
|
it 'should pass the options into the fieldset tag as attributes' do
|
66
75
|
output_buffer.should have_tag("form fieldset##{@id_option}")
|
67
76
|
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
68
77
|
end
|
78
|
+
|
69
79
|
end
|
70
80
|
|
71
81
|
end
|
@@ -75,9 +85,11 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
75
85
|
describe 'with no args (default buttons)' do
|
76
86
|
|
77
87
|
before do
|
78
|
-
|
79
|
-
concat(builder
|
80
|
-
|
88
|
+
with_deprecation_silenced do
|
89
|
+
concat(semantic_form_for(@new_post) do |builder|
|
90
|
+
concat(builder.buttons)
|
91
|
+
end)
|
92
|
+
end
|
81
93
|
end
|
82
94
|
|
83
95
|
it 'should render a form' do
|
@@ -109,9 +121,11 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
109
121
|
describe 'with button names as args' do
|
110
122
|
|
111
123
|
before do
|
112
|
-
|
113
|
-
concat(
|
114
|
-
|
124
|
+
with_deprecation_silenced do
|
125
|
+
concat(semantic_form_for(@new_post) do |builder|
|
126
|
+
concat(builder.buttons(:commit))
|
127
|
+
end)
|
128
|
+
end
|
115
129
|
end
|
116
130
|
|
117
131
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
@@ -124,9 +138,11 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
124
138
|
describe 'with button names as args and an options hash' do
|
125
139
|
|
126
140
|
before do
|
127
|
-
|
128
|
-
concat(
|
129
|
-
|
141
|
+
with_deprecation_silenced do
|
142
|
+
concat(semantic_form_for(@new_post) do |builder|
|
143
|
+
concat(builder.buttons(:commit, :name => "Now click a button", :id => "my-id"))
|
144
|
+
end)
|
145
|
+
end
|
130
146
|
end
|
131
147
|
|
132
148
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
@@ -9,7 +9,7 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
describe 'when the object responds to :persisted? (ActiveModel)' do
|
14
14
|
|
15
15
|
before do
|
@@ -19,17 +19,19 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should call :persisted?' do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
with_deprecation_silenced do
|
23
|
+
with_config :i18n_lookups_by_default, false do
|
24
|
+
@new_post.should_receive(:persisted?)
|
25
|
+
@new_post.should_not_receive(:new_record?)
|
26
|
+
semantic_form_for(@new_post) do |builder|
|
27
|
+
concat(builder.commit_button)
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
end
|
32
|
-
|
34
|
+
|
33
35
|
describe 'when not persisted' do
|
34
36
|
|
35
37
|
before do
|
@@ -39,30 +41,33 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'should have a submit button label' do
|
42
|
-
|
43
|
-
|
44
|
-
concat(builder
|
45
|
-
|
44
|
+
with_deprecation_silenced do
|
45
|
+
with_config :i18n_lookups_by_default, false do
|
46
|
+
concat(semantic_form_for(@new_post) do |builder|
|
47
|
+
concat(builder.commit_button)
|
48
|
+
end)
|
49
|
+
end
|
46
50
|
end
|
47
|
-
|
51
|
+
|
48
52
|
output_buffer.should have_tag('.commit input[@value="Submit Post"]')
|
49
53
|
end
|
50
54
|
end
|
51
|
-
|
52
|
-
|
55
|
+
|
53
56
|
describe 'when used on any record' do
|
54
57
|
|
55
58
|
before do
|
56
59
|
@new_post.stub!(:new_record?).and_return(false)
|
57
|
-
|
58
|
-
concat(builder
|
59
|
-
|
60
|
+
with_deprecation_silenced do
|
61
|
+
concat(semantic_form_for(@new_post) do |builder|
|
62
|
+
concat(builder.commit_button)
|
63
|
+
end)
|
64
|
+
end
|
60
65
|
end
|
61
66
|
|
62
67
|
it 'should render a commit li' do
|
63
68
|
output_buffer.should have_tag('li.commit')
|
64
69
|
end
|
65
|
-
|
70
|
+
|
66
71
|
it 'should render a button li' do
|
67
72
|
output_buffer.should have_tag('li.button')
|
68
73
|
end
|
@@ -77,9 +82,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
77
82
|
|
78
83
|
it 'should pass options given in :button_html to the button' do
|
79
84
|
@new_post.stub!(:new_record?).and_return(false)
|
80
|
-
|
81
|
-
concat(
|
82
|
-
|
85
|
+
with_deprecation_silenced do
|
86
|
+
concat(semantic_form_for(@new_post) do |builder|
|
87
|
+
concat(builder.commit_button('text', :button_html => {:class => 'my_class', :id => 'my_id'}))
|
88
|
+
end)
|
89
|
+
end
|
83
90
|
|
84
91
|
output_buffer.should have_tag('li.commit input#my_id')
|
85
92
|
output_buffer.should have_tag('li.commit input.my_class')
|
@@ -98,9 +105,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
98
105
|
it 'should use the default if set' do
|
99
106
|
with_config :default_commit_button_accesskey, 's' do
|
100
107
|
@new_post.stub!(:new_record?).and_return(false)
|
101
|
-
|
102
|
-
concat(
|
103
|
-
|
108
|
+
with_deprecation_silenced do
|
109
|
+
concat(semantic_form_for(@new_post) do |builder|
|
110
|
+
concat(builder.commit_button('text', :button_html => {}))
|
111
|
+
end)
|
112
|
+
end
|
104
113
|
output_buffer.should have_tag('li.commit input[@accesskey="s"]')
|
105
114
|
end
|
106
115
|
end
|
@@ -108,9 +117,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
108
117
|
it 'should use the value set in options over the default' do
|
109
118
|
with_config :default_commit_button_accesskey, 's' do
|
110
119
|
@new_post.stub!(:new_record?).and_return(false)
|
111
|
-
|
112
|
-
concat(
|
113
|
-
|
120
|
+
with_deprecation_silenced do
|
121
|
+
concat(semantic_form_for(@new_post) do |builder|
|
122
|
+
concat(builder.commit_button('text', :accesskey => 'o'))
|
123
|
+
end)
|
124
|
+
end
|
114
125
|
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
|
115
126
|
output_buffer.should have_tag('li.commit input[@accesskey="o"]')
|
116
127
|
end
|
@@ -119,9 +130,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
119
130
|
it 'should use the value set in button_html over options' do
|
120
131
|
with_config :default_commit_button_accesskey, 's' do
|
121
132
|
@new_post.stub!(:new_record?).and_return(false)
|
122
|
-
|
123
|
-
concat(
|
124
|
-
|
133
|
+
with_deprecation_silenced do
|
134
|
+
concat(semantic_form_for(@new_post) do |builder|
|
135
|
+
concat(builder.commit_button('text', :accesskey => 'o', :button_html => {:accesskey => 't'}))
|
136
|
+
end)
|
137
|
+
end
|
125
138
|
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
|
126
139
|
output_buffer.should_not have_tag('li.commit input[@accesskey="o"]')
|
127
140
|
output_buffer.should have_tag('li.commit input[@accesskey="t"]')
|
@@ -134,9 +147,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
134
147
|
|
135
148
|
before do
|
136
149
|
@new_post.stub!(:new_record?).and_return(false)
|
137
|
-
|
138
|
-
concat(
|
139
|
-
|
150
|
+
with_deprecation_silenced do
|
151
|
+
concat(semantic_form_for(@new_post) do |builder|
|
152
|
+
concat(builder.commit_button("a string", :button_html => { :class => "pretty"}))
|
153
|
+
end)
|
154
|
+
end
|
140
155
|
end
|
141
156
|
|
142
157
|
it "should render the string as the value of the button" do
|
@@ -153,9 +168,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
153
168
|
|
154
169
|
before do
|
155
170
|
@new_post.stub!(:new_record?).and_return(false)
|
156
|
-
|
157
|
-
concat(
|
158
|
-
|
171
|
+
with_deprecation_silenced do
|
172
|
+
concat(semantic_form_for(@new_post) do |builder|
|
173
|
+
concat(builder.commit_button(:button_html => { :class => "pretty"}))
|
174
|
+
end)
|
175
|
+
end
|
159
176
|
end
|
160
177
|
|
161
178
|
it "should deal with the options hash" do
|
@@ -170,9 +187,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
170
187
|
describe 'when used without object' do
|
171
188
|
describe 'when explicit label is provided' do
|
172
189
|
it 'should render an input with the explicitly specified label' do
|
173
|
-
|
174
|
-
concat(
|
175
|
-
|
190
|
+
with_deprecation_silenced do
|
191
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
192
|
+
concat(builder.commit_button("Click!"))
|
193
|
+
end)
|
194
|
+
end
|
176
195
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="submit"]')
|
177
196
|
end
|
178
197
|
end
|
@@ -188,9 +207,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
188
207
|
end
|
189
208
|
|
190
209
|
it 'should render an input with default I18n-localized label (fallback)' do
|
191
|
-
|
192
|
-
concat(
|
193
|
-
|
210
|
+
with_deprecation_silenced do
|
211
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
212
|
+
concat(builder.commit_button)
|
213
|
+
end)
|
214
|
+
end
|
194
215
|
output_buffer.should have_tag('li.commit input[@value="Submit Post"][@class~="submit"]')
|
195
216
|
end
|
196
217
|
end
|
@@ -204,11 +225,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
204
225
|
}
|
205
226
|
}
|
206
227
|
end
|
207
|
-
|
228
|
+
|
208
229
|
after do
|
209
230
|
::I18n.backend.reload!
|
210
231
|
end
|
211
|
-
|
232
|
+
|
212
233
|
it 'should render an input with localized label (I18n)' do
|
213
234
|
with_config :i18n_lookups_by_default, true do
|
214
235
|
::I18n.backend.store_translations :en,
|
@@ -219,18 +240,22 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
219
240
|
}
|
220
241
|
}
|
221
242
|
}
|
222
|
-
|
223
|
-
concat(
|
224
|
-
|
243
|
+
with_deprecation_silenced do
|
244
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
245
|
+
concat(builder.commit_button)
|
246
|
+
end)
|
247
|
+
end
|
225
248
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
|
226
249
|
end
|
227
250
|
end
|
228
|
-
|
251
|
+
|
229
252
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
230
253
|
with_config :i18n_lookups_by_default, true do
|
231
|
-
|
232
|
-
concat(
|
233
|
-
|
254
|
+
with_deprecation_silenced do
|
255
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
256
|
+
concat(builder.commit_button)
|
257
|
+
end)
|
258
|
+
end
|
234
259
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
|
235
260
|
end
|
236
261
|
end
|
@@ -247,9 +272,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
247
272
|
|
248
273
|
describe 'when explicit label is provided' do
|
249
274
|
it 'should render an input with the explicitly specified label' do
|
250
|
-
|
251
|
-
concat(
|
252
|
-
|
275
|
+
with_deprecation_silenced do
|
276
|
+
concat(semantic_form_for(@new_post) do |builder|
|
277
|
+
concat(builder.commit_button("Click!"))
|
278
|
+
end)
|
279
|
+
end
|
253
280
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="create"]')
|
254
281
|
end
|
255
282
|
end
|
@@ -265,9 +292,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
265
292
|
end
|
266
293
|
|
267
294
|
it 'should render an input with default I18n-localized label (fallback)' do
|
268
|
-
|
269
|
-
concat(builder
|
270
|
-
|
295
|
+
with_deprecation_silenced do
|
296
|
+
concat(semantic_form_for(@new_post) do |builder|
|
297
|
+
concat(builder.commit_button)
|
298
|
+
end)
|
299
|
+
end
|
271
300
|
output_buffer.should have_tag('li.commit input[@value="Create Post"][@class~="create"]')
|
272
301
|
end
|
273
302
|
end
|
@@ -296,18 +325,22 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
296
325
|
}
|
297
326
|
}
|
298
327
|
}
|
299
|
-
|
300
|
-
concat(builder
|
301
|
-
|
328
|
+
with_deprecation_silenced do
|
329
|
+
concat(semantic_form_for(@new_post) do |builder|
|
330
|
+
concat(builder.commit_button)
|
331
|
+
end)
|
332
|
+
end
|
302
333
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
|
303
334
|
end
|
304
335
|
end
|
305
336
|
|
306
337
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
307
338
|
with_config :i18n_lookups_by_default, true do
|
308
|
-
|
309
|
-
concat(builder
|
310
|
-
|
339
|
+
with_deprecation_silenced do
|
340
|
+
concat(semantic_form_for(@new_post) do |builder|
|
341
|
+
concat(builder.commit_button)
|
342
|
+
end)
|
343
|
+
end
|
311
344
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
|
312
345
|
end
|
313
346
|
end
|
@@ -324,9 +357,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
324
357
|
|
325
358
|
describe 'when explicit label is provided' do
|
326
359
|
it 'should render an input with the explicitly specified label' do
|
327
|
-
|
328
|
-
concat(
|
329
|
-
|
360
|
+
with_deprecation_silenced do
|
361
|
+
concat(semantic_form_for(@new_post) do |builder|
|
362
|
+
concat(builder.commit_button("Click!"))
|
363
|
+
end)
|
364
|
+
end
|
330
365
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="update"]')
|
331
366
|
end
|
332
367
|
end
|
@@ -342,9 +377,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
342
377
|
end
|
343
378
|
|
344
379
|
it 'should render an input with default I18n-localized label (fallback)' do
|
345
|
-
|
346
|
-
concat(builder
|
347
|
-
|
380
|
+
with_deprecation_silenced do
|
381
|
+
concat(semantic_form_for(@new_post) do |builder|
|
382
|
+
concat(builder.commit_button)
|
383
|
+
end)
|
384
|
+
end
|
348
385
|
output_buffer.should have_tag('li.commit input[@value="Save Post"][@class~="update"]')
|
349
386
|
end
|
350
387
|
end
|
@@ -374,18 +411,22 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
374
411
|
}
|
375
412
|
}
|
376
413
|
}
|
377
|
-
|
378
|
-
concat(builder
|
379
|
-
|
414
|
+
with_deprecation_silenced do
|
415
|
+
concat(semantic_form_for(@new_post) do |builder|
|
416
|
+
concat(builder.commit_button)
|
417
|
+
end)
|
418
|
+
end
|
380
419
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
|
381
420
|
end
|
382
421
|
end
|
383
422
|
|
384
423
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
385
424
|
with_config :i18n_lookups_by_default, true do
|
386
|
-
|
387
|
-
concat(builder
|
388
|
-
|
425
|
+
with_deprecation_silenced do
|
426
|
+
concat(semantic_form_for(@new_post) do |builder|
|
427
|
+
concat(builder.commit_button)
|
428
|
+
end)
|
429
|
+
end
|
389
430
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
|
390
431
|
::I18n.backend.store_translations :en, :formtastic => {}
|
391
432
|
end
|
@@ -417,9 +458,11 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
417
458
|
@new_user_post = ::UserPost.new
|
418
459
|
|
419
460
|
@new_user_post.stub!(:new_record?).and_return(true)
|
420
|
-
|
421
|
-
concat(
|
422
|
-
|
461
|
+
with_deprecation_silenced do
|
462
|
+
concat(semantic_form_for(@new_user_post, :url => '') do |builder|
|
463
|
+
concat(builder.commit_button())
|
464
|
+
end)
|
465
|
+
end
|
423
466
|
end
|
424
467
|
|
425
468
|
it "should render the string as the value of the button" do
|
@@ -427,29 +470,35 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
427
470
|
end
|
428
471
|
|
429
472
|
end
|
430
|
-
|
473
|
+
|
431
474
|
describe ':wrapper_html option' do
|
432
475
|
|
433
476
|
describe 'when provided' do
|
434
477
|
it 'should be passed down to the li tag' do
|
435
|
-
|
436
|
-
concat(
|
437
|
-
|
478
|
+
with_deprecation_silenced do
|
479
|
+
concat(semantic_form_for(@new_post) do |builder|
|
480
|
+
concat(builder.commit_button('text', :wrapper_html => {:id => :another_id}))
|
481
|
+
end)
|
482
|
+
end
|
438
483
|
output_buffer.should have_tag("form li#another_id")
|
439
484
|
end
|
440
485
|
|
441
486
|
it 'should append given classes to li default classes' do
|
442
|
-
|
443
|
-
concat(
|
444
|
-
|
487
|
+
with_deprecation_silenced do
|
488
|
+
concat(semantic_form_for(@new_post) do |builder|
|
489
|
+
concat(builder.commit_button('text', :wrapper_html => {:class => :another_class}))
|
490
|
+
end)
|
491
|
+
end
|
445
492
|
output_buffer.should have_tag("form li.commit")
|
446
493
|
output_buffer.should have_tag("form li.another_class")
|
447
494
|
end
|
448
495
|
|
449
496
|
it 'should allow classes to be an array' do
|
450
|
-
|
451
|
-
concat(
|
452
|
-
|
497
|
+
with_deprecation_silenced do
|
498
|
+
concat(semantic_form_for(@new_post) do |builder|
|
499
|
+
concat(builder.commit_button('text', :wrapper_html => {:class => [ :my_class, :another_class ]}))
|
500
|
+
end)
|
501
|
+
end
|
453
502
|
output_buffer.should have_tag("form li.commit")
|
454
503
|
output_buffer.should have_tag("form li.my_class")
|
455
504
|
output_buffer.should have_tag("form li.another_class")
|
@@ -457,14 +506,25 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
457
506
|
end
|
458
507
|
|
459
508
|
describe 'when not provided' do
|
460
|
-
it 'should use default
|
461
|
-
|
462
|
-
concat(
|
463
|
-
|
509
|
+
it 'should use default class' do
|
510
|
+
with_deprecation_silenced do
|
511
|
+
concat(semantic_form_for(@new_post) do |builder|
|
512
|
+
concat(builder.commit_button('text'))
|
513
|
+
end)
|
514
|
+
end
|
464
515
|
output_buffer.should have_tag("form li.commit.button")
|
465
516
|
end
|
517
|
+
|
518
|
+
it 'should use default id' do
|
519
|
+
with_deprecation_silenced do
|
520
|
+
concat(semantic_form_for(@new_post) do |builder|
|
521
|
+
concat(builder.commit_button('text'))
|
522
|
+
end)
|
523
|
+
end
|
524
|
+
output_buffer.should have_tag("form li.commit.button input#post_submit")
|
525
|
+
end
|
466
526
|
end
|
467
527
|
|
468
528
|
end
|
469
|
-
|
529
|
+
|
470
530
|
end
|