1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/json_params_parsing_test.rb
Matthew Draper 87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30

49 lines
1.2 KiB
Ruby

require "abstract_unit"
require "action_dispatch"
require "active_record"
class JsonParamsParsingTest < ActionDispatch::IntegrationTest
def test_prevent_null_query
# Make sure we have data to find
klass = Class.new(ActiveRecord::Base) do
def self.name; "Foo"; end
establish_connection adapter: "sqlite3", database: ":memory:"
connection.create_table "foos" do |t|
t.string :title
t.timestamps null: false
end
end
klass.create
assert klass.first
app = ->(env) {
request = ActionDispatch::Request.new env
params = ActionController::Parameters.new request.parameters
if params[:t]
klass.find_by_title(params[:t])
else
nil
end
}
assert_nil app.call(make_env("t" => nil))
assert_nil app.call(make_env("t" => [nil]))
[[[nil]], [[[nil]]]].each do |data|
assert_nil app.call(make_env("t" => data))
end
ensure
klass.connection.drop_table("foos")
end
private
def make_env(json)
data = JSON.dump json
content_length = data.length
{
"CONTENT_LENGTH" => content_length,
"CONTENT_TYPE" => "application/json",
"rack.input" => StringIO.new(data)
}
end
end