Commit e15e75820d128b85878accc63a51c10da41f79e4

Authored by Luciano Prestes
Committed by David Silva
1 parent a490ebe7

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,7 +23,7 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
23 @license_info = if params[:license_info].nil? 23 @license_info = if params[:license_info].nil?
24 LicenseInfo.new 24 LicenseInfo.new
25 else 25 else
26 - LicenseInfo.find(params[:license_info][:version]) 26 + LicenseInfo.find(params[:license_info][:id])
27 end 27 end
28 28
29 control_software_creation 29 control_software_creation
@@ -123,8 +123,12 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController @@ -123,8 +123,12 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
123 @software_info.license_info = @license 123 @software_info.license_info = @license
124 @software_info.update_attributes(params[:software]) 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 @software_info.verify_license_info(another_license_version, another_license_link) 133 @software_info.verify_license_info(another_license_version, another_license_link)
130 134
@@ -141,13 +145,19 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController @@ -141,13 +145,19 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
141 end 145 end
142 146
143 def send_software_to_moderation 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 @software_info = SoftwareInfo.create_after_moderation(user, 154 @software_info = SoftwareInfo.create_after_moderation(user,
145 params[:software_info].merge({ 155 params[:software_info].merge({
146 :environment => environment, 156 :environment => environment,
147 :name => params[:community][:name], 157 :name => params[:community][:name],
148 :license_info => @license_info, 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 add_admin_to_community 162 add_admin_to_community
153 163
@@ -173,7 +183,8 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController @@ -173,7 +183,8 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
173 @another_license_version = "" 183 @another_license_version = ""
174 @another_license_link = "" 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 @another_license_version = @software_info.license_info.version 188 @another_license_version = @software_info.license_info.version
178 @another_license_link = @software_info.license_info.link 189 @another_license_link = @software_info.license_info.link
179 end 190 end
lib/software_info.rb
@@ -68,8 +68,9 @@ class SoftwareInfo &lt; ActiveRecord::Base @@ -68,8 +68,9 @@ class SoftwareInfo &lt; ActiveRecord::Base
68 68
69 def license_info 69 def license_info
70 license = LicenseInfo.find_by_id self.license_info_id 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 LicenseInfo.new( 74 LicenseInfo.new(
74 :version => self.another_license_version, 75 :version => self.another_license_version,
75 :link => self.another_license_link 76 :link => self.another_license_link
@@ -80,10 +81,14 @@ class SoftwareInfo &lt; ActiveRecord::Base @@ -80,10 +81,14 @@ class SoftwareInfo &lt; ActiveRecord::Base
80 end 81 end
81 82
82 def another_license(version, link) 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 end 92 end
88 93
89 def validate_name_lenght 94 def validate_name_lenght
@@ -137,7 +142,9 @@ class SoftwareInfo &lt; ActiveRecord::Base @@ -137,7 +142,9 @@ class SoftwareInfo &lt; ActiveRecord::Base
137 end 142 end
138 143
139 def verify_license_info another_license_version, another_license_link 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 version = another_license_version 148 version = another_license_version
142 link = another_license_link 149 link = another_license_link
143 150
public/mpog-software-validations.js
@@ -108,7 +108,7 @@ @@ -108,7 +108,7 @@
108 } 108 }
109 109
110 function show_another_license_on_page_load() { 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 function hide_infos() { 114 function hide_infos() {
@@ -222,7 +222,7 @@ @@ -222,7 +222,7 @@
222 222
223 replace_software_creations_step(); 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 show_another_license_on_page_load(); 226 show_another_license_on_page_load();
227 }); 227 });
228 })(); 228 })();
test/helpers/software_test_helper.rb
@@ -171,6 +171,7 @@ module SoftwareTestHelper @@ -171,6 +171,7 @@ module SoftwareTestHelper
171 171
172 #Fields for license info 172 #Fields for license info
173 fields_license['version'] = LicenseInfo.last.version 173 fields_license['version'] = LicenseInfo.last.version
  174 + fields_license['id'] = LicenseInfo.last.id
174 hash_list << fields_license 175 hash_list << fields_license
175 176
176 #Fields for community 177 #Fields for community
views/_main_software_editor_extras.html.erb
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 14
15 <h3> <%= _("Licenses") %> </h3> 15 <h3> <%= _("Licenses") %> </h3>
16 <div id='licenses'> 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 <br /> 18 <br />
19 19
20 <h4> <%= _("License link") %> </h4> 20 <h4> <%= _("License link") %> </h4>
views/mpog_software_plugin_myprofile/new_software.html.erb
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 <%= fields_for @license_info do |lcv| %> 45 <%= fields_for @license_info do |lcv| %>
46 <div class="formfieldline"> 46 <div class="formfieldline">
47 <h4> <%= lcv.label _("License Version: ") %> </h4> 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 <h4> <%= _("License link") %> </h4> 50 <h4> <%= _("License link") %> </h4>
51 <% LicenseHelper.getListLicenses.each do | license | %> 51 <% LicenseHelper.getListLicenses.each do | license | %>