Skip to content
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

Support rack 2 #151

Merged
merged 2 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pkg
doc
coverage
Gemfile.lock
/Gemfile*.lock
VERSION
*.rbc
.bundle
*.swp
/.bundle
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ language: ruby
sudo: false
before_install:
- which bundle || gem install bundler
script:
- bundle list
- bundle exec rake
rvm:
- 2.2.7
- 2.3.4
- 2.4.1
- ruby-head
- jruby-9.1.8.0
- jruby-head
gemfile:
- Gemfile
- Gemfile.rack-1.x
matrix:
allow_failures:
- rvm: ruby-head
Expand Down
15 changes: 11 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
source 'https://rubygems.org'

gem 'rspec'
gem "rack"
gem "sinatra"
gemspec

# Development dependency
gem 'rake'
gem 'rspec'
# To use rack 2
gem 'sinatra', '~> 2.0.0.rc2'
# Keep version < 1 to supress deprecated warning temporary.
gem 'codeclimate-test-reporter', '< 1', :require => false

gem "codeclimate-test-reporter", group: :test, require: nil
# For Thorfile. Run "bundle exec thor help" to see the help.
gem 'thor'
gem 'git'
49 changes: 0 additions & 49 deletions Gemfile.lock

This file was deleted.

13 changes: 13 additions & 0 deletions Gemfile.rack-1.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
source 'https://rubygems.org'

gemspec

# Runtime dependency
gem 'rack', '< 2'

# Development dependency
gem 'rake'
gem 'rspec'
gem 'sinatra'
# Keep version < 1 to supress deprecated warning temporary.
gem 'codeclimate-test-reporter', '< 1', :require => false
14 changes: 7 additions & 7 deletions spec/rack/test/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
:input => StringIO.new(data)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params = Rack::Multipart.parse_multipart(env)
Copy link
Contributor

@perlun perlun May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junaruga Does the Rack::Multipart class/module exist in Rack 1.x as well? I mean, is this approach fine with both Rack versions?

Copy link
Contributor Author

@junaruga junaruga May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@perlun yes it exists in Rack 1.x too. Yes it is fine for both rack 1.x and 2.x. Because Rack::Multipart exists in both versions.

This modification is because rack project have just deleted the code to access from Rack::Utils to Multipart from rack 2.x.

Below are the commit in rack. and You can also see this kind of modification (replacement) in the commit.

rack/rack@b2d7396

$ git show b2d73960e9ea6b8b15321ef190f13a290d1aedf0 lib/rack/utils.rb
...
-    Multipart = Rack::Multipart
-
...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, great. Then I will approve and merge this now. Thanks @junaruga!

check expect(params["submit-name"]).to eq("Larry")
check expect(params["files"][:filename]).to eq("foo.txt")
expect(params["files"][:tempfile].read).to eq("bar\n")
Expand All @@ -82,7 +82,7 @@
:input => StringIO.new(data)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params = Rack::Multipart.parse_multipart(env)
check expect(params["submit-name"]).to eq("Larry")

check expect(params["files"][0][:filename]).to eq("foo.txt")
Expand All @@ -102,7 +102,7 @@
:input => StringIO.new(data)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params = Rack::Multipart.parse_multipart(env)
check expect(params["people"][0]["submit-name"]).to eq("Larry")
check expect(params["people"][0]["files"][:filename]).to eq("foo.txt")
expect(params["people"][0]["files"][:tempfile].read).to eq("bar\n")
Expand All @@ -119,7 +119,7 @@
:input => StringIO.new(data)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params = Rack::Multipart.parse_multipart(env)
check expect(params["files"][:filename]).to eq("foo.txt")
expect(params["files"][:tempfile].read).to eq("bar\n")
check expect(params["foo"]).to eq([{"id" => "1", "name" => "Dave"}, {"id" => "2", "name" => "Steve"}])
Expand All @@ -137,7 +137,7 @@
:input => StringIO.new(data)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params = Rack::Multipart.parse_multipart(env)
check expect(params["files"][:filename]).to eq("foo.txt")
expect(params["files"][:tempfile].read).to eq("bar\n")
check expect(params["foo"]).to eq({"bar" => [{"id" => "1", "name" => "Dave"},
Expand All @@ -155,7 +155,7 @@
:input => StringIO.new(data)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params = Rack::Multipart.parse_multipart(env)
check expect(params["files"][0][:filename]).to eq("foo.txt")
expect(params["files"][0][:tempfile].read).to eq("bar\n")
check expect(params["foo"][0]).to eq("1")
Expand All @@ -173,7 +173,7 @@
:input => StringIO.new(data)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params = Rack::Multipart.parse_multipart(env)
check expect(params["foo"][0]["id"]).to eq("1")
check expect(params["foo"][0]["data"][:filename]).to eq("foo.txt")
expect(params["foo"][0]["data"][:tempfile].read).to eq("bar\n")
Expand Down