Changeset 1002

Show
Ignore:
Timestamp:
11/14/07 21:36:21 (1 year ago)
Author:
iv..@gweezlebur.com
Message:

Add file_field and file_control to merb_helpers / thanks ShayArnett? / Closes #297

Files:

Legend:

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

    r923 r1002  
    2121  s.email = EMAIL 
    2222  s.homepage = HOMEPAGE 
    23   s.requirements << 'merb' 
     23  s.add_dependency("merb", ">=0.4") 
    2424  s.require_path = 'lib' 
    2525  s.autorequire = PLUGIN 
     
    2727end 
    2828 
    29 spec.add_dependency("merb", ">=0.4") 
    3029 
    3130Rake::GemPackageTask.new(spec) do |pkg| 
  • plugins/merb_helpers/lib/form_helpers.rb

    r947 r1002  
    166166      end 
    167167       
     168      ## file input control 
     169      def file_control(col, attrs = {}) 
     170        errorify_field(attrs, col) 
     171        file_field(control_name_value(col, attrs)) 
     172      end 
     173       
     174      def file_field(attrs = {}) 
     175        attrs.merge!(:type => "file") 
     176        optional_label(attrs) { self_closing_tag("input", attrs) } 
     177      end 
     178       
    168179      private 
    169180      # Fake out the browser to send back the method for RESTful stuff. 
  • plugins/merb_helpers/specs/merb_helpers_spec.rb

    r947 r1002  
    466466end 
    467467 
     468describe "file_field (basic)" do 
     469  it_should_behave_like "FakeBufferConsumer" 
     470   
     471  it "should return a basic file field based on the values passed in" do 
     472    file_field(:name => "foo", :value => "bar").should match_tag( :input, :type => "file", :name => "foo", :value => "bar") 
     473  end 
     474   
     475  it "should wrap the field in a label if the :label option is passed to the file_field" do 
     476    result = file_field(:label => "LABEL" ) 
     477    result.should match(/<label>LABEL<input type="file"\s*\/><\/label>/) 
     478  end 
     479end 
     480 
     481describe "file_control (data bound)" do 
     482  it_should_behave_like "FakeBufferConsumer" 
     483   
     484  it "should take a string object and return a useful file control" do 
     485    f = form_for :obj do 
     486      file_control(:foo).should match_tag(:input, :type => "file", :name => "fake_model[foo]", :value => "foowee") 
     487    end 
     488  end 
     489 
     490  it "should take additional attributes and use them" do 
     491    form_for :obj do 
     492      file_control(:foo, :bar => "7").should match_tag(:input, :type => "file", :name => "fake_model[foo]", :value => "foowee", :bar => "7") 
     493    end 
     494  end 
     495   
     496  it "should wrap the file_control in a label if the :label option is passed in" do 
     497    form_for :obj do 
     498      _buffer << text_control(:foo, :label => "LABEL") 
     499    end 
     500    _buffer.should match(/<label>LABEL<input/) 
     501    res = _buffer.scan(/<[^>]*>/) 
     502    res[2].should_not match_tag(:input, :label => "LABEL") 
     503  end 
     504end 
     505