-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make emails serializable Fixes <#91>. * Ensure that an attachment cannot be added more than once to the same email * Add back `attachments` argument to `.def_equals` call
- Loading branch information
Showing
2 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require "json" | ||
require "./spec_helper" | ||
|
||
private class User | ||
|
@@ -84,6 +85,17 @@ private class UndeliverableEmail < Carbon::Email | |
to Carbon::Address.new("[email protected]") | ||
end | ||
|
||
private class SerializableEmail < BareMinimumEmail | ||
include JSON::Serializable | ||
|
||
MEMORY = IO::Memory.new | ||
|
||
attachment({io: MEMORY, file_name: "file.txt", mime_type: "text/plain"}) | ||
|
||
# This is to check that an attachment cannot be added more than once | ||
attachment({file_name: "file.txt", mime_type: "text/plain", io: MEMORY}) | ||
end | ||
|
||
describe Carbon::Email do | ||
it "can build a bare minimum email" do | ||
email = BareMinimumEmail.new | ||
|
@@ -153,6 +165,13 @@ describe Carbon::Email do | |
email.html_body.should contain "Email body" | ||
end | ||
|
||
it "can be serialized" do | ||
email = SerializableEmail.from_json("{}") | ||
|
||
email.attachments.size.should eq(1) | ||
email.attachments.first[:io]?.should eq(SerializableEmail::MEMORY) | ||
end | ||
|
||
context "deliverable?" do | ||
it "is not delivery it is digiorno" do | ||
email = UndeliverableEmail.new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters