Permalink
Browse files

* add FTP host validation.

  • Loading branch information...
1 parent cac6da5 commit 2c43f082965669a3c8867c4d3061224055bcae8a @kou committed Mar 15, 2009
Showing with 41 additions and 0 deletions.
  1. +4 −0 app/models/site.rb
  2. +2 −0 config/locales/ja.yml
  3. +12 −0 test/test_helper.rb
  4. +23 −0 test/unit/site_test.rb
View
@@ -1,3 +1,5 @@
+require 'uri'
+
class Site < ActiveRecord::Base
DEFAULT_NAME = "default"
class << self
@@ -6,6 +8,8 @@ def default
end
end
+ validates_format_of :ftp_host, :with => URI::HOST, :allow_blank => true
+
def blank_configuration?
title.blank? and !have_ftp_configuration?
end
@@ -91,6 +91,8 @@ ja:
page:
name: 名前
published: 公開
+ site:
+ ftp_host: "FTPホスト"
title:
controller:
View
@@ -49,6 +49,18 @@ class Test::Unit::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
+
+ def assert_valid(object)
+ unless object.valid?
+ flunk("#{object}: #{object.errors.inspect}")
+ end
+ end
+
+ def assert_not_valid(expected_errors, object)
+ assert_not_predicate(object, :valid?)
+ assert_equal(expected_errors.sort,
+ object.errors.full_messages.sort)
+ end
end
class ActionController::TestUploadedFile
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
require 'test_helper'
class SiteTest < ActiveSupport::TestCase
@@ -8,4 +9,26 @@ def test_default
assert_not_nil(Site.default)
assert_equal(1, Site.count)
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_not_valid_ftp_host(["FTPホスト は不正な値です。"], "example com")
+ end
+
+ private
+ def assert_valid_ftp_host(host)
+ site = Site.default
+ site.ftp_host = host
+ assert_valid(site)
+ end
+
+ def assert_not_valid_ftp_host(expected_errors, host)
+ site = Site.default
+ site.ftp_host = host
+ assert_not_valid(expected_errors, site)
+ end
end

0 comments on commit 2c43f08

Please sign in to comment.