Permalink
Browse files

* add FTP path validation.

  • Loading branch information...
1 parent 2c43f08 commit fd096b5c2f80b66ab7d4e15810a72e90d419ddae @kou committed Mar 15, 2009
Showing with 30 additions and 9 deletions.
  1. +1 −0 app/models/site.rb
  2. +1 −0 config/locales/ja.yml
  3. +28 −9 test/unit/site_test.rb
View
@@ -9,6 +9,7 @@ def default
end
validates_format_of :ftp_host, :with => URI::HOST, :allow_blank => true
+ validates_format_of :ftp_path, :with => URI::ABS_PATH, :allow_blank => true
def blank_configuration?
title.blank? and !have_ftp_configuration?
View
@@ -93,6 +93,7 @@ ja:
published: 公開
site:
ftp_host: "FTPホスト"
+ ftp_path: "FTPパス"
title:
controller:
View
@@ -11,24 +11,43 @@ def test_default
end
def test_ftp_host_validation
- assert_valid_ftp_host("")
- assert_valid_ftp_host("192.168.1.1")
- assert_valid_ftp_host("ftp.example.com")
- assert_valid_ftp_host("ftp")
+ assert_valid_attribute(:ftp_host, nil)
+ assert_valid_attribute(:ftp_host, "")
+ assert_valid_attribute(:ftp_host, "192.168.1.1")
+ assert_valid_attribute(:ftp_host, "ftp.example.com")
+ assert_valid_attribute(:ftp_host, "ftp")
- assert_not_valid_ftp_host(["FTPホスト は不正な値です。"], "example com")
+ assert_not_valid_attribute(["FTPホスト は不正な値です。"],
+ :ftp_host,
+ "example com")
+ end
+
+ def test_ftp_path_validation
+ assert_valid_attribute(:ftp_path, nil)
+ assert_valid_attribute(:ftp_path, "")
+ assert_valid_attribute(:ftp_path, "/")
+ assert_valid_attribute(:ftp_path, "/directory/")
+
+ assert_not_valid_attribute(["FTPパス は不正な値です。"],
+ :ftp_path,
+ "/have space")
+ assert_not_valid_attribute(["FTPパス は不正な値です。"],
+ :ftp_path,
+ "relative-path")
end
private
- def assert_valid_ftp_host(host)
+ def assert_valid_attribute(name, value)
site = Site.default
- site.ftp_host = host
+ site.send("#{name}=", value)
assert_valid(site)
+ site
end
- def assert_not_valid_ftp_host(expected_errors, host)
+ def assert_not_valid_attribute(expected_errors, name, value)
site = Site.default
- site.ftp_host = host
+ site.send("#{name}=", value)
assert_not_valid(expected_errors, site)
+ site
end
end

0 comments on commit fd096b5

Please sign in to comment.