Browse Source

allow Liquid in the recipients option

Andrew Cantino 9 years ago
parent
commit
7887fb3815
2 changed files with 5 additions and 2 deletions
  1. 1 1
      app/concerns/email_concern.rb
  2. 4 1
      spec/support/shared_examples/email_concern.rb

+ 1 - 1
app/concerns/email_concern.rb

@@ -13,7 +13,7 @@ module EmailConcern
     if options['recipients'].present?
       emails = options['recipients']
       emails = [emails] if emails.is_a?(String)
-      unless emails.all? { |email| email =~ Devise.email_regexp }
+      unless emails.all? { |email| email =~ Devise.email_regexp || email =~ /\{\{/ }
         errors.add(:base, "'when provided, 'recipients' should be an email address or an array of email addresses")
       end
     end

+ 4 - 1
spec/support/shared_examples/email_concern.rb

@@ -35,7 +35,7 @@ shared_examples_for EmailConcern do
       expect(agent).not_to be_valid
     end
 
-    it "should validate that recipients, when provided, is one or more valid email addresses" do
+    it "should validate that recipients, when provided, is one or more valid email addresses or Liquid commands" do
       agent.options['recipients'] = ''
       expect(agent).to be_valid
 
@@ -48,6 +48,9 @@ shared_examples_for EmailConcern do
       agent.options['recipients'] = ['bob@example.com']
       expect(agent).to be_valid
 
+      agent.options['recipients'] = '{{ email }}'
+      expect(agent).to be_valid
+
       agent.options['recipients'] = ['bob@example.com', 'jane@example.com']
       expect(agent).to be_valid