Permalink
Browse files

Merge pull request #26384 from y-yagi/make_fixture_file_upload_in_int…

…egration_test

make `fixture_file_upload` work in integration tests
  • Loading branch information...
eileencodes authored and kaspth committed Sep 4, 2016
1 parent 71487a3 commit 12c629f50b043d0919639b7aa3bfe7264f2b2b76
View
@@ -1,3 +1,7 @@
+* Make `fixture_file_upload` work in integration tests.
+
+ *Yuji Yaginuma*
+
* Add `to_param` to `ActionController::Parameters` deprecations.
In the future `ActionController::Parameters` are discouraged from being used
@@ -167,7 +167,7 @@ class Session
DEFAULT_HOST = "www.example.com"
include Minitest::Assertions
- include TestProcess, RequestHelpers, Assertions
+ include RequestHelpers, Assertions
%w( status status_message headers body redirect? ).each do |method|
delegate method, :to => :response, :allow_nil => true
@@ -686,6 +686,8 @@ def method_missing(sym, *args, &block)
# Consult the Rails Testing Guide for more.
class IntegrationTest < ActiveSupport::TestCase
+ include TestProcess
+
module UrlOptions
extend ActiveSupport::Concern
def url_options
@@ -1251,3 +1251,39 @@ def post_to_foos(as:)
end
end
end
+
+class IntegrationFileUploadTest < ActionDispatch::IntegrationTest
+ class IntegrationController < ActionController::Base
+ def test_file_upload
+ render plain: params[:file].size
+ end
+ end
+
+ def self.routes
+ @routes ||= ActionDispatch::Routing::RouteSet.new
+ end
+
+ def self.call(env)
+ routes.call(env)
+ end
+
+ def app
+ self.class
+ end
+
+ def self.fixture_path
+ File.dirname(__FILE__) + "/../fixtures/multipart"
+ end
+
+ routes.draw do
+ post "test_file_upload", to: "integration_file_upload_test/integration#test_file_upload"
+ end
+
+ def test_fixture_file_upload
+ post "/test_file_upload",
+ params: {
+ file: fixture_file_upload("/mona_lisa.jpg", "image/jpg")
+ }
+ assert_equal "159528", @response.body
+ end
+end

0 comments on commit 12c629f

Please sign in to comment.