Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_attachment supports multiple files #240

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# blastula 0.3.3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should be 0.3.4 now or any other header for development version now that 0.3.3 has been release


* The `file` argument of `add_attachment()` now supports a vector of strings (#239, thanks @shrektan for the PR).

# blastula 0.3.2

* Email content width is now customizable in the `blastula_email()` and `compose_email()` functions. The default width is now increased to 1000px (#178).
Expand Down
15 changes: 7 additions & 8 deletions R/add_attachment.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ add_attachment <- function(email,
normalizePath(mustWork = TRUE)

# Create the attachment list
attachment_list <-
list(
file_path = expanded_path,
content_type = content_type,
disposition = "attachment",
filename = filename
)
attachment_list <- Map(function(path, type, name) list(
file_path = path,
content_type = type,
disposition = "attachment",
filename = name
), expanded_path, content_type, filename, USE.NAMES = FALSE)

# Add the attachment list to `email$attachments`
email$attachments <- c(email$attachments, list(attachment_list))
email$attachments <- c(email$attachments, attachment_list)

email
}
14 changes: 14 additions & 0 deletions tests/testthat/test-compose_email.R
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rich-iannone you may want to consider to use withr for your tests - it is really useful for such usage when needing to create temp file. Everything will be cleaned up after each tests when using withr::local_tempfile() for example.

Quite a good helper package, which is install with testthat so available in testthat suits of tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea very much! I've been a bit slow to adopt withr but I do think I should take advantage of its functions that help with testing.

Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,17 @@ Here is a plot:
class = "character"
)
})

test_that("add_attachment supports multiple files", {
files <- c(tempfile(fileext = ".txt"), tempfile(fileext = ".txt"))
writeLines("file1", files[1])
writeLines("file2", files[2])
email <- compose_email("test")
out1 <- add_attachment(email, files)$attachments
out2 <- local({
email <- add_attachment(email, files[1])
email <- add_attachment(email, files[2])
email$attachments
})
expect_equal(out1, out2)
})