streamsend 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,270 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "../../spec_helper")
2
-
3
- module StreamSend
4
- describe "Subscriber" do
5
- before(:each) do
6
- stub_http_request(:any, //).to_return(:body => "Page not found.", :status => 404)
7
-
8
- @username = "scott"
9
- @password = "topsecret"
10
- @host = "test.host"
11
-
12
- xml = <<-XML
13
- <?xml version="1.0" encoding="UTF-8"?>
14
- <audiences type="array">
15
- <audience>
16
- <id type="integer">2</id>
17
- </audience>
18
- </audiences>
19
- XML
20
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences.xml").to_return(:body => xml)
21
-
22
- StreamSend.configure(@username, @password, @host)
23
- end
24
-
25
- describe ".audience_id" do
26
- it "should return the id of the first audience" do
27
- StreamSend::Subscriber.audience_id.should == 2
28
- end
29
- end
30
-
31
- describe ".all" do
32
- describe "with subscribers" do
33
- before(:each) do
34
- xml = <<-XML
35
- <?xml version="1.0" encoding="UTF-8"?>
36
- <people type="array">
37
- <person>
38
- <id type="integer">2</id>
39
- <email-address>scott@gmail.com</email-address>
40
- <created-at type="datetime">2009-09-18T01:27:05Z</created-at>
41
- </person>
42
- </people>
43
- XML
44
-
45
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml").to_return(:body => xml)
46
- end
47
-
48
- it "should return array of one subscriber object" do
49
- subscribers = StreamSend::Subscriber.all
50
- subscribers.size.should == 1
51
-
52
- subscribers.first.should be_instance_of(StreamSend::Subscriber)
53
- subscribers.first.id.should == 2
54
- subscribers.first.email_address.should == "scott@gmail.com"
55
- subscribers.first.created_at.should == Time.parse("2009-09-18T01:27:05Z")
56
- end
57
- end
58
-
59
- describe "with no subscribers" do
60
- before(:each) do
61
- xml = <<-XML
62
- <?xml version="1.0" encoding="UTF-8"?>
63
- <people type="array"/>
64
- XML
65
-
66
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml").to_return(:body => xml)
67
- end
68
-
69
- it "should return an empty array" do
70
- StreamSend::Subscriber.all.should == []
71
- end
72
- end
73
-
74
- describe "with invalid audience" do
75
- before(:each) do
76
- xml = <<-XML
77
- <?xml version="1.0" encoding="UTF-8"?>
78
- <people type="array"/>
79
- XML
80
-
81
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/99/people.xml").to_return(:body => xml)
82
- end
83
-
84
- it "should raise an exception" do
85
- lambda { StreamSend::Subscriber.all }.should raise_error
86
- end
87
- end
88
- end
89
-
90
- describe ".find" do
91
- describe "with matching subscriber" do
92
- before(:each) do
93
- xml = <<-XML
94
- <?xml version="1.0" encoding="UTF-8"?>
95
- <people type="array">
96
- <person>
97
- <id type="integer">2</id>
98
- <email-address>scott@gmail.com</email-address>
99
- <created-at type="datetime">2009-09-18T01:27:05Z</created-at>
100
- </person>
101
- </people>
102
- XML
103
-
104
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml?email_address=scott@gmail.com").to_return(:body => xml)
105
- end
106
-
107
- it "should return subscriber" do
108
- subscriber = StreamSend::Subscriber.find("scott@gmail.com")
109
-
110
- subscriber.should be_instance_of(StreamSend::Subscriber)
111
- subscriber.id.should == 2
112
- subscriber.email_address.should == "scott@gmail.com"
113
- subscriber.created_at.should == Time.parse("2009-09-18T01:27:05Z")
114
- end
115
- end
116
-
117
- describe "with no matching subscriber" do
118
- before(:each) do
119
- xml = <<-XML
120
- <?xml version="1.0" encoding="UTF-8"?>
121
- <people type="array"\>
122
- XML
123
-
124
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml?email_address=bad.email@gmail.com").to_return(:body => xml)
125
- end
126
-
127
- it "should return nil" do
128
- StreamSend::Subscriber.find("bad.email@gmail.com").should == nil
129
- end
130
- end
131
-
132
- describe "with invalid audience" do
133
- before(:each) do
134
- xml = <<-XML
135
- <?xml version="1.0" encoding="UTF-8"?>
136
- <people type="array"\>
137
- XML
138
-
139
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/99/people.xml?email_address=bad.email@gmail.com").to_return(:body => xml)
140
- end
141
-
142
- it "should raise an exception" do
143
- lambda { StreamSend::Subscriber.find("scott@gmail.com") }.should raise_error
144
- end
145
- end
146
- end
147
-
148
- describe ".create" do
149
- describe "with valid subscriber parameters" do
150
- describe "with no existing subscribers using the given email address" do
151
- before(:each) do
152
- stub_http_request(:post, /audiences\/2\/people.xml/).with(:person => {"email_address" => "foo@bar.com", "first_name" => "JoeBob"}).to_return(:body => "", :headers => {"location" => "http://test.host/audiences/2/people/1"}, :status => 201)
153
- end
154
-
155
- it "should return the new subscriber's id" do
156
- subscriber_id = StreamSend::Subscriber.create({"email_address" => "foo@bar.com", "first_name" => "JoeBob"})
157
-
158
- subscriber_id.should_not be_nil
159
- subscriber_id.should == 1
160
- end
161
- end
162
-
163
- describe "with an existing subscriber using the given email address" do
164
- before(:each) do
165
- stub_http_request(:post, /audiences\/2\/people.xml/).with(:person => {"email_address" => "foo@bar.com", "first_name" => "JoeBob"}).to_return(:body => "<error>Email address has already been taken<error>")
166
- end
167
-
168
- it "should raise an exception" do
169
- lambda {
170
- subscriber_id = StreamSend::Subscriber.create({"email_address" => "foo@bar.com", "first_name" => "JoeBob"})
171
- }.should raise_error
172
- end
173
- end
174
- end
175
-
176
- describe "with invalid subscriber parameters" do
177
- before(:each) do
178
- stub_http_request(:post, /audiences\/2\/people.xml/).with({"email_address" => "foo.com", "first_name" => "JoeBob"}).to_return(:body => "<error>Email address does not appear to be valid</error>")
179
- end
180
-
181
- it "should raise an exception" do
182
- lambda {
183
- subscriber_id = StreamSend::Subscriber.create({"email_address" => "foo@bar.com", "first_name" => "JoeBob"})
184
- }.should raise_error
185
- end
186
- end
187
- end
188
-
189
- describe "#show" do
190
- describe "with valid subscriber instance" do
191
- before(:each) do
192
- xml = <<-XML
193
- <?xml version="1.0" encoding="UTF-8"?>
194
- <person>
195
- <id type="integer">2</id>
196
- <email-address>scott@gmail.com</email-address>
197
- <created-at type="datetime">2009-09-18T01:27:05Z</created-at>
198
- <first-name>Scott</first-name>
199
- <last-name>Albertson</last-name>
200
- </person>
201
- XML
202
-
203
- stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2.xml").to_return(:body => xml)
204
- end
205
-
206
- it "should return subscriber" do
207
- subscriber = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).show
208
-
209
- subscriber.should be_instance_of(StreamSend::Subscriber)
210
- subscriber.id.should == 2
211
- subscriber.email_address.should == "scott@gmail.com"
212
- subscriber.created_at.should == Time.parse("2009-09-18T01:27:05Z")
213
- subscriber.first_name.should == "Scott"
214
- subscriber.last_name.should == "Albertson"
215
- end
216
- end
217
-
218
- describe "with invalid subscriber instance" do
219
- it "should raise exception" do
220
- lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).show }.should raise_error
221
- end
222
- end
223
-
224
- describe "with invalid audience" do
225
- it "should raise exception" do
226
- lambda { StreamSend::Subscriber.new({"id" => 2}).show }.should raise_error
227
- end
228
- end
229
- end
230
-
231
- describe "#activate" do
232
- before(:each) do
233
- stub_http_request(:post, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2/activate.xml").to_return(:body => nil)
234
- end
235
-
236
- describe "with valid subscriber" do
237
- it "should be successful" do
238
- response = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).activate
239
- response.should be_true
240
- end
241
- end
242
-
243
- describe "with invalid subscriber" do
244
- it "should raise exception" do
245
- lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).activate }.should raise_error
246
- end
247
- end
248
- end
249
-
250
- describe "#unsubscribe" do
251
- before(:each) do
252
- stub_http_request(:post, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2/unsubscribe.xml").to_return(:body => nil)
253
- end
254
-
255
- describe "with valid subscriber" do
256
- it "should be successful" do
257
- response = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).unsubscribe
258
- response.should be_true
259
- end
260
- end
261
-
262
- describe "with invalid subscriber" do
263
- it "should raise exception" do
264
- lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).unsubscribe }.should raise_error
265
- end
266
- end
267
- end
268
- end
269
- end
270
-
@@ -1,9 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "spec_helper")
2
-
3
- describe StreamSend do
4
- describe ".configure" do
5
- it "should set username"
6
- it "should set password"
7
- it "should set host"
8
- end
9
- end