Changeset 732

Show
Ignore:
Timestamp:
10/08/07 16:55:50 (1 year ago)
Author:
wyca..@gmail.com
Message:

text_area helper

Files:

Legend:

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

    r731 r732  
    6666      end 
    6767       
     68      def name(col) 
     69        "#{@_object_name}[#{col}]" 
     70      end 
     71       
     72      def value(col) 
     73        @_obj.send(col) 
     74      end 
     75       
    6876      def name_value(col, attrs) 
    69         {:name => "#{@_object_name}[#{col}]", :value => "#{@_obj.send(col)}"}.merge(attrs) 
     77        {:name => name(col), :value => value(col)}.merge(attrs) 
    7078      end 
    7179       
     
    122130      end 
    123131       
     132      def text_area_control(col, attrs = {}) 
     133        errorify_field(attrs, col) 
     134        text_area_field(value(col), attrs.merge(:name => name(col))) 
     135      end 
     136       
     137      def text_area_field(val, attrs = {}) 
     138        open_tag("textarea", attrs) + 
     139        val + 
     140        "</textarea>" 
     141      end 
     142       
    124143      def submit_button(contents, attrs = {}) 
    125144        attrs.merge!(:type => "submit") 
  • plugins/merb_helpers/specs/merb_helpers_spec.rb

    r731 r732  
    177177end 
    178178 
     179describe "text area (basic)" do 
     180  include TagMatchers 
     181  it "should should return a basic text area based on the values passed in" do 
     182    text_area_field("foo", :name => "foo").should match_tag(:textarea, :name => "foo") 
     183  end 
     184end 
     185 
     186describe "text area (data bound)" do 
     187  it_should_behave_like "FakeBufferConsumer" 
     188   
     189  it "should return a bound text area" do 
     190    form_for :obj do 
     191      ta = text_area_control(:foo) 
     192      tab = text_area_control(:foobad) 
     193      ta.should match_tag(:textarea, :name => "obj[foo]") 
     194      tab.should match_tag(:textarea, :name => "obj[foobad]", :class => "error") 
     195      ta.should include("foowee") 
     196    end 
     197  end 
     198end 
     199 
     200 
    179201describe "submit_button" do 
    180202  it_should_behave_like "FakeBufferConsumer"