Changeset 1168

Show
Ignore:
Timestamp:
01/05/08 05:25:39 (9 months ago)
Author:
has.s..@gmail.com
Message:

Adds the the multipart => true option to form_for. Also fixes the spec task that was changed when the spec directory was renamed.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/merb_helpers/Rakefile

    r1027 r1168  
    4141   t.warning = true 
    4242   t.spec_opts = ["--format", "specdoc", "--colour"] 
    43    t.spec_files = Dir['specs/**/*_spec.rb'].sort    
     43   t.spec_files = Dir['spec/**/*_spec.rb'].sort    
    4444end 
  • plugins/merb_helpers/lib/merb_helpers/form_helpers.rb

    r1157 r1168  
    8686      #     </form> 
    8787      def form_tag(attrs = {}, &block) 
    88         attrs.merge!( :enctype => "multipart/form-data" ) if attrs.delete(:multipart
     88        set_multipart_attribute!(attrs
    8989        fake_form_method = set_form_method(attrs) 
    9090        concat(open_tag("form", attrs), block.binding) 
     
    109109      #     </form> 
    110110      def form_for(obj, attrs={}, &block) 
     111        set_multipart_attribute!(attrs) 
    111112        obj = obj_from_ivar_or_sym(obj) 
    112113        fake_form_method = set_form_method(attrs, obj) 
     
    558559      def errorify_field(attrs, col) 
    559560        attrs.add_html_class!("error") if @_obj.errors.on(col) 
    560       end          
     561      end    
     562       
     563      def set_multipart_attribute!(attrs = {}) 
     564        attrs.merge!( :enctype => "multipart/form-data" ) if attrs.delete(:multipart)       
     565      end 
    561566       
    562567    end 
  • plugins/merb_helpers/spec/merb_helpers_spec.rb

    r1146 r1168  
    119119    _buffer.should match_tag(:form, :method => "post") 
    120120    _buffer.should match_tag(:input, :type => "hidden", :value => "put", :name => "_method")     
     121  end 
     122   
     123  it "should set a form to be mutlipart" do 
     124    form_for(:obj, :multipart => true) do 
     125    end 
     126    _buffer.should match_tag( :form, :method => "post", :enctype => "multipart/form-data") 
    121127  end 
    122128   
     
    661667  before(:each) do 
    662668    @obj = mock("a model") 
     669    @obj.stub!(:id).and_return(5) 
    663670    Merb::Router.prepare do |r| 
    664671      r.resources :objs