Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4.1 breaks parser for quizzes #484

Open
kjayma opened this issue Aug 10, 2014 · 1 comment
Open

Rails 4.1 breaks parser for quizzes #484

kjayma opened this issue Aug 10, 2014 · 1 comment

Comments

@kjayma
Copy link

kjayma commented Aug 10, 2014

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.

kjayma added a commit to kjayma/surveyor that referenced this issue Aug 10, 2014
Changes made to correct_answer_id in resolve_question_correct_answer
are not being saved in Rails 4.1.  Workaround is
to save the question immediately after the correct answer is saved.
@prusswan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants