Changeset b71a93afaa069e73dee680b0a22e95f77a1cd660
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rd4a3873
|
rb71a93a
|
|
| 9 | 9 | def acts_as_ip_port(*names) |
| 10 | 10 | options = names.extract_options! |
| | 11 | |
| | 12 | options = { :allow_blank => false }.update(options) |
| 11 | 13 | |
| 12 | 14 | minimum_value, message = |
| … |
… |
|
| 25 | 27 | end |
| 26 | 28 | |
| 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] |
| 28 | 30 | end |
| 29 | 31 | end |
-
|
rd4a3873
|
rb71a93a
|
|
| 10 | 10 | acts_as_ip_port :port |
| 11 | 11 | acts_as_ip_port :user_port, :user_port => true |
| | 12 | acts_as_ip_port :optionnal_port, :allow_blank => true |
| 12 | 13 | end |
| 13 | 14 | |
| … |
… |
|
| 41 | 42 | end |
| 42 | 43 | |
| | 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 | |
| 43 | 56 | describe "user port" do |
| 44 | 57 | |