-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mail::YAML#load compatible with Psych 3.x and Psych 4.x.
Co-authored-by: Vít Ondruch <[email protected]>
- Loading branch information
1 parent
c08d569
commit a20fdd5
Showing
5 changed files
with
50 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'yaml' | ||
|
||
module Mail | ||
module YAML | ||
def self.load(yaml) | ||
permitted_classes = [ | ||
Symbol, | ||
|
||
Mail::Body, | ||
|
||
# Delivery methods as listed in mail/configuration.rb | ||
Mail::SMTP, | ||
Mail::Sendmail, | ||
Mail::Exim, | ||
Mail::FileDelivery, | ||
Mail::SMTPConnection, | ||
Mail::TestMailer, | ||
Mail::LoggerDelivery, | ||
|
||
Mail.delivery_method.class, | ||
] | ||
|
||
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') | ||
::YAML.safe_load(yaml, :permitted_classes => permitted_classes) | ||
else | ||
::YAML.safe_load(yaml, permitted_classes) | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -194,7 +194,7 @@ def create_mail_with_splat_args | |
|
||
it "should serialize the basic information to YAML" do | ||
yaml = @yaml_mail.to_yaml | ||
yaml_output = YAML.load(yaml) | ||
yaml_output = Mail::YAML.load(yaml) | ||
expect(yaml_output['headers']['To']).to eq "[email protected]" | ||
expect(yaml_output['headers']['Cc']).to eq "[email protected]" | ||
expect(yaml_output['headers']['Subject']).to eq "subject" | ||
|
@@ -212,7 +212,7 @@ def create_mail_with_splat_args | |
it "should serialize a Message with a custom delivery_handler" do | ||
@yaml_mail.delivery_handler = DeliveryAgent | ||
yaml = @yaml_mail.to_yaml | ||
yaml_output = YAML.load(yaml) | ||
yaml_output = Mail::YAML.load(yaml) | ||
expect(yaml_output['delivery_handler']).to eq "DeliveryAgent" | ||
end | ||
|
||
|
@@ -224,15 +224,15 @@ def create_mail_with_splat_args | |
|
||
it "should not deserialize a delivery_handler that does not exist" do | ||
yaml = @yaml_mail.to_yaml | ||
yaml_hash = YAML.load(yaml) | ||
yaml_hash = Mail::YAML.load(yaml) | ||
yaml_hash['delivery_handler'] = "NotARealClass" | ||
deserialized = Mail::Message.from_yaml(yaml_hash.to_yaml) | ||
expect(deserialized.delivery_handler).to be_nil | ||
end | ||
|
||
it "should deserialize parts as an instance of Mail::PartsList" do | ||
yaml = @yaml_mail.to_yaml | ||
yaml_hash = YAML.load(yaml) | ||
yaml_hash = Mail::YAML.load(yaml) | ||
deserialized = Mail::Message.from_yaml(yaml_hash.to_yaml) | ||
expect(deserialized.parts).to be_kind_of(Mail::PartsList) | ||
end | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# encoding: utf-8 | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
describe Mail::YAML do | ||
|
||
describe "#load" do | ||
|
||
it 'loads YAML' do | ||
expect(Mail::YAML.load('{}')).to eq({}) | ||
end | ||
end | ||
end |