Skip to content

Commit

Permalink
Merge pull request #265 from rohan-techfreak/rohankh-patch-1
Browse files Browse the repository at this point in the history
Fix #246, Modified Mail Class calling with SendGrid::Mail
  • Loading branch information
thinkingserious authored Oct 22, 2018
2 parents 046a098 + c6d3a3a commit ce266bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion USE_CASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ I hope you are having a great day in -city- :)
require 'sendgrid-ruby'
include SendGrid

mail = Mail.new
mail = SendGrid::Mail.new
mail.from = Email.new(email: '[email protected]')
mail.subject = 'I\'m replacing the subject tag'
personalization = Personalization.new
Expand Down
4 changes: 2 additions & 2 deletions examples/helpers/mail/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def hello_world
subject = 'Hello World from the SendGrid Ruby Library'
to = Email.new(email: '[email protected]')
content = Content.new(type: 'text/plain', value: 'some text here')
mail = Mail.new(from, subject, to, content)
mail = SendGrid::Mail.new(from, subject, to, content)
# puts JSON.pretty_generate(mail.to_json)
puts mail.to_json

Expand All @@ -19,7 +19,7 @@ def hello_world
end

def kitchen_sink
mail = Mail.new
mail = SendGrid::Mail.new
mail.from = Email.new(email: '[email protected]')
mail.subject = 'Hello World from the SendGrid Ruby Library'
personalization = Personalization.new
Expand Down
30 changes: 15 additions & 15 deletions test/sendgrid/helpers/mail/test_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def test_hello_world
to = Email.new(email: '[email protected]')
subject = 'Sending with SendGrid is Fun'
content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
mail = Mail.new(from, subject, to, content)
mail = SendGrid::Mail.new(from, subject, to, content)

assert_equal(mail.to_json, JSON.parse('{"from":{"email":"[email protected]"}, "subject":"Sending with SendGrid is Fun", "personalizations":[{"to":[{"email":"[email protected]"}]}], "content":[{"type":"text/plain", "value":"and easy to do anywhere, even with Ruby"}]}'))
end

def test_kitchen_sink
mail = Mail.new
mail = SendGrid::Mail.new
mail.from = Email.new(email: "[email protected]")
mail.subject = "Hello World from the SendGrid Ruby Library"
personalization = Personalization.new
Expand Down Expand Up @@ -119,39 +119,39 @@ def test_kitchen_sink
end

def test_that_personalizations_is_empty_initially
mail = Mail.new
mail = SendGrid::Mail.new
assert_equal([], mail.personalizations)
end

def test_that_contents_is_empty_initially
mail = Mail.new
mail = SendGrid::Mail.new
assert_equal([], mail.contents)
end

def test_that_attachments_is_empty_initially
mail = Mail.new
mail = SendGrid::Mail.new
assert_equal([], mail.attachments)
end

def test_that_categories_is_empty_initially
mail = Mail.new
mail = SendGrid::Mail.new
assert_equal([], mail.categories)
end

def test_add_personalization
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_personalization('foo')
assert_equal(['foo'.to_json], mail.personalizations)
end

def test_add_content
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_content('foo')
assert_equal(['foo'.to_json], mail.contents)
end

def test_add_section
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1'))
expected_json = {
"sections"=>{
Expand All @@ -170,7 +170,7 @@ def test_add_section
end

def test_add_header
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_header(Header.new(key: 'X-Test3', value: 'test3'))
expected_json = {
"headers"=>{
Expand All @@ -189,7 +189,7 @@ def test_add_header
end

def test_add_custom_arg
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_custom_arg(CustomArg.new(key: 'campaign 1', value: 'welcome 1'))
expected_json = {
"custom_args"=>{
Expand Down Expand Up @@ -223,20 +223,20 @@ def test_add_non_string_custom_arg
end

def test_add_attachment
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_attachment('foo')
assert_equal(['foo'.to_json], mail.attachments)
end

def test_add_valid_category
mail = Mail.new
mail = SendGrid::Mail.new
category = Category.new(name: 'foo')
mail.add_category(category)
assert_equal(['foo'], mail.categories)
end

def test_add_more_than_1_valid_category
mail = Mail.new
mail = SendGrid::Mail.new
category_1 = Category.new(name: 'foo')
category_2 = Category.new(name: 'bar')
mail.add_category(category_1)
Expand All @@ -245,7 +245,7 @@ def test_add_more_than_1_valid_category
end

def test_add_invalid_category
mail = Mail.new
mail = SendGrid::Mail.new
assert_raises(NoMethodError) do
mail.add_category('foo')
end
Expand Down

0 comments on commit ce266bf

Please sign in to comment.