Params not permitted when using active storage
Opened this issue · 0 comments
benkoshy commented
Steps to Reproduce
I have created a minimal rails app - via Github. Here it is: https://github.com/BKSpurgeon/active-storage-test
There is a User model. We make use of the active storage gem to load an 'avatar' of the user.
The problem: in summary, the specs are not passing, when they should.
Expected Behaviour
Both of the following specs should succeed:
## spec/requests/user_spec.rb
require 'rails_helper'
RSpec.describe "Users", type: :request do
describe "it attaches uploaded files" do
it 'attaches the uploaded file' do
file = fixture_file_upload(Rails.root.join('public', 'avatar.jpg'), 'image/jpg')
expect {
post api_users_path, params: { user: {username: "Ben", avatar: file } }
}.to change(ActiveStorage::Attachment, :count).by(1)
end
end
end
## spec/acceptance/api/users_controller_spec.rb
require 'acceptance_helper'
require 'action_dispatch/testing/test_process'
resource 'Api' do
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
header 'Host', 'example.com'
describe 'POST /api/users' do
post '/api/users' do
let(:avatar) { fixture_file_upload(Rails.root.join('public', 'avatar.jpg'), 'image/jpg') }
let(:username) { 'Test User' }
let(:params) { { user: { username: username, avatar: avatar } } }
context 'with avatar' do
it { expect { do_request(params) }.to change { ActiveStorage::Attachment.count }.from(0).to(1) }
endruby 2.6.3p62
end
end
end
Actual Behaviour
Only one of the specs pass: the request spec passes, but the controller spec does not pass.
System Configuration
Rails version: 5.2.3
Ruby Version: ruby 2.6.3p62