Commit bb0ede0adc46bced9b88c51586ad3da50de318cd
Committed by
Gabriela Navarro
1 parent
ec14e2f6
Exists in
master
and in
5 other branches
Add software_info validations and tests
-Remove acronym from required fields Signed-off-by: Luiz Matos <luizff.matos@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
3 changed files
with
15 additions
and
12 deletions
Show diff stats
lib/software_info.rb
| ... | ... | @@ -99,10 +99,10 @@ class SoftwareInfo < ActiveRecord::Base |
| 99 | 99 | end |
| 100 | 100 | |
| 101 | 101 | def validate_acronym |
| 102 | - if self.acronym.blank? && self.errors.messages[:acronym].nil? | |
| 103 | - self.errors.add(:acronym, _("can't be blank")) | |
| 104 | - elsif self.acronym.length > 8 && self.errors.messages[:acronym].nil? | |
| 105 | - self.errors.add(:acronym, _("can't have more than 8 characteres")) | |
| 102 | + if self.acronym.length > 10 && self.errors.messages[:acronym].nil? | |
| 103 | + self.errors.add(:acronym, _("can't have more than 10 characteres")) | |
| 104 | + elsif self.acronym.match(/\s+/) | |
| 105 | + self.errors.add(:acronym, _("can't have whitespaces")) | |
| 106 | 106 | end |
| 107 | 107 | end |
| 108 | 108 | ... | ... |
test/unit/software_info_validation_test.rb
| ... | ... | @@ -45,13 +45,18 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
| 45 | 45 | assert_equal true, @software_info.save |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | - should "Not save SoftwareInfo if acronym is blank" do | |
| 48 | + should "Save SoftwareInfo if acronym is blank" do | |
| 49 | 49 | @software_info.acronym = "" |
| 50 | - assert_equal false, @software_info.save | |
| 50 | + assert_equal true, @software_info.save | |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | 53 | should "Not save SoftwareInfo if acronym has more than 8 characters" do |
| 54 | - @software_info.acronym = "123456789" | |
| 54 | + @software_info.acronym = "12345678901" | |
| 55 | + assert_equal false, @software_info.save | |
| 56 | + end | |
| 57 | + | |
| 58 | + should "Not save SoftwareInfo if acronym has whitespaces" do | |
| 59 | + @software_info.acronym = "AC DC" | |
| 55 | 60 | assert_equal false, @software_info.save |
| 56 | 61 | end |
| 57 | 62 | end | ... | ... |
views/mpog_software_plugin_myprofile/new_software.html.erb
| ... | ... | @@ -27,12 +27,10 @@ |
| 27 | 27 | <%= required f.text_field(:name) %> |
| 28 | 28 | |
| 29 | 29 | <%= fields_for @software_info do |swf| %> |
| 30 | - <span class='required-field'> | |
| 31 | - <div class="formfield type-text"> | |
| 30 | + <div class="formfield type-text"> | |
| 32 | 31 | <%= swf.label("acronym" ,_("Acronym"), :class=>"formlabel") %> |
| 33 | - <%= required swf.text_field(:acronym) %> | |
| 34 | - </div> | |
| 35 | - </span> | |
| 32 | + <%= swf.text_field(:acronym) %> | |
| 33 | + </div> | |
| 36 | 34 | |
| 37 | 35 | <div class="formfieldline"> |
| 38 | 36 | <%= swf.label _("Adherent to e-PING ?") %> | ... | ... |