speedo-formstrap 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +67 -65
- data/README.md +12 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/formtastic-bootstrap.rb +1 -0
- data/lib/formtastic-bootstrap/actions.rb +4 -0
- data/lib/formtastic-bootstrap/actions/base.rb +18 -0
- data/lib/formtastic-bootstrap/actions/button_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/input_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/link_action.rb +7 -0
- data/lib/formtastic-bootstrap/form_builder.rb +7 -5
- data/lib/formtastic-bootstrap/helpers.rb +3 -1
- data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/actions_helper.rb +23 -0
- data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +13 -9
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +11 -6
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +4 -4
- data/lib/formtastic-bootstrap/inputs/base.rb +2 -1
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +12 -23
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +16 -6
- data/lib/formtastic-bootstrap/inputs/base/numeric.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +5 -12
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +32 -14
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +7 -11
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +10 -9
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +5 -3
- data/lib/formtastic-bootstrap/inputs/number_input.rb +2 -2
- data/lib/formtastic-bootstrap/inputs/radio_input.rb +13 -12
- data/lib/formtastic-bootstrap/inputs/range_input.rb +2 -2
- data/spec/actions/button_action_spec.rb +68 -0
- data/spec/actions/generic_action_spec.rb +486 -0
- data/spec/actions/input_action_spec.rb +64 -0
- data/spec/actions/link_action_spec.rb +93 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -14
- 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 +55 -45
- data/spec/helpers/input_helper_spec.rb +188 -188
- data/spec/helpers/inputs_helper_spec.rb +116 -102
- data/spec/inputs/boolean_input_spec.rb +72 -44
- data/spec/inputs/check_boxes_input_spec.rb +108 -80
- data/spec/inputs/date_input_spec.rb +80 -14
- data/spec/inputs/datetime_input_spec.rb +12 -12
- data/spec/inputs/email_input_spec.rb +33 -5
- data/spec/inputs/file_input_spec.rb +33 -5
- data/spec/inputs/hidden_input_spec.rb +40 -12
- data/spec/inputs/number_input_spec.rb +126 -96
- data/spec/inputs/password_input_spec.rb +33 -5
- data/spec/inputs/phone_input_spec.rb +33 -5
- data/spec/inputs/radio_input_spec.rb +72 -44
- data/spec/inputs/range_input_spec.rb +93 -65
- data/spec/inputs/search_input_spec.rb +32 -5
- data/spec/inputs/select_input_spec.rb +123 -77
- data/spec/inputs/string_input_spec.rb +66 -21
- data/spec/inputs/text_input_spec.rb +40 -13
- data/spec/inputs/time_input_spec.rb +22 -22
- data/spec/inputs/time_zone_input_spec.rb +17 -17
- data/spec/inputs/url_input_spec.rb +33 -5
- data/spec/support/custom_macros.rb +59 -188
- data/spec/support/formtastic_spec_helper.rb +19 -3
- data/speedo-formstrap.gemspec +146 -0
- metadata +31 -16
@@ -2,7 +2,7 @@ module FormtasticBootstrap
|
|
2
2
|
module Inputs
|
3
3
|
class RangeInput < Formtastic::Inputs::RangeInput
|
4
4
|
include Base
|
5
|
-
include Base::
|
5
|
+
include Base::Numeric
|
6
6
|
|
7
7
|
def to_html
|
8
8
|
generic_input_wrapping do
|
@@ -12,4 +12,4 @@ module FormtasticBootstrap
|
|
12
12
|
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'ButtonAction', 'when submitting' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
|
+
|
13
|
+
concat(semantic_form_for(@new_post) do |builder|
|
14
|
+
concat(builder.action(:submit, :as => :button))
|
15
|
+
end)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should render a submit type of button' do
|
19
|
+
output_buffer.should have_tag('button[@type="submit"].action.button_action.btn.btn-primary')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'ButtonAction', 'when resetting' do
|
25
|
+
|
26
|
+
include FormtasticSpecHelper
|
27
|
+
|
28
|
+
before do
|
29
|
+
@output_buffer = ''
|
30
|
+
mock_everything
|
31
|
+
|
32
|
+
concat(semantic_form_for(@new_post) do |builder|
|
33
|
+
concat(builder.action(:reset, :as => :button))
|
34
|
+
end)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should render a reset type of button' do
|
38
|
+
output_buffer.should have_tag('button[@type="reset"].action.button_action.btn', :text => "Reset Post")
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should not be primary' do
|
42
|
+
output_buffer.should_not have_tag('button[@type="reset"].action.button_action.btn.btn-primary', :text => "Reset Post")
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should not render a value attribute' do
|
46
|
+
output_buffer.should_not have_tag('button[@value].action.button_action')
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'InputAction', 'when cancelling' do
|
52
|
+
|
53
|
+
include FormtasticSpecHelper
|
54
|
+
|
55
|
+
before do
|
56
|
+
@output_buffer = ''
|
57
|
+
mock_everything
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should raise an error' do
|
61
|
+
lambda {
|
62
|
+
concat(semantic_form_for(@new_post) do |builder|
|
63
|
+
concat(builder.action(:cancel, :as => :button))
|
64
|
+
end)
|
65
|
+
}.should raise_error(Formtastic::UnsupportedMethodForAction)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,486 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'InputAction::Base' do
|
5
|
+
|
6
|
+
# Most basic Action class to test Base
|
7
|
+
class ::GenericAction
|
8
|
+
include ::Formtastic::Actions::Base
|
9
|
+
|
10
|
+
def supported_methods
|
11
|
+
[:submit, :reset, :cancel]
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_html
|
15
|
+
wrapper do
|
16
|
+
builder.submit(text, button_html)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
include FormtasticSpecHelper
|
22
|
+
|
23
|
+
before do
|
24
|
+
@output_buffer = ''
|
25
|
+
mock_everything
|
26
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'wrapping HTML' do
|
30
|
+
|
31
|
+
before do
|
32
|
+
concat(semantic_form_for(@new_post) do |builder|
|
33
|
+
concat(builder.action(:submit, :as => :generic,
|
34
|
+
:wrapper_html => { :foo => 'bah' }
|
35
|
+
))
|
36
|
+
end)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should add the #foo id to the li' do
|
40
|
+
output_buffer.should have_tag('li#post_submit_action')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should add the .action and .generic_action classes to the li' do
|
44
|
+
output_buffer.should have_tag('li.action.generic_action')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should pass :wrapper_html HTML attributes to the wrapper' do
|
48
|
+
output_buffer.should have_tag('li.action.generic_action[@foo="bah"]')
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when a custom :id is provided" do
|
52
|
+
|
53
|
+
before do
|
54
|
+
concat(semantic_form_for(@new_post) do |builder|
|
55
|
+
concat(builder.action(:submit, :as => :generic,
|
56
|
+
:wrapper_html => { :id => 'foo_bah_bing' }
|
57
|
+
))
|
58
|
+
end)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should use the custom id" do
|
62
|
+
output_buffer.should have_tag('li#foo_bah_bing')
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when a custom class is provided as a string" do
|
68
|
+
|
69
|
+
before do
|
70
|
+
concat(semantic_form_for(@new_post) do |builder|
|
71
|
+
concat(builder.action(:submit, :as => :generic,
|
72
|
+
:wrapper_html => { :class => 'foo_bah_bing' }
|
73
|
+
))
|
74
|
+
end)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should add the custom class strng to the existing classes" do
|
78
|
+
output_buffer.should have_tag('li.action.generic_action.foo_bah_bing')
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when a custom class is provided as an array" do
|
84
|
+
|
85
|
+
before do
|
86
|
+
concat(semantic_form_for(@new_post) do |builder|
|
87
|
+
concat(builder.action(:submit, :as => :generic,
|
88
|
+
:wrapper_html => { :class => ['foo_bah_bing', 'zing_boo'] }
|
89
|
+
))
|
90
|
+
end)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should add the custom class strng to the existing classes" do
|
94
|
+
output_buffer.should have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'button HTML' do
|
102
|
+
|
103
|
+
before do
|
104
|
+
concat(semantic_form_for(@new_post) do |builder|
|
105
|
+
concat(builder.action(:submit, :as => :generic,
|
106
|
+
:button_html => { :foo => 'bah' }
|
107
|
+
))
|
108
|
+
end)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should pass :button_html HTML attributes to the button' do
|
112
|
+
output_buffer.should have_tag('li.action.generic_action input[@foo="bah"]')
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should respect a default_commit_button_accesskey configuration with nil' do
|
116
|
+
with_config :default_commit_button_accesskey, nil do
|
117
|
+
concat(semantic_form_for(@new_post) do |builder|
|
118
|
+
concat(builder.action(:submit, :as => :generic))
|
119
|
+
end)
|
120
|
+
output_buffer.should_not have_tag('li.action input[@accesskey]')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should respect a default_commit_button_accesskey configuration with a String' do
|
125
|
+
with_config :default_commit_button_accesskey, 's' do
|
126
|
+
concat(semantic_form_for(@new_post) do |builder|
|
127
|
+
concat(builder.action(:submit, :as => :generic))
|
128
|
+
end)
|
129
|
+
output_buffer.should have_tag('li.action input[@accesskey="s"]')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should respect an accesskey through options over configration' do
|
134
|
+
with_config :default_commit_button_accesskey, 's' do
|
135
|
+
concat(semantic_form_for(@new_post) do |builder|
|
136
|
+
concat(builder.action(:submit, :as => :generic, :accesskey => 'o'))
|
137
|
+
end)
|
138
|
+
output_buffer.should_not have_tag('li.action input[@accesskey="s"]')
|
139
|
+
output_buffer.should have_tag('li.action input[@accesskey="o"]')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe 'labelling' do
|
146
|
+
|
147
|
+
describe 'when used without object' do
|
148
|
+
|
149
|
+
describe 'when explicit label is provided' do
|
150
|
+
it 'should render an input with the explicitly specified label' do
|
151
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
152
|
+
concat(builder.action(:submit, :as => :generic, :label => "Click!"))
|
153
|
+
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
154
|
+
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
155
|
+
end)
|
156
|
+
output_buffer.should have_tag('li.generic_action input[@value="Click!"]')
|
157
|
+
output_buffer.should have_tag('li.generic_action input[@value="Reset!"]')
|
158
|
+
output_buffer.should have_tag('li.generic_action input[@value="Cancel!"]')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe 'when no explicit label is provided' do
|
163
|
+
describe 'when no I18n-localized label is provided' do
|
164
|
+
before do
|
165
|
+
::I18n.backend.store_translations :en, :formtastic => {
|
166
|
+
:submit => 'Submit %{model}',
|
167
|
+
:reset => 'Reset %{model}',
|
168
|
+
:cancel => 'Cancel %{model}'
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
after do
|
173
|
+
::I18n.backend.reload!
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should render an input with default I18n-localized label (fallback)' do
|
177
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
178
|
+
concat(builder.action(:submit, :as => :generic))
|
179
|
+
concat(builder.action(:reset, :as => :generic))
|
180
|
+
concat(builder.action(:cancel, :as => :generic))
|
181
|
+
end)
|
182
|
+
output_buffer.should have_tag('li.generic_action input[@value="Submit Post"]')
|
183
|
+
output_buffer.should have_tag('li.generic_action input[@value="Cancel Post"]')
|
184
|
+
output_buffer.should have_tag('li.generic_action input[@value="Reset Post"]')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'when I18n-localized label is provided' do
|
189
|
+
|
190
|
+
before do
|
191
|
+
::I18n.backend.store_translations :en,
|
192
|
+
:formtastic => {
|
193
|
+
:actions => {
|
194
|
+
:submit => 'Custom Submit',
|
195
|
+
:reset => 'Custom Reset',
|
196
|
+
:cancel => 'Custom Cancel'
|
197
|
+
}
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
after do
|
202
|
+
::I18n.backend.reload!
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should render an input with localized label (I18n)' do
|
206
|
+
with_config :i18n_lookups_by_default, true do
|
207
|
+
::I18n.backend.store_translations :en,
|
208
|
+
:formtastic => {
|
209
|
+
:actions => {
|
210
|
+
:post => {
|
211
|
+
:submit => 'Custom Submit %{model}',
|
212
|
+
:reset => 'Custom Reset %{model}',
|
213
|
+
:cancel => 'Custom Cancel %{model}'
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
219
|
+
concat(builder.action(:submit, :as => :generic))
|
220
|
+
concat(builder.action(:reset, :as => :generic))
|
221
|
+
concat(builder.action(:cancel, :as => :generic))
|
222
|
+
end)
|
223
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Submit Post"]})
|
224
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
225
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
230
|
+
with_config :i18n_lookups_by_default, true do
|
231
|
+
concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
232
|
+
concat(builder.action(:submit, :as => :generic))
|
233
|
+
concat(builder.action(:reset, :as => :generic))
|
234
|
+
concat(builder.action(:cancel, :as => :generic))
|
235
|
+
end)
|
236
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Submit"]})
|
237
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
238
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe 'when used on a new record' do
|
247
|
+
before do
|
248
|
+
@new_post.stub!(:new_record?).and_return(true)
|
249
|
+
end
|
250
|
+
|
251
|
+
describe 'when explicit label is provided' do
|
252
|
+
it 'should render an input with the explicitly specified label' do
|
253
|
+
concat(semantic_form_for(@new_post) do |builder|
|
254
|
+
concat(builder.action(:submit, :as => :generic, :label => "Click!"))
|
255
|
+
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
256
|
+
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
257
|
+
end)
|
258
|
+
output_buffer.should have_tag('li.generic_action input[@value="Click!"]')
|
259
|
+
output_buffer.should have_tag('li.generic_action input[@value="Reset!"]')
|
260
|
+
output_buffer.should have_tag('li.generic_action input[@value="Cancel!"]')
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'when no explicit label is provided' do
|
265
|
+
describe 'when no I18n-localized label is provided' do
|
266
|
+
before do
|
267
|
+
::I18n.backend.store_translations :en, :formtastic => {
|
268
|
+
:create => 'Create %{model}',
|
269
|
+
:reset => 'Reset %{model}',
|
270
|
+
:cancel => 'Cancel %{model}'
|
271
|
+
}
|
272
|
+
end
|
273
|
+
|
274
|
+
after do
|
275
|
+
::I18n.backend.reload!
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'should render an input with default I18n-localized label (fallback)' do
|
279
|
+
concat(semantic_form_for(@new_post) do |builder|
|
280
|
+
concat(builder.action(:submit, :as => :generic))
|
281
|
+
concat(builder.action(:reset, :as => :generic))
|
282
|
+
concat(builder.action(:cancel, :as => :generic))
|
283
|
+
end)
|
284
|
+
output_buffer.should have_tag('li.generic_action input[@value="Create Post"]')
|
285
|
+
output_buffer.should have_tag('li.generic_action input[@value="Reset Post"]')
|
286
|
+
output_buffer.should have_tag('li.generic_action input[@value="Cancel Post"]')
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe 'when I18n-localized label is provided' do
|
291
|
+
before do
|
292
|
+
::I18n.backend.store_translations :en,
|
293
|
+
:formtastic => {
|
294
|
+
:actions => {
|
295
|
+
:create => 'Custom Create',
|
296
|
+
:reset => 'Custom Reset',
|
297
|
+
:cancel => 'Custom Cancel'
|
298
|
+
}
|
299
|
+
}
|
300
|
+
end
|
301
|
+
|
302
|
+
after do
|
303
|
+
::I18n.backend.reload!
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'should render an input with localized label (I18n)' do
|
307
|
+
with_config :i18n_lookups_by_default, true do
|
308
|
+
::I18n.backend.store_translations :en,
|
309
|
+
:formtastic => {
|
310
|
+
:actions => {
|
311
|
+
:post => {
|
312
|
+
:create => 'Custom Create %{model}',
|
313
|
+
:reset => 'Custom Reset %{model}',
|
314
|
+
:cancel => 'Custom Cancel %{model}'
|
315
|
+
}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
concat(semantic_form_for(@new_post) do |builder|
|
319
|
+
concat(builder.action(:submit, :as => :generic))
|
320
|
+
concat(builder.action(:reset, :as => :generic))
|
321
|
+
concat(builder.action(:cancel, :as => :generic))
|
322
|
+
end)
|
323
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Create Post"]})
|
324
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
325
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
330
|
+
with_config :i18n_lookups_by_default, true do
|
331
|
+
concat(semantic_form_for(@new_post) do |builder|
|
332
|
+
concat(builder.action(:submit, :as => :generic))
|
333
|
+
concat(builder.action(:reset, :as => :generic))
|
334
|
+
concat(builder.action(:cancel, :as => :generic))
|
335
|
+
end)
|
336
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Create"]})
|
337
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
338
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
describe 'when used on an existing record' do
|
347
|
+
before do
|
348
|
+
@new_post.stub!(:persisted?).and_return(true)
|
349
|
+
end
|
350
|
+
|
351
|
+
describe 'when explicit label is provided' do
|
352
|
+
it 'should render an input with the explicitly specified label' do
|
353
|
+
concat(semantic_form_for(@new_post) do |builder|
|
354
|
+
concat(builder.action(:submit, :as => :generic, :label => "Click!"))
|
355
|
+
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
356
|
+
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
357
|
+
end)
|
358
|
+
output_buffer.should have_tag('li.generic_action input[@value="Click!"]')
|
359
|
+
output_buffer.should have_tag('li.generic_action input[@value="Reset!"]')
|
360
|
+
output_buffer.should have_tag('li.generic_action input[@value="Cancel!"]')
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
describe 'when no explicit label is provided' do
|
365
|
+
describe 'when no I18n-localized label is provided' do
|
366
|
+
before do
|
367
|
+
::I18n.backend.store_translations :en, :formtastic => {
|
368
|
+
:update => 'Save %{model}',
|
369
|
+
:reset => 'Reset %{model}',
|
370
|
+
:cancel => 'Cancel %{model}'
|
371
|
+
}
|
372
|
+
end
|
373
|
+
|
374
|
+
after do
|
375
|
+
::I18n.backend.reload!
|
376
|
+
end
|
377
|
+
|
378
|
+
it 'should render an input with default I18n-localized label (fallback)' do
|
379
|
+
concat(semantic_form_for(@new_post) do |builder|
|
380
|
+
concat(builder.action(:submit, :as => :generic))
|
381
|
+
concat(builder.action(:reset, :as => :generic))
|
382
|
+
concat(builder.action(:cancel, :as => :generic))
|
383
|
+
end)
|
384
|
+
output_buffer.should have_tag('li.generic_action input[@value="Save Post"]')
|
385
|
+
output_buffer.should have_tag('li.generic_action input[@value="Reset Post"]')
|
386
|
+
output_buffer.should have_tag('li.generic_action input[@value="Cancel Post"]')
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe 'when I18n-localized label is provided' do
|
391
|
+
before do
|
392
|
+
::I18n.backend.reload!
|
393
|
+
::I18n.backend.store_translations :en,
|
394
|
+
:formtastic => {
|
395
|
+
:actions => {
|
396
|
+
:update => 'Custom Save',
|
397
|
+
:reset => 'Custom Reset',
|
398
|
+
:cancel => 'Custom Cancel'
|
399
|
+
}
|
400
|
+
}
|
401
|
+
end
|
402
|
+
|
403
|
+
after do
|
404
|
+
::I18n.backend.reload!
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should render an input with localized label (I18n)' do
|
408
|
+
with_config :i18n_lookups_by_default, true do
|
409
|
+
::I18n.backend.store_translations :en,
|
410
|
+
:formtastic => {
|
411
|
+
:actions => {
|
412
|
+
:post => {
|
413
|
+
:update => 'Custom Save %{model}',
|
414
|
+
:reset => 'Custom Reset %{model}',
|
415
|
+
:cancel => 'Custom Cancel %{model}'
|
416
|
+
}
|
417
|
+
}
|
418
|
+
}
|
419
|
+
concat(semantic_form_for(@new_post) do |builder|
|
420
|
+
concat(builder.action(:submit, :as => :generic))
|
421
|
+
concat(builder.action(:reset, :as => :generic))
|
422
|
+
concat(builder.action(:cancel, :as => :generic))
|
423
|
+
end)
|
424
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Save Post"]})
|
425
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
426
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
431
|
+
with_config :i18n_lookups_by_default, true do
|
432
|
+
concat(semantic_form_for(@new_post) do |builder|
|
433
|
+
concat(builder.action(:submit, :as => :generic))
|
434
|
+
concat(builder.action(:reset, :as => :generic))
|
435
|
+
concat(builder.action(:cancel, :as => :generic))
|
436
|
+
end)
|
437
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Save"]})
|
438
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
439
|
+
output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
440
|
+
::I18n.backend.store_translations :en, :formtastic => {}
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
describe 'when the model is two words' do
|
450
|
+
|
451
|
+
before do
|
452
|
+
output_buffer = ''
|
453
|
+
class ::UserPost
|
454
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
455
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
456
|
+
|
457
|
+
def id
|
458
|
+
end
|
459
|
+
|
460
|
+
def persisted?
|
461
|
+
end
|
462
|
+
|
463
|
+
# Rails does crappy human_name
|
464
|
+
def self.human_name
|
465
|
+
"User post"
|
466
|
+
end
|
467
|
+
end
|
468
|
+
@new_user_post = ::UserPost.new
|
469
|
+
|
470
|
+
@new_user_post.stub!(:new_record?).and_return(true)
|
471
|
+
concat(semantic_form_for(@new_user_post, :url => '') do |builder|
|
472
|
+
concat(builder.action(:submit, :as => :generic))
|
473
|
+
concat(builder.action(:reset, :as => :generic))
|
474
|
+
concat(builder.action(:cancel, :as => :generic))
|
475
|
+
end)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "should render the string as the value of the button" do
|
479
|
+
output_buffer.should have_tag('li input[@value="Create User post"]')
|
480
|
+
output_buffer.should have_tag('li input[@value="Reset User post"]')
|
481
|
+
output_buffer.should have_tag('li input[@value="Cancel User post"]')
|
482
|
+
end
|
483
|
+
|
484
|
+
end
|
485
|
+
|
486
|
+
end
|