diff --git a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6
index 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.yml
index 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 Poll
insert: Insert Poll
help:
- options_count: Enter at least 2 options
+ options_count: Enter at least 1 option
invalid_values: Minimum value must be smaller than the maximum value.
min_step_value: The minimum step value is 1
poll_type:
diff --git a/plugins/poll/config/locales/server.en.yml b/plugins/poll/config/locales/server.en.yml
index 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 'name
' attribute to uniquely identify your polls."
multiple_polls_with_same_name: "There are multiple polls with the same name: %{name}. Use the 'name
' 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 %{name} 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 %{name} 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.rb
index 88712bc6da4..ecdf3c849cf 100644
--- a/plugins/poll/lib/polls_validator.rb
+++ b/plugins/poll/lib/polls_validator.rb
@@ -18,7 +18,7 @@ module DiscoursePoll
return 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 DiscoursePoll
true
end
- def at_least_two_options?(poll)
- if poll["options"].size < 2
+ def at_least_one_option?(poll)
+ if poll["options"].size < 1
if 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"]))
end
return false
@@ -170,9 +170,9 @@ module DiscoursePoll
valid = false
elsif ((max - min + 1) / step) < 2
if 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"]))
end
valid = false
end
diff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rb
index 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 do
expect(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" do
post :create, params: {
- title: title, raw: "[poll]\n- A\n[/poll]"
+ title: title, raw: "[poll]\n[/poll]"
}, format: :json
expect(response).not_to be_successful
json = ::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"))
end
it "should have at most 'SiteSetting.poll_maximum_options' options" do
@@ -267,14 +267,14 @@ describe PostsController do
expect(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" do
post :create, params: {
- title: title, raw: "[poll name='foo']\n- A\n[/poll]"
+ title: title, raw: "[poll name='foo']\n[/poll]"
}, format: :json
expect(response).not_to be_successful
json = ::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"))
end
end
diff --git a/plugins/poll/spec/lib/polls_validator_spec.rb b/plugins/poll/spec/lib/polls_validator_spec.rb
index 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" do
raw = <<~RAW
[poll]
- * 1
[/poll]
RAW
@@ -165,12 +164,11 @@ describe ::DiscoursePoll::PollsValidator do
expect(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 do
expect(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 do
expect(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"))
end
end
end
diff --git a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6
index 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) {