Commit bb0ede0adc46bced9b88c51586ad3da50de318cd

Authored by Gust
Committed by Gabriela Navarro
1 parent ec14e2f6
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

-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 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 &lt; 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 ?") %>
... ...