diff --git a/lib/software_info.rb b/lib/software_info.rb index a284046..6dab44c 100644 --- a/lib/software_info.rb +++ b/lib/software_info.rb @@ -99,10 +99,10 @@ class SoftwareInfo < ActiveRecord::Base end def validate_acronym - if self.acronym.blank? && self.errors.messages[:acronym].nil? - self.errors.add(:acronym, _("can't be blank")) - elsif self.acronym.length > 8 && self.errors.messages[:acronym].nil? - self.errors.add(:acronym, _("can't have more than 8 characteres")) + if self.acronym.length > 10 && self.errors.messages[:acronym].nil? + self.errors.add(:acronym, _("can't have more than 10 characteres")) + elsif self.acronym.match(/\s+/) + self.errors.add(:acronym, _("can't have whitespaces")) end end diff --git a/test/unit/software_info_validation_test.rb b/test/unit/software_info_validation_test.rb index 6daac57..40c3635 100644 --- a/test/unit/software_info_validation_test.rb +++ b/test/unit/software_info_validation_test.rb @@ -45,13 +45,18 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase assert_equal true, @software_info.save end - should "Not save SoftwareInfo if acronym is blank" do + should "Save SoftwareInfo if acronym is blank" do @software_info.acronym = "" - assert_equal false, @software_info.save + assert_equal true, @software_info.save end should "Not save SoftwareInfo if acronym has more than 8 characters" do - @software_info.acronym = "123456789" + @software_info.acronym = "12345678901" + assert_equal false, @software_info.save + end + + should "Not save SoftwareInfo if acronym has whitespaces" do + @software_info.acronym = "AC DC" assert_equal false, @software_info.save end end diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index 15f1613..f96579a 100644 --- a/views/mpog_software_plugin_myprofile/new_software.html.erb +++ b/views/mpog_software_plugin_myprofile/new_software.html.erb @@ -27,12 +27,10 @@ <%= required f.text_field(:name) %> <%= fields_for @software_info do |swf| %> - -
+
<%= swf.label("acronym" ,_("Acronym"), :class=>"formlabel") %> - <%= required swf.text_field(:acronym) %> -
- + <%= swf.text_field(:acronym) %> +
<%= swf.label _("Adherent to e-PING ?") %> -- libgit2 0.21.2