Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Remove dependent destroy circular dependency
Browse files Browse the repository at this point in the history
rails/rails#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.

rails/rails#18548
  • Loading branch information
jalvarado committed Dec 30, 2015
1 parent e0a91a7 commit 2f5d2d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/question_models/question_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/survey_models/survey_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions spec/features/survey_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f5d2d2

Please sign in to comment.