Changeset 947

Show
Ignore:
Timestamp:
11/11/07 02:47:01 (1 year ago)
Author:
luke.sutt..@gmail.com
Message:

Add password_control and password_field helpers.

Files:

Legend:

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

    r925 r947  
    7777      end 
    7878       
     79      def password_control(col, attrs = {}) 
     80        attrs.merge!(:name => control_name(col)) 
     81        errorify_field(attrs, col) 
     82        password_field(control_name_value(col, attrs)) 
     83      end 
     84       
     85      def password_field(attrs = {}) 
     86        attrs.delete(:value) 
     87        attrs.merge!(:type => 'password') 
     88        optional_label(attrs) { self_closing_tag("input", attrs) } 
     89      end 
     90       
    7991      # translate column values from the db to boolean 
    8092      # nil, false, 0 and '0' are false. All others are true 
  • plugins/merb_helpers/specs/merb_helpers_spec.rb

    r925 r947  
    193193end 
    194194 
     195describe "password_field (basic)" do 
     196  it_should_behave_like "FakeBufferConsumer" 
     197   
     198  it "should return a basic password field, but omit the value" do 
     199    password_field(:name => "foo", :value => "bar").should match_tag(:input, :type => "password", :name => "foo") 
     200  end 
     201   
     202  it "should wrap the field in a label if the :label option is passed to the text_field" do 
     203    result = password_field(:label => "LABEL" ) 
     204    result.should match(/<label>LABEL<input type="password"\s*\/><\/label>/) 
     205  end 
     206end 
     207 
     208describe "password_control (data bound)" do 
     209  it_should_behave_like "FakeBufferConsumer" 
     210   
     211  it "should take a string object and return a useful password control, but omit the value" do 
     212    f = form_for :obj do 
     213      password_control(:foo).should match_tag(:input, :type => "password", :name => "fake_model[foo]") 
     214    end 
     215  end 
     216 
     217  it "should take additional attributes and use them" do 
     218    form_for :obj do 
     219      password_control(:foo, :bar => "7").should match_tag(:input, :type => "password", :name => "fake_model[foo]", :bar => "7") 
     220    end 
     221  end 
     222   
     223  it "should wrap the text_control in a label if the :label option is passed in" do 
     224    form_for :obj do 
     225      _buffer << password_control(:foo, :label => "LABEL") 
     226    end 
     227    _buffer.should match(/<label>LABEL<input/) 
     228    res = _buffer.scan(/<[^>]*>/) 
     229    res[2].should_not match_tag(:input, :label => "LABEL") 
     230  end 
     231end 
     232 
    195233describe "checkbox_field (basic)" do 
    196234  it "should return a basic checkbox based on the values passed in" do