paperclip-storage-ftp 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -42,17 +42,15 @@ module Paperclip
|
|
42
42
|
|
43
43
|
def connection
|
44
44
|
connection = @@connections["#{host}:#{port}"] ||= build_connection
|
45
|
-
|
46
|
-
|
47
|
-
|
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.
|
14
|
+
gem.version = "1.0.1"
|
15
15
|
|
16
16
|
gem.add_dependency("paperclip")
|
17
17
|
|
data/spec/integration_spec.rb
CHANGED
@@ -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 "#
|
87
|
-
it "returns the
|
88
|
-
|
89
|
-
server.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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 "#
|
101
|
-
it "returns
|
102
|
-
connection = double("connection"
|
103
|
-
|
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
|
-
|
138
|
-
server.connection.should == connection
|
102
|
+
server.build_connection.should == connection
|
139
103
|
end
|
140
104
|
end
|
141
105
|
|
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.
|
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-
|
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
|