所以,这是我的问题。我有一个名为AdminNotifications的模型。它属于AdminUser模型。有一个QuorumAdminNotification模型,它继承自使用STI的AdminNotification。它目前是空的。当我运行我的规范时,我在所有测试中都会出现此错误:
Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: PG::Error: ERROR: column "admin_user" of relation "admin_notifications" does not exist LINE 1: ...admin_notifications" ("type", "event", "message", "admin_use... ^ : INSERT INTO "admin_notifications" ("type", "event", "message", "admin_user", "created_at", "updated_at", "id") VALUES
('Quorum','达到','已达到Quorum','admin','2012-08-28 14:50:43','2012-08-28 14:50:43',853808134)
如果我将继承列设置为不存在的列,则所有测试都会通过。
有谁知道为什么会这样?
以下是相关代码:
应用程序/模型/ admin_notification.rb
class AdminNotification < ActiveRecord::Base
belongs_to :admin_user
attr_accessible :message, :model, :record_id, :type
scope :addressed, where('admin_user_id IS NOT NULL')
scope :unaddressed, where('admin_user_id IS NULL')
def addressed?
!admin_user.nil?
end
end
规格/模型/ admin_notification_spec.rb
describe AdminNotification do
fixtures :admin_notifications
describe "#addressed?" do
it "should return false if admin_user is not set" do
AdminNotification.new.should_not be_addressed
end
it "should return true when admin_user is set" do
notification = AdminNotification.new
notification.stub(:admin_user).and_return(mock(AdminUser, nil?: false))
notification.should be_addressed
end
end
describe "addressed scope" do
it "returns all addressed notifications" do
AdminNotification.addressed.should == admin_notifications(:addressed1, :addressed2)
end
end
describe "unaddressed scope" do
it "returns all unaddressed notifications" do
AdminNotification.unaddressed.should == admin_notifications(:unaddressed1, :unaddressed2)
end
end
end
规格/装置/ admin_notification.yml
unaddressed1:
type: Quorum
event: reached
message: "Quorum has been reached"
unaddressed2:
type: Quorum
event: test
message: "Test message"
addressed1:
type: Quorum
event: reached
message: "Quorum has been reached"
admin_user: admin
addressed2:
type: Quorum
event: reached
message: "Quorum has been reached"
admin_user: admin
应用程序/规格/ admin_users.yml
admin:
email: admin@example.com
password: password
password_confirmation: password
谢谢!
答案 0 :(得分:0)
修正了它。
问题在于灯具中的类型字段
应该是
QuorumAdminNotification
不
仲裁