NUBIC/surveyor

Rails 4.1 breaks parser for quizzes

kjayma opened this issue · 1 comments

spec/lib/parser_spec.rb fails on context "quizzes" it "parses". The correct_answer_id is not set for questions with correct answers.

The problem seems to originate in the resolve_question_correct_answers method of parser.rb in the following line:

if self.context[:answer_references][question_reference_identifier] && (a = self.context[:answer_references][question_reference_identifier][correct_answer_reference]) && a.save

Prior to Rails 4.1.0, the save command appears localized to a, which is an Answer instance. In Rails 4.1.0 and later, this save appears to ripple back through the ancestors and saves the entire survey.

I'm not yet clear why this happens, as I could not find anything in the release notes that directly suggest this behavior.

In any case, context[:survey].save in method_missing fails to save the changes to correct_answer_id as context[:survey] has already been persisted (:autosave is not explicity set to true in the chain of parents). In 4.0.x, context[:survey] would be saved for the first time and correct_answer_id would be properly saved.

Also, there is a spelling error in resolve_question_correct_answers; "idenitifer" instead of "identifier". This does not affect functionality.

I tried to look at this a little closer, and was able to preserve the Rails 4.0 behavior by setting

belongs_to :question, autosave: false

in answer_methods.rb

For future reference: http://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html

Note that autosave: false is not same as not declaring :autosave. When the :autosave option is not present then new association records are saved but the updated association records are not saved.