mirror of
https://github.com/discourse/discourse.git
synced 2025-04-11 15:40:50 +08:00
DEV: Do not attempt to update polls if there are no polls before and after (#26573)
This commit is contained in:
parent
973a0028b4
commit
18bb6b0871
@ -70,6 +70,7 @@ after_initialize do
|
|||||||
|
|
||||||
validator = DiscoursePoll::PollsValidator.new(self)
|
validator = DiscoursePoll::PollsValidator.new(self)
|
||||||
return unless (polls = validator.validate_polls)
|
return unless (polls = validator.validate_polls)
|
||||||
|
return if polls.blank? && self.id.blank?
|
||||||
|
|
||||||
if polls.present?
|
if polls.present?
|
||||||
validator = DiscoursePoll::PostValidator.new(self)
|
validator = DiscoursePoll::PostValidator.new(self)
|
||||||
@ -78,6 +79,8 @@ after_initialize do
|
|||||||
|
|
||||||
# are we updating a post?
|
# are we updating a post?
|
||||||
if self.id.present?
|
if self.id.present?
|
||||||
|
return if polls.blank? && ::Poll.where(post: self).empty?
|
||||||
|
|
||||||
DiscoursePoll::PollsUpdater.update(self, polls)
|
DiscoursePoll::PollsUpdater.update(self, polls)
|
||||||
else
|
else
|
||||||
self.extracted_polls = polls
|
self.extracted_polls = polls
|
||||||
|
@ -186,5 +186,27 @@ RSpec.describe DiscoursePoll::PollsUpdater do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when no polls" do
|
||||||
|
it "does not attempt to update polls" do
|
||||||
|
DiscoursePoll::PollsUpdater.stubs(:update).raises(StandardError)
|
||||||
|
no_poll_post = Fabricate(:post)
|
||||||
|
|
||||||
|
raw = <<~RAW
|
||||||
|
no poll here, moving on
|
||||||
|
RAW
|
||||||
|
|
||||||
|
no_poll_post.raw = raw
|
||||||
|
expect(no_poll_post.valid?).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not need to validate post" do
|
||||||
|
DiscoursePoll::PostValidator.stubs(:validate_post).raises(StandardError)
|
||||||
|
no_poll_post =
|
||||||
|
Post.new(user: user, topic: Fabricate(:topic), raw: "no poll here, meoving on")
|
||||||
|
|
||||||
|
expect(no_poll_post.valid?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user