maily_herald 0.0.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +10 -4
  3. data/.rspec +5 -0
  4. data/Gemfile +1 -12
  5. data/Gemfile.lock +129 -82
  6. data/Guardfile +25 -0
  7. data/LICENSE +10 -0
  8. data/README.md +346 -0
  9. data/Rakefile +5 -0
  10. data/app/controllers/maily_herald/tokens_controller.rb +11 -0
  11. data/app/helpers/maily_herald/tokens_helper.rb +17 -0
  12. data/app/mailers/maily_herald/mailer.rb +91 -0
  13. data/app/models/maily_herald/dispatch.rb +76 -0
  14. data/app/models/maily_herald/list.rb +99 -0
  15. data/app/models/maily_herald/log.rb +67 -0
  16. data/app/models/maily_herald/mailing.rb +139 -7
  17. data/app/models/maily_herald/one_time_mailing.rb +26 -0
  18. data/app/models/maily_herald/periodical_mailing.rb +145 -0
  19. data/app/models/maily_herald/sequence.rb +169 -2
  20. data/app/models/maily_herald/sequence_mailing.rb +71 -0
  21. data/app/models/maily_herald/subscription.rb +67 -0
  22. data/bin/maily_herald +16 -0
  23. data/config/database.yml +5 -0
  24. data/config/locales/en.yml +6 -11
  25. data/config/routes.rb +10 -0
  26. data/config/spring.rb +1 -0
  27. data/db/migrate/20150205120443_create_maily_herald_tables.rb +53 -0
  28. data/db/migrate_legacy/20130711124555_create_maily_herald_tables.rb +67 -0
  29. data/db/migrate_legacy/20140612101023_create_lists.rb +33 -0
  30. data/lib/generators/maily_herald/install_generator.rb +3 -3
  31. data/lib/generators/templates/README +2 -0
  32. data/lib/generators/templates/maily_herald.rb +1 -0
  33. data/lib/maily_herald.rb +345 -23
  34. data/lib/maily_herald/autonaming.rb +34 -0
  35. data/lib/maily_herald/capistrano.rb +5 -0
  36. data/lib/maily_herald/capistrano/tasks.cap +67 -0
  37. data/lib/maily_herald/capistrano/tasks2.rb +20 -0
  38. data/lib/maily_herald/cli.rb +293 -0
  39. data/lib/maily_herald/condition_evaluator.rb +82 -0
  40. data/lib/maily_herald/config.rb +5 -0
  41. data/lib/maily_herald/context.rb +223 -77
  42. data/lib/maily_herald/engine.rb +17 -0
  43. data/lib/maily_herald/logging.rb +90 -0
  44. data/lib/maily_herald/manager.rb +53 -0
  45. data/lib/maily_herald/model_extensions.rb +15 -0
  46. data/lib/maily_herald/template_renderer.rb +16 -0
  47. data/lib/maily_herald/utils.rb +78 -5
  48. data/lib/maily_herald/version.rb +1 -1
  49. data/maily_herald.gemspec +17 -9
  50. data/spec/controllers/maily_herald/tokens_controller_spec.rb +81 -0
  51. data/spec/dummy/Guardfile +35 -0
  52. data/spec/dummy/app/mailers/test_mailer.rb +11 -0
  53. data/spec/dummy/app/models/product.rb +2 -0
  54. data/spec/dummy/app/models/user.rb +4 -0
  55. data/spec/dummy/app/views/test_mailer/sample_mail.text.erb +1 -0
  56. data/spec/dummy/bin/rails +10 -0
  57. data/spec/dummy/bin/rake +7 -0
  58. data/spec/dummy/bin/rspec +7 -0
  59. data/spec/dummy/bin/spring +18 -0
  60. data/spec/dummy/config/application.rb +1 -1
  61. data/spec/dummy/config/environments/development.rb +1 -0
  62. data/spec/dummy/config/environments/test.rb +1 -0
  63. data/spec/dummy/config/initializers/maily_herald.rb +103 -0
  64. data/spec/dummy/config/locales/maily_herald.en.yml +28 -0
  65. data/spec/dummy/db/migrate/20130723074347_create_users.rb +18 -0
  66. data/spec/dummy/db/schema.rb +82 -0
  67. data/spec/factories/products.rb +5 -0
  68. data/spec/factories/users.rb +11 -0
  69. data/spec/lib/context_spec.rb +41 -0
  70. data/spec/lib/maily_herald_spec.rb +32 -0
  71. data/spec/lib/utils_spec.rb +48 -0
  72. data/spec/mailers/maily_herald/mailer_spec.rb +38 -0
  73. data/spec/models/maily_herald/list_spec.rb +64 -0
  74. data/spec/models/maily_herald/log_spec.rb +36 -0
  75. data/spec/models/maily_herald/mailing_spec.rb +34 -0
  76. data/spec/models/maily_herald/one_time_mailing_spec.rb +112 -0
  77. data/spec/models/maily_herald/periodical_mailing_spec.rb +339 -0
  78. data/spec/models/maily_herald/sequence_mailing_spec.rb +18 -0
  79. data/spec/models/maily_herald/sequence_spec.rb +429 -0
  80. data/spec/models/maily_herald/subscription_spec.rb +32 -0
  81. data/spec/spec_helper.rb +31 -11
  82. metadata +199 -54
  83. data/MIT-LICENSE +0 -20
  84. data/README.rdoc +0 -3
  85. data/app/assets/images/maily_herald/.gitkeep +0 -0
  86. data/app/assets/javascripts/maily_herald/application.js +0 -15
  87. data/app/assets/stylesheets/maily_herald/application.css +0 -13
  88. data/app/helpers/maily_herald/application_helper.rb +0 -4
  89. data/app/helpers/maily_herald_helper.rb +0 -9
  90. data/app/models/maily_herald/mailing_record.rb +0 -6
  91. data/app/views/layouts/maily_herald/application.html.erb +0 -14
  92. data/db/migrate/20130711124555_create_maily_herald_tables.rb +0 -38
  93. data/lib/maily_herald/worker.rb +0 -15
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailyHerald::SequenceMailing do
4
+ before(:each) do
5
+ @sequence = MailyHerald.sequence(:newsletters)
6
+ @mailing = @sequence.mailings.first
7
+ end
8
+
9
+ describe "Validations" do
10
+ it do
11
+ @mailing.absolute_delay = nil
12
+ @mailing.should_not be_valid
13
+
14
+ @mailing.absolute_delay = ""
15
+ @mailing.should_not be_valid
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,429 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailyHerald::Sequence do
4
+ before(:each) do
5
+ @sequence = MailyHerald.sequence(:newsletters)
6
+ @sequence.should be_a MailyHerald::Sequence
7
+ @sequence.should_not be_a_new_record
8
+ @sequence.start_at.should eq("user.created_at")
9
+ @sequence.mailings.length.should eq(3)
10
+
11
+ @list = @sequence.list
12
+ @list.name.should eq "generic_list"
13
+ end
14
+
15
+ after(:all) do
16
+ Timecop.return
17
+ end
18
+
19
+ describe "Subscriptions" do
20
+ before(:each) do
21
+ @entity = FactoryGirl.create :user
22
+ @list.subscribe! @entity
23
+ end
24
+
25
+ it "should find or initialize sequence subscription" do
26
+ subscription = @sequence.subscription_for @entity
27
+ subscription.should be_valid
28
+ subscription.should_not be_a_new_record
29
+ subscription.should be_a(MailyHerald::Subscription)
30
+ subscription.should be_active
31
+ end
32
+
33
+ it "should find or initialize sequence subscription via mailing" do
34
+ subscription = @sequence.mailings.first.subscription_for @entity
35
+ subscription.should be_valid
36
+ subscription.should_not be_a_new_record
37
+ subscription.should be_a(MailyHerald::Subscription)
38
+ subscription.should eq(@sequence.subscription_for(@entity))
39
+ subscription.should be_active
40
+ end
41
+ end
42
+
43
+ describe "Updating schedules" do
44
+ before(:each) do
45
+ @entity = FactoryGirl.create :user
46
+ @list.subscribe! @entity
47
+ @subscription = @list.subscription_for(@entity)
48
+ @mailing = @sequence.next_mailing(@entity)
49
+ end
50
+
51
+ after(:each) do
52
+ @mailing.enable!
53
+ end
54
+
55
+ it "should be triggered by disabling mailing" do
56
+ schedule = @sequence.schedule_for(@entity)
57
+
58
+ expect(schedule.processing_at.to_i).to eq((@entity.created_at + @mailing.absolute_delay).to_i)
59
+
60
+ @mailing.update_attribute :absolute_delay, 2.hours
61
+
62
+ schedule = @sequence.schedule_for(@entity)
63
+ expect(schedule.processing_at.to_i).to eq((@entity.created_at + 2.hours).to_i)
64
+
65
+ @mailing.disable!
66
+ schedule.reload
67
+ expect(schedule.mailing.id).not_to eq(@mailing.id)
68
+ expect(schedule.mailing.id).to eq(@sequence.next_mailing(@entity).id)
69
+ end
70
+ end
71
+
72
+ describe "Markup evaluation" do
73
+ before(:each) do
74
+ @entity = FactoryGirl.create :user
75
+ @list.subscribe! @entity
76
+ @orig_start_at = @sequence.start_at
77
+ end
78
+
79
+ after(:each) do
80
+ @sequence.update_attribute(:start_at, @orig_start_at)
81
+ end
82
+
83
+ it "should parse start_var" do
84
+ @entity.should be_a(User)
85
+ @sequence.processed_logs(@entity).should be_empty
86
+ @sequence.next_processing_time(@entity).should be_a(Time)
87
+ end
88
+
89
+ it "should use absolute start date if provided and greater that evaluated start date" do
90
+ @entity.should be_a(User)
91
+ time = (@entity.created_at + rand(100).days + rand(24).hours + rand(60).minutes).round
92
+ @sequence.start_at = time.to_s
93
+ @sequence.save
94
+ @sequence.next_processing_time(@entity).should be_a(Time)
95
+ @sequence.next_processing_time(@entity).should eq(time + @sequence.mailings.first.absolute_delay)
96
+
97
+ @subscription = @sequence.subscription_for(@entity)
98
+ end
99
+ end
100
+
101
+ describe "Scheduled Processing" do
102
+ before(:each) do
103
+ @entity = FactoryGirl.create :user
104
+ @template_tmp = @sequence.mailings[1].template
105
+ @list.subscribe! @entity
106
+ @subscription = @list.subscription_for(@entity)
107
+ end
108
+
109
+ after(:each) do
110
+ @sequence.mailings[1].enable!
111
+ @sequence.mailings[1].update_attribute(:conditions, nil)
112
+ @sequence.mailings[1].update_attribute(:template, @template_tmp)
113
+ end
114
+
115
+ it "should deliver mailings with delays" do
116
+ @sequence.mailings.length.should eq(3)
117
+ #@sequence.start.should be_nil
118
+
119
+ @sequence.processed_mailings(@entity).length.should eq(0)
120
+ @sequence.pending_mailings(@entity).length.should eq(@sequence.mailings.length)
121
+ @sequence.next_mailing(@entity).absolute_delay.should_not eq(0)
122
+ @sequence.next_processing_time(@entity).round.should eq((@entity.created_at + @sequence.mailings.first.absolute_delay).round)
123
+ @subscription.should_not be_a_new_record
124
+ @subscription.should be_active
125
+ #@subscription.should be_processable
126
+ @subscription.should_not be_a_new_record
127
+
128
+ Timecop.freeze @entity.created_at
129
+
130
+ @sequence.run
131
+
132
+ MailyHerald::Subscription.count.should eq(1)
133
+ MailyHerald::Log.delivered.count.should eq(0)
134
+
135
+ Timecop.freeze @entity.created_at + @sequence.mailings.first.absolute_delay
136
+
137
+ @sequence.run
138
+
139
+ MailyHerald::Subscription.count.should eq(1)
140
+ MailyHerald::Log.delivered.count.should eq(1)
141
+
142
+ @sequence.processed_mailings(@entity).length.should eq(1)
143
+ @sequence.pending_mailings(@entity).length.should eq(@sequence.mailings.length - 1)
144
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings[1])
145
+
146
+ @sequence.last_processed_mailing(@entity).should eq @sequence.mailings.first
147
+ log = @sequence.mailing_processing_log_for(@entity, @sequence.mailings.first)
148
+ log.processing_at.to_i.should eq (@entity.created_at + @sequence.mailings.first.absolute_delay).to_i
149
+
150
+ Timecop.freeze @entity.created_at + (@sequence.mailings[0].absolute_delay + @sequence.mailings[1].absolute_delay)/2.0
151
+
152
+ @sequence.run
153
+
154
+ MailyHerald::Subscription.count.should eq(1)
155
+ MailyHerald::Log.delivered.count.should eq(1)
156
+
157
+ Timecop.freeze @entity.created_at + @sequence.mailings[1].absolute_delay
158
+
159
+ @sequence.run
160
+
161
+ MailyHerald::Subscription.count.should eq(1)
162
+ MailyHerald::Log.delivered.count.should eq(2)
163
+
164
+ log = @sequence.mailing_processing_log_for(@entity, @sequence.mailings.first)
165
+ log.should be_a(MailyHerald::Log)
166
+ log.entity.should eq(@entity)
167
+
168
+ log = @sequence.mailing_processing_log_for(@entity, @sequence.mailings[1])
169
+ log.should be_a(MailyHerald::Log)
170
+ log.entity.should eq(@entity)
171
+ log.entity_email.should eq(@entity.email)
172
+ end
173
+
174
+ it "should handle processing with start date evaluated to the past date" do
175
+ @sequence.mailings.length.should eq(3)
176
+ #@sequence.start.should be_nil
177
+
178
+ start_at = @entity.created_at.round + 1.year
179
+
180
+ @sequence.processed_mailings(@entity).length.should eq(0)
181
+ @sequence.pending_mailings(@entity).length.should eq(@sequence.mailings.length)
182
+ @sequence.next_mailing(@entity).absolute_delay.should_not eq(0)
183
+ @sequence.next_processing_time(@entity).round.should eq((@entity.created_at + @sequence.mailings.first.absolute_delay).round)
184
+
185
+ Timecop.freeze start_at
186
+
187
+ @sequence.run
188
+
189
+ MailyHerald::Subscription.count.should eq(1)
190
+ MailyHerald::Log.delivered.count.should eq(1)
191
+
192
+ Timecop.freeze start_at + 1
193
+
194
+ @sequence.run
195
+
196
+ MailyHerald::Subscription.count.should eq(1)
197
+ MailyHerald::Log.delivered.count.should eq(1)
198
+
199
+ @sequence.next_processing_time(@entity).to_i.should eq((start_at - @sequence.mailings.first.absolute_delay + @sequence.pending_mailings(@entity).first.absolute_delay).to_i)
200
+ Timecop.freeze start_at - @sequence.mailings.first.absolute_delay + @sequence.pending_mailings(@entity).first.absolute_delay
201
+
202
+ @sequence.run
203
+
204
+ MailyHerald::Subscription.count.should eq(1)
205
+ MailyHerald::Log.delivered.count.should eq(2)
206
+ end
207
+
208
+ it "should calculate delivery times relatively based on existing logs" do
209
+ @sequence.mailings.length.should eq(3)
210
+ #@sequence.start.should be_nil
211
+
212
+ Timecop.freeze @entity.created_at + @sequence.mailings[0].absolute_delay
213
+
214
+ @sequence.run
215
+
216
+ MailyHerald::Log.delivered.count.should eq(1)
217
+
218
+ Timecop.freeze @entity.created_at + @sequence.mailings[2].absolute_delay
219
+
220
+ @sequence.run
221
+ @sequence.run
222
+
223
+ MailyHerald::Log.delivered.count.should eq(2)
224
+
225
+ Timecop.freeze @entity.created_at + @sequence.mailings[2].absolute_delay + (@sequence.mailings[2].absolute_delay - @sequence.mailings[1].absolute_delay)
226
+
227
+ @sequence.run
228
+
229
+ MailyHerald::Log.delivered.count.should eq(3)
230
+ end
231
+
232
+ it "should skip disabled mailings and go on with processing" do
233
+ @sequence.mailings.length.should eq(3)
234
+ #@sequence.start.should be_nil
235
+ @sequence.should be_enabled
236
+
237
+ @sequence.mailings[0].should be_enabled
238
+ @sequence.mailings[1].should be_enabled
239
+ @sequence.mailings[2].should be_enabled
240
+
241
+ @sequence.mailings[1].disable!
242
+ @sequence.mailings[1].should_not be_enabled
243
+
244
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings.first)
245
+ @sequence.pending_mailings(@entity).first.should be_enabled
246
+
247
+ Timecop.freeze @entity.created_at + @sequence.pending_mailings(@entity).first.absolute_delay
248
+
249
+ @sequence.run
250
+
251
+ MailyHerald::Log.delivered.count.should eq(1)
252
+ @sequence.processed_mailings(@entity).length.should eq(1)
253
+
254
+ @sequence.pending_mailings(@entity).should_not include(@sequence.mailings[1])
255
+ @sequence.next_mailing(@entity).should eq(@sequence.mailings[2])
256
+
257
+ Timecop.freeze @entity.created_at + @sequence.mailings[2].absolute_delay
258
+
259
+ @sequence.run
260
+
261
+ MailyHerald::Log.delivered.count.should eq(2)
262
+ @sequence.pending_mailings(@entity).should be_empty
263
+ end
264
+
265
+ it "should skip mailings with unmet conditions and create logs for them" do
266
+ @sequence.mailings[1].update_attribute(:conditions, "false")
267
+
268
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings.first)
269
+ Timecop.freeze @entity.created_at + @sequence.pending_mailings(@entity).first.absolute_delay
270
+ @sequence.run
271
+ MailyHerald::Log.processed.count.should eq(1)
272
+ MailyHerald::Log.delivered.count.should eq(1)
273
+ MailyHerald::Log.skipped.count.should eq(0)
274
+ MailyHerald::Log.error.count.should eq(0)
275
+
276
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings[1])
277
+ Timecop.freeze @entity.created_at + @sequence.pending_mailings(@entity).first.absolute_delay
278
+ @sequence.run
279
+ MailyHerald::Log.processed.count.should eq(2)
280
+ MailyHerald::Log.delivered.count.should eq(1)
281
+ MailyHerald::Log.skipped.count.should eq(1)
282
+ MailyHerald::Log.error.count.should eq(0)
283
+
284
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings[2])
285
+ Timecop.freeze @entity.created_at + @sequence.pending_mailings(@entity).first.absolute_delay
286
+ @sequence.run
287
+ MailyHerald::Log.processed.count.should eq(3)
288
+ MailyHerald::Log.delivered.count.should eq(2)
289
+ MailyHerald::Log.skipped.count.should eq(1)
290
+ MailyHerald::Log.error.count.should eq(0)
291
+ end
292
+
293
+ pending "should skip mailings with errors and create logs for them" do
294
+ @sequence.mailings[1].update_attribute(:template, "foo {{error =! here bar")
295
+
296
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings.first)
297
+ @sequence.processable?(@entity).should be_truthy
298
+ Timecop.freeze @entity.created_at + @sequence.pending_mailings(@entity).first.absolute_delay
299
+ @sequence.run
300
+ MailyHerald::Log.processed.count.should eq(1)
301
+ MailyHerald::Log.delivered.count.should eq(1)
302
+ MailyHerald::Log.skipped.count.should eq(0)
303
+ MailyHerald::Log.error.count.should eq(0)
304
+
305
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings[1])
306
+ Timecop.freeze @entity.created_at + @sequence.pending_mailings(@entity).first.absolute_delay
307
+ @sequence.run
308
+ MailyHerald::Log.processed.count.should eq(2)
309
+ MailyHerald::Log.delivered.count.should eq(1)
310
+ MailyHerald::Log.skipped.count.should eq(0)
311
+ MailyHerald::Log.error.count.should eq(1)
312
+
313
+ @sequence.pending_mailings(@entity).first.should eq(@sequence.mailings[2])
314
+ Timecop.freeze @entity.created_at + @sequence.pending_mailings(@entity).first.absolute_delay
315
+ @sequence.run
316
+ MailyHerald::Log.processed.count.should eq(3)
317
+ MailyHerald::Log.delivered.count.should eq(2)
318
+ MailyHerald::Log.skipped.count.should eq(0)
319
+ MailyHerald::Log.error.count.should eq(1)
320
+ end
321
+
322
+ end
323
+
324
+ pending "Error handling" do
325
+ before(:each) do
326
+ @old_start_at = @sequence.start_at
327
+ @sequence.update_attribute(:start_at, "")
328
+ @entity = FactoryGirl.create :user
329
+ @list.subscribe! @entity
330
+ end
331
+
332
+ after(:each) do
333
+ @sequence.update_attribute(:start_at, @old_start_at)
334
+ end
335
+
336
+ it "should handle start_var parsing errors or nil start time" do
337
+ @sequence.start_at.should eq("")
338
+ @sequence = @sequence.subscription_for @entity
339
+ @sequence.last_processing_time(@entity).should be_nil
340
+ @sequence.next_processing_time(@entity).should be_nil
341
+
342
+ Timecop.freeze @entity.created_at
343
+ @sequence.run
344
+
345
+ @sequence = @sequence.subscription_for @entity
346
+ @sequence.last_processing_time(@entity).should be_nil
347
+ @sequence.next_processing_time(@entity).should be_nil
348
+ end
349
+
350
+ pending "should allow to set start date via text field" do
351
+ datetime = "2013-01-01 10:11"
352
+
353
+ @sequence.start_at = datetime
354
+ @sequence.should be_valid
355
+ @sequence.start_at.should eq(datetime)
356
+
357
+ @sequence.start_at = ""
358
+ @sequence.should be_valid
359
+ end
360
+ end
361
+
362
+ #describe "Without autosubscribe" do
363
+ #before(:each) do
364
+ #@sequence.update_attribute(:autosubscribe, false)
365
+ #@sequence.should be_valid
366
+ #@sequence.save.should be_truthy
367
+ #@entity = FactoryGirl.create :user
368
+ #end
369
+
370
+ #after(:each) do
371
+ #@sequence.update_attribute(:autosubscribe, true)
372
+ #end
373
+
374
+ #it "should create inactive subscription" do
375
+ #subscription = @sequence.subscription_for @entity
376
+
377
+ #MailyHerald::MailingSubscription.count.should eq(0)
378
+ #MailyHerald::SequenceSubscription.count.should eq(1)
379
+ #MailyHerald::Log.count.should eq(0)
380
+
381
+ #Timecop.freeze @entity.created_at
382
+
383
+ #@sequence.run
384
+
385
+ #MailyHerald::MailingSubscription.count.should eq(0)
386
+ #MailyHerald::SequenceSubscription.count.should eq(1)
387
+ #MailyHerald::Log.count.should eq(0)
388
+ #end
389
+ #end
390
+
391
+ pending "Subscription override" do
392
+ before(:each) do
393
+ @entity = FactoryGirl.create :user
394
+ end
395
+
396
+ after(:each) do
397
+ @sequence.update_attribute(:override_subscription, false)
398
+ end
399
+
400
+ it "should be able to override subscription" do
401
+ subscription = @sequence.subscription_for @entity
402
+
403
+ subscription.should be_active
404
+
405
+ next_processing = @sequence.next_processing_time(@entity)
406
+
407
+ subscription.deactivate!
408
+ subscription.should_not be_active
409
+
410
+ @sequence.logs(@entity).count.should eq(0)
411
+ @sequence.last_processing_time(@entity).should be_nil
412
+
413
+ Timecop.freeze next_processing
414
+
415
+ @sequence.run
416
+
417
+ @sequence.logs(@entity).count.should eq(0)
418
+ @sequence.last_processing_time(@entity).should be_nil
419
+
420
+ @sequence.update_attribute(:override_subscription, true)
421
+
422
+ @sequence.run
423
+
424
+ @sequence.logs(@entity).count.should eq(1)
425
+ @sequence.last_processing_time(@entity).to_i.should eq(next_processing.to_i)
426
+ end
427
+ end
428
+
429
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailyHerald::Subscription do
4
+ before(:each) do
5
+ @entity = FactoryGirl.create :user
6
+ @mailing = MailyHerald.one_time_mailing :test_mailing
7
+ @list = @mailing.list
8
+
9
+ @subscription = @list.subscribe! @entity
10
+ end
11
+
12
+ describe "Associations" do
13
+ it "should have valid associations" do
14
+ @subscription.entity.should eq(@entity)
15
+ @subscription.list.should eq(@list)
16
+ @subscription.should be_valid
17
+ @subscription.should_not be_a_new_record
18
+ end
19
+ end
20
+
21
+ describe "Template rendering" do
22
+ it "should produce output" do
23
+ @mailing.stub(:template).and_return("test {{user.name}}")
24
+ expect(@mailing.render_template(@entity)).to eq("test #{@entity.name}")
25
+ end
26
+
27
+ it "should validate syntax" do
28
+ @mailing.stub(:template).and_return("{% if 1 =! 2 %}ok{% endif %}")
29
+ expect {@mailing.render_template(@entity)}.to raise_error
30
+ end
31
+ end
32
+ end