Radio, Web and Free Software

Changeset b71a93afaa069e73dee680b0a22e95f77a1cd660

Show
Ignore:
Timestamp:
07/28/10 10:09:13 (5 weeks ago)
Author:
Alban Peignier <alban.peignier@…>
Parents:
9c57242449064854924f422f41f763d41dcae867
Children:
e67e28d59604c3c34a634ea37824b23bc828b268
git-committer:
Alban Peignier <alban.peignier@free.fr> / 2010-07-28T10:09:13Z+0200
Message:

Add :allow_blank option to acts_as_ip_port

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lib/acts_as_ip_port.rb

    rd4a3873 rb71a93a  
    99    def acts_as_ip_port(*names) 
    1010      options = names.extract_options! 
     11       
     12      options = { :allow_blank => false }.update(options) 
    1113 
    1214      minimum_value, message =  
     
    2527        end 
    2628 
    27         validates_numericality_of name, :only_integer => true, :greater_than => minimum_value, :less_than => 65536, :message => message 
     29        validates_numericality_of name, :only_integer => true, :greater_than => minimum_value, :less_than => 65536, :message => message, :allow_blank => options[:allow_blank] 
    2830      end 
    2931    end 
  • spec/lib/acts_as_ip_port_spec.rb

    rd4a3873 rb71a93a  
    1010    acts_as_ip_port :port 
    1111    acts_as_ip_port :user_port, :user_port => true 
     12    acts_as_ip_port :optionnal_port, :allow_blank => true 
    1213  end 
    1314 
     
    4142  end 
    4243 
     44  it "should not accept value blank value by default" do 
     45    @model.should_not allow_values_for(:port, "") 
     46  end 
     47 
     48  context "when allow_blank is true" do 
     49 
     50    it "should accept value blank value" do 
     51      @model.should allow_values_for(:optionnal_port, "") 
     52    end 
     53     
     54  end 
     55 
    4356  describe "user port" do 
    4457