Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use the following command in your rails console : `Decidim::User.find_each { |us

**Fixed**:

- **decidim-surveys**: Fix validation issue on survey sortable question [\#314](https://github.com/OpenSourcePolitics/decidim/pull/314)
- **decidim-surveys**: Fix issue when copying. [\#308](https://github.com/decidim/decidim/pull/308)
- **decidim-admin**: Add email validation to ManagedUserPromotionForm. [\#295](https://github.com/OpenSourcePolitics/decidim/pull/295)
- **decidim-budgets**: Fix display of budgets when votes count is activated. [\#268](https://github.com/OpenSourcePolitics/decidim/pull/268)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SurveyAnswerForm < Decidim::Form
validates :selected_choices, presence: true, if: :mandatory_choices?

validate :max_choices, if: -> { question.max_choices }
validate :all_choices, if: -> { question.question_type == "sorting" }
validate :all_choices, if: :sortable_question_validatable?

delegate :mandatory_body?, :mandatory_choices?, to: :question

Expand Down Expand Up @@ -49,6 +49,11 @@ def selected_choices

private

def sortable_question_validatable?
return false unless question.question_type == "sorting"
mandatory_choices? || !selected_choices.empty?
end

def max_choices
errors.add(:choices, :too_many) if selected_choices.size > question.max_choices
end
Expand Down
2 changes: 2 additions & 0 deletions decidim-surveys/config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ fr:
attributes:
survey_answer:
body: Réponse
selected_choices: La selection
choices: Les choix
survey_question:
mandatory: Réponse à la question obligatoire
max_choices: Nombre de choix maximum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ module Surveys
expect(subject).not_to be_valid
end
end

context "and question type is sorting" do
let(:question_type) { "sorting" }

it "is not valid if no a single options checked" do
subject.choices = []

expect(subject).not_to be_valid
end
end
end

context "when the question has max_choices set" do
Expand Down Expand Up @@ -108,6 +118,12 @@ module Surveys

expect(subject).not_to be_valid
end

it "is valid if no options checked" do
subject.choices = []

expect(subject).to be_valid
end
end
end
end
Expand Down