Commit 2d859b46 authored by David F.'s avatar David F.
Browse files

Merge branch '62-email-valid-with-other-recipients' into '1.1.x'

Emails valid with only other recipients provided: refs #62.

See merge request CDSA33/OLIGAA!61
parents 0714d117 e17e4261
......@@ -30,7 +30,8 @@ class Email < ActiveRecord::Base
attr_accessible :sender, :recipients_by_contact_types, :other_recipients_enabled, :other_recipients, :novel_attributes, :member_id, :recipients
validates_presence_of :sender, :recipients
validates_presence_of :sender
validates_presence_of :recipients, unless: ->(email) { email.other_recipients.present? }
default_scope :order => "sent_at DESC"
scope :unsent, where(sent_at: nil)
......@@ -95,4 +96,4 @@ class Email < ActiveRecord::Base
recipients ? recipients.gsub(/\s/,'').split(/,/) : []
end
end
\ No newline at end of file
end
......@@ -56,4 +56,9 @@ OLIGAA::Application.configure do
# Expands the lines which load the assets
config.assets.debug = true
# For gem mailcatcher
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
end
......@@ -34,6 +34,24 @@ describe Email do
end
it { is_expected.to validate_presence_of(:sender) }
it { is_expected.to validate_presence_of(:sender) }
describe "regarding recipients" do
it "is valid with recipients and other recipients" do
email = build :email
expect(email).to be_valid
end
it "is valid with only recipients" do
email = build :email, other_recipients: nil
expect(email).to be_valid
end
it "is valid with only other recipients" do
email = build :email, recipients: nil
expect(email).to be_valid
end
it "is not valid without recipients nor other recipients" do
email = build :email, recipients: nil, other_recipients: nil
expect(email).not_to be_valid
end
end
end
describe "scopes" do
......@@ -116,4 +134,4 @@ describe Email do
expect(email.all_recipients).to eq(%w[c1@ip.fr c2@ip.fr c3@ip.fr])
end
end
end
\ No newline at end of file
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment