0
class Horse < ActiveRecord::Base
attr_accessible :body_scores_attributes
has_many :body_scores, :dependent => :destroy
accepts_nested_attributes_for :body_scores, :reject_if => :reject_body_scores
private
def reject_body_scores(attributed)
new_record? || attributed['date'].blank? || attributed['score'].blank?
end
end
和如何为reject_body_scores(归因)方法编写测试代码?
class BodyScore < ActiveRecord::Base
attr_accessible :horse_id, :score, :scoring_date
belongs_to :horse
validates :horse_id, :score, :scoring_date, :presence => true
end
感谢您的回复。我在编写测试代码方面很新,所以这帮助我更好地理解。 – nbh