Commit bc0a550617d0d9c5b65d881e866dbbbd33dff9c4
1 parent
8880af6d
Exists in
master
and in
19 other branches
Validates presence of license on software_info
* Add a migration to fix softwares with no license * Add validates presence of license on software_info * Add test to not save software_info without license Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Omar Junior <omarroinuj@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Showing
7 changed files
with
103 additions
and
31 deletions
Show diff stats
src/noosfero-spb/software_communities/db/migrate/20160112191716_add_license_to_softwares_with_none.rb
0 → 100644
| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | +class AddLicenseToSoftwaresWithNone < ActiveRecord::Migration | |
| 2 | + def up | |
| 3 | + execute("UPDATE software_infos SET license_info_id=(SELECT id FROM license_infos WHERE version='Another') WHERE license_info_id IS NULL;") | |
| 4 | + end | |
| 5 | + | |
| 6 | + def down | |
| 7 | + say "This migration can't be reverted" | |
| 8 | + end | |
| 9 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_info.rb
| ... | ... | @@ -84,11 +84,12 @@ class SoftwareInfo < ActiveRecord::Base |
| 84 | 84 | validates_length_of :finality, :maximum => 4000 |
| 85 | 85 | validates_length_of :objectives, :maximum => 4000 |
| 86 | 86 | validates_length_of :features, :maximum => 4000 |
| 87 | - validates_presence_of :finality, :community | |
| 87 | + validates_presence_of :finality, :community, :license_info | |
| 88 | 88 | |
| 89 | 89 | validate :validate_acronym |
| 90 | 90 | |
| 91 | - settings_items :another_license_version, :another_license_link | |
| 91 | + settings_items :another_license_version, :default => 'Another' | |
| 92 | + settings_items :another_license_link, :default => '#' | |
| 92 | 93 | settings_items :sisp, :default => false |
| 93 | 94 | |
| 94 | 95 | serialize :agency_identification |
| ... | ... | @@ -136,16 +137,14 @@ class SoftwareInfo < ActiveRecord::Base |
| 136 | 137 | } |
| 137 | 138 | |
| 138 | 139 | def license_info |
| 139 | - license = LicenseInfo.find_by_id self.license_info_id | |
| 140 | 140 | license_another = LicenseInfo.find_by_version("Another") |
| 141 | 141 | |
| 142 | - if license_another && license.id == license_another.id | |
| 143 | - LicenseInfo.new( | |
| 144 | - :version => self.another_license_version, | |
| 145 | - :link => self.another_license_link | |
| 146 | - ) | |
| 142 | + if license_another && self.license_info_id == license_another.id | |
| 143 | + license_another.version = self.another_license_version | |
| 144 | + license_another.link = self.another_license_link | |
| 145 | + license_another | |
| 147 | 146 | else |
| 148 | - license | |
| 147 | + super | |
| 149 | 148 | end |
| 150 | 149 | end |
| 151 | 150 | ... | ... |
src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb
| ... | ... | @@ -54,7 +54,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 54 | 54 | :license => fields[0], |
| 55 | 55 | :software_info => fields[2] |
| 56 | 56 | ) |
| 57 | - assert_equal SoftwareInfo.last.community.name, "Debian" | |
| 57 | + | |
| 58 | + new_software = Community.find_by_identifier("debian").software_info | |
| 59 | + assert_equal new_software.community.name, "Debian" | |
| 58 | 60 | end |
| 59 | 61 | |
| 60 | 62 | should 'edit a new software adding basic information' do |
| ... | ... | @@ -76,7 +78,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 76 | 78 | :language => {}, |
| 77 | 79 | :database => {} |
| 78 | 80 | ) |
| 79 | - assert_equal SoftwareInfo.last.repository_link, "www.github.com/test" | |
| 81 | + | |
| 82 | + edited_software = Community.find_by_identifier("debian").software_info | |
| 83 | + assert_equal edited_software.repository_link, "www.github.com/test" | |
| 80 | 84 | end |
| 81 | 85 | |
| 82 | 86 | should 'edit a new software adding specific information' do |
| ... | ... | @@ -98,7 +102,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 98 | 102 | :software => fields[4], |
| 99 | 103 | :license => fields[5] |
| 100 | 104 | ) |
| 101 | - assert_equal SoftwareInfo.last.acronym, "test" | |
| 105 | + | |
| 106 | + edited_software = Community.find_by_identifier("debian").software_info | |
| 107 | + assert_equal edited_software.acronym, "test" | |
| 102 | 108 | end |
| 103 | 109 | |
| 104 | 110 | should 'non admin cant edit a new software' do |
| ... | ... | @@ -124,6 +130,32 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 124 | 130 | assert_response 302 |
| 125 | 131 | end |
| 126 | 132 | |
| 133 | + should 'edit a software and does not change Another License values' do | |
| 134 | + another_license = LicenseInfo.create(:version => "Another", :link => "#") | |
| 135 | + software = create_software(software_fields) | |
| 136 | + software.community.add_admin(@person) | |
| 137 | + software.save! | |
| 138 | + | |
| 139 | + post( | |
| 140 | + :edit_software, | |
| 141 | + :profile => software.community.identifier, | |
| 142 | + :license => { "license_infos_id"=>another_license.id, "version"=>"Another Version", "link"=>"www.link.com" }, | |
| 143 | + :software => {}, | |
| 144 | + :library => {}, | |
| 145 | + :operating_system => {}, | |
| 146 | + :language => {}, | |
| 147 | + :database => {} | |
| 148 | + ) | |
| 149 | + | |
| 150 | + another_license.reload | |
| 151 | + edited_software = Community.find_by_identifier("debian").software_info | |
| 152 | + | |
| 153 | + assert_equal edited_software.another_license_version, "Another Version" | |
| 154 | + assert_equal edited_software.another_license_link, "www.link.com" | |
| 155 | + assert_equal another_license.version, "Another" | |
| 156 | + assert_equal another_license.link, "#" | |
| 157 | + end | |
| 158 | + | |
| 127 | 159 | should 'only admin upgrade a generic software to a public software' do |
| 128 | 160 | admin_person = create_user('admin').person |
| 129 | 161 | @environment.add_admin(admin_person) |
| ... | ... | @@ -142,7 +174,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 142 | 174 | :software => fields[4], |
| 143 | 175 | ) |
| 144 | 176 | |
| 145 | - assert SoftwareInfo.last.public_software? | |
| 177 | + edited_software = Community.find_by_identifier("debian").software_info | |
| 178 | + assert edited_software.public_software? | |
| 146 | 179 | end |
| 147 | 180 | |
| 148 | 181 | should 'not upgrade a generic software to a public software if user is not an admin' do |
| ... | ... | @@ -158,7 +191,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 158 | 191 | :software => fields[4] |
| 159 | 192 | ) |
| 160 | 193 | |
| 161 | - refute SoftwareInfo.last.public_software? | |
| 194 | + edited_software = Community.find_by_identifier("debian").software_info | |
| 195 | + refute edited_software.public_software? | |
| 162 | 196 | end |
| 163 | 197 | |
| 164 | 198 | ["e_ping","e_mag","icp_brasil","e_arq","intern"].map do |attr| |
| ... | ... | @@ -176,7 +210,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 176 | 210 | :software => fields[4] |
| 177 | 211 | ) |
| 178 | 212 | |
| 179 | - refute SoftwareInfo.last.send(attr) | |
| 213 | + edited_software = Community.find_by_identifier("debian").software_info | |
| 214 | + refute edited_software.send(attr) | |
| 180 | 215 | end |
| 181 | 216 | end |
| 182 | 217 | |
| ... | ... | @@ -199,7 +234,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 199 | 234 | :software => fields[4] |
| 200 | 235 | ) |
| 201 | 236 | |
| 202 | - assert SoftwareInfo.last.send(attr) | |
| 237 | + edited_software = Community.find_by_identifier("debian").software_info | |
| 238 | + assert edited_software.send(attr) | |
| 203 | 239 | end |
| 204 | 240 | end |
| 205 | 241 | |
| ... | ... | @@ -214,7 +250,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 214 | 250 | :profile => @person.identifier |
| 215 | 251 | ) |
| 216 | 252 | |
| 217 | - assert_equal SoftwareInfo.last.license_info, LicenseInfo.last | |
| 253 | + new_software = Community.find_by_identifier("new-software").software_info | |
| 254 | + assert_equal new_software.license_info, LicenseInfo.last | |
| 218 | 255 | end |
| 219 | 256 | |
| 220 | 257 | should "create software_info with 'Another' license_info" do |
| ... | ... | @@ -235,10 +272,11 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 235 | 272 | :profile => @person.identifier |
| 236 | 273 | ) |
| 237 | 274 | |
| 238 | - assert_equal license_another.id, SoftwareInfo.last.license_info_id | |
| 239 | - assert_equal nil, SoftwareInfo.last.license_info.id | |
| 240 | - assert_equal another_license_version, SoftwareInfo.last.license_info.version | |
| 241 | - assert_equal another_license_link, SoftwareInfo.last.license_info.link | |
| 275 | + new_software = Community.find_by_identifier("new-software").software_info | |
| 276 | + assert_equal license_another.id, new_software.license_info_id | |
| 277 | + assert_equal license_another.id, new_software.license_info.id | |
| 278 | + assert_equal another_license_version, new_software.license_info.version | |
| 279 | + assert_equal another_license_link, new_software.license_info.link | |
| 242 | 280 | end |
| 243 | 281 | |
| 244 | 282 | should "create software_info after finish task with 'Another' license_info" do |
| ... | ... | @@ -251,6 +289,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 251 | 289 | :new_software, |
| 252 | 290 | :community => { :name => "New Software", :identifier => "new-software" }, |
| 253 | 291 | :software_info => { :finality => "something", :repository_link => "" }, |
| 292 | + :license_info => { :version => license_another.version }, | |
| 254 | 293 | :license => { :license_infos_id => license_another.id, |
| 255 | 294 | :version => another_license_version, |
| 256 | 295 | :link=> another_license_link |
| ... | ... | @@ -261,10 +300,11 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 261 | 300 | @environment.add_admin(@person) |
| 262 | 301 | Task.last.send('finish', @person) |
| 263 | 302 | |
| 264 | - assert_equal license_another.id, SoftwareInfo.last.license_info_id | |
| 265 | - assert_equal nil, SoftwareInfo.last.license_info.id | |
| 266 | - assert_equal another_license_version, SoftwareInfo.last.license_info.version | |
| 267 | - assert_equal another_license_link, SoftwareInfo.last.license_info.link | |
| 303 | + new_software = Community.find_by_identifier("new-software").software_info | |
| 304 | + assert_equal license_another.id, new_software.license_info_id | |
| 305 | + assert_equal license_another.id, new_software.license_info.id | |
| 306 | + assert_equal another_license_version, new_software.license_info.version | |
| 307 | + assert_equal another_license_link, new_software.license_info.link | |
| 268 | 308 | end |
| 269 | 309 | |
| 270 | 310 | should "show error messages on create software_info" do |
| ... | ... | @@ -316,8 +356,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC |
| 316 | 356 | @environment.add_admin(@person) |
| 317 | 357 | Task.last.send('finish', @person) |
| 318 | 358 | |
| 359 | + new_software = Community.find_by_identifier("new-software").software_info | |
| 319 | 360 | assert_equal "New Software", Task.last.data[:name] |
| 320 | - assert_equal "New Software", SoftwareInfo.last.community.name | |
| 361 | + assert_equal "New Software", new_software.community.name | |
| 321 | 362 | end |
| 322 | 363 | |
| 323 | 364 | should "dont create software without accept task" do | ... | ... |
src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb
| ... | ... | @@ -9,9 +9,12 @@ module PluginTestHelper |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def create_software_info name, finality = "something", acronym = "" |
| 12 | + license = create_license_info("GPL") | |
| 12 | 13 | community = create_community(name) |
| 14 | + | |
| 13 | 15 | software_info = SoftwareInfo.new |
| 14 | 16 | software_info.community = community |
| 17 | + software_info.license_info = license | |
| 15 | 18 | software_info.finality = finality |
| 16 | 19 | software_info.acronym = acronym |
| 17 | 20 | software_info.public_software = true |
| ... | ... | @@ -55,7 +58,7 @@ module PluginTestHelper |
| 55 | 58 | end |
| 56 | 59 | |
| 57 | 60 | def create_license_info version, link = "" |
| 58 | - license = LicenseInfo.create(:version => version) | |
| 61 | + license = LicenseInfo.find_or_create_by_version(version) | |
| 59 | 62 | license.link = link |
| 60 | 63 | license.save |
| 61 | 64 | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_info_test.rb
| ... | ... | @@ -36,7 +36,6 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
| 36 | 36 | @software_info.another_license(another_license_version, another_license_link) |
| 37 | 37 | |
| 38 | 38 | assert_equal @software_info.license_info_id, @license_another.id |
| 39 | - assert_equal @software_info.license_info.id, nil | |
| 40 | 39 | assert_equal @software_info.license_info.version, another_license_version |
| 41 | 40 | assert_equal @software_info.license_info.link, another_license_link |
| 42 | 41 | end |
| ... | ... | @@ -53,7 +52,16 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
| 53 | 52 | assert_equal 1, SoftwareInfo.search_by_query("", Environment.default).count |
| 54 | 53 | assert_equal software_info, SoftwareInfo.search_by_query("", Environment.default).first |
| 55 | 54 | assert_equal 1, SoftwareInfo.search_by_query("", other_env).count |
| 56 | - assert_equal true, SoftwareInfo.search_by_query("", other_env).includes?(another_software_info) | |
| 55 | + assert_equal true, SoftwareInfo.search_by_query("", other_env).include?(another_software_info) | |
| 57 | 56 | end |
| 58 | 57 | |
| 58 | + should "start another license with default values" do | |
| 59 | + software_info = create_software_info("software_test") | |
| 60 | + license_another = create_license_info("Another") | |
| 61 | + | |
| 62 | + software_info.license_info_id = license_another.id | |
| 63 | + | |
| 64 | + assert_equal software_info.license_info.version, "Another" | |
| 65 | + assert_equal software_info.license_info.link, "#" | |
| 66 | + end | |
| 59 | 67 | end | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb
| ... | ... | @@ -31,6 +31,8 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
| 31 | 31 | @operating_system.operating_system_name = @operating_system_name |
| 32 | 32 | @operating_system.save |
| 33 | 33 | |
| 34 | + @license_info = LicenseInfo.create(:version => 'New License', :link => '#') | |
| 35 | + | |
| 34 | 36 | @software_info = SoftwareInfo.new( |
| 35 | 37 | :acronym => "SFTW", |
| 36 | 38 | :e_mag => true, |
| ... | ... | @@ -41,7 +43,8 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
| 41 | 43 | :operating_platform => true, |
| 42 | 44 | :objectives => "", |
| 43 | 45 | :features => "", |
| 44 | - :finality => "something" | |
| 46 | + :finality => "something", | |
| 47 | + :license_info => @license_info | |
| 45 | 48 | ) |
| 46 | 49 | @software_info.software_languages << @software_language |
| 47 | 50 | @software_info.software_databases << @software_database |
| ... | ... | @@ -119,4 +122,10 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
| 119 | 122 | assert_equal false, @software_info.save |
| 120 | 123 | assert_equal true, @software_info.errors.full_messages.include?(error_msg) |
| 121 | 124 | end |
| 125 | + | |
| 126 | + should "not save software without license" do | |
| 127 | + @software_info.license_info = nil | |
| 128 | + | |
| 129 | + assert_equal false, @software_info.save | |
| 130 | + end | |
| 122 | 131 | end | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_registration_test.rb
| ... | ... | @@ -5,6 +5,8 @@ class SoftwareRegistrationTest < ActiveSupport::TestCase |
| 5 | 5 | def setup |
| 6 | 6 | @environment = Environment.default |
| 7 | 7 | @environment.enable_plugin(SoftwareCommunitiesPlugin) |
| 8 | + | |
| 9 | + @license_info = LicenseInfo.create(:version => "New License", :link => "#") | |
| 8 | 10 | end |
| 9 | 11 | |
| 10 | 12 | def teardown |
| ... | ... | @@ -31,7 +33,8 @@ class SoftwareRegistrationTest < ActiveSupport::TestCase |
| 31 | 33 | :name => "Teste Two", |
| 32 | 34 | :requestor => person, |
| 33 | 35 | :environment => @environment, |
| 34 | - :finality => "something" | |
| 36 | + :finality => "something", | |
| 37 | + :license_info => @license_info | |
| 35 | 38 | ) |
| 36 | 39 | |
| 37 | 40 | software_count = SoftwareInfo.count | ... | ... |