Commit 69a6bc082e834d55bc6e919f53fcf0f7c69193df

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent bb0ede0a
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Add software_info validations and tests

(correcoes_aderencia)

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
lib/software_info.rb
... ... @@ -14,6 +14,13 @@ class SoftwareInfo &lt; 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 &lt; 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 &lt; 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 &lt; 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">
... ...