-
Notifications
You must be signed in to change notification settings - Fork 552
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
Handle file
objects like file_upload
#689
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class FileTest < Test::Unit::TestCase | ||
should "be listable" do | ||
files = Stripe::File.list | ||
assert_requested :get, "#{Stripe.api_base}/v1/files" | ||
assert files.data.is_a?(Array) | ||
assert files.data[0].is_a?(Stripe::File) | ||
end | ||
|
||
should "be retrievable" do | ||
file = Stripe::File.retrieve("file_123") | ||
assert_requested :get, "#{Stripe.api_base}/v1/files/file_123" | ||
assert file.is_a?(Stripe::File) | ||
end | ||
|
||
context ".create" do | ||
setup do | ||
# We don't point to the same host for the API and uploads in | ||
# production, but `stripe-mock` supports both APIs. | ||
Stripe.uploads_base = Stripe.api_base | ||
|
||
# Set `api_base` to `nil` to ensure that these requests are _not_ sent | ||
# to the default API hostname. | ||
Stripe.api_base = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit awkward, but it's necessary because if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. It may be worth adding a comment that notes that |
||
end | ||
|
||
should "be creatable with a File" do | ||
file = Stripe::File.create( | ||
purpose: "dispute_evidence", | ||
file: ::File.new(__FILE__) | ||
) | ||
assert_requested :post, "#{Stripe.uploads_base}/v1/files" | ||
assert file.is_a?(Stripe::File) | ||
end | ||
|
||
should "be creatable with a Tempfile" do | ||
tempfile = Tempfile.new("foo") | ||
tempfile.write("Hello world") | ||
tempfile.rewind | ||
|
||
file = Stripe::File.create( | ||
purpose: "dispute_evidence", | ||
file: tempfile | ||
) | ||
assert_requested :post, "#{Stripe.uploads_base}/v1/files" | ||
assert file.is_a?(Stripe::File) | ||
end | ||
|
||
should "be creatable with Faraday::UploadIO" do | ||
file = Stripe::File.create( | ||
purpose: "dispute_evidence", | ||
file: Faraday::UploadIO.new(::File.new(__FILE__), nil) | ||
) | ||
assert_requested :post, "#{Stripe.uploads_base}/v1/files" | ||
assert file.is_a?(Stripe::File) | ||
end | ||
end | ||
|
||
should "be deserializable when `object=file`" do | ||
file = Stripe::Util.convert_to_stripe_object({ object: "file" }, {}) | ||
assert file.is_a?(Stripe::File) | ||
end | ||
|
||
should "be deserializable when `object=file_upload`" do | ||
file = Stripe::Util.convert_to_stripe_object({ object: "file_upload" }, {}) | ||
assert file.is_a?(Stripe::File) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may eventually want to rename this to
files_base
for consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought of that but was afraid it should count as a breaking change. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, true (although hopefully no one's overriding this). It does seem less churnful to just leave it for now though, so NM. If we ever feel strongly about it later, we can always change it then.