Skip to content

Instantly share code, notes, and snippets.

@ise
Created March 15, 2021 08:04
Show Gist options
  • Save ise/5e5c2d6eaca5df8258c57b03707326ab to your computer and use it in GitHub Desktop.
Save ise/5e5c2d6eaca5df8258c57b03707326ab to your computer and use it in GitHub Desktop.
rails params
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "rails", "6.1.0"
end
require "rack/test"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
post "/" => "test#create"
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def create
render json: params
end
end
require "minitest/autorun"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
data = [
{
"b" => 20,
"c" => 30
},
{
"a" => 10
}
]
post "/", params: {
data: data
}
assert last_response.ok?
result = JSON.parse(last_response.body).dig("params", "data")
assert_equal data, result
end
private
def app
Rails.application
end
end
__END__
# Running:
I, [2021-03-15T08:00:07.920027 #1] INFO -- : Started POST "/" for 127.0.0.1 at 2021-03-15 08:00:07 +0000
F
Failure:
BugTest#test_returns_success [tmp/params_test.rb:60]:
--- expected
+++ actual
@@ -1 +1 @@
-[{"b"=>20, "c"=>30}, {"a"=>10}]
+[{"b"=>"20", "c"=>"30", "a"=>"10"}]
rails test tmp/params_test.rb:44
Finished in 0.332642s, 3.0062 runs/s, 6.0125 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment