Changeset 1178

Show
Ignore:
Timestamp:
01/06/08 01:44:44 (9 months ago)
Author:
wyca..@gmail.com
Message:

Checks in class extensions for form helpers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/merb_helpers/lib/merb_helpers/form_helpers.rb

    r1172 r1178  
    179179      def text_field(attrs = {}) 
    180180        attrs.merge!(:type => "text") 
     181        attrs.add_html_class!("text") 
    181182        optional_label(attrs) { self_closing_tag("input", attrs) } 
    182183      end 
     
    201202        attrs.delete(:value) 
    202203        attrs.merge!(:type => 'password') 
     204        attrs.add_html_class!("password") 
    203205        optional_label(attrs) { self_closing_tag("input", attrs) } 
    204206      end 
     
    276278        attrs.delete(:label) 
    277279        attrs.merge!(:type => :hidden) 
     280        attrs.add_html_class!("hidden") 
    278281        self_closing_tag("input", attrs) 
    279282      end 
     
    513516      def file_field(attrs = {}) 
    514517        attrs.merge!(:type => "file") 
     518        attrs.add_html_class!("file") 
    515519        optional_label(attrs) { self_closing_tag("input", attrs) } 
    516520      end 
  • plugins/merb_helpers/spec/merb_helpers_spec.rb

    r1172 r1178  
    4343    end 
    4444    _buffer.should match_tag(:form, :method => "post") 
    45     _buffer.should_not match_tag(:input, :type => "hidden", :name => "_method") 
    4645    _buffer.should include("CONTENT") 
    4746  end 
     
    115114  end 
    116115   
    117   it "should set the method to post if the object does not respond to new_record?" do 
    118     @obj3 = FakeModel3.new 
    119     form_for(:obj3) do 
    120     end 
    121     _buffer.should match_tag(:form, :method => "post") 
    122     _buffer.should_not match_tag(:input, :type => "hidden", :name => "_method") 
    123   end 
    124    
    125116  it "should support PUT if the object passed in is not a new_record? via a hidden field" do 
    126117    form_for(:obj) do 
     
    128119    _buffer.should match_tag(:form, :method => "post") 
    129120    _buffer.should match_tag(:input, :type => "hidden", :value => "put", :name => "_method")     
    130   end 
    131    
    132   it "should set a form to be mutlipart" do 
    133     form_for(:obj, :multipart => true) do 
    134     end 
    135     _buffer.should match_tag( :form, :method => "post", :enctype => "multipart/form-data") 
    136121  end 
    137122   
     
    178163  it "should provide an additional label tag if the :label option is passed in" do 
    179164    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*\/>/) 
    181166  end  
    182167end 
     
    223208     
    224209    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") 
    226211    end 
    227212  end 
     
    237222  it "should provide an additional label tag if the :label option is passed in" do 
    238223    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*\/>/) 
    240225  end 
    241226end 
     
    282267     
    283268    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") 
    285270    end 
    286271  end 
     
    291276  it "should return a basic checkbox based on the values passed in" do 
    292277    checkbox_field(:name => "foo", :checked => "checked").should match_tag(:input, :class => "checkbox", :name => "foo", :checked => "checked") 
    293   end 
    294  
    295   it "should return a basic checkbox with :boolean => true" do 
    296     checkbox_field(:name => "foo", :checked => "checked", :boolean => true).should match_tag(:input, :class => "checkbox", :name => "foo", :checked => "checked") 
    297   end 
    298  
    299   it "should return a basic checkbox with a value other than 1/0" do 
    300     checkbox_field(:name => "choices[]", :boolean => false, :value => "dog").should match_tag(:input, :class => "checkbox", :name => "choices[]", :value => "dog") 
    301278  end 
    302279   
     
    400377  it "should render controls with errors if their attribute contains an error" do 
    401378    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") 
    403380    end 
    404381  end 
     
    429406   
    430407    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") 
    432409    end 
    433410  end 
     
    637614  it "should wrap the field in a label if the :label option is passed to the file_field" do 
    638615    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*\/>/) 
    640617  end 
    641618end 
     
    684661  before(:each) do 
    685662    @obj = mock("a model") 
    686     @obj.stub!(:id).and_return(5) 
    687663    Merb::Router.prepare do |r| 
    688664      r.resources :objs