Convert 'port' to integer.

Akinori MUSHA 11 年之前
父节点
当前提交
8d4c72d744
共有 2 个文件被更改,包括 14 次插入2 次删除
  1. 1 1
      app/models/agents/imap_folder_agent.rb
  2. 13 1
      spec/models/agents/imap_folder_agent_spec.rb

+ 1 - 1
app/models/agents/imap_folder_agent.rb

@@ -305,7 +305,7 @@ module Agents
305 305
       host, port, ssl, username = options.values_at(:host, :port, :ssl, :username)
306 306
 
307 307
       log "Connecting to #{host}#{':%d' % port if port}#{' via SSL' if ssl}"
308
-      Client.open(host, port, ssl) { |imap|
308
+      Client.open(host, Integer(port), ssl) { |imap|
309 309
         log "Logging in as #{username}"
310 310
         imap.login(username, options[:password])
311 311
 

+ 13 - 1
spec/models/agents/imap_folder_agent_spec.rb

@@ -90,11 +90,23 @@ describe Agents::ImapFolderAgent do
90 90
       end
91 91
 
92 92
       it 'should validate the integer fields' do
93
+        @checker.options['expected_update_period_in_days'] = 'nonsense'
94
+        @checker.should_not be_valid
95
+
93 96
         @checker.options['expected_update_period_in_days'] = '2'
94 97
         @checker.should be_valid
95 98
 
96
-        @checker.options['expected_update_period_in_days'] = 'nonsense'
99
+        @checker.options['port'] = -1
100
+        @checker.should_not be_valid
101
+
102
+        @checker.options['port'] = 'imap'
97 103
         @checker.should_not be_valid
104
+
105
+        @checker.options['port'] = '143'
106
+        @checker.should be_valid
107
+
108
+        @checker.options['port'] = 993
109
+        @checker.should be_valid
98 110
       end
99 111
 
100 112
       it 'should validate the boolean fields' do