Changeset 1108

Show
Ignore:
Timestamp:
12/14/07 06:03:30 (9 months ago)
Author:
has.s..@gmail.com
Message:

Fixes issue with merb_helpers errorifying fields with new records. closes #346

Files:

Legend:

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

    r1041 r1108  
    531531       
    532532      def errorify_field(attrs, col) 
    533         attrs.add_html_class!("error") if !@_obj.valid? && @_obj.errors.on(col) 
     533        attrs.add_html_class!("error") if @_obj.errors.on(col) 
    534534      end          
    535535       
  • plugins/merb_helpers/specs/merb_helpers_spec.rb

    r1028 r1108  
    3232    errs = error_messages_for(@obj, proc {|err| "<li>#{err[0]} column: #{err[1]}</li>"}) 
    3333    errs.should include("<li>foo column: bar</li>") 
    34   end 
    35    
     34  end   
    3635end 
    3736 
     
    165164    result = text_field(:label => "LABEL" ) 
    166165    result.should match(/<label>LABEL<\/label><input type="text"\s*\/>/) 
    167   end 
     166  end  
    168167end 
    169168 
     
    191190    res[2].should_not match_tag(:input, :label => "LABEL") 
    192191  end 
     192   
     193  it "should not errorify the field for a new object" do 
     194    f = form_for :obj do 
     195      text_control(:foo, :bar =>"7").should_not match_tag(:input, :type => "text", :name => "fake_model[foo]", :class => "error")     
     196    end 
     197  end 
     198   
     199  it "should errorify a field for a model with errors" do 
     200    model = mock("model") 
     201    model.stub!(:new_record?).and_return(true) 
     202    model.stub!(:class).and_return("MyClass") 
     203    model.stub!(:foo).and_return("FOO") 
     204    errors = mock("errors") 
     205    errors.should_receive(:on).with(:foo).and_return(true) 
     206     
     207    model.stub!(:errors).and_return(errors) 
     208     
     209    f = form_for model do 
     210      text_control(:foo).should match_tag(:input, :class => "error") 
     211    end 
     212  end 
    193213end 
    194214 
     
    229249    res[2].should_not match_tag(:input, :label => "LABEL") 
    230250  end 
     251   
     252  it "should not errorify the field for a new object" do 
     253    f = form_for :obj do 
     254      password_control(:foo, :bar =>"7").should_not match_tag(:input, :class => "error")     
     255    end 
     256  end 
     257   
     258  it "should errorify a field for a model with errors" do 
     259    model = mock("model") 
     260    model.stub!(:new_record?).and_return(true) 
     261    model.stub!(:class).and_return("MyClass") 
     262    model.stub!(:foo).and_return("FOO") 
     263    errors = mock("errors") 
     264    errors.should_receive(:on).with(:foo).and_return(true) 
     265     
     266    model.stub!(:errors).and_return(errors) 
     267     
     268    f = form_for model do 
     269      password_control(:foo).should match_tag(:input, :class => "error") 
     270    end 
     271  end 
     272   
    231273end 
    232274 
     
    288330    res[2].should_not match_tag(:input, :label => "LABEL") 
    289331    end 
     332     
     333    it "should not errorify the field for a new object" do 
     334      f = form_for :obj do 
     335        checkbox_control(:foo, :bar =>"7").should_not match_tag(:input, :type => "checkbox", :class => "error checkbox") 
     336      end 
     337    end 
     338 
     339    it "should errorify a field for a model with errors" do 
     340      model = mock("model") 
     341      model.stub!(:new_record?).and_return(true) 
     342      model.stub!(:class).and_return("MyClass") 
     343      model.stub!(:foo).and_return("FOO") 
     344      errors = mock("errors") 
     345      errors.should_receive(:on).with(:foo).and_return(true) 
     346     
     347      model.stub!(:errors).and_return(errors) 
     348     
     349      f = form_for model do 
     350        checkbox_control(:foo, :bar =>"7").should match_tag(:input, :type => "checkbox", :class => "error checkbox") 
     351      end 
     352    end 
    290353end 
    291354 
     
    323386      res.should_not match(/<label>LABEL/) 
    324387      res.should_not match_tag(:input, :label=> "LABEL")   
     388    end 
     389  end 
     390   
     391  it "should not errorify the field for a new object" do 
     392    f = form_for :obj do 
     393      hidden_control(:foo, :bar =>"7").should_not match_tag(:input, :type => "hidden", :class => "error") 
     394    end 
     395  end 
     396 
     397  it "should not errorify a field for a model with errors" do 
     398    model = mock("model") 
     399    model.stub!(:new_record?).and_return(true) 
     400    model.stub!(:class).and_return("MyClass") 
     401    model.stub!(:foo).and_return("FOO") 
     402    errors = mock("errors") 
     403    errors.should_receive(:on).with(:foo).and_return(true) 
     404   
     405    model.stub!(:errors).and_return(errors) 
     406   
     407    f = form_for model do 
     408      hidden_control(:foo, :bar =>"7").should match_tag(:input, :type => "hidden", :name => "my_class[foo]", :class => "error") 
    325409    end 
    326410  end 
  • plugins/merb_helpers/specs/spec_helper.rb

    r1006 r1108  
    33require 'rubygems' 
    44require 'merb' 
    5 # require 'merb/test/rspec' 
     5require 'merb/test/rspec' 
     6require 'merb/test/helper' 
     7 
     8Spec::Runner.configure do |config| 
     9  config.include(Merb::Test::Helper) 
     10  config.include(Merb::Test::RspecMatchers) 
     11  config.include(Merb::Test::MerbRspecControllerRedirect)   
     12end 
    613 
    714class FakeModel