A platform for community discussion. Free, open, simple.
FEATURE: Allow single option polls (#8853)
Mark VanLandingham5d97286fa713
diff --git a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6index 48bae0380dc..00b7f8f6208 100644--- a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6+++ b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6@@ -272,9 +272,9 @@ export default Controller.extend({)disableInsert(count, isRegular, isMultiple, isNumber, pollMin, pollMax) {return (- (isRegular && count < 2) ||+ (isRegular && count < 1) ||(isMultiple && count < pollMin && pollMin >= pollMax) ||- (isNumber ? false : count < 2)+ (isNumber ? false : count < 1));},diff --git a/plugins/poll/config/locales/client.en.yml b/plugins/poll/config/locales/client.en.ymlindex c776f7feba6..ae4a258e883 100644--- a/plugins/poll/config/locales/client.en.yml+++ b/plugins/poll/config/locales/client.en.yml@@ -100,7 +100,7 @@ en:title: Build Pollinsert: Insert Pollhelp:- options_count: Enter at least 2 options+ options_count: Enter at least 1 optioninvalid_values: Minimum value must be smaller than the maximum value.min_step_value: The minimum step value is 1poll_type:diff --git a/plugins/poll/config/locales/server.en.yml b/plugins/poll/config/locales/server.en.ymlindex a90e12313b6..058ab93e775 100644--- a/plugins/poll/config/locales/server.en.yml+++ b/plugins/poll/config/locales/server.en.yml@@ -30,8 +30,8 @@ en:multiple_polls_without_name: "There are multiple polls without a name. Use the '<code>name</code>' attribute to uniquely identify your polls."multiple_polls_with_same_name: "There are multiple polls with the same name: <strong>%{name}</strong>. Use the '<code>name</code>' attribute to uniquely identify your polls."- default_poll_must_have_at_least_2_options: "Poll must have at least 2 options."- named_poll_must_have_at_least_2_options: "Poll named <strong>%{name}</strong> must have at least 2 options."+ default_poll_must_have_at_least_1_option: "Poll must have at least 1 option."+ named_poll_must_have_at_least_1_option: "Poll named <strong>%{name}</strong> must have at least 1 option."default_poll_must_have_less_options:one: "Poll must have less than %{count} option."diff --git a/plugins/poll/lib/polls_validator.rb b/plugins/poll/lib/polls_validator.rbindex 88712bc6da4..ecdf3c849cf 100644--- a/plugins/poll/lib/polls_validator.rb+++ b/plugins/poll/lib/polls_validator.rb@@ -18,7 +18,7 @@ module DiscoursePollreturn false unless unique_poll_name?(polls, poll)return false unless unique_options?(poll)return false unless any_blank_options?(poll)- return false unless at_least_two_options?(poll)+ return false unless at_least_one_option?(poll)return false unless valid_number_of_options?(poll)return false unless valid_multiple_choice_settings?(poll)polls[poll["name"]] = poll@@ -92,12 +92,12 @@ module DiscoursePolltrueend- def at_least_two_options?(poll)- if poll["options"].size < 2+ def at_least_one_option?(poll)+ if poll["options"].size < 1if poll["name"] == ::DiscoursePoll::DEFAULT_POLL_NAME- @post.errors.add(:base, I18n.t("poll.default_poll_must_have_at_least_2_options"))+ @post.errors.add(:base, I18n.t("poll.default_poll_must_have_at_least_1_option"))else- @post.errors.add(:base, I18n.t("poll.named_poll_must_have_at_least_2_options", name: poll["name"]))+ @post.errors.add(:base, I18n.t("poll.named_poll_must_have_at_least_1_option", name: poll["name"]))endreturn false@@ -170,9 +170,9 @@ module DiscoursePollvalid = falseelsif ((max - min + 1) / step) < 2if poll["name"] == ::DiscoursePoll::DEFAULT_POLL_NAME- @post.errors.add(:base, I18n.t("poll.default_poll_must_have_at_least_2_options"))+ @post.errors.add(:base, I18n.t("poll.default_poll_must_have_at_least_1_option"))else- @post.errors.add(:base, I18n.t("poll.named_poll_must_have_at_least_2_options", name: poll["name"]))+ @post.errors.add(:base, I18n.t("poll.named_poll_must_have_at_least_1_option", name: poll["name"]))endvalid = falseenddiff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rbindex e0eea906037..411247c8f74 100644--- a/plugins/poll/spec/controllers/posts_controller_spec.rb+++ b/plugins/poll/spec/controllers/posts_controller_spec.rb@@ -72,14 +72,14 @@ describe PostsController doexpect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_different_options"))end- it "should have at least 2 options" do+ it "should have at least 1 options" dopost :create, params: {- title: title, raw: "[poll]\n- A\n[/poll]"+ title: title, raw: "[poll]\n[/poll]"}, format: :jsonexpect(response).not_to be_successfuljson = ::JSON.parse(response.body)- expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_at_least_2_options"))+ expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_at_least_1_option"))endit "should have at most 'SiteSetting.poll_maximum_options' options" do@@ -267,14 +267,14 @@ describe PostsController doexpect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_different_options", name: "foo"))end- it "should have at least 2 options" do+ it "should have at least 1 option" dopost :create, params: {- title: title, raw: "[poll name='foo']\n- A\n[/poll]"+ title: title, raw: "[poll name='foo']\n[/poll]"}, format: :jsonexpect(response).not_to be_successfuljson = ::JSON.parse(response.body)- expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_at_least_2_options", name: "foo"))+ expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_at_least_1_option", name: "foo"))endenddiff --git a/plugins/poll/spec/lib/polls_validator_spec.rb b/plugins/poll/spec/lib/polls_validator_spec.rbindex 46048806e25..761fc359f17 100644--- a/plugins/poll/spec/lib/polls_validator_spec.rb+++ b/plugins/poll/spec/lib/polls_validator_spec.rb@@ -154,10 +154,9 @@ describe ::DiscoursePoll::PollsValidator do)end- it "ensure that polls have at least 2 options" do+ it "ensure that polls have at least 1 option" doraw = <<~RAW[poll]- * 1[/poll]RAW@@ -165,12 +164,11 @@ describe ::DiscoursePoll::PollsValidator doexpect(post.valid?).to eq(false)expect(post.errors[:base]).to include(- I18n.t("poll.default_poll_must_have_at_least_2_options")+ I18n.t("poll.default_poll_must_have_at_least_1_option"))raw = <<~RAW[poll name=test]- * 1[/poll]RAW@@ -178,7 +176,7 @@ describe ::DiscoursePoll::PollsValidator doexpect(post.valid?).to eq(false)expect(post.errors[:base]).to include(- I18n.t("poll.named_poll_must_have_at_least_2_options", name: "test")+ I18n.t("poll.named_poll_must_have_at_least_1_option", name: "test"))end@@ -365,7 +363,7 @@ describe ::DiscoursePoll::PollsValidator doexpect(post.valid?).to eq(false)expect(post.errors[:base]).to include("Min #{I18n.t("errors.messages.less_than", count: 2_147_483_647)}")expect(post.errors[:base]).to include("Max #{I18n.t("errors.messages.less_than", count: 2_147_483_647)}")- expect(post.errors[:base]).to include(I18n.t("poll.default_poll_must_have_at_least_2_options"))+ expect(post.errors[:base]).to include(I18n.t("poll.default_poll_must_have_at_least_1_option"))endendenddiff --git a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6index 3653717de26..e8ec02908c2 100644--- a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6+++ b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6@@ -195,10 +195,17 @@ test("disableInsert", function(assert) {controller.setProperties({pollType: controller.regularPollType,- pollOptionsCount: 1+ pollOptionsCount: 0});assert.equal(controller.disableInsert, true, "it should be true");++ controller.setProperties({+ pollType: controller.regularPollType,+ pollOptionsCount: 1+ });++ assert.equal(controller.disableInsert, false, "it should be false");});test("number pollOutput", function(assert) {