Commit 69a6bc082e834d55bc6e919f53fcf0f7c69193df
Committed by
Gabriela Navarro
1 parent
bb0ede0a
Exists in
master
and in
5 other branches
Add software_info validations and tests
(correcoes_aderencia) Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
3 changed files
with
41 additions
and
2 deletions
Show diff stats
lib/software_info.rb
... | ... | @@ -14,6 +14,13 @@ class SoftwareInfo < ActiveRecord::Base |
14 | 14 | |
15 | 15 | has_one :controlled_vocabulary |
16 | 16 | |
17 | + validates :features, :objectives, | |
18 | + :presence=>true, | |
19 | + :length => { | |
20 | + :maximum => 4000, | |
21 | + :too_long => _("Software features is too long (maximum is 4000 characters)") | |
22 | + } | |
23 | + | |
17 | 24 | validate :validate_operating_platform, :validate_acronym, :valid_software_info, :valid_databases, :valid_operating_systems |
18 | 25 | |
19 | 26 | # used on find_by_contents |
... | ... | @@ -99,6 +106,8 @@ class SoftwareInfo < ActiveRecord::Base |
99 | 106 | end |
100 | 107 | |
101 | 108 | def validate_acronym |
109 | + self.acronym = "" if self.acronym.nil? | |
110 | + | |
102 | 111 | if self.acronym.length > 10 && self.errors.messages[:acronym].nil? |
103 | 112 | self.errors.add(:acronym, _("can't have more than 10 characteres")) |
104 | 113 | elsif self.acronym.match(/\s+/) | ... | ... |
test/unit/software_info_validation_test.rb
... | ... | @@ -29,6 +29,8 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
29 | 29 | @software_info.software_databases << @software_database |
30 | 30 | @software_info.operating_systems << @operating_system |
31 | 31 | |
32 | + @software_info.features = "Do a lot of things" | |
33 | + @software_info.objectives = "All tests should pass !" | |
32 | 34 | end |
33 | 35 | |
34 | 36 | should 'Save SoftwareInfo if all fields are filled' do |
... | ... | @@ -59,4 +61,32 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
59 | 61 | @software_info.acronym = "AC DC" |
60 | 62 | assert_equal false, @software_info.save |
61 | 63 | end |
64 | + | |
65 | + should "Not save if objectives are empty" do | |
66 | + @software_info.objectives = "" | |
67 | + | |
68 | + assert_equal false, @software_info.save | |
69 | + assert_equal true, @software_info.errors.full_messages.include?(_("Objectives can't be blank")) | |
70 | + end | |
71 | + | |
72 | + should "Not save if features are empty" do | |
73 | + @software_info.features = "" | |
74 | + | |
75 | + assert_equal false, @software_info.save | |
76 | + assert_equal true, @software_info.errors.full_messages.include?(_("Features can't be blank")) | |
77 | + end | |
78 | + | |
79 | + should "Not save if features are longer than 4000" do | |
80 | + @software_info.features = "a"*4001 | |
81 | + | |
82 | + assert_equal false, @software_info.save | |
83 | + assert_equal true, @software_info.errors.full_messages.include?(_("Features Software features is too long (maximum is 4000 characters)")) | |
84 | + end | |
85 | + | |
86 | + should "Not save if objectives are longer than 4000" do | |
87 | + @software_info.objectives = "a"*4001 | |
88 | + | |
89 | + assert_equal false, @software_info.save | |
90 | + assert_equal true, @software_info.errors.full_messages.include?(_("Objectives Software features is too long (maximum is 4000 characters)")) | |
91 | + end | |
62 | 92 | end | ... | ... |
views/mpog_software_plugin_myprofile/new_software.html.erb
... | ... | @@ -82,12 +82,12 @@ |
82 | 82 | |
83 | 83 | <div class="formfieldline"> |
84 | 84 | <%= swf.label "objectives", _("Objectives: ")%><br /> |
85 | - <%= swf.text_area(:objectives, :class=>"expand-field") %> | |
85 | + <%= required swf.text_area(:objectives, :class=>"expand-field") %> | |
86 | 86 | </div> |
87 | 87 | |
88 | 88 | <div class="formfieldline"> |
89 | 89 | <%= swf.label "features", _("Features: ")%><br /> |
90 | - <%= swf.text_area(:features, :class=>"expand-field") %> | |
90 | + <%= required swf.text_area(:features, :class=>"expand-field") %> | |
91 | 91 | </div> |
92 | 92 | |
93 | 93 | <div class="formfieldline formfield type-text"> | ... | ... |