diff --git a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6
index 60fc833e39c..f237c7b90f1 100644
--- a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6
+++ b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6
@@ -11,6 +11,15 @@ function optionHtml(option) {
return new RawHtml({ html: `${option.html}` });
}
+function fetchVoters(payload) {
+ return ajax("/polls/voters.json", {
+ type: "get",
+ data: payload
+ }).catch(() => {
+ bootbox.alert(I18n.t('poll.error_while_fetching_voters'));
+ });
+}
+
createWidget('discourse-poll-option', {
tagName: 'li',
@@ -71,8 +80,7 @@ createWidget('discourse-poll-voters', {
return {
loaded: 'new',
pollVoters: [],
- offset: 0,
- canLoadMore: false
+ offset: 1,
};
},
@@ -80,47 +88,45 @@ createWidget('discourse-poll-voters', {
const { attrs, state } = this;
if (state.loaded === 'loading') { return; }
- const { voterIds } = attrs;
-
- if (!voterIds.length) { return; }
-
- const windowSize = Math.round(($('.poll-container:eq(0)').width() / 25) * 2);
- const index = state.offset * windowSize;
- const ids = voterIds.slice(index, index + windowSize);
-
state.loaded = 'loading';
- return ajax("/polls/voters.json", {
- type: "get",
- data: { user_ids: ids }
+
+ return fetchVoters({
+ post_id: attrs.postId,
+ poll_name: attrs.pollName,
+ option_id: attrs.optionId,
+ offset: state.offset
}).then(result => {
state.loaded = 'loaded';
- state.pollVoters = state.pollVoters.concat(result.users);
- state.canLoadMore = state.pollVoters.length < attrs.totalVotes;
+ state.offset += 1;
+
+ const pollResult = result[attrs.pollName]
+ const newVoters = attrs.pollType === 'number' ? pollResult : pollResult[attrs.optionId];
+ state.pollVoters = state.pollVoters.concat(newVoters);
+
this.scheduleRerender();
- }).catch(() => {
- bootbox.alert(I18n.t('poll.error_while_fetching_voters'));
});
},
loadMore() {
- this.state.offset += 1;
return this.fetchVoters();
},
html(attrs, state) {
- if (state.loaded === 'new') {
- this.fetchVoters();
- return;
+ if (attrs.pollVoters && state.loaded === 'new') {
+ state.pollVoters = attrs.pollVoters;
}
+ console.log(state.pollVoters);
const contents = state.pollVoters.map(user => {
+ if (user === undefined) debugger;
+
return h('li', [avatarFor('tiny', {
username: user.username,
template: user.avatar_template
}), ' ']);
});
- if (state.canLoadMore) {
+ if (state.pollVoters.length < attrs.totalVotes) {
contents.push(this.attach('discourse-poll-load-more', { id: attrs.id() }));
}
@@ -131,13 +137,37 @@ createWidget('discourse-poll-voters', {
createWidget('discourse-poll-standard-results', {
tagName: 'ul.results',
+ buildKey: attrs => `${attrs.id}-standard-results`,
- html(attrs) {
+ defaultState() {
+ return {
+ loaded: 'new'
+ };
+ },
+
+ fetchVoters() {
+ const { attrs, state } = this;
+
+ if (state.loaded === 'new') {
+ fetchVoters({
+ post_id: attrs.post.id,
+ poll_name: attrs.poll.get('name')
+ }).then(result => {
+ state.voters = result[attrs.poll.get('name')];
+ state.loaded = 'loaded';
+ this.scheduleRerender();
+ });
+ }
+ },
+
+ html(attrs, state) {
const { poll } = attrs;
const options = poll.get('options');
if (options) {
const voters = poll.get('voters');
+ const isPublic = poll.get('public');
+
const ordered = _.clone(options).sort((a, b) => {
if (a.votes < b.votes) {
return 1;
@@ -158,6 +188,8 @@ createWidget('discourse-poll-standard-results', {
const rounded = attrs.isMultiple ? percentages.map(Math.floor) : evenRound(percentages);
+ if (isPublic) this.fetchVoters();
+
return ordered.map((option, idx) => {
const contents = [];
const per = rounded[idx].toString();
@@ -171,11 +203,14 @@ createWidget('discourse-poll-standard-results', {
h('div.bar', { attributes: { style: `width:${per}%` }})
));
- if (poll.get('public')) {
+ if (isPublic) {
contents.push(this.attach('discourse-poll-voters', {
id: () => `poll-voters-${option.id}`,
+ postId: attrs.post.id,
+ optionId: option.id,
+ pollName: poll.get('name'),
totalVotes: option.votes,
- voterIds: option.voter_ids
+ pollVoters: (state.voters && state.voters[option.id]) || []
}));
}
@@ -186,8 +221,33 @@ createWidget('discourse-poll-standard-results', {
});
createWidget('discourse-poll-number-results', {
- html(attrs) {
+ buildKey: attrs => `${attrs.id}-number-results`,
+
+ defaultState() {
+ return {
+ loaded: 'new'
+ };
+ },
+
+ fetchVoters() {
+ const { attrs, state } = this;
+
+ if (state.loaded === 'new') {
+
+ fetchVoters({
+ post_id: attrs.post.id,
+ poll_name: attrs.poll.get('name')
+ }).then(result => {
+ state.voters = result[attrs.poll.get('name')];
+ state.loaded = 'loaded';
+ this.scheduleRerender();
+ });
+ }
+ },
+
+ html(attrs, state) {
const { poll } = attrs;
+ const isPublic = poll.get('public');
const totalScore = poll.get('options').reduce((total, o) => {
return total + parseInt(o.html, 10) * parseInt(o.votes, 10);
@@ -199,12 +259,16 @@ createWidget('discourse-poll-number-results', {
const results = [h('div.poll-results-number-rating',
new RawHtml({ html: `${averageRating}` }))];
- if (poll.get('public')) {
- const options = poll.get('options');
+ if (isPublic) {
+ this.fetchVoters();
+
results.push(this.attach('discourse-poll-voters', {
id: () => `poll-voters-${poll.get('name')}`,
totalVotes: poll.get('voters'),
- voterIds: [].concat(...(options.map(option => option.voter_ids)))
+ pollVoters: state.voters || [],
+ postId: attrs.post.id,
+ pollName: poll.get('name'),
+ pollType: poll.get('type')
}));
}
@@ -427,7 +491,6 @@ export default createWidget('discourse-poll', {
},
toggleStatus() {
-
const { state, attrs } = this;
const { poll } = attrs;
const isClosed = poll.get('status') === 'closed';
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index 5a193b1ace9..73dc402eeb3 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -211,13 +211,61 @@ after_initialize do
end
def voters
- user_ids = params.require(:user_ids)
+ post_id = params.require(:post_id)
+ poll_name = params.require(:poll_name)
- users = User.where(id: user_ids).map do |user|
- UserNameSerializer.new(user).serializable_hash
+ post = Post.find_by(id: post_id)
+ raise Discourse::InvalidParameters.new("post_id is invalid") if !post
+
+ poll = post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD][poll_name]
+ raise Discourse::InvalidParameters.new("poll_name is invalid") if !poll
+
+ user_ids = []
+ options = poll["options"]
+
+ if poll["type"] != "number"
+ options.each do |option|
+ if (params[:option_id])
+ next unless option["id"] == params[:option_id].to_s
+ end
+
+ next unless option["voter_ids"]
+ user_ids << option["voter_ids"].slice((params[:offset].to_i || 0) * 25, 25)
+ end
+
+ user_ids.flatten!
+ user_ids.uniq!
+
+ poll_votes = post.custom_fields[DiscoursePoll::VOTES_CUSTOM_FIELD]
+
+ result = {}
+
+ User.where(id: user_ids).map do |user|
+ user_hash = UserNameSerializer.new(user).serializable_hash
+
+ poll_votes[user.id.to_s][poll_name].each do |option_id|
+ if (params[:option_id])
+ next unless option_id == params[:option_id].to_s
+ end
+
+ result[option_id] ||= []
+ result[option_id] << user_hash
+ end
+ end
+ else
+ user_ids = options.map { |option| option["voter_ids"] }.sort!
+ user_ids.flatten!
+ user_ids.uniq!
+ user_ids = user_ids.slice((params[:offset].to_i || 0) * 25, 25)
+
+ result = []
+
+ users = User.where(id: user_ids).map do |user|
+ result << UserNameSerializer.new(user).serializable_hash
+ end
end
- render json: { users: users }
+ render json: { poll_name => result }
end
end
@@ -294,7 +342,16 @@ after_initialize do
polls: post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD]})
end
- add_to_serializer(:post, :polls, false) { post_custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD] }
+ add_to_serializer(:post, :polls, false) do
+ polls = post_custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD].dup
+
+ polls.each do |_, poll|
+ poll["options"].each do |option|
+ option.delete("voter_ids")
+ end
+ end
+ end
+
add_to_serializer(:post, :include_polls?) { post_custom_fields.present? && post_custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD].present? }
add_to_serializer(:post, :polls_votes, false) do
diff --git a/plugins/poll/spec/integration/poll_endpoints_spec.rb b/plugins/poll/spec/integration/poll_endpoints_spec.rb
index 6aeb65cd300..d2c5a4caacd 100644
--- a/plugins/poll/spec/integration/poll_endpoints_spec.rb
+++ b/plugins/poll/spec/integration/poll_endpoints_spec.rb
@@ -1,18 +1,118 @@
require "rails_helper"
describe "DiscoursePoll endpoints" do
- describe "fetch voters from user_ids" do
+ describe "fetch voters for a poll" do
let(:user) { Fabricate(:user) }
+ let(:post) { Fabricate(:post, raw: "[poll public=true]\n- A\n- B\n[/poll]") }
it "should return the right response" do
- get "/polls/voters.json", { user_ids: [user.id] }
+ DiscoursePoll::Poll.vote(
+ post.id,
+ DiscoursePoll::DEFAULT_POLL_NAME,
+ ["5c24fc1df56d764b550ceae1b9319125"],
+ user
+ )
+
+ get "/polls/voters.json", {
+ post_id: post.id,
+ poll_name: DiscoursePoll::DEFAULT_POLL_NAME
+ }
expect(response.status).to eq(200)
- json = JSON.parse(response.body)["users"].first
+ poll = JSON.parse(response.body)[DiscoursePoll::DEFAULT_POLL_NAME]
+ option = poll["5c24fc1df56d764b550ceae1b9319125"]
- expect(json["name"]).to eq(user.name)
- expect(json["title"]).to eq(user.title)
+ expect(option.length).to eq(1)
+ expect(option.first["id"]).to eq(user.id)
+ expect(option.first["username"]).to eq(user.username)
+ end
+
+ it 'should return the right response for a single option' do
+ DiscoursePoll::Poll.vote(
+ post.id,
+ DiscoursePoll::DEFAULT_POLL_NAME,
+ ["5c24fc1df56d764b550ceae1b9319125", "e89dec30bbd9bf50fabf6a05b4324edf"],
+ user
+ )
+
+ get "/polls/voters.json", {
+ post_id: post.id,
+ poll_name: DiscoursePoll::DEFAULT_POLL_NAME,
+ option_id: 'e89dec30bbd9bf50fabf6a05b4324edf'
+ }
+
+ expect(response.status).to eq(200)
+
+ poll = JSON.parse(response.body)[DiscoursePoll::DEFAULT_POLL_NAME]
+
+ expect(poll['5c24fc1df56d764b550ceae1b9319125']).to eq(nil)
+
+ option = poll['e89dec30bbd9bf50fabf6a05b4324edf']
+
+ expect(option.length).to eq(1)
+ expect(option.first["id"]).to eq(user.id)
+ expect(option.first["username"]).to eq(user.username)
+ end
+
+ describe 'when post_id is blank' do
+ it 'should raise the right error' do
+ expect { get "/polls/voters.json", { poll_name: DiscoursePoll::DEFAULT_POLL_NAME } }
+ .to raise_error(ActionController::ParameterMissing)
+ end
+ end
+
+ describe 'when post_id is not valid' do
+ it 'should raise the right error' do
+ expect do
+ get "/polls/voters.json", {
+ post_id: -1,
+ poll_name: DiscoursePoll::DEFAULT_POLL_NAME
+ }
+ end.to raise_error(Discourse::InvalidParameters, 'post_id is invalid')
+ end
+ end
+
+ describe 'when poll_name is blank' do
+ it 'should raise the right error' do
+ expect { get "/polls/voters.json", { post_id: post.id } }
+ .to raise_error(ActionController::ParameterMissing)
+ end
+ end
+
+ describe 'when poll_name is not valid' do
+ it 'should raise the right error' do
+ expect do
+ get "/polls/voters.json", post_id: post.id, poll_name: 'wrongpoll'
+ end.to raise_error(Discourse::InvalidParameters, 'poll_name is invalid')
+ end
+ end
+
+ context "number poll" do
+ let(:post) { Fabricate(:post, raw: '[poll type=number min=1 max=20 step=1 public=true][/poll]') }
+
+ it 'should return the right response' do
+ post
+
+ DiscoursePoll::Poll.vote(
+ post.id,
+ DiscoursePoll::DEFAULT_POLL_NAME,
+ ["4d8a15e3cc35750f016ce15a43937620"],
+ user
+ )
+
+ get "/polls/voters.json", {
+ post_id: post.id,
+ poll_name: DiscoursePoll::DEFAULT_POLL_NAME
+ }
+
+ expect(response.status).to eq(200)
+
+ poll = JSON.parse(response.body)[DiscoursePoll::DEFAULT_POLL_NAME]
+
+ expect(poll.first["id"]).to eq(user.id)
+ expect(poll.first["username"]).to eq(user.username)
+ end
end
end
end
diff --git a/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 b/plugins/poll/test/javascripts/acceptance/polls-test.js.es6
index 35aec81b5c4..d8ff2c6efb0 100644
--- a/plugins/poll/test/javascripts/acceptance/polls-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/polls-test.js.es6
@@ -2,23 +2,18 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Rendering polls", {
loggedIn: true,
- settings: { poll_enabled: true },
- setup() {
- const response = object => {
- return [
- 200,
- { "Content-Type": "application/json" },
- object
- ];
- };
-
- server.get('/t/13.json', () => {
- return response({"post_stream":{"posts":[{"id":19,"name":null,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","created_at":"2016-12-01T02:39:49.199Z","cooked":"
\n\n","post_number":1,"post_type":1,"updated_at":"2016-12-01T02:47:18.317Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":13,"topic_slug":"this-is-a-test-topic-for-polls","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":2,"can_edit":true,"can_delete":false,"can_recover":true,"can_wiki":true,"read":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"polls":{"poll":{"options":[{"id":"57ddd734344eb7436d64a7d68a0df444","html":"test","votes":0},{"id":"b5b78d79ab5b5d75d4d33d8b87f5d2aa","html":"haha","votes":0}],"voters":2,"status":"open","name":"poll"},"test":{"options":[{"id":"c26ad90783b0d80936e5fdb292b7963c","html":"donkey","votes":0},{"id":"99f2b9ac452ba73b115fcf3556e6d2d4","html":"kong","votes":0}],"voters":3,"status":"open","name":"test"}}}],"stream":[19]},"timeline_lookup":[[1,0]],"id":13,"title":"This is a test topic for polls","fancy_title":"This is a test topic for polls","posts_count":1,"created_at":"2016-12-01T02:39:48.055Z","views":1,"reply_count":0,"participant_count":1,"like_count":0,"last_posted_at":"2016-12-01T02:39:49.199Z","visible":true,"closed":false,"archived":false,"has_summary":false,"archetype":"regular","slug":"this-is-a-test-topic-for-polls","category_id":1,"word_count":10,"deleted_at":null,"user_id":1,"draft":null,"draft_key":"topic_13","draft_sequence":4,"posted":true,"unpinned":null,"pinned_globally":false,"pinned":false,"pinned_at":null,"pinned_until":null,"details":{"auto_close_at":null,"auto_close_hours":null,"auto_close_based_on_last_post":false,"created_by":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"last_poster":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"participants":[{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","post_count":1}],"suggested_topics":[{"id":8,"title":"Welcome to Discourse","fancy_title":"Welcome to Discourse","slug":"welcome-to-discourse","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2016-11-24T02:10:54.328Z","last_posted_at":"2016-11-24T02:10:54.393Z","bumped":true,"bumped_at":"2016-11-24T02:10:54.393Z","unseen":false,"pinned":true,"unpinned":null,"excerpt":"The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important! \n\nEdit this into a brief description of your community: \n\n\nWho is it for?\nWhat can they …","visible":true,"closed":false,"archived":false,"bookmarked":null,"liked":null,"archetype":"regular","like_count":0,"views":0,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":-1,"username":"system","avatar_template":"/letter_avatar_proxy/v2/letter/s/bcef8e/{size}.png"}}]},{"id":12,"title":"Some testing topic testing","fancy_title":"Some testing topic testing","slug":"some-testing-topic-testing","posts_count":4,"reply_count":0,"highest_post_number":4,"image_url":null,"created_at":"2016-11-24T08:36:08.773Z","last_posted_at":"2016-12-01T01:15:52.008Z","bumped":true,"bumped_at":"2016-12-01T01:15:52.008Z","unseen":false,"last_read_post_number":4,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":2,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"}}]},{"id":11,"title":"Some testing topic","fancy_title":"Some testing topic","slug":"some-testing-topic","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2016-11-24T08:35:26.758Z","last_posted_at":"2016-11-24T08:35:26.894Z","bumped":true,"bumped_at":"2016-11-24T08:35:26.894Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":0,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"}}]}],"notification_level":3,"notifications_reason_id":1,"can_move_posts":true,"can_edit":true,"can_delete":true,"can_recover":true,"can_remove_allowed_users":true,"can_invite_to":true,"can_create_post":true,"can_reply_as_new_topic":true,"can_flag_topic":true},"highest_post_number":1,"last_read_post_number":1,"last_read_post_id":19,"deleted_by":null,"has_deleted":false,"actions_summary":[{"id":4,"count":0,"hidden":false,"can_act":true},{"id":7,"count":0,"hidden":false,"can_act":true},{"id":8,"count":0,"hidden":false,"can_act":true}],"chunk_size":20,"bookmarked":false});
- });
- }
+ settings: { poll_enabled: true }
});
test("Single Poll", () => {
+ server.get('/t/13.json', () => {
+ return [
+ 200,
+ { "Content-Type": "application/json" },
+ {"post_stream":{"posts":[{"id":19,"name":null,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","created_at":"2016-12-01T02:39:49.199Z","cooked":"\n\n","post_number":1,"post_type":1,"updated_at":"2016-12-01T02:47:18.317Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":13,"topic_slug":"this-is-a-test-topic-for-polls","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":2,"can_edit":true,"can_delete":false,"can_recover":true,"can_wiki":true,"read":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"polls":{"poll":{"options":[{"id":"57ddd734344eb7436d64a7d68a0df444","html":"test","votes":0},{"id":"b5b78d79ab5b5d75d4d33d8b87f5d2aa","html":"haha","votes":0}],"voters":2,"status":"open","name":"poll"},"test":{"options":[{"id":"c26ad90783b0d80936e5fdb292b7963c","html":"donkey","votes":0},{"id":"99f2b9ac452ba73b115fcf3556e6d2d4","html":"kong","votes":0}],"voters":3,"status":"open","name":"test"}}}],"stream":[19]},"timeline_lookup":[[1,0]],"id":13,"title":"This is a test topic for polls","fancy_title":"This is a test topic for polls","posts_count":1,"created_at":"2016-12-01T02:39:48.055Z","views":1,"reply_count":0,"participant_count":1,"like_count":0,"last_posted_at":"2016-12-01T02:39:49.199Z","visible":true,"closed":false,"archived":false,"has_summary":false,"archetype":"regular","slug":"this-is-a-test-topic-for-polls","category_id":1,"word_count":10,"deleted_at":null,"user_id":1,"draft":null,"draft_key":"topic_13","draft_sequence":4,"posted":true,"unpinned":null,"pinned_globally":false,"pinned":false,"pinned_at":null,"pinned_until":null,"details":{"auto_close_at":null,"auto_close_hours":null,"auto_close_based_on_last_post":false,"created_by":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"last_poster":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"participants":[{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","post_count":1}],"suggested_topics":[{"id":8,"title":"Welcome to Discourse","fancy_title":"Welcome to Discourse","slug":"welcome-to-discourse","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2016-11-24T02:10:54.328Z","last_posted_at":"2016-11-24T02:10:54.393Z","bumped":true,"bumped_at":"2016-11-24T02:10:54.393Z","unseen":false,"pinned":true,"unpinned":null,"excerpt":"The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important! \n\nEdit this into a brief description of your community: \n\n\nWho is it for?\nWhat can they …","visible":true,"closed":false,"archived":false,"bookmarked":null,"liked":null,"archetype":"regular","like_count":0,"views":0,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":-1,"username":"system","avatar_template":"/letter_avatar_proxy/v2/letter/s/bcef8e/{size}.png"}}]},{"id":12,"title":"Some testing topic testing","fancy_title":"Some testing topic testing","slug":"some-testing-topic-testing","posts_count":4,"reply_count":0,"highest_post_number":4,"image_url":null,"created_at":"2016-11-24T08:36:08.773Z","last_posted_at":"2016-12-01T01:15:52.008Z","bumped":true,"bumped_at":"2016-12-01T01:15:52.008Z","unseen":false,"last_read_post_number":4,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":2,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"}}]},{"id":11,"title":"Some testing topic","fancy_title":"Some testing topic","slug":"some-testing-topic","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2016-11-24T08:35:26.758Z","last_posted_at":"2016-11-24T08:35:26.894Z","bumped":true,"bumped_at":"2016-11-24T08:35:26.894Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":0,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"}}]}],"notification_level":3,"notifications_reason_id":1,"can_move_posts":true,"can_edit":true,"can_delete":true,"can_recover":true,"can_remove_allowed_users":true,"can_invite_to":true,"can_create_post":true,"can_reply_as_new_topic":true,"can_flag_topic":true},"highest_post_number":1,"last_read_post_number":1,"last_read_post_id":19,"deleted_by":null,"has_deleted":false,"actions_summary":[{"id":4,"count":0,"hidden":false,"can_act":true},{"id":7,"count":0,"hidden":false,"can_act":true},{"id":8,"count":0,"hidden":false,"can_act":true}],"chunk_size":20,"bookmarked":false}
+ ]
+ });
+
visit("/t/this-is-a-test-topic-for-polls/13");
andThen(() => {
@@ -29,3 +24,97 @@ test("Single Poll", () => {
equal(find('.info-number', polls[1]).text(), '3', 'it should display the right number of votes');
});
});
+
+test("Public poll", () => {
+ server.get('/t/12.json', () => {
+ return [
+ 200,
+ { "Content-Type": "application/json" },
+ {"post_stream":{"posts":[{"id":15,"name":null,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","created_at":"2017-01-31T08:39:06.237Z","cooked":"\n
\n
\n
\n
0voters
\n
Choose up to 3 options
\n
Votes are public.
\n
\n
\n
\n
","post_number":1,"post_type":1,"updated_at":"2017-01-31T08:39:06.237Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":12,"topic_slug":"this-is-a-topic-created-for-testing","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":1,"can_edit":true,"can_delete":false,"can_recover":true,"can_wiki":true,"read":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"polls":{"poll":{"options":[{"id":"4d8a15e3cc35750f016ce15a43937620","html":"1","votes":29},{"id":"cd314db7dfbac2b10687b6f39abfdf41","html":"2","votes":29},{"id":"68b434ff88aeae7054e42cd05a4d9056","html":"3","votes":42}],"voters":100,"status":"open","name":"poll","type":"multiple","min":"1","max":"3","public":"true"}}}],"stream":[15]},"timeline_lookup":[[1,0]],"id":12,"title":"This is a topic created for testing","fancy_title":"This is a topic created for testing","posts_count":1,"created_at":"2017-01-31T08:39:06.094Z","views":1,"reply_count":0,"participant_count":1,"like_count":0,"last_posted_at":"2017-01-31T08:39:06.237Z","visible":true,"closed":false,"archived":false,"has_summary":false,"archetype":"regular","slug":"this-is-a-topic-created-for-testing","category_id":1,"word_count":13,"deleted_at":null,"user_id":1,"draft":null,"draft_key":"topic_12","draft_sequence":1,"posted":true,"unpinned":null,"pinned_globally":false,"pinned":false,"pinned_at":null,"pinned_until":null,"details":{"auto_close_at":null,"auto_close_hours":null,"auto_close_based_on_last_post":false,"created_by":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"last_poster":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"participants":[{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","post_count":1,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_color":null,"primary_group_flair_bg_color":null}],"suggested_topics":[{"id":8,"title":"Welcome to Discourse","fancy_title":"Welcome to Discourse","slug":"welcome-to-discourse","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:53:45.363Z","last_posted_at":"2017-01-31T07:53:45.439Z","bumped":true,"bumped_at":"2017-01-31T07:53:45.439Z","unseen":false,"pinned":true,"unpinned":null,"excerpt":"The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important! \n\nEdit this into a brief description of your community: \n\n\nWho is it for?\nWhat can they …","visible":true,"closed":false,"archived":false,"bookmarked":null,"liked":null,"archetype":"regular","like_count":0,"views":0,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":-1,"username":"system","avatar_template":"/letter_avatar_proxy/v2/letter/s/bcef8e/{size}.png"}}]},{"id":11,"title":"This is a test post to try out posts","fancy_title":"This is a test post to try out posts","slug":"this-is-a-test-post-to-try-out-posts","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:55:58.407Z","last_posted_at":"2017-01-31T07:55:58.634Z","bumped":true,"bumped_at":"2017-01-31T07:55:58.634Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":1,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"}}]}],"notification_level":3,"notifications_reason_id":1,"can_move_posts":true,"can_edit":true,"can_delete":true,"can_recover":true,"can_remove_allowed_users":true,"can_invite_to":true,"can_create_post":true,"can_reply_as_new_topic":true,"can_flag_topic":true},"highest_post_number":1,"last_read_post_number":1,"last_read_post_id":15,"deleted_by":null,"has_deleted":false,"actions_summary":[{"id":4,"count":0,"hidden":false,"can_act":true},{"id":7,"count":0,"hidden":false,"can_act":true},{"id":8,"count":0,"hidden":false,"can_act":true}],"chunk_size":20,"bookmarked":false,"featured_link":null}
+ ]
+ });
+
+ server.get('/polls/voters.json', request => {
+ let body = {};
+
+ if (_.isEqual(request.queryParams, { post_id: "15", poll_name: "poll" })) {
+ body = {"poll":{"68b434ff88aeae7054e42cd05a4d9056":[{"id":402,"username":"bruce400","avatar_template":"/letter_avatar_proxy/v2/letter/b/edb3f5/{size}.png","name":"Bruce Wayne","title":null},{"id":409,"username":"bruce407","avatar_template":"/letter_avatar_proxy/v2/letter/b/59ef9b/{size}.png","name":"Bruce Wayne","title":null},{"id":410,"username":"bruce408","avatar_template":"/letter_avatar_proxy/v2/letter/b/96bed5/{size}.png","name":"Bruce Wayne","title":null},{"id":411,"username":"bruce409","avatar_template":"/letter_avatar_proxy/v2/letter/b/85f322/{size}.png","name":"Bruce Wayne","title":null},{"id":421,"username":"bruce419","avatar_template":"/letter_avatar_proxy/v2/letter/b/848f3c/{size}.png","name":"Bruce Wayne","title":null},{"id":422,"username":"bruce420","avatar_template":"/letter_avatar_proxy/v2/letter/b/bc8723/{size}.png","name":"Bruce Wayne","title":null},{"id":423,"username":"bruce421","avatar_template":"/letter_avatar_proxy/v2/letter/b/7ab992/{size}.png","name":"Bruce Wayne","title":null},{"id":426,"username":"bruce424","avatar_template":"/letter_avatar_proxy/v2/letter/b/5daacb/{size}.png","name":"Bruce Wayne","title":null},{"id":429,"username":"bruce427","avatar_template":"/letter_avatar_proxy/v2/letter/b/ea666f/{size}.png","name":"Bruce Wayne","title":null},{"id":437,"username":"bruce435","avatar_template":"/letter_avatar_proxy/v2/letter/b/8491ac/{size}.png","name":"Bruce Wayne","title":null},{"id":440,"username":"bruce438","avatar_template":"/letter_avatar_proxy/v2/letter/b/dc4da7/{size}.png","name":"Bruce Wayne","title":null},{"id":442,"username":"bruce440","avatar_template":"/letter_avatar_proxy/v2/letter/b/ee7513/{size}.png","name":"Bruce Wayne","title":null},{"id":443,"username":"bruce441","avatar_template":"/letter_avatar_proxy/v2/letter/b/ba8739/{size}.png","name":"Bruce Wayne","title":null},{"id":445,"username":"bruce443","avatar_template":"/letter_avatar_proxy/v2/letter/b/c6cbf5/{size}.png","name":"Bruce Wayne","title":null},{"id":450,"username":"bruce448","avatar_template":"/letter_avatar_proxy/v2/letter/b/b782af/{size}.png","name":"Bruce Wayne","title":null},{"id":451,"username":"bruce449","avatar_template":"/letter_avatar_proxy/v2/letter/b/7c8e57/{size}.png","name":"Bruce Wayne","title":null},{"id":453,"username":"bruce451","avatar_template":"/letter_avatar_proxy/v2/letter/b/e19adc/{size}.png","name":"Bruce Wayne","title":null},{"id":455,"username":"bruce453","avatar_template":"/letter_avatar_proxy/v2/letter/b/e79b87/{size}.png","name":"Bruce Wayne","title":null},{"id":461,"username":"bruce459","avatar_template":"/letter_avatar_proxy/v2/letter/b/9de053/{size}.png","name":"Bruce Wayne","title":null},{"id":466,"username":"bruce464","avatar_template":"/letter_avatar_proxy/v2/letter/b/cdc98d/{size}.png","name":"Bruce Wayne","title":null},{"id":468,"username":"bruce466","avatar_template":"/letter_avatar_proxy/v2/letter/b/d78d45/{size}.png","name":"Bruce Wayne","title":null},{"id":477,"username":"bruce475","avatar_template":"/letter_avatar_proxy/v2/letter/b/f05b48/{size}.png","name":"Bruce Wayne","title":null},{"id":478,"username":"bruce476","avatar_template":"/letter_avatar_proxy/v2/letter/b/e36b37/{size}.png","name":"Bruce Wayne","title":null},{"id":498,"username":"bruce496","avatar_template":"/letter_avatar_proxy/v2/letter/b/d26b3c/{size}.png","name":"Bruce Wayne","title":null},{"id":501,"username":"bruce499","avatar_template":"/letter_avatar_proxy/v2/letter/b/e9c0ed/{size}.png","name":"Bruce Wayne","title":null}],"cd314db7dfbac2b10687b6f39abfdf41":[{"id":403,"username":"bruce401","avatar_template":"/letter_avatar_proxy/v2/letter/b/e36b37/{size}.png","name":"Bruce Wayne","title":null},{"id":404,"username":"bruce402","avatar_template":"/letter_avatar_proxy/v2/letter/b/da6949/{size}.png","name":"Bruce Wayne","title":null},{"id":405,"username":"bruce403","avatar_template":"/letter_avatar_proxy/v2/letter/b/91b2a8/{size}.png","name":"Bruce Wayne","title":null},{"id":408,"username":"bruce406","avatar_template":"/letter_avatar_proxy/v2/letter/b/7c8e57/{size}.png","name":"Bruce Wayne","title":null},{"id":413,"username":"bruce411","avatar_template":"/letter_avatar_proxy/v2/letter/b/258eb7/{size}.png","name":"Bruce Wayne","title":null},{"id":414,"username":"bruce412","avatar_template":"/letter_avatar_proxy/v2/letter/b/e68b1a/{size}.png","name":"Bruce Wayne","title":null},{"id":416,"username":"bruce414","avatar_template":"/letter_avatar_proxy/v2/letter/b/b5ac83/{size}.png","name":"Bruce Wayne","title":null},{"id":418,"username":"bruce416","avatar_template":"/letter_avatar_proxy/v2/letter/b/a88e4f/{size}.png","name":"Bruce Wayne","title":null},{"id":419,"username":"bruce417","avatar_template":"/letter_avatar_proxy/v2/letter/b/91b2a8/{size}.png","name":"Bruce Wayne","title":null},{"id":433,"username":"bruce431","avatar_template":"/letter_avatar_proxy/v2/letter/b/5f8ce5/{size}.png","name":"Bruce Wayne","title":null},{"id":434,"username":"bruce432","avatar_template":"/letter_avatar_proxy/v2/letter/b/e480ec/{size}.png","name":"Bruce Wayne","title":null},{"id":435,"username":"bruce433","avatar_template":"/letter_avatar_proxy/v2/letter/b/77aa72/{size}.png","name":"Bruce Wayne","title":null},{"id":439,"username":"bruce437","avatar_template":"/letter_avatar_proxy/v2/letter/b/b9e5f3/{size}.png","name":"Bruce Wayne","title":null},{"id":441,"username":"bruce439","avatar_template":"/letter_avatar_proxy/v2/letter/b/da6949/{size}.png","name":"Bruce Wayne","title":null},{"id":448,"username":"bruce446","avatar_template":"/letter_avatar_proxy/v2/letter/b/4af34b/{size}.png","name":"Bruce Wayne","title":null},{"id":449,"username":"bruce447","avatar_template":"/letter_avatar_proxy/v2/letter/b/eb8c5e/{size}.png","name":"Bruce Wayne","title":null},{"id":452,"username":"bruce450","avatar_template":"/letter_avatar_proxy/v2/letter/b/85e7bf/{size}.png","name":"Bruce Wayne","title":null},{"id":462,"username":"bruce460","avatar_template":"/letter_avatar_proxy/v2/letter/b/bc79bd/{size}.png","name":"Bruce Wayne","title":null},{"id":464,"username":"bruce462","avatar_template":"/letter_avatar_proxy/v2/letter/b/f6c823/{size}.png","name":"Bruce Wayne","title":null},{"id":465,"username":"bruce463","avatar_template":"/letter_avatar_proxy/v2/letter/b/b19c9b/{size}.png","name":"Bruce Wayne","title":null},{"id":470,"username":"bruce468","avatar_template":"/letter_avatar_proxy/v2/letter/b/e5b9ba/{size}.png","name":"Bruce Wayne","title":null},{"id":471,"username":"bruce469","avatar_template":"/letter_avatar_proxy/v2/letter/b/9e8a1a/{size}.png","name":"Bruce Wayne","title":null},{"id":474,"username":"bruce472","avatar_template":"/letter_avatar_proxy/v2/letter/b/ed655f/{size}.png","name":"Bruce Wayne","title":null},{"id":476,"username":"bruce474","avatar_template":"/letter_avatar_proxy/v2/letter/b/a9a28c/{size}.png","name":"Bruce Wayne","title":null},{"id":486,"username":"bruce484","avatar_template":"/letter_avatar_proxy/v2/letter/b/0ea827/{size}.png","name":"Bruce Wayne","title":null}],"4d8a15e3cc35750f016ce15a43937620":[{"id":406,"username":"bruce404","avatar_template":"/letter_avatar_proxy/v2/letter/b/51bf81/{size}.png","name":"Bruce Wayne","title":null},{"id":407,"username":"bruce405","avatar_template":"/letter_avatar_proxy/v2/letter/b/d9b06d/{size}.png","name":"Bruce Wayne","title":null},{"id":412,"username":"bruce410","avatar_template":"/letter_avatar_proxy/v2/letter/b/2acd7d/{size}.png","name":"Bruce Wayne","title":null},{"id":415,"username":"bruce413","avatar_template":"/letter_avatar_proxy/v2/letter/b/ce7236/{size}.png","name":"Bruce Wayne","title":null},{"id":417,"username":"bruce415","avatar_template":"/letter_avatar_proxy/v2/letter/b/6de8d8/{size}.png","name":"Bruce Wayne","title":null},{"id":420,"username":"bruce418","avatar_template":"/letter_avatar_proxy/v2/letter/b/bbce88/{size}.png","name":"Bruce Wayne","title":null},{"id":424,"username":"bruce422","avatar_template":"/letter_avatar_proxy/v2/letter/b/dbc845/{size}.png","name":"Bruce Wayne","title":null},{"id":425,"username":"bruce423","avatar_template":"/letter_avatar_proxy/v2/letter/b/22d042/{size}.png","name":"Bruce Wayne","title":null},{"id":427,"username":"bruce425","avatar_template":"/letter_avatar_proxy/v2/letter/b/ac8455/{size}.png","name":"Bruce Wayne","title":null},{"id":428,"username":"bruce426","avatar_template":"/letter_avatar_proxy/v2/letter/b/df788c/{size}.png","name":"Bruce Wayne","title":null},{"id":430,"username":"bruce428","avatar_template":"/letter_avatar_proxy/v2/letter/b/a88e4f/{size}.png","name":"Bruce Wayne","title":null},{"id":431,"username":"bruce429","avatar_template":"/letter_avatar_proxy/v2/letter/b/958977/{size}.png","name":"Bruce Wayne","title":null},{"id":432,"username":"bruce430","avatar_template":"/letter_avatar_proxy/v2/letter/b/85f322/{size}.png","name":"Bruce Wayne","title":null},{"id":436,"username":"bruce434","avatar_template":"/letter_avatar_proxy/v2/letter/b/bc79bd/{size}.png","name":"Bruce Wayne","title":null},{"id":438,"username":"bruce436","avatar_template":"/letter_avatar_proxy/v2/letter/b/45deac/{size}.png","name":"Bruce Wayne","title":null},{"id":444,"username":"bruce442","avatar_template":"/letter_avatar_proxy/v2/letter/b/df705f/{size}.png","name":"Bruce Wayne","title":null},{"id":446,"username":"bruce444","avatar_template":"/letter_avatar_proxy/v2/letter/b/35a633/{size}.png","name":"Bruce Wayne","title":null},{"id":447,"username":"bruce445","avatar_template":"/letter_avatar_proxy/v2/letter/b/e47774/{size}.png","name":"Bruce Wayne","title":null},{"id":454,"username":"bruce452","avatar_template":"/letter_avatar_proxy/v2/letter/b/57b2e6/{size}.png","name":"Bruce Wayne","title":null},{"id":458,"username":"bruce456","avatar_template":"/letter_avatar_proxy/v2/letter/b/13edae/{size}.png","name":"Bruce Wayne","title":null},{"id":459,"username":"bruce457","avatar_template":"/letter_avatar_proxy/v2/letter/b/a698b9/{size}.png","name":"Bruce Wayne","title":null},{"id":481,"username":"bruce479","avatar_template":"/letter_avatar_proxy/v2/letter/b/90db22/{size}.png","name":"Bruce Wayne","title":null},{"id":492,"username":"bruce490","avatar_template":"/letter_avatar_proxy/v2/letter/b/dfb087/{size}.png","name":"Bruce Wayne","title":null},{"id":494,"username":"bruce492","avatar_template":"/letter_avatar_proxy/v2/letter/b/f1d935/{size}.png","name":"Bruce Wayne","title":null},{"id":500,"username":"bruce498","avatar_template":"/letter_avatar_proxy/v2/letter/b/b9e5f3/{size}.png","name":"Bruce Wayne","title":null}]}};
+ } else if (_.isEqual(request.queryParams, { post_id: "15", poll_name: "poll", offset: "1", option_id: "68b434ff88aeae7054e42cd05a4d9056" })) {
+ body = {"poll":{"68b434ff88aeae7054e42cd05a4d9056":[{"id":402,"username":"bruce400","avatar_template":"/letter_avatar_proxy/v2/letter/b/edb3f5/{size}.png","name":"Bruce Wayne","title":null},{"id":409,"username":"bruce407","avatar_template":"/letter_avatar_proxy/v2/letter/b/59ef9b/{size}.png","name":"Bruce Wayne","title":null},{"id":410,"username":"bruce408","avatar_template":"/letter_avatar_proxy/v2/letter/b/96bed5/{size}.png","name":"Bruce Wayne","title":null},{"id":411,"username":"bruce409","avatar_template":"/letter_avatar_proxy/v2/letter/b/85f322/{size}.png","name":"Bruce Wayne","title":null},{"id":421,"username":"bruce419","avatar_template":"/letter_avatar_proxy/v2/letter/b/848f3c/{size}.png","name":"Bruce Wayne","title":null},{"id":422,"username":"bruce420","avatar_template":"/letter_avatar_proxy/v2/letter/b/bc8723/{size}.png","name":"Bruce Wayne","title":null},{"id":423,"username":"bruce421","avatar_template":"/letter_avatar_proxy/v2/letter/b/7ab992/{size}.png","name":"Bruce Wayne","title":null},{"id":426,"username":"bruce424","avatar_template":"/letter_avatar_proxy/v2/letter/b/5daacb/{size}.png","name":"Bruce Wayne","title":null},{"id":429,"username":"bruce427","avatar_template":"/letter_avatar_proxy/v2/letter/b/ea666f/{size}.png","name":"Bruce Wayne","title":null},{"id":437,"username":"bruce435","avatar_template":"/letter_avatar_proxy/v2/letter/b/8491ac/{size}.png","name":"Bruce Wayne","title":null},{"id":440,"username":"bruce438","avatar_template":"/letter_avatar_proxy/v2/letter/b/dc4da7/{size}.png","name":"Bruce Wayne","title":null},{"id":442,"username":"bruce440","avatar_template":"/letter_avatar_proxy/v2/letter/b/ee7513/{size}.png","name":"Bruce Wayne","title":null},{"id":443,"username":"bruce441","avatar_template":"/letter_avatar_proxy/v2/letter/b/ba8739/{size}.png","name":"Bruce Wayne","title":null},{"id":445,"username":"bruce443","avatar_template":"/letter_avatar_proxy/v2/letter/b/c6cbf5/{size}.png","name":"Bruce Wayne","title":null},{"id":450,"username":"bruce448","avatar_template":"/letter_avatar_proxy/v2/letter/b/b782af/{size}.png","name":"Bruce Wayne","title":null},{"id":451,"username":"bruce449","avatar_template":"/letter_avatar_proxy/v2/letter/b/7c8e57/{size}.png","name":"Bruce Wayne","title":null},{"id":453,"username":"bruce451","avatar_template":"/letter_avatar_proxy/v2/letter/b/e19adc/{size}.png","name":"Bruce Wayne","title":null},{"id":455,"username":"bruce453","avatar_template":"/letter_avatar_proxy/v2/letter/b/e79b87/{size}.png","name":"Bruce Wayne","title":null},{"id":456,"username":"bruce454","avatar_template":"/letter_avatar_proxy/v2/letter/b/74df32/{size}.png","name":"Bruce Wayne","title":null},{"id":461,"username":"bruce459","avatar_template":"/letter_avatar_proxy/v2/letter/b/9de053/{size}.png","name":"Bruce Wayne","title":null},{"id":466,"username":"bruce464","avatar_template":"/letter_avatar_proxy/v2/letter/b/cdc98d/{size}.png","name":"Bruce Wayne","title":null},{"id":468,"username":"bruce466","avatar_template":"/letter_avatar_proxy/v2/letter/b/d78d45/{size}.png","name":"Bruce Wayne","title":null},{"id":477,"username":"bruce475","avatar_template":"/letter_avatar_proxy/v2/letter/b/f05b48/{size}.png","name":"Bruce Wayne","title":null},{"id":478,"username":"bruce476","avatar_template":"/letter_avatar_proxy/v2/letter/b/e36b37/{size}.png","name":"Bruce Wayne","title":null},{"id":498,"username":"bruce496","avatar_template":"/letter_avatar_proxy/v2/letter/b/d26b3c/{size}.png","name":"Bruce Wayne","title":null}]}};
+ }
+
+ return [200, { "Content-Type": "application/json" }, body];
+ });
+
+ visit("/t/this-is-a-topic-created-for-testing/12");
+
+ andThen(() => {
+ const polls = find('.poll');
+ equal(polls.length, 1, 'it should render the poll correctly');
+ });
+
+ click('button.toggle-results');
+
+ andThen(() => {
+ equal(
+ find('.poll-voters:first li').length, 25,
+ 'it should display the right number of voters'
+ );
+ });
+
+ click('.poll-voters-toggle-expand:first a');
+
+ andThen(() => {
+ equal(
+ find('.poll-voters:first li').length, 50,
+ 'it should display the right number of voters'
+ )
+ });
+});
+
+test("Public number poll", () => {
+ server.get('/t/13.json', () => {
+ return [
+ 200,
+ { "Content-Type": "application/json" },
+ {"post_stream":{"posts":[{"id":16,"name":null,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","created_at":"2017-01-31T09:11:11.281Z","cooked":"\n
\n
\n- 1
\n- 2
\n- 3
\n- 4
\n- 5
\n- 6
\n- 7
\n- 8
\n- 9
\n- 10
\n- 11
\n- 12
\n- 13
\n- 14
\n- 15
\n- 16
\n- 17
\n- 18
\n- 19
\n- 20
\n
\n
\n
0voters
\n
Votes are public.
\n
\n
\n
\n
","post_number":1,"post_type":1,"updated_at":"2017-01-31T09:11:11.281Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":13,"topic_slug":"this-is-a-topic-for-testing-number-poll","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":1,"can_edit":true,"can_delete":false,"can_recover":true,"can_wiki":true,"read":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"polls":{"poll":{"options":[{"id":"4d8a15e3cc35750f016ce15a43937620","html":"1","votes":2},{"id":"cd314db7dfbac2b10687b6f39abfdf41","html":"2","votes":1},{"id":"68b434ff88aeae7054e42cd05a4d9056","html":"3","votes":1},{"id":"aa2393b424f2f395abb63bf785760a3b","html":"4","votes":0},{"id":"8b2f2930cac0574c3450f5db9a6fb7f9","html":"5","votes":1},{"id":"60cad69e0cfcb3fa77a68d11d3758002","html":"6","votes":0},{"id":"9ab1070dec27185440cdabb4948a5e9a","html":"7","votes":1},{"id":"99944bf07088f815a966d585daed6a7e","html":"8","votes":3},{"id":"345a83050400d78f5fac98d381b45e23","html":"9","votes":3},{"id":"46c01f638a50d86e020f47469733b8be","html":"10","votes":3},{"id":"07f7f85b2a3809faff68a35e81a664eb","html":"11","votes":2},{"id":"b3e8c14e714910cb8dd7089f097be133","html":"12","votes":4},{"id":"b4f15431e07443c372d521e4ed131abe","html":"13","votes":2},{"id":"a77bc9a30933e5af327211db2da46e17","html":"14","votes":2},{"id":"303d7c623da1985e94a9d27d43596934","html":"15","votes":2},{"id":"4e885ead68ff4456f102843df9fbbd7f","html":"16","votes":1},{"id":"cbf6e2b72e403b12d7ee63a138f32647","html":"17","votes":2},{"id":"9364fa2d67fbd62c473165441ad69571","html":"18","votes":2},{"id":"eb8661f072794ea57baa7827cd8ffc88","html":"19","votes":1},{"id":"b373436e858c0821135f994a5ff3345f","html":"20","votes":2}],"voters":35,"status":"open","name":"poll","type":"number","min":"1","max":"20","step":"1","public":"true"}}}],"stream":[16]},"timeline_lookup":[[1,0]],"id":13,"title":"This is a topic for testing number poll","fancy_title":"This is a topic for testing number poll","posts_count":1,"created_at":"2017-01-31T09:11:11.161Z","views":1,"reply_count":0,"participant_count":1,"like_count":0,"last_posted_at":"2017-01-31T09:11:11.281Z","visible":true,"closed":false,"archived":false,"has_summary":false,"archetype":"regular","slug":"this-is-a-topic-for-testing-number-poll","category_id":1,"word_count":12,"deleted_at":null,"user_id":1,"draft":null,"draft_key":"topic_13","draft_sequence":1,"posted":true,"unpinned":null,"pinned_globally":false,"pinned":false,"pinned_at":null,"pinned_until":null,"details":{"auto_close_at":null,"auto_close_hours":null,"auto_close_based_on_last_post":false,"created_by":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"last_poster":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"},"participants":[{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png","post_count":1,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_color":null,"primary_group_flair_bg_color":null}],"suggested_topics":[{"id":8,"title":"Welcome to Discourse","fancy_title":"Welcome to Discourse","slug":"welcome-to-discourse","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:53:45.363Z","last_posted_at":"2017-01-31T07:53:45.439Z","bumped":true,"bumped_at":"2017-01-31T07:53:45.439Z","unseen":false,"pinned":true,"unpinned":null,"excerpt":"The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important! \n\nEdit this into a brief description of your community: \n\n\nWho is it for?\nWhat can they …","visible":true,"closed":false,"archived":false,"bookmarked":null,"liked":null,"archetype":"regular","like_count":0,"views":0,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":-1,"username":"system","avatar_template":"/letter_avatar_proxy/v2/letter/s/bcef8e/{size}.png"}}]},{"id":11,"title":"This is a test post to try out posts","fancy_title":"This is a test post to try out posts","slug":"this-is-a-test-post-to-try-out-posts","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:55:58.407Z","last_posted_at":"2017-01-31T07:55:58.634Z","bumped":true,"bumped_at":"2017-01-31T07:55:58.634Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":1,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"}}]},{"id":12,"title":"This is a topic created for testing","fancy_title":"This is a topic created for testing","slug":"this-is-a-topic-created-for-testing","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T08:39:06.094Z","last_posted_at":"2017-01-31T08:39:06.237Z","bumped":true,"bumped_at":"2017-01-31T09:10:46.528Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":1,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/letter_avatar_proxy/v2/letter/t/ecae2f/{size}.png"}}]}],"notification_level":3,"notifications_reason_id":1,"can_move_posts":true,"can_edit":true,"can_delete":true,"can_recover":true,"can_remove_allowed_users":true,"can_invite_to":true,"can_create_post":true,"can_reply_as_new_topic":true,"can_flag_topic":true},"highest_post_number":1,"last_read_post_number":1,"last_read_post_id":16,"deleted_by":null,"has_deleted":false,"actions_summary":[{"id":4,"count":0,"hidden":false,"can_act":true},{"id":7,"count":0,"hidden":false,"can_act":true},{"id":8,"count":0,"hidden":false,"can_act":true}],"chunk_size":20,"bookmarked":false,"featured_link":null}
+ ]
+ });
+
+ server.get('/polls/voters.json', request => {
+ let body = {};
+
+ if (_.isEqual(request.queryParams, { post_id: "16", poll_name: "poll" })) {
+ body = {"poll":[{"id":402,"username":"bruce400","avatar_template":"/letter_avatar_proxy/v2/letter/b/edb3f5/{size}.png","name":"Bruce Wayne","title":null},{"id":403,"username":"bruce401","avatar_template":"/letter_avatar_proxy/v2/letter/b/e36b37/{size}.png","name":"Bruce Wayne","title":null},{"id":404,"username":"bruce402","avatar_template":"/letter_avatar_proxy/v2/letter/b/da6949/{size}.png","name":"Bruce Wayne","title":null},{"id":405,"username":"bruce403","avatar_template":"/letter_avatar_proxy/v2/letter/b/91b2a8/{size}.png","name":"Bruce Wayne","title":null},{"id":406,"username":"bruce404","avatar_template":"/letter_avatar_proxy/v2/letter/b/51bf81/{size}.png","name":"Bruce Wayne","title":null},{"id":407,"username":"bruce405","avatar_template":"/letter_avatar_proxy/v2/letter/b/d9b06d/{size}.png","name":"Bruce Wayne","title":null},{"id":408,"username":"bruce406","avatar_template":"/letter_avatar_proxy/v2/letter/b/7c8e57/{size}.png","name":"Bruce Wayne","title":null},{"id":409,"username":"bruce407","avatar_template":"/letter_avatar_proxy/v2/letter/b/59ef9b/{size}.png","name":"Bruce Wayne","title":null},{"id":410,"username":"bruce408","avatar_template":"/letter_avatar_proxy/v2/letter/b/96bed5/{size}.png","name":"Bruce Wayne","title":null},{"id":411,"username":"bruce409","avatar_template":"/letter_avatar_proxy/v2/letter/b/85f322/{size}.png","name":"Bruce Wayne","title":null},{"id":412,"username":"bruce410","avatar_template":"/letter_avatar_proxy/v2/letter/b/2acd7d/{size}.png","name":"Bruce Wayne","title":null},{"id":413,"username":"bruce411","avatar_template":"/letter_avatar_proxy/v2/letter/b/258eb7/{size}.png","name":"Bruce Wayne","title":null},{"id":414,"username":"bruce412","avatar_template":"/letter_avatar_proxy/v2/letter/b/e68b1a/{size}.png","name":"Bruce Wayne","title":null},{"id":415,"username":"bruce413","avatar_template":"/letter_avatar_proxy/v2/letter/b/ce7236/{size}.png","name":"Bruce Wayne","title":null},{"id":416,"username":"bruce414","avatar_template":"/letter_avatar_proxy/v2/letter/b/b5ac83/{size}.png","name":"Bruce Wayne","title":null},{"id":417,"username":"bruce415","avatar_template":"/letter_avatar_proxy/v2/letter/b/6de8d8/{size}.png","name":"Bruce Wayne","title":null},{"id":419,"username":"bruce417","avatar_template":"/letter_avatar_proxy/v2/letter/b/91b2a8/{size}.png","name":"Bruce Wayne","title":null},{"id":421,"username":"bruce419","avatar_template":"/letter_avatar_proxy/v2/letter/b/848f3c/{size}.png","name":"Bruce Wayne","title":null},{"id":422,"username":"bruce420","avatar_template":"/letter_avatar_proxy/v2/letter/b/bc8723/{size}.png","name":"Bruce Wayne","title":null},{"id":424,"username":"bruce422","avatar_template":"/letter_avatar_proxy/v2/letter/b/dbc845/{size}.png","name":"Bruce Wayne","title":null},{"id":425,"username":"bruce423","avatar_template":"/letter_avatar_proxy/v2/letter/b/22d042/{size}.png","name":"Bruce Wayne","title":null},{"id":427,"username":"bruce425","avatar_template":"/letter_avatar_proxy/v2/letter/b/ac8455/{size}.png","name":"Bruce Wayne","title":null},{"id":430,"username":"bruce428","avatar_template":"/letter_avatar_proxy/v2/letter/b/a88e4f/{size}.png","name":"Bruce Wayne","title":null},{"id":431,"username":"bruce429","avatar_template":"/letter_avatar_proxy/v2/letter/b/958977/{size}.png","name":"Bruce Wayne","title":null},{"id":435,"username":"bruce433","avatar_template":"/letter_avatar_proxy/v2/letter/b/77aa72/{size}.png","name":"Bruce Wayne","title":null}]};
+ } else if (_.isEqual(request.queryParams, { post_id: "16", poll_name: "poll", offset: "1" })) {
+ body = {"poll":[{"id":418,"username":"bruce416","avatar_template":"/letter_avatar_proxy/v2/letter/b/a88e4f/{size}.png","name":"Bruce Wayne","title":null},{"id":420,"username":"bruce418","avatar_template":"/letter_avatar_proxy/v2/letter/b/bbce88/{size}.png","name":"Bruce Wayne","title":null},{"id":423,"username":"bruce421","avatar_template":"/letter_avatar_proxy/v2/letter/b/7ab992/{size}.png","name":"Bruce Wayne","title":null},{"id":426,"username":"bruce424","avatar_template":"/letter_avatar_proxy/v2/letter/b/5daacb/{size}.png","name":"Bruce Wayne","title":null},{"id":428,"username":"bruce426","avatar_template":"/letter_avatar_proxy/v2/letter/b/df788c/{size}.png","name":"Bruce Wayne","title":null},{"id":429,"username":"bruce427","avatar_template":"/letter_avatar_proxy/v2/letter/b/ea666f/{size}.png","name":"Bruce Wayne","title":null},{"id":432,"username":"bruce430","avatar_template":"/letter_avatar_proxy/v2/letter/b/85f322/{size}.png","name":"Bruce Wayne","title":null},{"id":433,"username":"bruce431","avatar_template":"/letter_avatar_proxy/v2/letter/b/5f8ce5/{size}.png","name":"Bruce Wayne","title":null},{"id":434,"username":"bruce432","avatar_template":"/letter_avatar_proxy/v2/letter/b/e480ec/{size}.png","name":"Bruce Wayne","title":null},{"id":436,"username":"bruce434","avatar_template":"/letter_avatar_proxy/v2/letter/b/bc79bd/{size}.png","name":"Bruce Wayne","title":null}]};
+ }
+
+ return [200, { "Content-Type": "application/json" }, body];
+ });
+
+ visit("/t/this-is-a-topic-for-testing-number-poll/13");
+
+ andThen(() => {
+ const polls = find('.poll');
+ equal(polls.length, 1, 'it should render the poll correctly');
+ });
+
+ click('button.toggle-results');
+
+ andThen(() => {
+ equal(
+ find('.poll-voters:first li').length, 25,
+ 'it should display the right number of voters'
+ );
+ });
+
+ click('.poll-voters-toggle-expand:first a');
+
+ andThen(() => {
+ equal(
+ find('.poll-voters:first li').length, 35,
+ 'it should display the right number of voters'
+ )
+ });
+});