{"id":551,"date":"2022-08-30T15:03:14","date_gmt":"2022-08-30T15:03:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/ruby-soundcloud-gem-cannot-test-uploaded-file-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:03:14","modified_gmt":"2022-08-30T15:03:14","slug":"ruby-soundcloud-gem-cannot-test-uploaded-file-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/ruby-soundcloud-gem-cannot-test-uploaded-file-collection-of-common-programming-errors\/","title":{"rendered":"Ruby Soundcloud Gem: Cannot Test Uploaded File-Collection of common programming errors"},"content":{"rendered":"<p>Haven&#8217;t seen much on testing for the soundcloud gem. Most everything has been splendid &#8211; however I found that uploading files to SoundCloud through my specs is a bit tricky.<\/p>\n<p>Here&#8217;s the problem:<\/p>\n<p>spec:<\/p>\n<pre><code>file = \"#{Rails.root}\/spec\/factories\/files\/sample.mp3\"\ntitle = \"From the test suite\"\ntrack = @client.post('\/tracks', track: {title: title, asset_data: File.new(file)})\n<\/code><\/pre>\n<p>Whether or not I use<\/p>\n<pre><code>File.new\n<\/code><\/pre>\n<p>or<\/p>\n<pre><code>File.expand_path\n<\/code><\/pre>\n<p>the error is the same: <strong>NoMethodError: undefined method `map&#8217; for #String:0x007fa1ce8425c0<\/strong><\/p>\n<p>The successful code in the controller is:<\/p>\n<pre><code>file = params[\"soundcloud_file\"]\ntitle = params[\"title\"]\ntrack = client.post('\/tracks', track: {\n  title: title\n  asset_data: File.new(file.tempfile, 'rb')\n  })\n<\/code><\/pre>\n<p>Now I understand that params[&#8220;soundcloud_file&#8221;] is an ActionDispatch::Http::UploadedFile, so that&#8217;s what I&#8217;ve been attempting to work with for the past hour or so with no luck.<\/p>\n<p>I&#8217;m open to any way to successfully test an upload.<\/p>\n<ol>\n<li>\n<p>The problem was with the &#8216;webmock&#8217; gem. Even using the required version for VCR (<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:50:42. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Haven&#8217;t seen much on testing for the soundcloud gem. Most everything has been splendid &#8211; however I found that uploading files to SoundCloud through my specs is a bit tricky. Here&#8217;s the problem: spec: file = &#8220;#{Rails.root}\/spec\/factories\/files\/sample.mp3&#8221; title = &#8220;From the test suite&#8221; track = @client.post(&#8216;\/tracks&#8217;, track: {title: title, asset_data: File.new(file)}) Whether or not I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}