Lecture >- Tests
Test >- Questions
ビジネスルール
When the lecture is started, a test can be given
If a test is being given, questions can be asked
推論
Therefore questions shouldn't be asked if the lecture hasn't been started.
質問モデル
class Question
belongs_to :test
belongs_to :lecture, :through => :test
def ask_question
raise "Test not started!" unless test.started?
raise "Lecture not started!" unless lecture.started?
end
end
質問モデルの状態がテストとクラスの状態に結びついていることは明らかです。
単体テストを作成する際には、これをテストするために、この状態をすべて設定する必要があります。これは、ビジネスケースがますます複雑になるにつれて、かなり扱いにくくなります。
どうすればこの問題を回避できますか?