Browse Source

Allow Liquid logic in recipients too

Andrew Cantino 9 years ago
parent
commit
7e70d507b4
2 changed files with 6 additions and 3 deletions
  1. 2 2
      app/concerns/email_concern.rb
  2. 4 1
      spec/support/shared_examples/email_concern.rb

+ 2 - 2
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 || email =~ /\{\{/ }
+      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
@@ -52,4 +52,4 @@ module EmailConcern
   def present_hash(hash, skip_key = nil)
     hash.to_a.sort_by {|a| a.first.to_s }.map { |k, v| "#{k}: #{v}" unless k.to_s == skip_key.to_s }.compact
   end
-end
+end

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

@@ -51,6 +51,9 @@ shared_examples_for EmailConcern do
       agent.options['recipients'] = '{{ email }}'
       expect(agent).to be_valid
 
+      agent.options['recipients'] = '{% if x %}a@x{% else %}b@y{% endif %}'
+      expect(agent).to be_valid
+
       agent.options['recipients'] = ['bob@example.com', 'jane@example.com']
       expect(agent).to be_valid
 
@@ -88,4 +91,4 @@ shared_examples_for EmailConcern do
       expect(agent.recipients('username' => 'bob', 'domain' => 'example.com')).to eq(["bob@example.com"])
     end
   end
-end
+end