Skip to content

Commit

Permalink
feat: add more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
drish committed Dec 28, 2024
1 parent 2abe0f4 commit 316c230
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion spec/railtie/mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def html_only(to, subject)
end
end

def with_headers_method(to, subject)
headers["X-Entity-Ref-ID"] = "123"
mail(to: to, subject: subject) do |format|
format.text { render plain: "txt" }
format.html { render html: "<p>html</p>".html_safe }
end
end

def with_overwritten_headers(to, subject)
headers["X-Entity-Ref-ID"] = "123"
mail(to: to, subject: subject, headers: {"X-Entity-Ref-ID": "overwritten"}) do |format|
format.text { render plain: "txt" }
format.html { render html: "<p>html</p>".html_safe }
end
end

def with_attachment(to, subject)
attachments['invoice.pdf'] = {
:content => File.read('resources/invoice.pdf'),
Expand Down Expand Up @@ -64,7 +80,7 @@ class TestMailerWithDisplayName < TestMailer
expect(body[:to]).to eql(["[email protected]"])
expect(body[:html]).to eql("<p>HTML!</p>")
expect(body[:text]).to eql("text")
expect(body[:headers][:"X-Entity-Ref-ID"]).to eql("123")
expect(body[:headers]["X-Entity-Ref-ID"]).to eql("123")
end

it "properly creates a html only msg" do
Expand Down Expand Up @@ -106,5 +122,27 @@ class TestMailerWithDisplayName < TestMailer
expect(body[:to]).to eql(["[email protected]"])
expect(body[:html]).to be nil
expect(body[:text]).to eql("text")
expect(body[:headers]).to be nil
end

it "properly creates header through headers method" do
message = TestMailer.with_headers_method("[email protected]", "Test!")
body = @mailer.build_resend_params(message)
expect(body[:from]).to eql("[email protected]")
expect(body[:to]).to eql(["[email protected]"])
expect(body[:html]).to eql("<p>html</p>")
expect(body[:text]).to eql("txt")
expect(body[:headers]["X-Entity-Ref-ID"]).to eql("123")
end

it "#mail properly overwrites #headers" do
message = TestMailer.with_overwritten_headers("[email protected]", "Test!")
body = @mailer.build_resend_params(message)
expect(body[:from]).to eql("[email protected]")
expect(body[:tags]).to eql(nil)
expect(body[:to]).to eql(["[email protected]"])
expect(body[:html]).to eql("<p>html</p>")
expect(body[:text]).to eql("txt")
expect(body[:headers]["X-Entity-Ref-ID"]).to eql("overwritten")
end
end

0 comments on commit 316c230

Please sign in to comment.