shrine associated model's factory does not pass FactoryBot.lint

I’m following this instruction https://shrinerb.com/docs/testing#test-data though,

factory :photo do
  image_data { TestData.image_data }
end

this factory does not pass FactoryBot.lint.

  1) FactoryBot .lint 
     Failure/Error: it { FactoryBot.lint traits: true }
     
     FactoryBot::InvalidFactoryError:
       The following factories are invalid:
     
       * photo - undefined method `to_hash' for #<String:0x000055a2fefcf3b8>
       Did you mean?  to_s (NoMethodError)
RSpec.describe 'FactoryBot' do
  describe '.lint' do
    it { FactoryBot.lint traits: true }
  end
end

I’m not sure this is an issue on shrine gem, but want to ask if anybody know how fix this?

@shrkw I suspect this is simply due to the column type you have specified in your schema. Please confirm: are you using a postgres jsonb column type or simply a string column type for your “image_data” column?

  • If you are using a jsonb, then in your test_data.rb file you must return attacher.data.
  • If you are using a string then you can simply return attacher.column_data

Any further questions, pls feel free to post.

1 Like

Oh! You’re totally right!
I’m using jsonb for image_data column but I missed the friendly comment.
I modified to attacher.data and works great fine!!
Thank you so much!!

1 Like