astrotrain 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +26 -0
- data/LICENSE +20 -0
- data/README +47 -0
- data/Rakefile +122 -0
- data/VERSION +1 -0
- data/astrotrain.gemspec +129 -0
- data/config/sample.rb +12 -0
- data/lib/astrotrain.rb +53 -0
- data/lib/astrotrain/api.rb +52 -0
- data/lib/astrotrain/logged_mail.rb +46 -0
- data/lib/astrotrain/mapping.rb +157 -0
- data/lib/astrotrain/mapping/http_post.rb +18 -0
- data/lib/astrotrain/mapping/jabber.rb +28 -0
- data/lib/astrotrain/mapping/transport.rb +55 -0
- data/lib/astrotrain/message.rb +330 -0
- data/lib/astrotrain/tmail.rb +58 -0
- data/lib/astrotrain/worker.rb +65 -0
- data/lib/vendor/rest-client/README.rdoc +104 -0
- data/lib/vendor/rest-client/Rakefile +84 -0
- data/lib/vendor/rest-client/bin/restclient +65 -0
- data/lib/vendor/rest-client/foo.diff +66 -0
- data/lib/vendor/rest-client/lib/rest_client.rb +188 -0
- data/lib/vendor/rest-client/lib/rest_client/net_http_ext.rb +23 -0
- data/lib/vendor/rest-client/lib/rest_client/payload.rb +185 -0
- data/lib/vendor/rest-client/lib/rest_client/request_errors.rb +75 -0
- data/lib/vendor/rest-client/lib/rest_client/resource.rb +103 -0
- data/lib/vendor/rest-client/rest-client.gemspec +18 -0
- data/lib/vendor/rest-client/spec/base.rb +5 -0
- data/lib/vendor/rest-client/spec/master_shake.jpg +0 -0
- data/lib/vendor/rest-client/spec/payload_spec.rb +71 -0
- data/lib/vendor/rest-client/spec/request_errors_spec.rb +44 -0
- data/lib/vendor/rest-client/spec/resource_spec.rb +52 -0
- data/lib/vendor/rest-client/spec/rest_client_spec.rb +219 -0
- data/test/api_test.rb +28 -0
- data/test/fixtures/apple_multipart.txt +100 -0
- data/test/fixtures/bad_content_type.txt +27 -0
- data/test/fixtures/basic.txt +14 -0
- data/test/fixtures/custom.txt +15 -0
- data/test/fixtures/fwd.txt +0 -0
- data/test/fixtures/gb2312_encoding.txt +16 -0
- data/test/fixtures/gb2312_encoding_invalid.txt +15 -0
- data/test/fixtures/html.txt +16 -0
- data/test/fixtures/iso-8859-1.txt +13 -0
- data/test/fixtures/mapped.txt +13 -0
- data/test/fixtures/multipart.txt +213 -0
- data/test/fixtures/multipart2.txt +213 -0
- data/test/fixtures/multiple.txt +13 -0
- data/test/fixtures/multiple_delivered_to.txt +14 -0
- data/test/fixtures/multiple_with_body_recipients.txt +15 -0
- data/test/fixtures/reply.txt +16 -0
- data/test/fixtures/utf-8.txt +13 -0
- data/test/logged_mail_test.rb +67 -0
- data/test/mapping_test.rb +129 -0
- data/test/message_test.rb +440 -0
- data/test/test_helper.rb +57 -0
- data/test/transport_test.rb +111 -0
- metadata +225 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class Astrotrain::TransportTest < Astrotrain::TestCase
|
4
|
+
describe "HttpPost" do
|
5
|
+
before :all do
|
6
|
+
@post = 'http://example.com'
|
7
|
+
@message = Astrotrain::Message.parse(mail(:custom))
|
8
|
+
@mapping = Astrotrain::Mapping.new(:destination => @post, :transport => 'http_post')
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
@trans = Astrotrain::Mapping::HttpPost.new(@message, @mapping, @message.recipients(%w(delivered_to)).first)
|
13
|
+
@expected_fields = @trans.fields.merge(:emails => @message.recipients(%w(original_to to)) * ",")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sets #fields" do
|
17
|
+
expected = {:subject => @message.subject, :from => @message.sender, :to => @message.recipients(%w(delivered_to)).first, :body => @message.body, :html => @message.html, :emails => @message.recipients(%w(original_to to)),
|
18
|
+
"headers[reply-to]" => "reply-to-me@example.com", 'headers[message-id]' => '<a16be7390810161014n52b603e9k1aa6bb803c6735aa@mail.gmail.com>', 'headers[to]' => "processor@astrotrain.com",
|
19
|
+
"headers[mime-version]"=>"1.0", "headers[content-type]"=>"text/plain; charset=ISO-8859-1", "headers[content-disposition]"=>"inline", "headers[content-transfer-encoding]"=>"7bit"}
|
20
|
+
assert_equal expected, @trans.fields
|
21
|
+
end
|
22
|
+
|
23
|
+
it "adds attachments to #fields" do
|
24
|
+
@multipart = Astrotrain::Message.parse(mail(:multipart))
|
25
|
+
@trans = Astrotrain::Mapping::HttpPost.new(@multipart, @mapping, @multipart.recipients.first)
|
26
|
+
assert_equal @multipart.attachments.first, @trans.fields[:attachments_0]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets fields with mapping separator set" do
|
30
|
+
@message = Astrotrain::Message.parse(mail(:reply))
|
31
|
+
@mapping.separator = "=" * 5
|
32
|
+
@trans = Astrotrain::Mapping::HttpPost.new(@message, @mapping, @message.recipients.first)
|
33
|
+
assert_equal "blah blah", @trans.fields[:body]
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "when processing" do
|
37
|
+
before do
|
38
|
+
stub(Astrotrain::Mapping::HttpPost).new {@trans}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "makes http post request" do
|
42
|
+
mock(RestClient).post(@mapping.destination, @expected_fields)
|
43
|
+
@trans.process
|
44
|
+
end
|
45
|
+
|
46
|
+
it "makes http post request from Transport" do
|
47
|
+
mock(RestClient).post(@mapping.destination, @expected_fields)
|
48
|
+
Astrotrain::Mapping::Transport.process(@message, @mapping, @message.recipients.first)
|
49
|
+
end
|
50
|
+
|
51
|
+
before :all do
|
52
|
+
Astrotrain::Mapping::Transport.processing = true
|
53
|
+
end
|
54
|
+
|
55
|
+
after :all do
|
56
|
+
Astrotrain::Mapping::Transport.processing = false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "jabber" do
|
62
|
+
before :all do
|
63
|
+
@dest = 'foo@bar.com'
|
64
|
+
@message = Astrotrain::Message.parse(mail(:custom))
|
65
|
+
@mapping = Astrotrain::Mapping.new(:destination => @dest, :transport => 'jabber')
|
66
|
+
end
|
67
|
+
|
68
|
+
before do
|
69
|
+
@trans = Astrotrain::Mapping::Jabber.new(@message, @mapping, @message.recipients(%w(delivered_to)).first)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "sets #content" do
|
73
|
+
expected = "From: %s\nTo: %s\nSubject: %s\nEmails: %s\n%s" % [@message.sender, @message.recipients(%w(delivered_to)).first, @message.subject, @message.recipients(%w(original_to to)) * ", ", @message.body]
|
74
|
+
assert_equal expected, @trans.content
|
75
|
+
end
|
76
|
+
|
77
|
+
it "sets content with mapping separator set" do
|
78
|
+
@message = Astrotrain::Message.parse(mail(:reply))
|
79
|
+
@mapping.separator = "=" * 5
|
80
|
+
@trans = Astrotrain::Mapping::Jabber.new(@message, @mapping, @message.recipients(%w(delivered_to)).first)
|
81
|
+
expected = "From: %s\nTo: %s\nSubject: %s\nEmails: %s\n%s" % [@message.sender, @message.recipients(%w(delivered_to)).first, @message.subject, '', "blah blah"]
|
82
|
+
assert_equal expected, @trans.content
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "when processing" do
|
86
|
+
before do
|
87
|
+
@conn = Object.new
|
88
|
+
stub(@trans).connection { @conn }
|
89
|
+
stub(Astrotrain::Mapping::Jabber).new { @trans }
|
90
|
+
end
|
91
|
+
|
92
|
+
it "makes jabber delivery" do
|
93
|
+
mock(@conn).deliver(@mapping.destination, @trans.content)
|
94
|
+
@trans.process
|
95
|
+
end
|
96
|
+
|
97
|
+
it "makes jabber delivery from Transport" do
|
98
|
+
mock(@conn).deliver(@mapping.destination, @trans.content)
|
99
|
+
Astrotrain::Mapping::Transport.process(@message, @mapping, @message.recipients(%w(delivered_to)).first)
|
100
|
+
end
|
101
|
+
|
102
|
+
before :all do
|
103
|
+
Astrotrain::Mapping::Transport.processing = true
|
104
|
+
end
|
105
|
+
|
106
|
+
after :all do
|
107
|
+
Astrotrain::Mapping::Transport.processing = false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: astrotrain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- technoweenie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: addressable
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: tmail
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.3.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: dm-core
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.11
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: dm-aggregates
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.11
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dm-timestamps
|
57
|
+
type: :runtime
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.9.11
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: dm-types
|
67
|
+
type: :runtime
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.9.11
|
74
|
+
version:
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: dm-validations
|
77
|
+
type: :runtime
|
78
|
+
version_requirement:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.9.11
|
84
|
+
version:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: context
|
87
|
+
type: :development
|
88
|
+
version_requirement:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rr
|
97
|
+
type: :development
|
98
|
+
version_requirement:
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
version:
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: sinatra
|
107
|
+
type: :development
|
108
|
+
version_requirement:
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
version:
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: xmppr4-simple
|
117
|
+
type: :development
|
118
|
+
version_requirement:
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: "0"
|
124
|
+
version:
|
125
|
+
description:
|
126
|
+
email: technoweenie@gmail.com
|
127
|
+
executables: []
|
128
|
+
|
129
|
+
extensions: []
|
130
|
+
|
131
|
+
extra_rdoc_files:
|
132
|
+
- LICENSE
|
133
|
+
- README
|
134
|
+
files:
|
135
|
+
- .gitignore
|
136
|
+
- LICENSE
|
137
|
+
- README
|
138
|
+
- Rakefile
|
139
|
+
- VERSION
|
140
|
+
- astrotrain.gemspec
|
141
|
+
- config/sample.rb
|
142
|
+
- lib/astrotrain.rb
|
143
|
+
- lib/astrotrain/api.rb
|
144
|
+
- lib/astrotrain/logged_mail.rb
|
145
|
+
- lib/astrotrain/mapping.rb
|
146
|
+
- lib/astrotrain/mapping/http_post.rb
|
147
|
+
- lib/astrotrain/mapping/jabber.rb
|
148
|
+
- lib/astrotrain/mapping/transport.rb
|
149
|
+
- lib/astrotrain/message.rb
|
150
|
+
- lib/astrotrain/tmail.rb
|
151
|
+
- lib/astrotrain/worker.rb
|
152
|
+
- lib/vendor/rest-client/README.rdoc
|
153
|
+
- lib/vendor/rest-client/Rakefile
|
154
|
+
- lib/vendor/rest-client/bin/restclient
|
155
|
+
- lib/vendor/rest-client/foo.diff
|
156
|
+
- lib/vendor/rest-client/lib/rest_client.rb
|
157
|
+
- lib/vendor/rest-client/lib/rest_client/net_http_ext.rb
|
158
|
+
- lib/vendor/rest-client/lib/rest_client/payload.rb
|
159
|
+
- lib/vendor/rest-client/lib/rest_client/request_errors.rb
|
160
|
+
- lib/vendor/rest-client/lib/rest_client/resource.rb
|
161
|
+
- lib/vendor/rest-client/rest-client.gemspec
|
162
|
+
- lib/vendor/rest-client/spec/base.rb
|
163
|
+
- lib/vendor/rest-client/spec/master_shake.jpg
|
164
|
+
- lib/vendor/rest-client/spec/payload_spec.rb
|
165
|
+
- lib/vendor/rest-client/spec/request_errors_spec.rb
|
166
|
+
- lib/vendor/rest-client/spec/resource_spec.rb
|
167
|
+
- lib/vendor/rest-client/spec/rest_client_spec.rb
|
168
|
+
- test/api_test.rb
|
169
|
+
- test/fixtures/apple_multipart.txt
|
170
|
+
- test/fixtures/bad_content_type.txt
|
171
|
+
- test/fixtures/basic.txt
|
172
|
+
- test/fixtures/custom.txt
|
173
|
+
- test/fixtures/fwd.txt
|
174
|
+
- test/fixtures/gb2312_encoding.txt
|
175
|
+
- test/fixtures/gb2312_encoding_invalid.txt
|
176
|
+
- test/fixtures/html.txt
|
177
|
+
- test/fixtures/iso-8859-1.txt
|
178
|
+
- test/fixtures/mapped.txt
|
179
|
+
- test/fixtures/multipart.txt
|
180
|
+
- test/fixtures/multipart2.txt
|
181
|
+
- test/fixtures/multiple.txt
|
182
|
+
- test/fixtures/multiple_delivered_to.txt
|
183
|
+
- test/fixtures/multiple_with_body_recipients.txt
|
184
|
+
- test/fixtures/reply.txt
|
185
|
+
- test/fixtures/utf-8.txt
|
186
|
+
- test/logged_mail_test.rb
|
187
|
+
- test/mapping_test.rb
|
188
|
+
- test/message_test.rb
|
189
|
+
- test/test_helper.rb
|
190
|
+
- test/transport_test.rb
|
191
|
+
has_rdoc: true
|
192
|
+
homepage: http://github.com/entp/astrotrain
|
193
|
+
licenses: []
|
194
|
+
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options:
|
197
|
+
- --charset=UTF-8
|
198
|
+
require_paths:
|
199
|
+
- lib
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: "0"
|
205
|
+
version:
|
206
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - ">="
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: "0"
|
211
|
+
version:
|
212
|
+
requirements: []
|
213
|
+
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 1.3.4
|
216
|
+
signing_key:
|
217
|
+
specification_version: 3
|
218
|
+
summary: email => http post
|
219
|
+
test_files:
|
220
|
+
- test/api_test.rb
|
221
|
+
- test/logged_mail_test.rb
|
222
|
+
- test/mapping_test.rb
|
223
|
+
- test/message_test.rb
|
224
|
+
- test/test_helper.rb
|
225
|
+
- test/transport_test.rb
|