序列化时 RSPEC 活动记录测试错误



我正在使用 rspec 来测试我的模型,该模型应该序列化 json。 顺便说一句,这是我的控制台中显示错误

这是我的 RSPEC 需要"rails_helper">

RSpec.describe Image, type: :model do
it { should belong_to :user }
it { should serialize(:path) }
end

这是我的图像模型

class Image < ApplicationRecord
belongs_to :user
attr_accessor :imagepath_data
serialize :path, JSON
mount_uploader :path, ImageUploader
end

当我运行捆绑执行 rspec 时,它会抛出错误

Image should serialize :path
Failure/Error: it { should serialize(:path) }
NoMethodError:
undefined method `cast_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x000000064a81d8>

任何人都可以解决这个问题吗

我相信你需要更新shoulda-mathcers

https://github.com/thoughtbot/shoulda-matchers/pull/965/commits/91c1d6a63ee80a1c024da45cf40451dac3aa9bed

最新更新