paperclip-storage-ftp 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,7 +19,7 @@ And then execute:
19
19
 
20
20
  $ bundle
21
21
 
22
- Or install it yourself as:
22
+ Or install it manually:
23
23
 
24
24
  $ gem install paperclip-storage-ftp
25
25
 
@@ -42,17 +42,15 @@ module Paperclip
42
42
 
43
43
  def connection
44
44
  connection = @@connections["#{host}:#{port}"] ||= build_connection
45
- if connection.closed?
46
- connection.connect(host, port)
47
- connection.login(user, password)
48
- end
45
+ connection.close
46
+ connection.connect(host, port)
47
+ connection.login(user, password)
49
48
  connection
50
49
  end
51
50
 
52
51
  def build_connection
53
52
  connection = Net::FTP.new
54
53
  connection.connect(host, port)
55
- connection.login(user, password)
56
54
  connection
57
55
  end
58
56
 
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
12
  gem.name = "paperclip-storage-ftp"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "1.0.0"
14
+ gem.version = "1.0.1"
15
15
 
16
16
  gem.add_dependency("paperclip")
17
17
 
@@ -29,4 +29,21 @@ describe "Integration", :integration => true do
29
29
 
30
30
  File.exists?(FtpServer::HOME_PATH + "/#{user.id}/original/avatar.jpg").should be_false
31
31
  end
32
+
33
+ it "survives temporarily closed ftp connections" do
34
+ user = User.new
35
+ user.avatar = file
36
+ user.save!
37
+
38
+ user.avatar = nil
39
+ user.save!
40
+
41
+ FtpServer.restart
42
+
43
+ user.avatar = file
44
+ user.save!
45
+ file.close
46
+
47
+ File.exists?(FtpServer::HOME_PATH + "/#{user.id}/original/avatar.jpg").should be_true
48
+ end
32
49
  end
@@ -83,59 +83,23 @@ describe Paperclip::Storage::Ftp::Server do
83
83
  end
84
84
  end
85
85
 
86
- context "#build_connection" do
87
- it "returns the ftp connection for the given server" do
88
- server.host = "ftp.example.com"
89
- server.user = "user"
90
- server.password = "password"
91
-
92
- ftp = double("ftp")
93
- Net::FTP.should_receive(:new).and_return(ftp)
94
- ftp.should_receive(:connect).with(server.host, server.port)
95
- ftp.should_receive(:login).with(server.user, server.password)
96
- server.build_connection.should == ftp
86
+ context "#connection" do
87
+ it "returns the reconnected connection for the given server (to avoid closed socket errors)" do
88
+ connection = double("connection")
89
+ server.should_receive(:build_connection).once.and_return(connection)
90
+ connection.should_receive(:close).twice
91
+ connection.should_receive(:connect).with(server.host, server.port).twice
92
+ connection.should_receive(:login).with(server.user, server.password).twice
93
+ 2.times { server.connection.should == connection }
97
94
  end
98
95
  end
99
96
 
100
- context "#connection" do
101
- it "returns the memoized ftp connection for the given server" do
102
- connection = double("connection", :closed? => false)
103
- server.should_receive(:build_connection).once.and_return(connection)
104
- server.connection.should == connection
105
-
106
- # same host, same port => memoize
107
- same_server = Paperclip::Storage::Ftp::Server.new(
108
- :host => server.host,
109
- :port => server.port
110
- )
111
- same_server.should_receive(:build_connection).never
112
- same_server.connection.should == connection
113
-
114
- # different host => do not memoize
115
- other_host_connection = double("other_host_connection", :closed? => false)
116
- other_host_server = Paperclip::Storage::Ftp::Server.new(
117
- :host => "other.#{server.host}",
118
- :port => server.port
119
- )
120
- other_host_server.should_receive(:build_connection).once.and_return(other_host_connection)
121
- other_host_server.connection.should == other_host_connection
122
-
123
- # different port => do not memoize
124
- other_port_connection = double("other_port_connection", :closed? => false)
125
- other_port_server = Paperclip::Storage::Ftp::Server.new(
126
- :host => server.host,
127
- :port => server.port + 1
128
- )
129
- other_port_server.should_receive(:build_connection).once.and_return(other_port_connection)
130
- other_port_server.connection.should == other_port_connection
131
- end
132
-
133
- it "reconnects if the connection is closed" do
134
- connection = double("connection", :closed? => true)
135
- server.stub(:build_connection) { connection }
97
+ context "#build_connection" do
98
+ it "returns an ftp connection for the given server" do
99
+ connection = double("connection")
100
+ Net::FTP.should_receive(:new).and_return(connection)
136
101
  connection.should_receive(:connect).with(server.host, server.port)
137
- connection.should_receive(:login).with(server.user, server.password)
138
- server.connection.should == connection
102
+ server.build_connection.should == connection
139
103
  end
140
104
  end
141
105
 
@@ -9,6 +9,10 @@ class FtpServer
9
9
  daemon_controller.start unless daemon_controller.running?
10
10
  end
11
11
 
12
+ def self.restart
13
+ daemon_controller.restart
14
+ end
15
+
12
16
  def self.clear
13
17
  FileUtils.rm_r(Dir.glob(HOME_PATH + "/*"))
14
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-storage-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-01 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paperclip
@@ -126,12 +126,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  - - ! '>='
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
+ segments:
130
+ - 0
131
+ hash: 4104313546954494732
129
132
  required_rubygems_version: !ruby/object:Gem::Requirement
130
133
  none: false
131
134
  requirements:
132
135
  - - ! '>='
133
136
  - !ruby/object:Gem::Version
134
137
  version: '0'
138
+ segments:
139
+ - 0
140
+ hash: 4104313546954494732
135
141
  requirements: []
136
142
  rubyforge_project:
137
143
  rubygems_version: 1.8.24