0
所以,這是我的問題。我有一個名爲AdminNotifications的模型。它屬於AdminUser模型。有一個使用STI從AdminNotification繼承的QuorumAdminNotification模型。它目前是空的。當我跑我的天賦,我得到的所有測試這個錯誤:當在STI模型上運行我的規範時獲取Active :: Record :: StatementInvalid
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
(「仲裁」,「達」,「定額已經達到了」,「管理」,「2012-08-28 十四點50分43' 秒,‘2012-08-28十四點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
app/spec/admin_users.yml
admin:
email: [email protected]
password: password
password_confirmation: password
謝謝!