mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Add the title attribute to polls (#10759)
Adds an optional title attribute to polls. The rationale for this addition is that polls themselves didn't contain context/question and relied on post body to explain them. That context wasn't always obvious (e.g. when there are multiple polls in a single post) or available (e.g. when you display the poll breakdown - you see the answers, but not the question) As a side note, here's a word on how the poll plugin works: > We have a markdown poll renderer, which we use in the builder UI and the composer preview, but… when you submit a post, raw markdown is cooked into html (twice), then we extract data from the generated html and save it to the database. When it's render time, we first display the cooked html poll, and then extract some data from that html, get the data from the post's JSON (and identify that poll using the extracted html stuff) to then render the poll using widgets and the JSON data.
This commit is contained in:
@@ -139,6 +139,17 @@ describe PostsController do
|
||||
expect(Poll.where(post_id: json["id"]).count).to eq(1)
|
||||
end
|
||||
|
||||
it "accepts polls with titles" do
|
||||
post :create, params: {
|
||||
title: title, raw: "[poll]\n# What's up?\n- one\n[/poll]"
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_successful
|
||||
poll = Poll.last
|
||||
expect(poll).to_not be_nil
|
||||
expect(poll.title).to eq("What’s up?")
|
||||
end
|
||||
|
||||
describe "edit window" do
|
||||
|
||||
describe "within the first 5 minutes" do
|
||||
|
||||
@@ -95,7 +95,7 @@ describe PrettyText do
|
||||
|
||||
cooked = PrettyText.cook md
|
||||
|
||||
expected = <<~MD
|
||||
expected = <<~HTML
|
||||
<div class="poll" data-poll-status="open" data-poll-type="multiple" data-poll-name="poll">
|
||||
<div>
|
||||
<div class="poll-container">
|
||||
@@ -113,7 +113,7 @@ describe PrettyText do
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
MD
|
||||
HTML
|
||||
|
||||
# note, hashes should remain stable even if emoji changes cause text content is hashed
|
||||
expect(n cooked).to eq(n expected)
|
||||
@@ -153,4 +153,20 @@ describe PrettyText do
|
||||
excerpt = PrettyText.excerpt(post.cooked, SiteSetting.post_onebox_maxlength)
|
||||
expect(excerpt).to eq("A post with a poll \npoll")
|
||||
end
|
||||
|
||||
it "supports the title attribute" do
|
||||
cooked = PrettyText.cook <<~MD
|
||||
[poll]
|
||||
# What's your favorite *berry*? :wink: https://google.com/
|
||||
* Strawberry
|
||||
* Raspberry
|
||||
* Blueberry
|
||||
[/poll]
|
||||
MD
|
||||
|
||||
expect(cooked).to include(<<~HTML)
|
||||
<div class="poll-title">What’s your favorite <em>berry</em>? <img src="/images/emoji/twitter/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"> <a href="https://google.com/" rel="noopener nofollow ugc">https://google.com/</a>
|
||||
</div>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user