contactology 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/.gitignore +5 -0
  2. data/.infinity_test +16 -0
  3. data/.rspec +3 -0
  4. data/.rvmrc +41 -0
  5. data/.watchr +36 -0
  6. data/Gemfile +6 -0
  7. data/Rakefile +1 -0
  8. data/contactology.gemspec +28 -0
  9. data/lib/contactology.rb +125 -0
  10. data/lib/contactology/api.rb +80 -0
  11. data/lib/contactology/basic_object.rb +21 -0
  12. data/lib/contactology/campaign.rb +127 -0
  13. data/lib/contactology/campaign/preview.rb +11 -0
  14. data/lib/contactology/campaigns.rb +2 -0
  15. data/lib/contactology/campaigns/standard.rb +80 -0
  16. data/lib/contactology/campaigns/transactional.rb +58 -0
  17. data/lib/contactology/configuration.rb +42 -0
  18. data/lib/contactology/contact.rb +193 -0
  19. data/lib/contactology/errors.rb +4 -0
  20. data/lib/contactology/issue.rb +24 -0
  21. data/lib/contactology/issues.rb +18 -0
  22. data/lib/contactology/list.rb +192 -0
  23. data/lib/contactology/list_proxy.rb +25 -0
  24. data/lib/contactology/parser.rb +5 -0
  25. data/lib/contactology/send_result.rb +35 -0
  26. data/lib/contactology/stash.rb +29 -0
  27. data/lib/contactology/transactional_message.rb +38 -0
  28. data/lib/contactology/version.rb +3 -0
  29. data/spec/factories/campaigns.rb +18 -0
  30. data/spec/factories/contacts.rb +3 -0
  31. data/spec/factories/issues.rb +9 -0
  32. data/spec/factories/lists.rb +3 -0
  33. data/spec/factories/transactional_messages.rb +5 -0
  34. data/spec/fixtures/net/campaign/destroy.yml +246 -0
  35. data/spec/fixtures/net/campaign/find/failure.yml +36 -0
  36. data/spec/fixtures/net/campaign/find/success.yml +176 -0
  37. data/spec/fixtures/net/campaign/find_by_name/failure.yml +36 -0
  38. data/spec/fixtures/net/campaign/find_by_name/success.yml +211 -0
  39. data/spec/fixtures/net/campaign/preview.yml +106 -0
  40. data/spec/fixtures/net/campaigns/standard/create/failure.yml +106 -0
  41. data/spec/fixtures/net/campaigns/standard/create/invalid.yml +141 -0
  42. data/spec/fixtures/net/campaigns/standard/create/success.yml +176 -0
  43. data/spec/fixtures/net/campaigns/standard/send_campaign/failure.yml +316 -0
  44. data/spec/fixtures/net/campaigns/standard/send_campaign/success.yml +316 -0
  45. data/spec/fixtures/net/campaigns/transactional/create/failure.yml +36 -0
  46. data/spec/fixtures/net/campaigns/transactional/create/success.yml +71 -0
  47. data/spec/fixtures/net/contact/active.yml +106 -0
  48. data/spec/fixtures/net/contact/change_email/success.yml +176 -0
  49. data/spec/fixtures/net/contact/change_email/unknown.yml +36 -0
  50. data/spec/fixtures/net/contact/create.yml +106 -0
  51. data/spec/fixtures/net/contact/destroy.yml +141 -0
  52. data/spec/fixtures/net/contact/find/active.yml +106 -0
  53. data/spec/fixtures/net/contact/find/suppressed.yml +141 -0
  54. data/spec/fixtures/net/contact/find/unknown.yml +36 -0
  55. data/spec/fixtures/net/contact/lists/empty.yml +106 -0
  56. data/spec/fixtures/net/contact/lists/full.yml +246 -0
  57. data/spec/fixtures/net/contact/lists/unknown.yml +71 -0
  58. data/spec/fixtures/net/contact/suppress.yml +141 -0
  59. data/spec/fixtures/net/list/all.yml +141 -0
  60. data/spec/fixtures/net/list/create.yml +106 -0
  61. data/spec/fixtures/net/list/destroy.yml +176 -0
  62. data/spec/fixtures/net/list/find/success.yml +141 -0
  63. data/spec/fixtures/net/list/find/unknown.yml +36 -0
  64. data/spec/fixtures/net/list/import/success.yml +351 -0
  65. data/spec/fixtures/net/list/subscribe/success.yml +211 -0
  66. data/spec/fixtures/net/list/unsubscribe/success.yml +246 -0
  67. data/spec/fixtures/net/transactional_message/send_message/failure.yml +176 -0
  68. data/spec/fixtures/net/transactional_message/send_message/success.yml +176 -0
  69. data/spec/models/contactology/api_spec.rb +51 -0
  70. data/spec/models/contactology/campaign_spec.rb +75 -0
  71. data/spec/models/contactology/campaigns/standard_spec.rb +84 -0
  72. data/spec/models/contactology/campaigns/transactional_spec.rb +28 -0
  73. data/spec/models/contactology/configuration_spec.rb +29 -0
  74. data/spec/models/contactology/contact_spec.rb +175 -0
  75. data/spec/models/contactology/issues_spec.rb +34 -0
  76. data/spec/models/contactology/list_spec.rb +125 -0
  77. data/spec/models/contactology/send_result_spec.rb +65 -0
  78. data/spec/models/contactology/stash_spec.rb +65 -0
  79. data/spec/models/contactology/transactional_message_spec.rb +65 -0
  80. data/spec/models/contactology_spec.rb +67 -0
  81. data/spec/requests/contacts_spec.rb +4 -0
  82. data/spec/spec_helper.rb +15 -0
  83. data/spec/support/contactology.rb +34 -0
  84. data/spec/support/factory_girl.rb +19 -0
  85. data/spec/support/vcr.rb +11 -0
  86. metadata +282 -0
@@ -0,0 +1,176 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://api.emailcampaigns.net:443/2/REST/?campaignName=factory%20campaign&key=%{API_KEY}&method=Campaign_Create_Transactional&senderEmail=sender@example.com&senderName=Sender%20Example&subject=Test%20Creation&content%5Btext%5D=This%20is%20a%20good%20email.%20%7BCOMPANY_ADDRESS%7D&testContact%5Bemail%5D=test-contact@example.com&testReplacements%5Bfirst_name%5D=John
6
+ body:
7
+ headers:
8
+ accept:
9
+ - application/json
10
+ user-agent:
11
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
12
+ response: !ruby/struct:VCR::Response
13
+ status: !ruby/struct:VCR::ResponseStatus
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ x-powered-by:
18
+ - PHP/5.2.10
19
+ set-cookie:
20
+ - PHPSESSID=a7ab7567f3ff2131b7dec2c6026d5f48; path=/
21
+ expires:
22
+ - Thu, 19 Nov 1981 08:52:00 GMT
23
+ cache-control:
24
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
25
+ pragma:
26
+ - no-cache
27
+ content-type:
28
+ - text/plain;charset=UTF-8
29
+ transfer-encoding:
30
+ - chunked
31
+ date:
32
+ - Wed, 03 Aug 2011 18:42:25 GMT
33
+ server:
34
+ - lighttpd/1.4.28
35
+ body: "41"
36
+ http_version: "1.1"
37
+ - !ruby/struct:VCR::HTTPInteraction
38
+ request: !ruby/struct:VCR::Request
39
+ method: :get
40
+ uri: https://api.emailcampaigns.net:443/2/REST/?campaignId=41&key=%{API_KEY}&method=Campaign_Delete
41
+ body:
42
+ headers:
43
+ accept:
44
+ - application/json
45
+ user-agent:
46
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
47
+ response: !ruby/struct:VCR::Response
48
+ status: !ruby/struct:VCR::ResponseStatus
49
+ code: 200
50
+ message: OK
51
+ headers:
52
+ x-powered-by:
53
+ - PHP/5.2.10
54
+ set-cookie:
55
+ - PHPSESSID=e3d590776569a8ee5778463d527b6cee; path=/
56
+ expires:
57
+ - Thu, 19 Nov 1981 08:52:00 GMT
58
+ cache-control:
59
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
60
+ pragma:
61
+ - no-cache
62
+ content-type:
63
+ - text/plain;charset=UTF-8
64
+ transfer-encoding:
65
+ - chunked
66
+ date:
67
+ - Wed, 03 Aug 2011 18:42:37 GMT
68
+ server:
69
+ - lighttpd/1.4.28
70
+ body: "true"
71
+ http_version: "1.1"
72
+ - !ruby/struct:VCR::HTTPInteraction
73
+ request: !ruby/struct:VCR::Request
74
+ method: :get
75
+ uri: https://api.emailcampaigns.net:443/2/REST/?email=factory-contact@example.com&key=%{API_KEY}&method=Contact_Add&optionalParameters%5BupdateCustomFields%5D=true
76
+ body:
77
+ headers:
78
+ accept:
79
+ - application/json
80
+ user-agent:
81
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
82
+ response: !ruby/struct:VCR::Response
83
+ status: !ruby/struct:VCR::ResponseStatus
84
+ code: 200
85
+ message: OK
86
+ headers:
87
+ x-powered-by:
88
+ - PHP/5.2.10
89
+ set-cookie:
90
+ - PHPSESSID=b621ce46effde38db4e184f9d7696854; path=/
91
+ expires:
92
+ - Thu, 19 Nov 1981 08:52:00 GMT
93
+ cache-control:
94
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
95
+ pragma:
96
+ - no-cache
97
+ content-type:
98
+ - text/plain;charset=UTF-8
99
+ transfer-encoding:
100
+ - chunked
101
+ date:
102
+ - Wed, 03 Aug 2011 18:42:37 GMT
103
+ server:
104
+ - lighttpd/1.4.28
105
+ body: "true"
106
+ http_version: "1.1"
107
+ - !ruby/struct:VCR::HTTPInteraction
108
+ request: !ruby/struct:VCR::Request
109
+ method: :get
110
+ uri: https://api.emailcampaigns.net:443/2/REST/?campaignId=41&key=%{API_KEY}&method=Campaign_Send_Transactional&source=Factory%20Created&contact%5Bemail%5D=factory-contact@example.com&contact%5Bstatus%5D=active&replacements%5B_contactology%5D=Contactology
111
+ body:
112
+ headers:
113
+ accept:
114
+ - application/json
115
+ user-agent:
116
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
117
+ response: !ruby/struct:VCR::Response
118
+ status: !ruby/struct:VCR::ResponseStatus
119
+ code: 200
120
+ message: OK
121
+ headers:
122
+ x-powered-by:
123
+ - PHP/5.2.10
124
+ set-cookie:
125
+ - PHPSESSID=5b0f14e37596fa1d352c4c0d30bac45f; path=/
126
+ expires:
127
+ - Thu, 19 Nov 1981 08:52:00 GMT
128
+ cache-control:
129
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
130
+ pragma:
131
+ - no-cache
132
+ content-type:
133
+ - text/plain;charset=UTF-8
134
+ transfer-encoding:
135
+ - chunked
136
+ date:
137
+ - Wed, 03 Aug 2011 18:42:44 GMT
138
+ server:
139
+ - lighttpd/1.4.28
140
+ body: "{\"result\":\"error\",\"message\":\"Input Error: Campaign 41 has the wrong status\",\"code\":601}"
141
+ http_version: "1.1"
142
+ - !ruby/struct:VCR::HTTPInteraction
143
+ request: !ruby/struct:VCR::Request
144
+ method: :get
145
+ uri: https://api.emailcampaigns.net:443/2/REST/?email=factory-contact@example.com&key=%{API_KEY}&method=Contact_Delete
146
+ body:
147
+ headers:
148
+ accept:
149
+ - application/json
150
+ user-agent:
151
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
152
+ response: !ruby/struct:VCR::Response
153
+ status: !ruby/struct:VCR::ResponseStatus
154
+ code: 200
155
+ message: OK
156
+ headers:
157
+ x-powered-by:
158
+ - PHP/5.2.10
159
+ set-cookie:
160
+ - PHPSESSID=cff8d4a314315bf7b97448e78c3b5cf5; path=/
161
+ expires:
162
+ - Thu, 19 Nov 1981 08:52:00 GMT
163
+ cache-control:
164
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
165
+ pragma:
166
+ - no-cache
167
+ content-type:
168
+ - text/plain;charset=UTF-8
169
+ transfer-encoding:
170
+ - chunked
171
+ date:
172
+ - Wed, 03 Aug 2011 18:42:45 GMT
173
+ server:
174
+ - lighttpd/1.4.28
175
+ body: "true"
176
+ http_version: "1.1"
@@ -0,0 +1,176 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://api.emailcampaigns.net:443/2/REST/?campaignName=factory%20campaign&key=%{API_KEY}&method=Campaign_Create_Transactional&senderEmail=sender@example.com&senderName=Sender%20Example&subject=Test%20Creation&content%5Btext%5D=This%20is%20a%20good%20email.%20%7BCOMPANY_ADDRESS%7D&testContact%5Bemail%5D=test-contact@example.com&testReplacements%5Bfirst_name%5D=John
6
+ body:
7
+ headers:
8
+ accept:
9
+ - application/json
10
+ user-agent:
11
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
12
+ response: !ruby/struct:VCR::Response
13
+ status: !ruby/struct:VCR::ResponseStatus
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ x-powered-by:
18
+ - PHP/5.2.10
19
+ set-cookie:
20
+ - PHPSESSID=a3d028b280a6a685b1edadf81226c508; path=/
21
+ expires:
22
+ - Thu, 19 Nov 1981 08:52:00 GMT
23
+ cache-control:
24
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
25
+ pragma:
26
+ - no-cache
27
+ content-type:
28
+ - text/plain;charset=UTF-8
29
+ transfer-encoding:
30
+ - chunked
31
+ date:
32
+ - Wed, 03 Aug 2011 18:40:52 GMT
33
+ server:
34
+ - lighttpd/1.4.28
35
+ body: "40"
36
+ http_version: "1.1"
37
+ - !ruby/struct:VCR::HTTPInteraction
38
+ request: !ruby/struct:VCR::Request
39
+ method: :get
40
+ uri: https://api.emailcampaigns.net:443/2/REST/?email=factory-contact@example.com&key=%{API_KEY}&method=Contact_Add&optionalParameters%5BupdateCustomFields%5D=true
41
+ body:
42
+ headers:
43
+ accept:
44
+ - application/json
45
+ user-agent:
46
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
47
+ response: !ruby/struct:VCR::Response
48
+ status: !ruby/struct:VCR::ResponseStatus
49
+ code: 200
50
+ message: OK
51
+ headers:
52
+ x-powered-by:
53
+ - PHP/5.2.10
54
+ set-cookie:
55
+ - PHPSESSID=e60ade78606994be673baa8f8461a3e0; path=/
56
+ expires:
57
+ - Thu, 19 Nov 1981 08:52:00 GMT
58
+ cache-control:
59
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
60
+ pragma:
61
+ - no-cache
62
+ content-type:
63
+ - text/plain;charset=UTF-8
64
+ transfer-encoding:
65
+ - chunked
66
+ date:
67
+ - Wed, 03 Aug 2011 18:40:53 GMT
68
+ server:
69
+ - lighttpd/1.4.28
70
+ body: "true"
71
+ http_version: "1.1"
72
+ - !ruby/struct:VCR::HTTPInteraction
73
+ request: !ruby/struct:VCR::Request
74
+ method: :get
75
+ uri: https://api.emailcampaigns.net:443/2/REST/?campaignId=40&key=%{API_KEY}&method=Campaign_Send_Transactional&source=Factory%20Created&contact%5Bemail%5D=factory-contact@example.com&contact%5Bstatus%5D=active&replacements%5B_contactology%5D=Contactology
76
+ body:
77
+ headers:
78
+ accept:
79
+ - application/json
80
+ user-agent:
81
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
82
+ response: !ruby/struct:VCR::Response
83
+ status: !ruby/struct:VCR::ResponseStatus
84
+ code: 200
85
+ message: OK
86
+ headers:
87
+ x-powered-by:
88
+ - PHP/5.2.10
89
+ set-cookie:
90
+ - PHPSESSID=9a509e6a963052da2f2fbde75b0386a0; path=/
91
+ expires:
92
+ - Thu, 19 Nov 1981 08:52:00 GMT
93
+ cache-control:
94
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
95
+ pragma:
96
+ - no-cache
97
+ content-type:
98
+ - text/plain;charset=UTF-8
99
+ transfer-encoding:
100
+ - chunked
101
+ date:
102
+ - Wed, 03 Aug 2011 18:40:42 GMT
103
+ server:
104
+ - lighttpd/1.4.28
105
+ body: "true"
106
+ http_version: "1.1"
107
+ - !ruby/struct:VCR::HTTPInteraction
108
+ request: !ruby/struct:VCR::Request
109
+ method: :get
110
+ uri: https://api.emailcampaigns.net:443/2/REST/?email=factory-contact@example.com&key=%{API_KEY}&method=Contact_Delete
111
+ body:
112
+ headers:
113
+ accept:
114
+ - application/json
115
+ user-agent:
116
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
117
+ response: !ruby/struct:VCR::Response
118
+ status: !ruby/struct:VCR::ResponseStatus
119
+ code: 200
120
+ message: OK
121
+ headers:
122
+ x-powered-by:
123
+ - PHP/5.2.10
124
+ set-cookie:
125
+ - PHPSESSID=15422e85f610e927b0b4df605d54bcf5; path=/
126
+ expires:
127
+ - Thu, 19 Nov 1981 08:52:00 GMT
128
+ cache-control:
129
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
130
+ pragma:
131
+ - no-cache
132
+ content-type:
133
+ - text/plain;charset=UTF-8
134
+ transfer-encoding:
135
+ - chunked
136
+ date:
137
+ - Wed, 03 Aug 2011 18:40:54 GMT
138
+ server:
139
+ - lighttpd/1.4.28
140
+ body: "true"
141
+ http_version: "1.1"
142
+ - !ruby/struct:VCR::HTTPInteraction
143
+ request: !ruby/struct:VCR::Request
144
+ method: :get
145
+ uri: https://api.emailcampaigns.net:443/2/REST/?campaignId=40&key=%{API_KEY}&method=Campaign_Delete
146
+ body:
147
+ headers:
148
+ accept:
149
+ - application/json
150
+ user-agent:
151
+ - contactology/0.0.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
152
+ response: !ruby/struct:VCR::Response
153
+ status: !ruby/struct:VCR::ResponseStatus
154
+ code: 200
155
+ message: OK
156
+ headers:
157
+ x-powered-by:
158
+ - PHP/5.2.10
159
+ set-cookie:
160
+ - PHPSESSID=11e73c367ff0d2ed1cf4a04e495af4c3; path=/
161
+ expires:
162
+ - Thu, 19 Nov 1981 08:52:00 GMT
163
+ cache-control:
164
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
165
+ pragma:
166
+ - no-cache
167
+ content-type:
168
+ - text/plain;charset=UTF-8
169
+ transfer-encoding:
170
+ - chunked
171
+ date:
172
+ - Wed, 03 Aug 2011 18:40:55 GMT
173
+ server:
174
+ - lighttpd/1.4.28
175
+ body: "true"
176
+ http_version: "1.1"
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ class APIClient
4
+ extend Contactology::API
5
+
6
+ def self.go!
7
+ query('call', {
8
+ :on_timeout => 'timed out',
9
+ :on_error => Proc.new { |response| response['result'] },
10
+ :on_success => Proc.new { |response| 'successful' if response.kind_of?(TrueClass) }
11
+ })
12
+ end
13
+ end
14
+
15
+ class APIError
16
+ def self.call(env)
17
+ [200, {'Content-type' => 'text/plain'}, ["{\"result\":\"error\",\"message\":\"Input error: no contact found with that email\",\"code\":601}"]]
18
+ end
19
+ end
20
+
21
+ class APISuccess
22
+ def self.call(env)
23
+ [200, {'Content-type' => 'text/plain'}, ['true']]
24
+ end
25
+ end
26
+
27
+ describe Contactology::API do
28
+ context 'handlers' do
29
+ it 'executes the on_success handler for a successful response' do
30
+ WebMock.stub_request(:get, /.*/).to_rack(APISuccess)
31
+ APIClient.go!.should == 'successful'
32
+ end
33
+
34
+ it 'executes the on_error handler for an unsuccessful response' do
35
+ WebMock.stub_request(:get, /.*/).to_rack(APIError)
36
+ APIClient.go!.should == 'error'
37
+ end
38
+
39
+ it 'executes the on_timeout handler for connection timeout' do
40
+ WebMock.stub_request(:get, /.*/).to_timeout
41
+ APIClient.go!.should == 'timed out'
42
+ end
43
+ end
44
+
45
+ context '#request_headers' do
46
+ subject { APIClient.request_headers }
47
+
48
+ its(['Accept']) { should == 'application/json' }
49
+ its(['User-Agent']) { should match %r{^contactology/#{Regexp.escape(Contactology::VERSION)} \(Rubygems; Ruby #{Regexp.escape(RUBY_VERSION)} #{Regexp.escape(RUBY_PLATFORM)}\)$} }
50
+ end
51
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Contactology::Campaign do
4
+ context '.create' do
5
+ it 'raises a NotImplementedError' do
6
+ expect { Contactology::Campaign.create({}) }.to raise_error(NotImplementedError)
7
+ end
8
+ end
9
+
10
+ context '.find' do
11
+ context 'for a known campaign' do
12
+ use_vcr_cassette 'campaign/find/success'
13
+ let(:list) { Factory :list }
14
+ let(:campaign) { Factory :standard_campaign, :recipients => list }
15
+ subject { Contactology::Campaign.find campaign.id }
16
+ after(:each) { list.destroy; campaign.destroy }
17
+
18
+ it { should be_instance_of Contactology::Campaign }
19
+ end
20
+
21
+ context 'for an unknown campaign' do
22
+ use_vcr_cassette 'campaign/find/failure'
23
+ subject { Contactology::Campaign.find 123456789 }
24
+
25
+ it { should be_nil }
26
+ end
27
+ end
28
+
29
+ context '.find_by_name' do
30
+ context 'for a known campaign' do
31
+ use_vcr_cassette 'campaign/find_by_name/success'
32
+ let(:list) { Factory :list }
33
+ let(:campaign) { Factory :standard_campaign, :recipients => list, :name => 'test-find-by-name' }
34
+ after(:each) { list.destroy; campaign.destroy }
35
+ subject { Contactology::Campaign.find_by_name campaign.name }
36
+
37
+ it { should be_instance_of Contactology::Campaign }
38
+ its(:name) { should == campaign.name }
39
+ end
40
+
41
+ context 'for an unknown campaign' do
42
+ use_vcr_cassette 'campaign/find_by_name/failure'
43
+ subject { Contactology::Campaign.find_by_name 'unknown' }
44
+
45
+ it { should be_nil }
46
+ end
47
+ end
48
+
49
+ context '#destroy' do
50
+ use_vcr_cassette 'campaign/destroy'
51
+ let(:list) { Factory :list }
52
+ let(:campaign) { Factory :standard_campaign, :recipients => list }
53
+
54
+ subject { list.destroy; campaign.destroy }
55
+
56
+ it 'removes the campaign from Contactology' do
57
+ expect { subject }.to change { Contactology::Campaign.find campaign.id }.to(nil)
58
+ end
59
+
60
+ it { should be_true }
61
+ end
62
+
63
+ context '#preview' do
64
+ use_vcr_cassette 'campaign/preview', :record => :new_episodes
65
+ let(:campaign) { Factory :transactional_campaign }
66
+ after(:each) { campaign.destroy }
67
+
68
+ subject { campaign.preview }
69
+
70
+ it { should be_kind_of Contactology::Campaign::Preview }
71
+ its(:text) { should_not be_nil }
72
+ its(:html) { should_not be_nil }
73
+ its(:links) { should be_kind_of Enumerable }
74
+ end
75
+ end