mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
FIX: Avoid exception when rendering a poll in a trashed post
Maintain the poll belongs_to post relation when a post is trashed
This commit is contained in:
parent
ba616ffb50
commit
84be92c067
@ -4,7 +4,7 @@ class Poll < ActiveRecord::Base
|
||||
# because we want to use the 'type' column and don't want to use STI
|
||||
self.inheritance_column = nil
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :post, -> { unscope(:where) }
|
||||
|
||||
has_many :poll_options, -> { order(:id) }, dependent: :destroy
|
||||
has_many :poll_votes
|
||||
@ -51,7 +51,7 @@ class Poll < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def is_me?(user)
|
||||
user && post.user&.id == user&.id
|
||||
user && post && post.user&.id == user&.id
|
||||
end
|
||||
|
||||
def has_voted?(user)
|
||||
|
@ -69,4 +69,18 @@ describe ::DiscoursePoll::Poll do
|
||||
expect(poll.can_see_results?(user)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when post is trashed' do
|
||||
it "maintains the association" do
|
||||
user = Fabricate(:user)
|
||||
post = Fabricate(:post, raw: "[poll results=staff_only]\n- A\n- B\n[/poll]", user: user)
|
||||
poll = post.polls.first
|
||||
|
||||
post.trash!
|
||||
poll.reload
|
||||
|
||||
expect(poll.post).to eq(post)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user