Ruby on rails 日志规范中参数数量错误(给定1,预期2)的Rspec错误
我想测试logs方法,但我不知道为什么我得到了一个错误,错误的参数数量为1,预期为2 我要测试的类:Ruby on rails 日志规范中参数数量错误(给定1,预期2)的Rspec错误,ruby-on-rails,rspec,Ruby On Rails,Rspec,我想测试logs方法,但我不知道为什么我得到了一个错误,错误的参数数量为1,预期为2 我要测试的类: class LogAdminData def initialize(admin_obj:, type:, old_data:, new_data:) @type = type @old_data = old_data @new_data = new_data.except(%w[created_at updated_at]) @admin_email = ad
class LogAdminData
def initialize(admin_obj:, type:, old_data:, new_data:)
@type = type
@old_data = old_data
@new_data = new_data.except(%w[created_at updated_at])
@admin_email = admin_obj.email
@admin_role = admin_obj.role
end
def call
log_admin_data!
end
private
attr_reader :type, :old_data, :new_data, :admin_email, :admin_role
def log_admin_data!
AdminPanelLog.update(
admin_email: admin_email,
admin_role: admin_role,
type: type,
new_data: new_data,
old_data: old_data,
)
end
end
这些是规格:
RSpec.describe LogAdminData do
include_context 'with admin_user form'
let(:type) { 'Update attributes' }
let!(:admin_user) { create :admin_user, :super_admin }
describe '.call' do
subject(:admin_logs) do
described_class.new(
admin_obj: admin_user,
type: type,
old_data: admin_user_form,
new_data: admin_user_form,
).call
end
it { is_expected.to be_successful }
end
end
我认为问题在于调用方法,所以我更改了日志管理数据!并从attr_reader传递所有参数,但这不是问题所在 您必须更改AdminPanelLog.create上的AdminPanelLog.update调用,因为您创建了新记录,而没有更新现有记录
由于您有类型列,它是为ActiveRecord单表继承保留的,所以您应该通过为其设置另一列来关闭STI:
类AdminPanelLog