FEATURE: Allow single option polls (#8853)
This commit is contained in:
parent
53529a3427
commit
5d97286fa7
|
@ -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)
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue