Commit e15e75820d128b85878accc63a51c10da41f79e4
Committed by
David Silva
1 parent
a490ebe7
Exists in
master
and in
5 other branches
Fix another version and link to failure tests
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
6 changed files
with
35 additions
and
16 deletions
Show diff stats
controllers/mpog_software_plugin_myprofile_controller.rb
... | ... | @@ -23,7 +23,7 @@ class MpogSoftwarePluginMyprofileController < 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 < 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 < 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 < 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 < 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 < 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 < 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
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 | %> | ... | ... |