Ruby on rails Rails 6 ActiveStorage-参数中不允许使用测试夹具文件上传()

Ruby on rails Rails 6 ActiveStorage-参数中不允许使用测试夹具文件上传(),ruby-on-rails,image,integration-testing,ruby-on-rails-6,Ruby On Rails,Image,Integration Testing,Ruby On Rails 6,我试图通过上传一个图像来测试我的控制器,但是在我的集成测试中,这个参数是不允许的。我做错什么了吗?我正在使用最新的Rails 6.0.2.1。下面是我的测试和我的控制器 测试 test "should return error" do image = fixture_file_upload(file_fixture('avatar.jpg'), 'image/jpg') put organisation_images_path(@organiser), params: {

我试图通过上传一个图像来测试我的控制器,但是在我的集成测试中,这个参数是不允许的。我做错什么了吗?我正在使用最新的Rails 6.0.2.1。下面是我的测试和我的控制器

测试

test "should return error" do
  image = fixture_file_upload(file_fixture('avatar.jpg'), 'image/jpg')
  put organisation_images_path(@organiser), 
      params: { organiser: { avatar: image } },
      as: :json

  assert_response :success
end
控制器

def update
  if @organiser.update(org_params)
    render json: {url: url_for(@organiser.avatar)}
  else
    render json: {errors: @organiser.errors.full_messages}, status: :unprocessable_entity
  end
end

private
def org_params
  params.require(:organiser).permit(:avatar)
end
参数

<ActionController::Parameters {"organiser"=><ActionController::Parameters {"avatar"=><ActionController::Parameters {"original_filename"=>"avatar.jpg", "tempfile"=>"#<File:0x00007f8469065b40>", "content_type"=>"image/jpg"} permitted: false>} permitted: false>, "controller"=>"resources/images", "action"=>"update", "organisation_id"=>"123", "image"=>{"organiser"=>{"cover"=>{"original_filename"=>"avatar.jpg", "tempfile"=>"#<File:0x00007f8469065b40>", "content_type"=>"image/jpg"}}}} permitted: false>
“avatar.jpg”、“tempfile”=>“#”、“content\u type”=>“image/jpg”}允许:false>、允许:false>、“controller”=>“resources/images”、“action”=>“update”、“organization\u id”=>“123”、“image”=>{“organizer”=>{“cover”=>{“original\u filename”=>“avatar.jpg”、“tempfile”=>、“content\u type”=>“image/jpg”}允许:false>

正如您所看到的,
avatar
参数是不允许的,这是在我第一次调用
org_params
之后发生的。

如果您以任何其他方式发送JSON请求,这是否真的有效?如果fixture_file_upload能够像多部分表单那样工作,我会感到惊讶。我正在使用javascript(StimulusJS)发送参数,并使用
Rails.ajax
发送
dataType
设置为
json
的数据。
data
是通过
FormData()
对象创建的。您将如何测试这一点?我猜当您发送ajax请求时,内容实际上是表单数据,并且内容配置是多部分的,这将解释为什么它会工作。使用JSON发送文件实际上相当麻烦,因为您必须对它们进行base64编码。如果没有运行js.OK的系统测试,我不太确定如何测试它。非常感谢。我可能会在没有as::json的情况下进行集成测试,然后像你说的那样使用系统测试来运行JS。如果你以任何其他方式发送json请求,这真的有效吗?如果fixture_file_upload能够像多部分表单那样工作,我会感到惊讶。我正在使用javascript(StimulusJS)发送参数,并使用
Rails.ajax
发送
dataType
设置为
json
的数据。
data
是通过
FormData()
对象创建的。您将如何测试这一点?我猜当您发送ajax请求时,内容实际上是表单数据,并且内容配置是多部分的,这将解释为什么它会工作。使用JSON发送文件实际上相当麻烦,因为您必须对它们进行base64编码。如果没有运行js.OK的系统测试,我不太确定如何测试它。非常感谢。我可能会在不使用as::json的情况下进行集成测试,然后像您所说的那样使用系统测试来运行JS。