Changeset 1178
- Timestamp:
- 01/06/08 01:44:44 (9 months ago)
- Files:
-
- plugins/merb_helpers/lib/merb_helpers/form_helpers.rb (modified) (4 diffs)
- plugins/merb_helpers/spec/merb_helpers_spec.rb (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/merb_helpers/lib/merb_helpers/form_helpers.rb
r1172 r1178 179 179 def text_field(attrs = {}) 180 180 attrs.merge!(:type => "text") 181 attrs.add_html_class!("text") 181 182 optional_label(attrs) { self_closing_tag("input", attrs) } 182 183 end … … 201 202 attrs.delete(:value) 202 203 attrs.merge!(:type => 'password') 204 attrs.add_html_class!("password") 203 205 optional_label(attrs) { self_closing_tag("input", attrs) } 204 206 end … … 276 278 attrs.delete(:label) 277 279 attrs.merge!(:type => :hidden) 280 attrs.add_html_class!("hidden") 278 281 self_closing_tag("input", attrs) 279 282 end … … 513 516 def file_field(attrs = {}) 514 517 attrs.merge!(:type => "file") 518 attrs.add_html_class!("file") 515 519 optional_label(attrs) { self_closing_tag("input", attrs) } 516 520 end plugins/merb_helpers/spec/merb_helpers_spec.rb
r1172 r1178 43 43 end 44 44 _buffer.should match_tag(:form, :method => "post") 45 _buffer.should_not match_tag(:input, :type => "hidden", :name => "_method")46 45 _buffer.should include("CONTENT") 47 46 end … … 115 114 end 116 115 117 it "should set the method to post if the object does not respond to new_record?" do118 @obj3 = FakeModel3.new119 form_for(:obj3) do120 end121 _buffer.should match_tag(:form, :method => "post")122 _buffer.should_not match_tag(:input, :type => "hidden", :name => "_method")123 end124 125 116 it "should support PUT if the object passed in is not a new_record? via a hidden field" do 126 117 form_for(:obj) do … … 128 119 _buffer.should match_tag(:form, :method => "post") 129 120 _buffer.should match_tag(:input, :type => "hidden", :value => "put", :name => "_method") 130 end131 132 it "should set a form to be mutlipart" do133 form_for(:obj, :multipart => true) do134 end135 _buffer.should match_tag( :form, :method => "post", :enctype => "multipart/form-data")136 121 end 137 122 … … 178 163 it "should provide an additional label tag if the :label option is passed in" do 179 164 result = text_field(:label => "LABEL" ) 180 result.should match(/<label>LABEL<\/label><input type="text" \s*\/>/)165 result.should match(/<label>LABEL<\/label><input type="text" class="text"\s*\/>/) 181 166 end 182 167 end … … 223 208 224 209 f = form_for model do 225 text_control(:foo).should match_tag(:input, :class => "error ")210 text_control(:foo).should match_tag(:input, :class => "error text") 226 211 end 227 212 end … … 237 222 it "should provide an additional label tag if the :label option is passed in" do 238 223 result = password_field(:label => "LABEL" ) 239 result.should match(/<label.*>LABEL<\/label><input type="password" \s*\/>/)224 result.should match(/<label.*>LABEL<\/label><input type="password" class="password"\s*\/>/) 240 225 end 241 226 end … … 282 267 283 268 f = form_for model do 284 password_control(:foo).should match_tag(:input, :class => "error ")269 password_control(:foo).should match_tag(:input, :class => "error password") 285 270 end 286 271 end … … 291 276 it "should return a basic checkbox based on the values passed in" do 292 277 checkbox_field(:name => "foo", :checked => "checked").should match_tag(:input, :class => "checkbox", :name => "foo", :checked => "checked") 293 end294 295 it "should return a basic checkbox with :boolean => true" do296 checkbox_field(:name => "foo", :checked => "checked", :boolean => true).should match_tag(:input, :class => "checkbox", :name => "foo", :checked => "checked")297 end298 299 it "should return a basic checkbox with a value other than 1/0" do300 checkbox_field(:name => "choices[]", :boolean => false, :value => "dog").should match_tag(:input, :class => "checkbox", :name => "choices[]", :value => "dog")301 278 end 302 279 … … 400 377 it "should render controls with errors if their attribute contains an error" do 401 378 form_for :obj do 402 hidden_control(:foobad).should match_tag(:input, :type =>"hidden", :name => "fake_model[foobad]", :value => "foowee", :class => "error ")379 hidden_control(:foobad).should match_tag(:input, :type =>"hidden", :name => "fake_model[foobad]", :value => "foowee", :class => "error hidden") 403 380 end 404 381 end … … 429 406 430 407 f = form_for model do 431 hidden_control(:foo, :bar =>"7").should match_tag(:input, :type => "hidden", :name => "my_class[foo]", :class => "error ")408 hidden_control(:foo, :bar =>"7").should match_tag(:input, :type => "hidden", :name => "my_class[foo]", :class => "error hidden") 432 409 end 433 410 end … … 637 614 it "should wrap the field in a label if the :label option is passed to the file_field" do 638 615 result = file_field(:label => "LABEL" ) 639 result.should match(/<label>LABEL<\/label><input type="file" \s*\/>/)616 result.should match(/<label>LABEL<\/label><input type="file" class="file"\s*\/>/) 640 617 end 641 618 end … … 684 661 before(:each) do 685 662 @obj = mock("a model") 686 @obj.stub!(:id).and_return(5)687 663 Merb::Router.prepare do |r| 688 664 r.resources :objs
