1
belongs_to
とhas_many
という2つのモデルを以下のようにリンクしています。RSpec使用する場合はrespond_to
Class OtherModel < ActiveRecord::Base
belongs_to my_model
end
class MyModel < ActiveRecord::Base
has_many other_models
end
以下に示す正しい関係があることを確認するためのテストがあります。
RSpec.describe MyModel, type: :model do
it {should have_many(:other_models)}
it {should respond_to(:other_models)}
end
RSpec.describe OtherModel, type: :model do
it {should have_many(:my_model)}
it {should respond_to(:my_model)}
end
この関係では、respond_to
が必要ですか? have_manyがまだチェックしていないことを確認するのは何ですか?この場合にrespond_to
が不要な場合は、適切な時期はいつですか?私の現在の理解から、have_many
は、フィールドが存在することを既に確認しており、したがって、respond_to
のチェックを廃止しました。