paperclip-storage-ftp 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18a15c30e1b75f999126536007200110375d2005
4
- data.tar.gz: c402de4d71aa7749219617cd3c9a07636b45e979
3
+ metadata.gz: 7ac0615dacb3edb9fd6ed435afa757d631e96946
4
+ data.tar.gz: 78db92783d426bb615b9beef8133d2e717d69740
5
5
  SHA512:
6
- metadata.gz: 558948f893a8728ea1bf72506a6991357a2c685524919707e818df3b1cc7d1ff68df0e6cb475756b8e8dbdeb7b0f4a9620ead026f1cbc57846def429f769335e
7
- data.tar.gz: a2ef9e53c6f7150ee4f19f9e12d7646ffced3dfd09ce497eb7f7b74d95a5502c95286b7170a13cbe33b294daf20d9276bf4d40df9eb95efd294b891bc4503fa2
6
+ metadata.gz: f42bcf600a6cddde9324da644dfbed5de0d4af895318041cd357772bd48a59a15c38537579037701e8fecbccc5578474efd19130c6842875f08fac4757644461
7
+ data.tar.gz: ac45ef8e943368a069369c5c56d7645c740f1124d28b72e768205692653fda754bb323584baa5047fbfd1174fb0cffafcc9fe531193ba29cf5018a96734225bd
data/.travis.yml CHANGED
@@ -9,3 +9,7 @@ gemfile:
9
9
  - gemfiles/Gemfile.paperclip-2.x
10
10
  - gemfiles/Gemfile.paperclip-3.x
11
11
  - gemfiles/Gemfile.paperclip-4.x
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: jruby-19mode
15
+ - rvm: rbx
data/README.md CHANGED
@@ -79,6 +79,11 @@ end
79
79
 
80
80
  ## Changelog
81
81
 
82
+ ### 1.2.1
83
+
84
+ * Raise `Paperclip::Storage::Ftp::NoServerAvailable` error when using `:ftp_ignore_failing_connections => true` but all servers are down
85
+ * Avoid connecting to all servers for operations that just need one
86
+
82
87
  ### 1.2.0
83
88
 
84
89
  * New options `:ftp_connect_timeout` and `:ftp_ignore_failing_connections`. See usage example above.
@@ -7,6 +7,9 @@ require "paperclip/storage/ftp/server"
7
7
  module Paperclip
8
8
  module Storage
9
9
  module Ftp
10
+
11
+ class NoServerAvailable < StandardError; end
12
+
10
13
  def exists?(style_name = default_style)
11
14
  return false unless original_filename
12
15
  with_primary_ftp_server do |server|
@@ -80,7 +83,11 @@ module Paperclip
80
83
  end
81
84
 
82
85
  def primary_ftp_server
83
- ftp_servers.first
86
+ @options[:ftp_servers].each do |server_options|
87
+ server = build_and_connect_server(server_options)
88
+ return server if server.connected?
89
+ end
90
+ raise NoServerAvailable
84
91
  end
85
92
 
86
93
  def with_ftp_servers(&blk)
@@ -93,15 +100,21 @@ module Paperclip
93
100
  end
94
101
 
95
102
  def ftp_servers
96
- ftp_servers = @options[:ftp_servers].map do |server_options|
97
- server = Server.new(server_options.merge(
98
- :connect_timeout => @options[:ftp_connect_timeout],
99
- :ignore_connect_errors => @options[:ftp_ignore_failing_connections]
100
- ))
101
- server.establish_connection
102
- server
103
+ servers = @options[:ftp_servers].map do |server_options|
104
+ build_and_connect_server(server_options)
103
105
  end
104
- ftp_servers.select{|s| s.connected? }
106
+ available_servers = servers.select{|s| s.connected? }
107
+ raise NoServerAvailable if available_servers.empty?
108
+ available_servers
109
+ end
110
+
111
+ def build_and_connect_server(server_options)
112
+ server = Server.new(server_options.merge(
113
+ :connect_timeout => @options[:ftp_connect_timeout],
114
+ :ignore_connect_errors => @options[:ftp_ignore_failing_connections]
115
+ ))
116
+ server.establish_connection
117
+ server
105
118
  end
106
119
  end
107
120
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
13
  gem.name = "paperclip-storage-ftp"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "1.2.0"
15
+ gem.version = "1.2.1"
16
16
 
17
17
  gem.add_dependency("paperclip")
18
18
 
@@ -149,9 +149,24 @@ describe Paperclip::Storage::Ftp do
149
149
  end
150
150
 
151
151
  context "#primary_ftp_server" do
152
- it "returns the first server in the list" do
153
- attachment.stub(:ftp_servers).and_return([first_server, second_server])
154
- attachment.primary_ftp_server.should == attachment.ftp_servers.first
152
+ it "returns the first configured server" do
153
+ first_server.stub(:connected? => true)
154
+ attachment.stub(:build_and_connect_server).and_return(first_server)
155
+ attachment.primary_ftp_server.should == first_server
156
+ end
157
+
158
+ it "returns the second server if first server is down" do
159
+ first_server.stub(:connected? => false)
160
+ second_server.stub(:connected? => true)
161
+ attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
162
+ attachment.primary_ftp_server.should == second_server
163
+ end
164
+
165
+ it "raises NoServerAvailable error if all servers are down" do
166
+ first_server.stub(:connected? => false)
167
+ second_server.stub(:connected? => false)
168
+ attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
169
+ expect { attachment.primary_ftp_server }.to raise_error(Paperclip::Storage::Ftp::NoServerAvailable)
155
170
  end
156
171
  end
157
172
 
@@ -166,21 +181,31 @@ describe Paperclip::Storage::Ftp do
166
181
 
167
182
  context "#ftp_servers" do
168
183
  it "returns the configured ftp servers" do
169
- Paperclip::Storage::Ftp::Server.any_instance.stub(:establish_connection)
170
- Paperclip::Storage::Ftp::Server.any_instance.stub(:connected?).and_return(true)
171
-
172
- attachment.ftp_servers.first.host.should == "ftp1.example.com"
173
- attachment.ftp_servers.first.user.should == "user1"
174
- attachment.ftp_servers.first.password.should == "password1"
175
- attachment.ftp_servers.first.port.should == 2121
176
- attachment.ftp_servers.first.connect_timeout.should == 5
177
- attachment.ftp_servers.first.ignore_connect_errors.should == true
178
- attachment.ftp_servers.second.host.should == "ftp2.example.com"
179
- attachment.ftp_servers.second.user.should == "user2"
180
- attachment.ftp_servers.second.password.should == "password2"
181
- attachment.ftp_servers.second.passive.should == true
182
- attachment.ftp_servers.second.connect_timeout.should == 5
183
- attachment.ftp_servers.second.ignore_connect_errors.should == true
184
+ first_server.stub(:connected? => true)
185
+ second_server.stub(:connected? => true)
186
+ attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
187
+ attachment.ftp_servers.should == [first_server, second_server]
188
+ end
189
+
190
+ it "raises NoServerAvailable error if all servers are down" do
191
+ first_server.stub(:connected? => false)
192
+ second_server.stub(:connected? => false)
193
+ attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
194
+ expect { attachment.ftp_servers }.to raise_error(Paperclip::Storage::Ftp::NoServerAvailable)
195
+ end
196
+ end
197
+
198
+ context "#build_and_connect_server" do
199
+ it "returns a connected server instance based on the given options" do
200
+ Paperclip::Storage::Ftp::Server.stub(:new).and_call_original
201
+
202
+ expected_options = attachment.options[:ftp_servers].first.merge(
203
+ :connect_timeout => attachment.options[:ftp_connect_timeout],
204
+ :ignore_connect_errors => attachment.options[:ftp_ignore_failing_connections]
205
+ )
206
+ expect(first_server).to receive(:establish_connection)
207
+ Paperclip::Storage::Ftp::Server.stub(:new).with(expected_options).and_return(first_server)
208
+ attachment.build_and_connect_server(attachment.options[:ftp_servers].first).should == first_server
184
209
  end
185
210
  end
186
211
  end
@@ -23,12 +23,13 @@ class FtpServer
23
23
 
24
24
  def self.daemon_controller
25
25
  @daemon_controller ||= DaemonController.new(
26
- :identifier => "Apache FtpServer",
27
- :start_command => "cd #{INSTALL_PATH}; ./bin/ftpd.sh res/conf/ftpd-typical.xml",
28
- :ping_command => [:tcp, '127.0.0.1', 2121],
29
- :pid_file => INSTALL_PATH + "/res/ftpd.pid",
30
- :log_file => INSTALL_PATH + "/res/log/ftpd.log",
31
- :start_timeout => ENV['TRAVIS'] ? 120 : 10
26
+ :identifier => "Apache FtpServer",
27
+ :start_command => "cd #{INSTALL_PATH}; ./bin/ftpd.sh res/conf/ftpd-typical.xml",
28
+ :ping_command => [:tcp, '127.0.0.1', 2121],
29
+ :pid_file => INSTALL_PATH + "/res/ftpd.pid",
30
+ :log_file => INSTALL_PATH + "/res/log/ftpd.log",
31
+ :start_timeout => ENV['TRAVIS'] ? 120 : 10,
32
+ :log_file_activity_timeout => ENV['TRAVIS'] ? 120 : 10
32
33
  )
33
34
  end
34
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-storage-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Röbke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  version_requirements: !ruby/object:Gem::Requirement