[Git][noosfero/noosfero][master] 4 commits: Prevents submitting an empty poll answer
Rodrigo Souto
gitlab at mg.gitlab.com
Fri Jul 13 15:50:36 BRT 2018
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
55aa83f3 by Matheus Richard at 2018-07-09T16:13:42Z
Prevents submitting an empty poll answer
- - - - -
5a1dbbee by Matheus Richard at 2018-07-10T14:58:40Z
Adds tests to custom_forms poll
- - - - -
fb0bd120 by Matheus Richard at 2018-07-11T12:59:57Z
Fixes before_save on custom_forms field
- - - - -
9b61261f by Rodrigo Souto at 2018-07-13T18:50:32Z
Merge branch 'prevent-empty-submissions' into 'master'
Prevent empty submissions
See merge request noosfero/noosfero!1567
- - - - -
5 changed files:
- plugins/custom_forms/lib/custom_forms_plugin/field.rb
- plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
- plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
- plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb
- plugins/custom_forms/views/custom_forms_plugin_myprofile/_poll.html.erb
Changes:
=====================================
plugins/custom_forms/lib/custom_forms_plugin/field.rb
=====================================
@@ -20,6 +20,13 @@ class CustomFormsPlugin::Field < ApplicationRecord
field.slug = field.name.to_slug if field.name.present?
end
+ before_save do |field|
+
+ if form != nil && form.kind == 'poll'
+ field.mandatory = true
+ end
+ end
+
def accept_multiple_answers?
self.show_as.in? ['check_box', 'multiple_select']
end
=====================================
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
=====================================
@@ -409,7 +409,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase
assert_nil form.image
end
- should 'return filtered polls of a pofile' do
+ should 'return filtered polls of a profile' do
another_profile = fast_create(Profile)
f1 = profile.forms.create(name: 'Form 1', :kind => 'poll')
f2 = profile.forms.create(name: 'Form 2', :kind => 'poll')
=====================================
plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
=====================================
@@ -33,6 +33,17 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase
assert_redirected_to :action => 'show'
end
+ should 'not save empty submission' do
+ form = CustomFormsPlugin::Form.create!(profile: profile, name: 'Free Software', identifier: 'free-software', kind: 'poll')
+ field1 = CustomFormsPlugin::TextField.create(name: 'Name', form: form)
+
+ assert_no_difference 'CustomFormsPlugin::Submission.count' do
+ post :show, :profile => profile.identifier, :id => form.identifier, :submission => {field1.id.to_s => ''}
+ end
+
+ assert_tag :tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' }
+ end
+
should 'display errors if user is not logged in and author_name is not uniq' do
logout
form = CustomFormsPlugin::Form.create(:profile => profile, :name => 'Free Software', :identifier => 'free-software')
=====================================
plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb
=====================================
@@ -11,6 +11,17 @@ class CustomFormsPlugin::FieldTest < ActiveSupport::TestCase
field = CustomFormsPlugin::Field.new
refute field.mandatory
end
+
+ should 'set mandatory field as true when form type is a poll' do
+ form = CustomFormsPlugin::Form.create!(profile: fast_create(Profile),
+ name: 'Free Software',
+ identifier: 'free',
+ kind: 'poll')
+ field = CustomFormsPlugin::Field.new(name: 'field', form: form)
+ field.save!
+
+ assert field.mandatory
+ end
should 'have answers' do
form = CustomFormsPlugin::Form.create!(:profile => fast_create(Profile),
=====================================
plugins/custom_forms/views/custom_forms_plugin_myprofile/_poll.html.erb
=====================================
@@ -6,7 +6,7 @@
<table class='actions'>
<tr>
<th class='poll-question'>
- <%= content_tag('span', content_tag('label', _('Question'), class: 'formlabel'), class: 'required-field') %>
+ <%= required content_tag('label', _('Question'), class: 'formlabel') %>
</th>
<th class='poll-select-type'><%= _('Type') %></th>
</tr>
@@ -60,7 +60,7 @@
<%= check_box_tag("form[fields_attributes][0][alternatives_attributes][#{field.alternatives.size}][selected_by_default]", '1', false) %>
</td>
<td class="poll-remove">
- <%= button_without_text :remove, _('Remove field'), '#', class: 'remove-poll-option' %>
+ <%= button_without_text :remove, nil, '#', class: 'remove-poll-option' %>
</td>
</tr>
</tbody>
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c64dd11b1fbd3d5eaa69f05f021b3393725dff91...9b61261f64703adf4afaa940371678c4e6040a94
--
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c64dd11b1fbd3d5eaa69f05f021b3393725dff91...9b61261f64703adf4afaa940371678c4e6040a94
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180713/2d74df2b/attachment-0001.html>
More information about the Noosfero-dev
mailing list