robincurry-dl-fughley 0.1.1 → 0.1.2
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/VERSION.yml +1 -1
- data/lib/dl_fughley.rb +10 -7
- data/test/dl_fughley_test.rb +42 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/dl_fughley.rb
CHANGED
@@ -44,9 +44,9 @@ module DL
|
|
44
44
|
options = {
|
45
45
|
:allow => [],
|
46
46
|
:email_field => :email,
|
47
|
-
:reply_to => :sender
|
47
|
+
:reply_to => :sender
|
48
48
|
}.merge!(people.extract_options!)
|
49
|
-
|
49
|
+
|
50
50
|
people.flatten!
|
51
51
|
|
52
52
|
if (options[:allow].nil? || options[:allow].empty?) ||
|
@@ -58,7 +58,7 @@ module DL
|
|
58
58
|
email.reply_to = email.from if options[:reply_to] == :sender
|
59
59
|
email.reply_to = to if options[:reply_to] == :list
|
60
60
|
email.from = options[:from] if options[:from]
|
61
|
-
|
61
|
+
|
62
62
|
case options[:subject_prefix]
|
63
63
|
when :list_name
|
64
64
|
email.subject = "[#{list.downcase}] #{email.subject}" unless email.subject =~ /\[#{list}\]/i
|
@@ -67,15 +67,18 @@ module DL
|
|
67
67
|
else
|
68
68
|
email.subject = "[#{options[:subject_prefix]}] #{email.subject}" unless email.subject =~ /\[#{options[:subject_prefix]}\]/i
|
69
69
|
end
|
70
|
-
|
71
70
|
|
72
|
-
ActionMailer
|
71
|
+
# yield to block if given, otherwise, go ahead and send the email using ActionMailer.
|
72
|
+
if block_given?
|
73
|
+
yield person, email
|
74
|
+
else
|
75
|
+
ActionMailer::Base.deliver(email)
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
77
|
-
end
|
78
|
-
|
81
|
+
end
|
79
82
|
end
|
80
83
|
|
81
84
|
ActiveRecord::Base.send(:include, DL::Fughley)
|
data/test/dl_fughley_test.rb
CHANGED
@@ -446,6 +446,48 @@ class DlFughleyTest < ActiveSupport::TestCase
|
|
446
446
|
end
|
447
447
|
end
|
448
448
|
|
449
|
+
context "distribute" do
|
450
|
+
setup do
|
451
|
+
Factory(:person)
|
452
|
+
Person.is_dl(:all)
|
453
|
+
|
454
|
+
# Reset deliveries during setup. Otherwise they will accumulate after each test.
|
455
|
+
ActionMailer::Base.deliveries = []
|
456
|
+
|
457
|
+
@email = to_email(
|
458
|
+
:from => 'user@example.com',
|
459
|
+
:to => 'all@example.com',
|
460
|
+
:subject => 're: [all-my-peeps] test to the whole group',
|
461
|
+
:body => 'Hello everybody!')
|
462
|
+
end
|
463
|
+
|
464
|
+
context "default" do
|
465
|
+
setup do
|
466
|
+
Person.distribute(@email)
|
467
|
+
end
|
468
|
+
|
469
|
+
should "send email via ActionMailer to each member of dl" do
|
470
|
+
assert_deliveries Person.count
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
context "with block" do
|
475
|
+
setup do
|
476
|
+
@count = 0
|
477
|
+
Person.distribute(@email) {|person, email| @count = @count+1 }
|
478
|
+
end
|
479
|
+
|
480
|
+
should "yield each person and email to the block" do
|
481
|
+
assert @count == Person.count
|
482
|
+
end
|
483
|
+
|
484
|
+
should "not send via ActionMailer (unless called by block)" do
|
485
|
+
assert_deliveries 0
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
|
449
491
|
|
450
492
|
private
|
451
493
|
def to_email(values)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robincurry-dl-fughley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- robincurry
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|