diff --git a/src/noosfero-spb/software_communities/db/migrate/20160112191716_add_license_to_softwares_with_none.rb b/src/noosfero-spb/software_communities/db/migrate/20160112191716_add_license_to_softwares_with_none.rb new file mode 100644 index 0000000..da37d38 --- /dev/null +++ b/src/noosfero-spb/software_communities/db/migrate/20160112191716_add_license_to_softwares_with_none.rb @@ -0,0 +1,9 @@ +class AddLicenseToSoftwaresWithNone < ActiveRecord::Migration + def up + execute("UPDATE software_infos SET license_info_id=(SELECT id FROM license_infos WHERE version='Another') WHERE license_info_id IS NULL;") + end + + def down + say "This migration can't be reverted" + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_info.rb b/src/noosfero-spb/software_communities/lib/software_info.rb index a9816f2..c0c874e 100644 --- a/src/noosfero-spb/software_communities/lib/software_info.rb +++ b/src/noosfero-spb/software_communities/lib/software_info.rb @@ -84,11 +84,12 @@ class SoftwareInfo < ActiveRecord::Base validates_length_of :finality, :maximum => 4000 validates_length_of :objectives, :maximum => 4000 validates_length_of :features, :maximum => 4000 - validates_presence_of :finality, :community + validates_presence_of :finality, :community, :license_info validate :validate_acronym - settings_items :another_license_version, :another_license_link + settings_items :another_license_version, :default => 'Another' + settings_items :another_license_link, :default => '#' settings_items :sisp, :default => false serialize :agency_identification @@ -136,16 +137,14 @@ class SoftwareInfo < ActiveRecord::Base } def license_info - license = LicenseInfo.find_by_id self.license_info_id license_another = LicenseInfo.find_by_version("Another") - if license_another && license.id == license_another.id - LicenseInfo.new( - :version => self.another_license_version, - :link => self.another_license_link - ) + if license_another && self.license_info_id == license_another.id + license_another.version = self.another_license_version + license_another.link = self.another_license_link + license_another else - license + super end end diff --git a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb index 5aae9cf..436cd8e 100644 --- a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb @@ -54,7 +54,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :license => fields[0], :software_info => fields[2] ) - assert_equal SoftwareInfo.last.community.name, "Debian" + + new_software = Community.find_by_identifier("debian").software_info + assert_equal new_software.community.name, "Debian" end should 'edit a new software adding basic information' do @@ -76,7 +78,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :language => {}, :database => {} ) - assert_equal SoftwareInfo.last.repository_link, "www.github.com/test" + + edited_software = Community.find_by_identifier("debian").software_info + assert_equal edited_software.repository_link, "www.github.com/test" end should 'edit a new software adding specific information' do @@ -98,7 +102,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :software => fields[4], :license => fields[5] ) - assert_equal SoftwareInfo.last.acronym, "test" + + edited_software = Community.find_by_identifier("debian").software_info + assert_equal edited_software.acronym, "test" end should 'non admin cant edit a new software' do @@ -124,6 +130,32 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC assert_response 302 end + should 'edit a software and does not change Another License values' do + another_license = LicenseInfo.create(:version => "Another", :link => "#") + software = create_software(software_fields) + software.community.add_admin(@person) + software.save! + + post( + :edit_software, + :profile => software.community.identifier, + :license => { "license_infos_id"=>another_license.id, "version"=>"Another Version", "link"=>"www.link.com" }, + :software => {}, + :library => {}, + :operating_system => {}, + :language => {}, + :database => {} + ) + + another_license.reload + edited_software = Community.find_by_identifier("debian").software_info + + assert_equal edited_software.another_license_version, "Another Version" + assert_equal edited_software.another_license_link, "www.link.com" + assert_equal another_license.version, "Another" + assert_equal another_license.link, "#" + end + should 'only admin upgrade a generic software to a public software' do admin_person = create_user('admin').person @environment.add_admin(admin_person) @@ -142,7 +174,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :software => fields[4], ) - assert SoftwareInfo.last.public_software? + edited_software = Community.find_by_identifier("debian").software_info + assert edited_software.public_software? end 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 :software => fields[4] ) - refute SoftwareInfo.last.public_software? + edited_software = Community.find_by_identifier("debian").software_info + refute edited_software.public_software? end ["e_ping","e_mag","icp_brasil","e_arq","intern"].map do |attr| @@ -176,7 +210,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :software => fields[4] ) - refute SoftwareInfo.last.send(attr) + edited_software = Community.find_by_identifier("debian").software_info + refute edited_software.send(attr) end end @@ -199,7 +234,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :software => fields[4] ) - assert SoftwareInfo.last.send(attr) + edited_software = Community.find_by_identifier("debian").software_info + assert edited_software.send(attr) end end @@ -214,7 +250,8 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :profile => @person.identifier ) - assert_equal SoftwareInfo.last.license_info, LicenseInfo.last + new_software = Community.find_by_identifier("new-software").software_info + assert_equal new_software.license_info, LicenseInfo.last end should "create software_info with 'Another' license_info" do @@ -235,10 +272,11 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :profile => @person.identifier ) - assert_equal license_another.id, SoftwareInfo.last.license_info_id - assert_equal nil, SoftwareInfo.last.license_info.id - assert_equal another_license_version, SoftwareInfo.last.license_info.version - assert_equal another_license_link, SoftwareInfo.last.license_info.link + new_software = Community.find_by_identifier("new-software").software_info + assert_equal license_another.id, new_software.license_info_id + assert_equal license_another.id, new_software.license_info.id + assert_equal another_license_version, new_software.license_info.version + assert_equal another_license_link, new_software.license_info.link end should "create software_info after finish task with 'Another' license_info" do @@ -251,6 +289,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :new_software, :community => { :name => "New Software", :identifier => "new-software" }, :software_info => { :finality => "something", :repository_link => "" }, + :license_info => { :version => license_another.version }, :license => { :license_infos_id => license_another.id, :version => another_license_version, :link=> another_license_link @@ -261,10 +300,11 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC @environment.add_admin(@person) Task.last.send('finish', @person) - assert_equal license_another.id, SoftwareInfo.last.license_info_id - assert_equal nil, SoftwareInfo.last.license_info.id - assert_equal another_license_version, SoftwareInfo.last.license_info.version - assert_equal another_license_link, SoftwareInfo.last.license_info.link + new_software = Community.find_by_identifier("new-software").software_info + assert_equal license_another.id, new_software.license_info_id + assert_equal license_another.id, new_software.license_info.id + assert_equal another_license_version, new_software.license_info.version + assert_equal another_license_link, new_software.license_info.link end should "show error messages on create software_info" do @@ -316,8 +356,9 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC @environment.add_admin(@person) Task.last.send('finish', @person) + new_software = Community.find_by_identifier("new-software").software_info assert_equal "New Software", Task.last.data[:name] - assert_equal "New Software", SoftwareInfo.last.community.name + assert_equal "New Software", new_software.community.name end should "dont create software without accept task" do diff --git a/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb b/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb index d7458ce..0f89976 100644 --- a/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb +++ b/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb @@ -9,9 +9,12 @@ module PluginTestHelper end def create_software_info name, finality = "something", acronym = "" + license = create_license_info("GPL") community = create_community(name) + software_info = SoftwareInfo.new software_info.community = community + software_info.license_info = license software_info.finality = finality software_info.acronym = acronym software_info.public_software = true @@ -55,7 +58,7 @@ module PluginTestHelper end def create_license_info version, link = "" - license = LicenseInfo.create(:version => version) + license = LicenseInfo.find_or_create_by_version(version) license.link = link license.save diff --git a/src/noosfero-spb/software_communities/test/unit/software_info_test.rb b/src/noosfero-spb/software_communities/test/unit/software_info_test.rb index bd5ea14..a99ca50 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_info_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_info_test.rb @@ -36,7 +36,6 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase @software_info.another_license(another_license_version, another_license_link) assert_equal @software_info.license_info_id, @license_another.id - assert_equal @software_info.license_info.id, nil assert_equal @software_info.license_info.version, another_license_version assert_equal @software_info.license_info.link, another_license_link end @@ -53,7 +52,16 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase assert_equal 1, SoftwareInfo.search_by_query("", Environment.default).count assert_equal software_info, SoftwareInfo.search_by_query("", Environment.default).first assert_equal 1, SoftwareInfo.search_by_query("", other_env).count - assert_equal true, SoftwareInfo.search_by_query("", other_env).includes?(another_software_info) + assert_equal true, SoftwareInfo.search_by_query("", other_env).include?(another_software_info) end + should "start another license with default values" do + software_info = create_software_info("software_test") + license_another = create_license_info("Another") + + software_info.license_info_id = license_another.id + + assert_equal software_info.license_info.version, "Another" + assert_equal software_info.license_info.link, "#" + end end diff --git a/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb index ae77da7..0688784 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb @@ -31,6 +31,8 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase @operating_system.operating_system_name = @operating_system_name @operating_system.save + @license_info = LicenseInfo.create(:version => 'New License', :link => '#') + @software_info = SoftwareInfo.new( :acronym => "SFTW", :e_mag => true, @@ -41,7 +43,8 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase :operating_platform => true, :objectives => "", :features => "", - :finality => "something" + :finality => "something", + :license_info => @license_info ) @software_info.software_languages << @software_language @software_info.software_databases << @software_database @@ -119,4 +122,10 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase assert_equal false, @software_info.save assert_equal true, @software_info.errors.full_messages.include?(error_msg) end + + should "not save software without license" do + @software_info.license_info = nil + + assert_equal false, @software_info.save + end end diff --git a/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb b/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb index afb787e..5e66480 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb @@ -5,6 +5,8 @@ class SoftwareRegistrationTest < ActiveSupport::TestCase def setup @environment = Environment.default @environment.enable_plugin(SoftwareCommunitiesPlugin) + + @license_info = LicenseInfo.create(:version => "New License", :link => "#") end def teardown @@ -31,7 +33,8 @@ class SoftwareRegistrationTest < ActiveSupport::TestCase :name => "Teste Two", :requestor => person, :environment => @environment, - :finality => "something" + :finality => "something", + :license_info => @license_info ) software_count = SoftwareInfo.count -- libgit2 0.21.2