Commit bb0ede0adc46bced9b88c51586ad3da50de318cd

Authored by Gust
Committed by Gabriela Navarro
1 parent ec14e2f6

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>
lib/software_info.rb
@@ -99,10 +99,10 @@ class SoftwareInfo &lt; ActiveRecord::Base @@ -99,10 +99,10 @@ class SoftwareInfo &lt; ActiveRecord::Base
99 end 99 end
100 100
101 def validate_acronym 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 end 106 end
107 end 107 end
108 108
test/unit/software_info_validation_test.rb
@@ -45,13 +45,18 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase @@ -45,13 +45,18 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase
45 assert_equal true, @software_info.save 45 assert_equal true, @software_info.save
46 end 46 end
47 47
48 - should "Not save SoftwareInfo if acronym is blank" do 48 + should "Save SoftwareInfo if acronym is blank" do
49 @software_info.acronym = "" 49 @software_info.acronym = ""
50 - assert_equal false, @software_info.save 50 + assert_equal true, @software_info.save
51 end 51 end
52 52
53 should "Not save SoftwareInfo if acronym has more than 8 characters" do 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 assert_equal false, @software_info.save 60 assert_equal false, @software_info.save
56 end 61 end
57 end 62 end
views/mpog_software_plugin_myprofile/new_software.html.erb
@@ -27,12 +27,10 @@ @@ -27,12 +27,10 @@
27 <%= required f.text_field(:name) %> 27 <%= required f.text_field(:name) %>
28 28
29 <%= fields_for @software_info do |swf| %> 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 <%= swf.label("acronym" ,_("Acronym"), :class=>"formlabel") %> 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 <div class="formfieldline"> 35 <div class="formfieldline">
38 <%= swf.label _("Adherent to e-PING ?") %> 36 <%= swf.label _("Adherent to e-PING ?") %>