Skip to content

Commit

Permalink
make fixture_file_upload work in integration tests
Browse files Browse the repository at this point in the history
Currently, `fixture_file_upload` does not work in integration test.
Because, `TestProcess` module has been include in `Session` class, but
`fixture_path` can not get from `Session` class.

Modify to include `TestProcess` in `IntegrationTest` class in order to get
correct value of `fixture_path`.
  • Loading branch information
y-yagi committed Sep 4, 2016
1 parent 55c5dff commit 333f10e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion actionpack/lib/action_dispatch/testing/integration.rb
Expand Up @@ -179,7 +179,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
Expand Down Expand Up @@ -711,6 +711,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
Expand Down
36 changes: 36 additions & 0 deletions actionpack/test/controller/integration_test.rb
Expand Up @@ -1281,3 +1281,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 333f10e

Please sign in to comment.