1
我有兩個模型Indicator belongs_to Privacy。在rails中rspec模型測試:方法工作,但測試不會通過
在指示我寫了一個方法返回的隱私設置
def privacy
Privacy.find(privacy_tag_id).content
end
,在軌控制檯進行的適當的名稱。如果我創建一個指標,然後運行Indicator.privacy,我會返回「紅色」或「綠色」或其他。但我無法讓我的rspec通過。下面是測試
describe "indicator" do
it "should return a human named when asked for its privacy level" do
@privacy = PrivacyTag.create(:content => "Secret")
@ind = Indicator.new(:content => 'test',
:privacy_tag_id => @privacy.id)
@ind.privacy.should == "Secret"
end
end
當我運行測試,我得到這個消息:
Failures:
1) indicator should return a human named when asked for its privacy level
Failure/Error: @ind.privacy.should_equal "Secret"
ActiveRecord::RecordNotFound:
Couldn't find PrivacyTag without an ID
# ./app/models/indicator.rb:13:in `privacy'
# ./spec/models/indicator_model_spec.rb:9:in `block (2 levels) in <top (required)>'
什麼我在我的測試做錯了什麼?有任何想法嗎?
良好的驗證電話。這正是問題所在。對不起,不包括模型。 –