【发布时间】:2018-01-16 17:55:51
【问题描述】:
我正在使用 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
当我运行 bundle exec rspec 时,它会抛出一个错误
Image should serialize :path
Failure/Error: it { should serialize(:path) }
NoMethodError:
undefined method `cast_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x000000064a81d8>
谁能解决这个问题
【问题讨论】:
-
看起来这是 GitHub 中的一个已知问题,PR 于 15 天前合并到他们的 rails 5 分支中......看起来 gem 的最后一次更新是大约 30 天前,所以可能不得不手动应用该补丁
标签: ruby-on-rails postgresql activerecord rspec shoulda