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

Node deletion problem while removing spam solved #2450

Merged
merged 3 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Answer < ActiveRecord::Base

attr_accessible :uid, :nid, :content, :cached_likes, :created_at, :updated_at

belongs_to :node, foreign_key: 'nid', dependent: :destroy
belongs_to :node, foreign_key: 'nid'
belongs_to :drupal_user, foreign_key: 'uid'
has_many :answer_selections, foreign_key: 'aid'
has_many :comments, foreign_key: 'aid', dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def updated_month
has_many :drupal_content_field_map_editor, foreign_key: 'nid' #, dependent: :destroy # re-enable in Rails 5
has_many :images, foreign_key: :nid
has_many :node_selections, foreign_key: :nid
has_many :answers, foreign_key: :nid
has_many :answers, foreign_key: :nid, dependent: :destroy

belongs_to :drupal_user, foreign_key: 'uid'

Expand Down
13 changes: 13 additions & 0 deletions test/functional/answers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,17 @@ def setup
assert answer.accepted
end

test 'answer deletion should not delete the question node' do
UserSession.create(users(:moderator))
answer = answers(:one)
answer.save
a = Answer.count
b = Node.count

xhr :post, :delete, id: answer.id

assert_equal Answer.count ,a - 1
assert_equal Node.count,b
assert_response :success
end
end
16 changes: 16 additions & 0 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,20 @@ def test_get_rss_feed
assert_equal "Only author can access the draft note", flash[:notice]
end

test 'question deletion should delete all its answers' do
UserSession.create(users(:moderator))
node = nodes(:question)
node.save
answer1 = answers(:one)
answer1.save
answer2 = answers(:two)
answer2.save
n_count = Node.count

xhr :post, :delete, id: node.id

assert_response :success
assert_equal Node.count, n_count - 1
assert_equal Answer.count, 0
end
end