kreeti / kt-paperclip

Easy file attachment management for ActiveRecord
Other
276 stars 94 forks source link

Error during migration from Ruby 3.0.x to 3.1.x #102

Closed guillaumebriday-pa closed 1 year ago

guillaumebriday-pa commented 1 year ago

Hi 👋

First thanks for this fork and the work you're doing!

Everything was running smoothly until I tried to upgrade my app from Ruby 3.0.x to Ruby 3.1.x. I changed nothing else than the ruby version and the method validates_attachment_content_type starts to fail with this error:

Screenshot 2022-12-06 at 09 33 12

I have no idea why, the data look correct but the record cannot be save

Any idea why?

Thanks in advance

josh-m-sharpe commented 1 year ago

Getting the same thing. Came here to find this bug report.

class PushNotificationMemberList < ApplicationRecord
  belongs_to :push_notification

  has_attached_file :csv, s3_permissions: :private

  validates_attachment :csv,
    content_type: { content_type: ["text/csv", "text/plain"] }
FactoryBot.define do
  factory :push_notification_member_list do
    push_notification

    after(:build) do |pnml|
      pnml.csv = Rack::Test::UploadedFile.new("test/fixtures/test_member_list.csv")
      pnml.csv_content_type = 'text/csv'
    end
  end
end
* push_notification_member_list - Validation failed: Csv has contents that are not what they are reported to be (ActiveRecord::RecordInvalid)
    test/models/factory_lint_test.rb:5:in `block in <class:FactoryLintTest>'
matthewford commented 1 year ago

Yup seeing this too. trying to patch this with validate_media_type: false

josh-m-sharpe commented 1 year ago

Yup seeing this too. trying to patch this with validate_media_type: false

This seems like a bit of a sledgehammer.


In my case, I am using CircleCI's docker image: https://hub.docker.com/r/cimg/ruby Turns out the 3.1.3 version of this image doesn't have file installed. So I fixed with a simple apt-get install file

I think, but am not 100% positive, this would've helped: https://github.com/kreeti/kt-paperclip/pull/103

ssinghi commented 1 year ago

@josh-m-sharpe I have merged your PR, can this issue be closed now? Thanks!