假设我有两个模型
class User < ActiveRecord::Base
has_many :friendships, :dependent => :destroy
has_many :followings, :through => :friendships, :foreign_key => "followed_id"
end
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :following, :class_name => "User", :foreign_key => "followed_id"
end
现在在我的 user_spec.rb 我有这个测试
it "should delete all friendships after user gets destroyed" do
@user.destroy
[@friendship].each do |friendship|
lambda do
Friendship.find(friendship)
end.should raise_error(ActiveRecord::RecordNotFound)
end
end
这是测试 :dependent => :destroy 关系的正确位置吗?或者这是否属于friendship_spec.rb 或者我测试这两个规范中的哪一个无关紧要?