Class: Cybertrain::Test::Upload

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/test/client.rb

Overview

One file for Client#post_multipart: the name of its form field, the filename and content type a browser would send, and its bytes. As a value in an integration test’s params: (what ActionDispatch::IntegrationTest#fixture_file_upload answers) its key there names the field, so field may be "":

Examples:

png = Cybertrain::Test.binary([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0, 255])
client.post_multipart("/posts", { "authenticity_token" => token },
                      [Cybertrain::Test::Upload.new("post[cover]", "cover.png", "image/png", png)])
post posts_url, params: { post: { cover: Cybertrain::Test::Upload.new("", "../evil.png", "image/png", png) } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, filename, content_type, data) ⇒ Upload

Returns a new instance of Upload.

Parameters:

  • field (String)
  • filename (String)
  • content_type (String)
  • data (String) —

    binary bytes; see Cybertrain::Test.binary



45
46
47
48
49
50
# File 'cybertrain/test/client.rb', line 45

def initialize(field, filename, content_type, data)
  @field = field
  @filename = filename
  @content_type = content_type
  @data = data
end

Instance Attribute Details

#content_type ⇒ String (readonly)

Returns the declared Content-Type of the part.

Returns:

  • (String) —

    the declared Content-Type of the part



34
35
36
# File 'cybertrain/test/client.rb', line 34

def content_type
  @content_type
end

#data ⇒ String (readonly)

Returns the file’s bytes (binary).

Returns:

  • (String) —

    the file’s bytes (binary)



38
39
40
# File 'cybertrain/test/client.rb', line 38

def data
  @data
end

#field ⇒ String (readonly)

Returns the form field name, as in post[cover].

Returns:

  • (String) —

    the form field name, as in post[cover]



26
27
28
# File 'cybertrain/test/client.rb', line 26

def field
  @field
end

#filename ⇒ String (readonly)

Returns the filename the browser reports.

Returns:

  • (String) —

    the filename the browser reports



30
31
32
# File 'cybertrain/test/client.rb', line 30

def filename
  @filename
end