私は 2 つのモデルを持っています。
インジケーターでは、プライバシー設定の適切な名前を返すメソッドを書きました
def privacy
Privacy.find(privacy_tag_id).content
end
それはレールコンソールで動作します。Indicator を作成して 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)>'
テストで何が間違っていますか? 何か案は?