Commit e15e75820d128b85878accc63a51c10da41f79e4

Authored by Luciano Prestes
Committed by David Silva
1 parent a490ebe7
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

Fix another version and link to failure tests

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
controllers/mpog_software_plugin_myprofile_controller.rb
... ... @@ -23,7 +23,7 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
23 23 @license_info = if params[:license_info].nil?
24 24 LicenseInfo.new
25 25 else
26   - LicenseInfo.find(params[:license_info][:version])
  26 + LicenseInfo.find(params[:license_info][:id])
27 27 end
28 28  
29 29 control_software_creation
... ... @@ -123,8 +123,12 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
123 123 @software_info.license_info = @license
124 124 @software_info.update_attributes(params[:software])
125 125  
126   - another_license_version = params[:license][:version]
127   - another_license_link = params[:license][:link]
  126 + another_license_version = nil
  127 + another_license_link = nil
  128 + if params[:license]
  129 + another_license_version = params[:license][:version]
  130 + another_license_link = params[:license][:link]
  131 + end
128 132  
129 133 @software_info.verify_license_info(another_license_version, another_license_link)
130 134  
... ... @@ -141,13 +145,19 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
141 145 end
142 146  
143 147 def send_software_to_moderation
  148 + another_license_version = ""
  149 + another_license_link = ""
  150 + if params[:license]
  151 + another_license_version = params[:license][:version]
  152 + another_license_link = params[:license][:link]
  153 + end
144 154 @software_info = SoftwareInfo.create_after_moderation(user,
145 155 params[:software_info].merge({
146 156 :environment => environment,
147 157 :name => params[:community][:name],
148 158 :license_info => @license_info,
149   - :another_license_version => params[:license][:version],
150   - :another_license_link => params[:license][:link] }))
  159 + :another_license_version => another_license_version,
  160 + :another_license_link => another_license_link }))
151 161  
152 162 add_admin_to_community
153 163  
... ... @@ -173,7 +183,8 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
173 183 @another_license_version = ""
174 184 @another_license_link = ""
175 185  
176   - if @software_info.license_info_id == LicenseInfo.find_by_version("Another").id
  186 + license_another = LicenseInfo.find_by_version("Another")
  187 + if license_another && @software_info.license_info_id == license_another.id
177 188 @another_license_version = @software_info.license_info.version
178 189 @another_license_link = @software_info.license_info.link
179 190 end
... ...
lib/software_info.rb
... ... @@ -68,8 +68,9 @@ class SoftwareInfo &lt; ActiveRecord::Base
68 68  
69 69 def license_info
70 70 license = LicenseInfo.find_by_id self.license_info_id
  71 + license_another = LicenseInfo.find_by_version("Another")
71 72  
72   - if license == LicenseInfo.find_by_version("Another")
  73 + if license_another && license.id == license_another.id
73 74 LicenseInfo.new(
74 75 :version => self.another_license_version,
75 76 :link => self.another_license_link
... ... @@ -80,10 +81,14 @@ class SoftwareInfo &lt; ActiveRecord::Base
80 81 end
81 82  
82 83 def another_license(version, link)
83   - self.another_license_version = version
84   - self.another_license_link = link
85   - self.license_info = LicenseInfo.find_by_version("Another")
86   - self.save!
  84 + license_another = LicenseInfo.find_by_version("Another")
  85 +
  86 + if license_another
  87 + self.another_license_version = version
  88 + self.another_license_link = link
  89 + self.license_info = license_another
  90 + self.save!
  91 + end
87 92 end
88 93  
89 94 def validate_name_lenght
... ... @@ -137,7 +142,9 @@ class SoftwareInfo &lt; ActiveRecord::Base
137 142 end
138 143  
139 144 def verify_license_info another_license_version, another_license_link
140   - if self.license_info_id == LicenseInfo.find_by_version("Another").id
  145 + license_another = LicenseInfo.find_by_version("Another")
  146 +
  147 + if license_another && self.license_info_id == license_another.id
141 148 version = another_license_version
142 149 link = another_license_link
143 150  
... ...
public/mpog-software-validations.js
... ... @@ -108,7 +108,7 @@
108 108 }
109 109  
110 110 function show_another_license_on_page_load() {
111   - jQuery("#license_info_version").trigger("change");
  111 + jQuery("#license_info_id").trigger("change");
112 112 }
113 113  
114 114 function hide_infos() {
... ... @@ -222,7 +222,7 @@
222 222  
223 223 replace_software_creations_step();
224 224  
225   - jQuery("#license_info_version").change(get_license_link);
  225 + jQuery("#license_info_id").change(get_license_link);
226 226 show_another_license_on_page_load();
227 227 });
228 228 })();
... ...
test/helpers/software_test_helper.rb
... ... @@ -171,6 +171,7 @@ module SoftwareTestHelper
171 171  
172 172 #Fields for license info
173 173 fields_license['version'] = LicenseInfo.last.version
  174 + fields_license['id'] = LicenseInfo.last.id
174 175 hash_list << fields_license
175 176  
176 177 #Fields for community
... ...
views/_main_software_editor_extras.html.erb
... ... @@ -14,7 +14,7 @@
14 14  
15 15 <h3> <%= _("Licenses") %> </h3>
16 16 <div id='licenses'>
17   - <%= select_tag(:version, options_for_select(LicenseHelper.getListLicenses.collect{|l| [l.version, l.id]}, :selected => context.profile.software_info.license_info.id), :onchange => "get_license_link('version')") %>
  17 + <%= select_tag(:id, options_for_select(LicenseHelper.getListLicenses.collect{|l| [l.version, l.id]}, :selected => context.profile.software_info.license_info.id), :onchange => "get_license_link('version')") %>
18 18 <br />
19 19  
20 20 <h4> <%= _("License link") %> </h4>
... ...
views/mpog_software_plugin_myprofile/new_software.html.erb
... ... @@ -45,7 +45,7 @@
45 45 <%= fields_for @license_info do |lcv| %>
46 46 <div class="formfieldline">
47 47 <h4> <%= lcv.label _("License Version: ") %> </h4>
48   - <%= lcv.select(:version, LicenseInfo.all.map {|l| [l.version, l.id]}, {:selected => 1}) %>
  48 + <%= lcv.select(:id, LicenseInfo.all.map {|l| [l.version, l.id]}, {:selected => 1}) %>
49 49  
50 50 <h4> <%= _("License link") %> </h4>
51 51 <% LicenseHelper.getListLicenses.each do | license | %>
... ...