このファクトリを使用して、テスト用のクイズを作成しています。
factory :quiz_with_two_choices_first_correct, :class => Quiz do |i|
quiz_type Quiz.SINGLE_ANSWER_CHOICE
weight 1
i.after_create do |quiz|
quiz.quiz_choices = [FactoryGirl.create(:quiz_choice, :body=>'Quiz Choice 1', :is_correct=>true, :position=>1),
FactoryGirl.create(:quiz_choice, :body=>'Quiz Choice 2', :is_correct=>false, :position=>2)]
end
end
私のクイズモデルには次のものがあります。
after_create { |record|
if !current_unit.nil? then
if current_unit_type.eql? FinalExam.to_s then
current_unit.total_weights=
current_unit.total_weights+ record.weight
current_unit.save
end
end
}
しかし、テストしようとすると、次のエラーが発生します。
Failure/Error: quiz= FactoryGirl.create(:quiz_with_two_choices)
NoMethodError:
undefined method `after_create=' for #<Quiz:0xb50075c>
これが私のテストです:
describe "When a final question is created" do
it "can't be deleted if any student is enrolled to it" do
quiz= FactoryGirl.create(:quiz_with_two_choices)
final_question = FinalExamQuestion.create(:quiz_id=>quiz.id)
quiz_count_before_try_to_destroy_quiz= Quiz.all.count
quiz.destroy
Quiz.all.count.should == quiz_count_before_try_to_destroy_quiz
end
it "can be deleted if there isn't any student enrolled to it" do
quiz= FactoryGirl.create(:quiz_with_two_choices)
quiz_count_before_try_to_destroy_quiz= Quiz.all.count
quiz.destroy
Quiz.all.count.should_not == quiz_count_before_try_to_destroy_quiz
end
end
それで、何が間違っているのでしょうか?