From 2f5d2d2cd6af9a42074ecebc6d190593dc5d3e69 Mon Sep 17 00:00:00 2001 From: Juan Alvarado Date: Wed, 30 Dec 2015 13:53:19 -0500 Subject: [PATCH] Remove dependent destroy circular dependency https://github.com/rails/rails/issues/13609 Having dependent: :destroy on both the question_content and survey_element for the assetable polymorphic belongs_to causes a loop in the destroy callbacks for rails 4.0 Removing the dependent :destroy solves the issue for 4.0, but they should be added back in for the move to rails 4.1 as the issue is fixed in rails. https://github.com/rails/rails/pull/18548 --- app/models/question_models/question_content.rb | 2 +- app/models/survey_models/survey_element.rb | 2 +- spec/features/survey_builder_spec.rb | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/question_models/question_content.rb b/app/models/question_models/question_content.rb index 11dce57f..5b600424 100644 --- a/app/models/question_models/question_content.rb +++ b/app/models/question_models/question_content.rb @@ -3,7 +3,7 @@ # QuestionContent contains fields shared between all question types (ChoiceQuestion, # TextQuestion, MatrixQuestion) and delegates behavior where appropriate. class QuestionContent < ActiveRecord::Base - belongs_to :questionable, :polymorphic => true, :dependent => :destroy + belongs_to :questionable, :polymorphic => true#, :dependent => :destroy has_many :criteria, :as => :source has_many :raw_responses, :foreign_key => "question_content_id" # likely currently unused. had a typo has_many :question_content_display_fields diff --git a/app/models/survey_models/survey_element.rb b/app/models/survey_models/survey_element.rb index a2bcf6d2..44047652 100644 --- a/app/models/survey_models/survey_element.rb +++ b/app/models/survey_models/survey_element.rb @@ -4,7 +4,7 @@ # which exists on a Page within a SurveyVersion. class SurveyElement < ActiveRecord::Base belongs_to :page - belongs_to :assetable, :polymorphic => true, :dependent => :destroy + belongs_to :assetable, :polymorphic => true#, :dependent => :destroy belongs_to :survey_version, :touch => true has_many :dashboard_elements, :dependent => :destroy diff --git a/spec/features/survey_builder_spec.rb b/spec/features/survey_builder_spec.rb index a168ebd7..15ff9474 100644 --- a/spec/features/survey_builder_spec.rb +++ b/spec/features/survey_builder_spec.rb @@ -17,6 +17,17 @@ add_text_question statement: "" expect(page).to_not have_css ".page_asset" end + + scenario "User deletes a text question" do + survey = create :survey + login_user + visit edit_survey_survey_version_path(survey, survey.survey_versions.first) + add_text_question statement: "Example Question" + within find('div.page_asset', text: "Example Question") do + click_link "Delete" + end + expect(page).to_not have_css ".page_asset", text: "Example Question" + end end context "choice question" do