merb-helpers 1.0.8.1 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/merb-helpers/form/builder.rb +11 -1
- data/spec/fixture/app/views/bound_check_box_specs/basic_unchecked.html.erb +3 -0
- data/spec/fixture/app/views/bound_select_specs/label.html.erb +3 -0
- data/spec/fixture/app/views/bound_text_area_specs/label.html.erb +3 -0
- data/spec/fixture/app/views/check_box_specs/label.html.erb +1 -1
- data/spec/fixture/app/views/file_field_specs/with_label.html.erb +1 -1
- data/spec/fixture/app/views/radio_button_specs/checked.html.erb +1 -0
- data/spec/fixture/app/views/radio_button_specs/unchecked.html.erb +1 -0
- data/spec/fixture/app/views/radio_group_specs/checked.html.erb +1 -0
- data/spec/fixture/app/views/select_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/select_specs/selected.html.erb +1 -0
- data/spec/fixture/app/views/text_field_specs/symbolized_name.html.erb +1 -0
- data/spec/merb_helpers_form_spec.rb +127 -39
- metadata +12 -3
@@ -171,6 +171,8 @@ module Merb::Helpers::Form::Builder
|
|
171
171
|
case type
|
172
172
|
when "checkbox"
|
173
173
|
update_unbound_check_box(attrs)
|
174
|
+
when "radio"
|
175
|
+
update_unbound_radio_button(attrs)
|
174
176
|
when "file"
|
175
177
|
@multipart = true
|
176
178
|
end
|
@@ -197,6 +199,10 @@ module Merb::Helpers::Form::Builder
|
|
197
199
|
attrs[:checked] = "checked" if attrs.delete(:checked)
|
198
200
|
end
|
199
201
|
|
202
|
+
def update_unbound_radio_button(attrs)
|
203
|
+
attrs[:checked] = "checked" if attrs.delete(:checked)
|
204
|
+
end
|
205
|
+
|
200
206
|
# Accepts a collection (hash, array, enumerable, your type) and returns a string of option tags.
|
201
207
|
# Given a collection where the elements respond to first and last (such as a two-element array),
|
202
208
|
# the "lasts" serve as option values and the "firsts" as option text. Hashes are turned into
|
@@ -268,7 +274,7 @@ module Merb::Helpers::Form::Builder
|
|
268
274
|
end
|
269
275
|
|
270
276
|
def considered_true?(value)
|
271
|
-
value && value != "0" && value != 0
|
277
|
+
value && value != "false" && value != "0" && value != 0
|
272
278
|
end
|
273
279
|
|
274
280
|
def control_name(method)
|
@@ -315,6 +321,8 @@ module Merb::Helpers::Form::Builder
|
|
315
321
|
def unbound_label(attrs = {})
|
316
322
|
if attrs[:id]
|
317
323
|
label_attrs = {:for => attrs[:id]}
|
324
|
+
elsif attrs[:name]
|
325
|
+
label_attrs = {:for => attrs[:name]}
|
318
326
|
else
|
319
327
|
label_attrs = {}
|
320
328
|
end
|
@@ -366,6 +374,8 @@ module Merb::Helpers::Form::Builder
|
|
366
374
|
end
|
367
375
|
|
368
376
|
def update_unbound_controls(attrs, type)
|
377
|
+
attrs.merge!(:id => attrs[:name]) if attrs[:name] && !attrs[:id]
|
378
|
+
|
369
379
|
case type
|
370
380
|
when "text", "radio", "password", "hidden", "checkbox", "file"
|
371
381
|
add_css_class(attrs, type)
|
@@ -1 +1 @@
|
|
1
|
-
<%= check_box(:label => "LABEL" ) %>
|
1
|
+
<%= check_box(:name => "foo", :label => "LABEL" ) %>
|
@@ -1 +1 @@
|
|
1
|
-
<%= file_field :label => 'LABEL' %>
|
1
|
+
<%= file_field(:name => "foo", :label => 'LABEL') %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= radio_button(:name => "foo", :value => "bar", :checked => true) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= radio_button(:name => "foo", :value => "bar", :checked => false) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= radio_group([{:value => 5, :label => "Five"}, {:value => 'bar', :label => 'Bar', :checked => true}]) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= select(:name => "foo", :collection => %w(one two three)) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= select(:name => "foo", :collection => %w(one two three), :selected => "three") %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= text_field(:name => :foo, :value => "bar", :style => "width: 100px", :label => "LABEL") %>
|
@@ -236,14 +236,9 @@ describe "text_field" do
|
|
236
236
|
|
237
237
|
it "should return a basic text field based on the values passed in" do
|
238
238
|
r = @c.render :basic
|
239
|
-
r.should have_selector("input[type=text][name=foo][value=bar]")
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should provide an additional label tag if the :label option is passed in" do
|
243
|
-
r = @c.render :basic
|
244
|
-
r.should match(/<label>LABEL<\/label>/)
|
239
|
+
r.should have_selector("input[type=text][id=foo][name=foo][value=bar]")
|
245
240
|
end
|
246
|
-
|
241
|
+
|
247
242
|
it "should update an existing :class with a new class" do
|
248
243
|
r = @c.render :class
|
249
244
|
r.should == "<input type=\"text\" class=\"awesome foobar text\"/>"
|
@@ -256,9 +251,14 @@ describe "text_field" do
|
|
256
251
|
|
257
252
|
it "should provide an additional label tag if the :label option is passed in as a hash" do
|
258
253
|
r = @c.render :label
|
259
|
-
r.should
|
254
|
+
r.should have_selector("label[class=cool][for=foo]:contains('LABEL')")
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should allow a symbolized name" do
|
258
|
+
r = @c.render :symbolized_name
|
259
|
+
r.should have_selector("input[type=text][name=foo][value=bar]")
|
260
|
+
r.should have_selector("label[for=foo]:contains('LABEL')")
|
260
261
|
end
|
261
|
-
|
262
262
|
end
|
263
263
|
|
264
264
|
describe "bound_text_field" do
|
@@ -270,7 +270,7 @@ describe "bound_text_field" do
|
|
270
270
|
|
271
271
|
it "should take a string object and return a useful text control" do
|
272
272
|
r = @c.render :basic
|
273
|
-
r.should have_selector("input[type=text][name='fake_model[foo]'][value=foowee]")
|
273
|
+
r.should have_selector("input[type=text][id=fake_model_foo][name='fake_model[foo]'][value=foowee]")
|
274
274
|
end
|
275
275
|
|
276
276
|
it "should take additional attributes and use them" do
|
@@ -283,6 +283,11 @@ describe "bound_text_field" do
|
|
283
283
|
form.should match(/<label.*>LABEL<\/label><input/)
|
284
284
|
form.should_not have_selector("input[label=LABEL]")
|
285
285
|
end
|
286
|
+
|
287
|
+
it "should render the label tag with the proper for= atttribute" do
|
288
|
+
form = @c.render :basic
|
289
|
+
form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
|
290
|
+
end
|
286
291
|
|
287
292
|
it "should not errorify the field for a new object" do
|
288
293
|
r = @c.render :basic
|
@@ -313,7 +318,7 @@ describe "bound_radio_button" do
|
|
313
318
|
|
314
319
|
it "should take a string object and return a useful text control" do
|
315
320
|
r = @c.render :basic
|
316
|
-
r.should have_selector("input[type=radio][name='fake_model[foo]'][value=foowee]")
|
321
|
+
r.should have_selector("input[type=radio][id=fake_model_foo][name='fake_model[foo]'][value=foowee]")
|
317
322
|
end
|
318
323
|
|
319
324
|
it "should take additional attributes and use them" do
|
@@ -326,6 +331,11 @@ describe "bound_radio_button" do
|
|
326
331
|
form.should have_selector("input + label:contains('LABEL')")
|
327
332
|
form.should_not have_selector("input[label]")
|
328
333
|
end
|
334
|
+
|
335
|
+
it "should render the label tag with the proper for= atttribute" do
|
336
|
+
form = @c.render :basic
|
337
|
+
form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
|
338
|
+
end
|
329
339
|
|
330
340
|
it "should not errorify the field for a new object" do
|
331
341
|
r = @c.render :basic
|
@@ -355,12 +365,12 @@ describe "password_field" do
|
|
355
365
|
|
356
366
|
it "should return a basic password field, but omit the value" do
|
357
367
|
r = @c.render :basic
|
358
|
-
r.should have_selector("input[type=password][name=foo]")
|
368
|
+
r.should have_selector("input[type=password][id=foo][name=foo]")
|
359
369
|
end
|
360
370
|
|
361
371
|
it "should provide an additional label tag if the :label option is passed in" do
|
362
372
|
r = @c.render :basic
|
363
|
-
r.should have_selector("label:contains('LABEL')")
|
373
|
+
r.should have_selector("label[for=foo]:contains('LABEL')")
|
364
374
|
end
|
365
375
|
|
366
376
|
it "should be disabled if :disabled => true is passed in" do
|
@@ -379,7 +389,7 @@ describe "bound_password_field" do
|
|
379
389
|
|
380
390
|
it "should take a string object and return a useful password control, but omit the value" do
|
381
391
|
r = @c.render :basic
|
382
|
-
r.should match_tag(:input, :type => "password", :name => "fake_model[foo]")
|
392
|
+
r.should match_tag(:input, :type => "password", :id => "fake_model_foo", :name => "fake_model[foo]")
|
383
393
|
end
|
384
394
|
|
385
395
|
it "should take additional attributes and use them" do
|
@@ -392,6 +402,11 @@ describe "bound_password_field" do
|
|
392
402
|
r.should match(/<label.*>LABEL<\/label><input/)
|
393
403
|
r.should_not match_tag(:input, :label => "LABEL")
|
394
404
|
end
|
405
|
+
|
406
|
+
it "should render the label tag with the proper for= atttribute" do
|
407
|
+
form = @c.render :basic
|
408
|
+
form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
|
409
|
+
end
|
395
410
|
|
396
411
|
it "should not errorify the field for a new object" do
|
397
412
|
r = @c.render :basic
|
@@ -423,12 +438,14 @@ describe "check_box" do
|
|
423
438
|
|
424
439
|
it "should return a basic checkbox based on the values passed in" do
|
425
440
|
r = @c.render :basic
|
426
|
-
r.should match_tag(:input, :class => "checkbox", :name => "foo", :checked => "checked")
|
441
|
+
r.should match_tag(:input, :class => "checkbox", :id => "foo", :name => "foo", :checked => "checked")
|
427
442
|
end
|
428
443
|
|
429
444
|
it "should provide an additional label tag if the :label option is passed in" do
|
430
445
|
result = @c.render :label
|
431
|
-
result.should
|
446
|
+
result.should have_selector("label[for=foo]:contains('LABEL')")
|
447
|
+
|
448
|
+
result.should match(/<input.*><label/)
|
432
449
|
res = result.scan(/<[^>]*>/)
|
433
450
|
res[0].should_not match_tag(:input, :label => "LABEL")
|
434
451
|
end
|
@@ -508,8 +525,8 @@ describe "bound_check_box" do
|
|
508
525
|
|
509
526
|
it "should take a string and return a useful checkbox control" do
|
510
527
|
r = @c.render :basic
|
511
|
-
r.should match_tag(:input, :type =>"checkbox", :name => "fake_model[baz]", :class => "checkbox", :value => "1", :checked => "checked", :id => "fake_model_baz")
|
512
|
-
r.should match_tag(:input, :type =>"hidden",
|
528
|
+
r.should match_tag(:input, :type =>"checkbox", :id => "fake_model_baz", :name => "fake_model[baz]", :class => "checkbox", :value => "1", :checked => "checked", :id => "fake_model_baz")
|
529
|
+
r.should match_tag(:input, :type =>"hidden", :name => "fake_model[baz]", :value => "0")
|
513
530
|
end
|
514
531
|
|
515
532
|
it "should raise an error if you try to use :value" do
|
@@ -548,6 +565,11 @@ describe "bound_check_box" do
|
|
548
565
|
form.should match( /<input.*><label.*>LABEL<\/label>/ )
|
549
566
|
form.should_not match_tag(:input, :label => "LABEL")
|
550
567
|
end
|
568
|
+
|
569
|
+
it "should render the label tag with the proper for= atttribute" do
|
570
|
+
form = @c.render :label
|
571
|
+
form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
|
572
|
+
end
|
551
573
|
|
552
574
|
it "should not errorify the field for a new object" do
|
553
575
|
r = @c.render :basic
|
@@ -581,7 +603,13 @@ describe "bound_check_box" do
|
|
581
603
|
r = @c.render :checked
|
582
604
|
r.should match_tag(:input, :type =>"checkbox", :value => "foowee", :checked => "checked")
|
583
605
|
r.should match_tag(:input, :type =>"checkbox", :value => "YES")
|
606
|
+
end
|
584
607
|
|
608
|
+
it "should render false attributes as not checked" do
|
609
|
+
@c.instance_variable_set(:@obj, FakeDMModel.new)
|
610
|
+
r = @c.render :basic_unchecked
|
611
|
+
r.should match_tag(:input, :type =>"checkbox", :name => "fake_dm_model[bat]")
|
612
|
+
r.should_not include("checked=")
|
585
613
|
end
|
586
614
|
end
|
587
615
|
|
@@ -593,7 +621,7 @@ describe "hidden_field" do
|
|
593
621
|
|
594
622
|
it "should return a basic checkbox based on the values passed in" do
|
595
623
|
r = @c.render :basic
|
596
|
-
r.should match_tag(:input, :type => "hidden", :name => "foo", :value => "bar")
|
624
|
+
r.should match_tag(:input, :type => "hidden", :id => "foo", :name => "foo", :value => "bar")
|
597
625
|
end
|
598
626
|
|
599
627
|
it "should not render a label if the :label option is passed in" do
|
@@ -617,7 +645,7 @@ describe "bound_hidden_field" do
|
|
617
645
|
|
618
646
|
it "should take a string and return a hidden field control" do
|
619
647
|
r = @c.render :basic
|
620
|
-
r.should match_tag(:input, :type =>"hidden", :name => "fake_model[foo]", :value => "foowee")
|
648
|
+
r.should match_tag(:input, :type =>"hidden", :id => "fake_model_foo", :name => "fake_model[foo]", :value => "foowee")
|
621
649
|
end
|
622
650
|
|
623
651
|
it "should render controls with errors if their attribute contains an error" do
|
@@ -630,7 +658,7 @@ describe "bound_hidden_field" do
|
|
630
658
|
r.should_not match(/<label>LABEL/)
|
631
659
|
r.should_not match_tag(:input, :label=> "LABEL")
|
632
660
|
end
|
633
|
-
|
661
|
+
|
634
662
|
it "should not errorify the field for a new object" do
|
635
663
|
r = @c.render :basic
|
636
664
|
r.should_not match_tag(:input, :type => "hidden", :class => "error")
|
@@ -666,18 +694,30 @@ describe "radio_button" do
|
|
666
694
|
|
667
695
|
it "should provide an additional label tag if the :label option is passed in" do
|
668
696
|
result = @c.render :label
|
669
|
-
# result.should match(/<label.*>LABEL<\/label><input/)
|
670
|
-
# res = result.scan(/<[^>]*>/)
|
671
|
-
# res[2].should_not match_tag(:input, :label => "LABEL")
|
672
697
|
result.should match(/<input.*><label.*>LABEL<\/label>/)
|
673
698
|
res = result.scan(/<[^>]*>/)
|
674
699
|
res[0].should_not match_tag(:input, :label => "LABEL")
|
675
700
|
end
|
676
701
|
|
702
|
+
it "should render the label tag with the proper for= atttribute" do
|
703
|
+
form = @c.render :label
|
704
|
+
form.should have_selector("label[for='foo']:contains('LABEL')")
|
705
|
+
end
|
706
|
+
|
677
707
|
it "should be disabled if :disabled => true is passed in" do
|
678
708
|
r = @c.render :disabled
|
679
709
|
r.should match_tag(:input, :type => "radio", :disabled => "disabled")
|
680
710
|
end
|
711
|
+
|
712
|
+
it "should be checked if :checked => true is passed in" do
|
713
|
+
r = @c.render :checked
|
714
|
+
r.should match_tag(:input, :type => "radio", :checked => "checked")
|
715
|
+
end
|
716
|
+
|
717
|
+
it "should be unchecked if :checked => false is passed in" do
|
718
|
+
r = @c.render :unchecked
|
719
|
+
r.should_not include("checked=")
|
720
|
+
end
|
681
721
|
end
|
682
722
|
|
683
723
|
describe "radio_group" do
|
@@ -688,9 +728,9 @@ describe "radio_group" do
|
|
688
728
|
|
689
729
|
it "should return a group of radio buttons" do
|
690
730
|
radio = @c.render :basic
|
691
|
-
|
692
|
-
|
693
|
-
|
731
|
+
radio_tags = radio.scan(/<[^>]*>/)
|
732
|
+
radio_tags[0].should match_tag(:input, :type => "radio", :value => "foowee")
|
733
|
+
radio_tags[3].should match_tag(:input, :type => "radio", :value => "baree")
|
694
734
|
end
|
695
735
|
|
696
736
|
it "should provide an additional label tag for each option in array-based options" do
|
@@ -710,7 +750,12 @@ describe "radio_group" do
|
|
710
750
|
radio.should match_tag(:input, :value => 'bar', :id => 'bar_id')
|
711
751
|
radio.should match_tag(:label, :for => 'bar_id')
|
712
752
|
end
|
713
|
-
|
753
|
+
|
754
|
+
it "should render the label tags on each radio button with the proper for= atttribute" do
|
755
|
+
form = @c.render :hash
|
756
|
+
form.should have_selector("label[for='bar_id']:contains('Bar')")
|
757
|
+
end
|
758
|
+
|
714
759
|
it "should apply attributes to each element" do
|
715
760
|
radio = @c.render :attributes
|
716
761
|
radio = radio.scan(/<[^>]*>/)
|
@@ -724,6 +769,11 @@ describe "radio_group" do
|
|
724
769
|
radio[0].should match_tag(:input, :type => "radio", :value => "foowee", :class => "CLASS radio")
|
725
770
|
radio[3].should match_tag(:input, :type => "radio", :value => "baree", :class => "BAREE radio")
|
726
771
|
end
|
772
|
+
|
773
|
+
it "should allow specifying a checked radio button" do
|
774
|
+
r = @c.render :checked
|
775
|
+
r.should match_tag(:input, :value => "bar", :checked => "checked")
|
776
|
+
end
|
727
777
|
end
|
728
778
|
|
729
779
|
|
@@ -736,8 +786,8 @@ describe "bound_radio_group" do
|
|
736
786
|
|
737
787
|
it "should return a group of radio buttons" do
|
738
788
|
r = @c.render :basic
|
739
|
-
r.should match_tag(:input, :type => "radio", :name => "fake_model[foo]", :value => "foowee", :checked => "checked")
|
740
|
-
r.should match_tag(:input, :type => "radio", :name => "fake_model[foo]", :value => "baree")
|
789
|
+
r.should match_tag(:input, :type => "radio", :id => "fake_model_foo_foowee", :name => "fake_model[foo]", :value => "foowee", :checked => "checked")
|
790
|
+
r.should match_tag(:input, :type => "radio", :id => "fake_model_foo_baree", :name => "fake_model[foo]", :value => "baree")
|
741
791
|
r.should_not match_tag(:checked => "checked")
|
742
792
|
end
|
743
793
|
|
@@ -748,6 +798,12 @@ describe "bound_radio_group" do
|
|
748
798
|
radio[0].should_not match_tag(:input, :label => "LABEL")
|
749
799
|
radio[3].should_not match_tag(:input, :label => "LABEL")
|
750
800
|
end
|
801
|
+
|
802
|
+
it "should render the label tags on each radio option with the proper for= atttribute" do
|
803
|
+
form = @c.render :basic
|
804
|
+
form.should have_selector("label[for=fake_model_foo_foowee]:contains('foowee')")
|
805
|
+
form.should have_selector("label[for=fake_model_foo_baree]:contains('baree')")
|
806
|
+
end
|
751
807
|
|
752
808
|
it "should accept array of hashes as options" do
|
753
809
|
r = @c.render :hashes
|
@@ -789,12 +845,12 @@ describe "text_area" do
|
|
789
845
|
|
790
846
|
it "should should return a basic text area based on the values passed in" do
|
791
847
|
r = @c.render :basic
|
792
|
-
r.should match_tag(:textarea, :name => "foo")
|
848
|
+
r.should match_tag(:textarea, :name => "foo", :id => "foo")
|
793
849
|
end
|
794
850
|
|
795
851
|
it "should handle a nil content" do
|
796
852
|
r = @c.render :nil
|
797
|
-
r.should == "<textarea name=\"foo\"></textarea>"
|
853
|
+
r.should == "<textarea name=\"foo\" id=\"foo\"></textarea>"
|
798
854
|
end
|
799
855
|
|
800
856
|
|
@@ -805,10 +861,12 @@ describe "text_area" do
|
|
805
861
|
# text_area("CONTENT", nil).should == "<textarea>CONTENT</textarea>"
|
806
862
|
# end
|
807
863
|
|
808
|
-
it "should render a label when the label is passed in" do
|
864
|
+
it "should render a label when the :label option is passed in" do
|
809
865
|
result = @c.render :label
|
810
866
|
result.should match(/<label.*>LABEL<\/label><textarea/)
|
811
867
|
result.should_not match_tag(:textarea, :label => "LABEL")
|
868
|
+
|
869
|
+
result.should have_selector("label[for=foo]:contains('LABEL')")
|
812
870
|
end
|
813
871
|
|
814
872
|
it "should be disabled if :disabled => true is passed in" do
|
@@ -830,6 +888,11 @@ describe "bound_text_area" do
|
|
830
888
|
r.should match_tag(:textarea, :id => 'fake_model_foo', :name => "fake_model[foo]")
|
831
889
|
r.should =~ />\s*#{@obj.foo}\s*</
|
832
890
|
end
|
891
|
+
|
892
|
+
it "should render the label tag with the proper for= atttribute" do
|
893
|
+
form = @c.render :label
|
894
|
+
form.should have_selector("label[for='fake_model_foo']:contains('LABEL')")
|
895
|
+
end
|
833
896
|
end
|
834
897
|
|
835
898
|
describe "select" do
|
@@ -842,10 +905,30 @@ describe "select" do
|
|
842
905
|
r = @c.render :blank
|
843
906
|
r.should =~ /<option.*>\s*<\/option>/
|
844
907
|
end
|
908
|
+
|
909
|
+
it "should render the select tag proper attributes" do
|
910
|
+
r = @c.render :basic
|
911
|
+
r.should match_tag( :select, :name => "foo", :id => "foo")
|
912
|
+
r.should have_selector("select[name=foo] option:contains('one')")
|
913
|
+
r.should have_selector("select[name=foo] option:contains('two')")
|
914
|
+
r.should have_selector("select[name=foo] option:contains('three')")
|
915
|
+
end
|
916
|
+
|
917
|
+
it "should allow selecting an option by passing in :selected => 'three'" do
|
918
|
+
r = @c.render :selected
|
919
|
+
r.should_not have_selector("select[name=foo] option[selected]:contains('one')")
|
920
|
+
r.should_not have_selector("select[name=foo] option[selected]:contains('two')")
|
921
|
+
r.should have_selector("select[name=foo] option[selected]:contains('three')")
|
922
|
+
end
|
845
923
|
|
846
924
|
it "should render the select tag with suffix '[]' to name when :multiple => true" do
|
847
925
|
r = @c.render :multiple
|
848
|
-
r.should match_tag( :select, :name => "foo[]"
|
926
|
+
r.should match_tag( :select, :name => "foo[]")
|
927
|
+
end
|
928
|
+
|
929
|
+
it "should render a label when the :label option is passed in" do
|
930
|
+
result = @c.render :label
|
931
|
+
result.should have_selector("label[for=foo]:contains('LABEL')")
|
849
932
|
end
|
850
933
|
end
|
851
934
|
|
@@ -890,6 +973,11 @@ describe "bound_select" do
|
|
890
973
|
r.should match_tag( :option, :value => '' )
|
891
974
|
r.should =~ /<option.*>\s*<\/option>/
|
892
975
|
end
|
976
|
+
|
977
|
+
it "should render the label tag with the proper for= atttribute" do
|
978
|
+
form = @c.render :label
|
979
|
+
form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
|
980
|
+
end
|
893
981
|
|
894
982
|
# Not sure how this makes any sense
|
895
983
|
# ---------------------------------
|
@@ -1071,12 +1159,12 @@ describe "file_field" do
|
|
1071
1159
|
|
1072
1160
|
it "should return a basic file field based on the values passed in" do
|
1073
1161
|
r = @c.render :with_values
|
1074
|
-
r.should have_selector("input[type=file][name=foo][value=bar]")
|
1162
|
+
r.should have_selector("input[type=file][id=foo][name=foo][value=bar]")
|
1075
1163
|
end
|
1076
1164
|
|
1077
1165
|
it "should wrap the field in a label if the :label option is passed to the file" do
|
1078
1166
|
r = @c.render :with_label
|
1079
|
-
r.should have_selector("label:contains('LABEL') + input.file[type=file]")
|
1167
|
+
r.should have_selector("label[for=foo]:contains('LABEL') + input.file[type=file]")
|
1080
1168
|
end
|
1081
1169
|
|
1082
1170
|
it "should be disabled if :disabled => true is passed in" do
|
@@ -1099,7 +1187,7 @@ describe "bound_file_field" do
|
|
1099
1187
|
|
1100
1188
|
it "should take a string object and return a useful file control" do
|
1101
1189
|
r = @c.render :takes_string
|
1102
|
-
r.should have_selector("input[type=file][name='fake_model[foo]'][value=foowee]")
|
1190
|
+
r.should have_selector("input[type=file][id=fake_model_foo][name='fake_model[foo]'][value=foowee]")
|
1103
1191
|
end
|
1104
1192
|
|
1105
1193
|
it "should take additional attributes and use them" do
|
@@ -1109,7 +1197,7 @@ describe "bound_file_field" do
|
|
1109
1197
|
|
1110
1198
|
it "should wrap the file_field in a label if the :label option is passed in" do
|
1111
1199
|
r = @c.render :with_label
|
1112
|
-
r.should have_selector("label:contains('LABEL')")
|
1200
|
+
r.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
|
1113
1201
|
r.should_not have_selector("input[label=LABEL]")
|
1114
1202
|
end
|
1115
1203
|
end
|
@@ -1278,4 +1366,4 @@ describe "escaping values" do
|
|
1278
1366
|
r.should =~ /&"<>/
|
1279
1367
|
end
|
1280
1368
|
|
1281
|
-
end
|
1369
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael D. Ivey
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-02-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.0.
|
23
|
+
version: 1.0.9
|
24
24
|
version:
|
25
25
|
description: Helper support for Merb
|
26
26
|
email: ivey@gweezlebur.com
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- spec/fixture/app/views
|
105
105
|
- spec/fixture/app/views/bound_check_box_specs
|
106
106
|
- spec/fixture/app/views/bound_check_box_specs/basic.html.erb
|
107
|
+
- spec/fixture/app/views/bound_check_box_specs/basic_unchecked.html.erb
|
107
108
|
- spec/fixture/app/views/bound_check_box_specs/checked.html.erb
|
108
109
|
- spec/fixture/app/views/bound_check_box_specs/errors.html.erb
|
109
110
|
- spec/fixture/app/views/bound_check_box_specs/label.html.erb
|
@@ -136,12 +137,14 @@ files:
|
|
136
137
|
- spec/fixture/app/views/bound_select_specs
|
137
138
|
- spec/fixture/app/views/bound_select_specs/basic.html.erb
|
138
139
|
- spec/fixture/app/views/bound_select_specs/blank.html.erb
|
140
|
+
- spec/fixture/app/views/bound_select_specs/label.html.erb
|
139
141
|
- spec/fixture/app/views/bound_select_specs/multiple.html.erb
|
140
142
|
- spec/fixture/app/views/bound_select_specs/prompt.html.erb
|
141
143
|
- spec/fixture/app/views/bound_select_specs/with_options.html.erb
|
142
144
|
- spec/fixture/app/views/bound_select_specs/with_options_with_blank.html.erb
|
143
145
|
- spec/fixture/app/views/bound_text_area_specs
|
144
146
|
- spec/fixture/app/views/bound_text_area_specs/basic.html.erb
|
147
|
+
- spec/fixture/app/views/bound_text_area_specs/label.html.erb
|
145
148
|
- spec/fixture/app/views/bound_text_field_specs
|
146
149
|
- spec/fixture/app/views/bound_text_field_specs/basic.html.erb
|
147
150
|
- spec/fixture/app/views/button_specs
|
@@ -233,11 +236,14 @@ files:
|
|
233
236
|
- spec/fixture/app/views/password_field_specs/disabled.html.erb
|
234
237
|
- spec/fixture/app/views/radio_button_specs
|
235
238
|
- spec/fixture/app/views/radio_button_specs/basic.html.erb
|
239
|
+
- spec/fixture/app/views/radio_button_specs/checked.html.erb
|
236
240
|
- spec/fixture/app/views/radio_button_specs/disabled.html.erb
|
237
241
|
- spec/fixture/app/views/radio_button_specs/label.html.erb
|
242
|
+
- spec/fixture/app/views/radio_button_specs/unchecked.html.erb
|
238
243
|
- spec/fixture/app/views/radio_group_specs
|
239
244
|
- spec/fixture/app/views/radio_group_specs/attributes.html.erb
|
240
245
|
- spec/fixture/app/views/radio_group_specs/basic.html.erb
|
246
|
+
- spec/fixture/app/views/radio_group_specs/checked.html.erb
|
241
247
|
- spec/fixture/app/views/radio_group_specs/hash.html.erb
|
242
248
|
- spec/fixture/app/views/radio_group_specs/specific_attributes.html.erb
|
243
249
|
- spec/fixture/app/views/relative_date_span_specs
|
@@ -250,8 +256,10 @@ files:
|
|
250
256
|
- spec/fixture/app/views/relative_date_specs/relative_tomorrow.html.erb
|
251
257
|
- spec/fixture/app/views/relative_date_specs/relative_yesterday.html.erb
|
252
258
|
- spec/fixture/app/views/select_specs
|
259
|
+
- spec/fixture/app/views/select_specs/basic.html.erb
|
253
260
|
- spec/fixture/app/views/select_specs/blank.html.erb
|
254
261
|
- spec/fixture/app/views/select_specs/multiple.html.erb
|
262
|
+
- spec/fixture/app/views/select_specs/selected.html.erb
|
255
263
|
- spec/fixture/app/views/submit_specs
|
256
264
|
- spec/fixture/app/views/submit_specs/disabled_submit.html.erb
|
257
265
|
- spec/fixture/app/views/submit_specs/submit_with_label.html.erb
|
@@ -271,6 +279,7 @@ files:
|
|
271
279
|
- spec/fixture/app/views/text_field_specs/class.html.erb
|
272
280
|
- spec/fixture/app/views/text_field_specs/disabled.html.erb
|
273
281
|
- spec/fixture/app/views/text_field_specs/label.html.erb
|
282
|
+
- spec/fixture/app/views/text_field_specs/symbolized_name.html.erb
|
274
283
|
- spec/fixture/config
|
275
284
|
- spec/fixture/config/environments
|
276
285
|
- spec/fixture/config/environments/development.rb
|