Commit 01d3165e52c24c0e94a588f370599f3ea04c0bd3
1 parent
228e43c2
Exists in
software_as_organization
fix unit tests of softare community
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
8 changed files
with
54 additions
and
35 deletions
Show diff stats
src/noosfero-spb/software_communities/db/migrate/20151125175514_change_software_info_structure.rb
| 1 | -class CreateSispInfo < ActiveRecord::Migration | |
| 1 | +class ChangeSoftwareInfoStructure < ActiveRecord::Migration | |
| 2 | 2 | def up |
| 3 | - create_table :sosftware_infos do |t| | |
| 4 | - t.integer :software_id | |
| 3 | + change_table :software_infos do |t| | |
| 4 | + t.references :software, index: true, foreign_key: true | |
| 5 | 5 | t.text :agency_identification |
| 6 | 6 | t.text :softawre_requirements |
| 7 | 7 | t.text :hardware_requirements | ... | ... |
src/noosfero-spb/software_communities/lib/create_software.rb
| ... | ... | @@ -26,18 +26,22 @@ class CreateSoftware < Task |
| 26 | 26 | identifier = self.identifier |
| 27 | 27 | identifier ||= self.name.to_slug |
| 28 | 28 | |
| 29 | - community = Community.create!(:name => self.name, | |
| 30 | - :identifier => identifier, | |
| 31 | - :template_id => template_id) | |
| 29 | + software = Software.new(:name => self.name, | |
| 30 | + :identifier => identifier, | |
| 31 | + :template_id => template_id) | |
| 32 | 32 | |
| 33 | - community.environment = self.environment | |
| 34 | - community.add_admin(self.requestor) | |
| 35 | 33 | |
| 36 | - software = SoftwareInfo.new(:finality => self.finality, | |
| 37 | - :repository_link => self.repository_link, :community_id => community.id, | |
| 38 | - :license_info => self.license_info) | |
| 39 | - software.verify_license_info(self.another_license_version, self.another_license_link) | |
| 34 | + software_info = SoftwareInfo.new(:finality => self.finality, | |
| 35 | + :repository_link => self.repository_link, | |
| 36 | + :license_info => self.license_info) | |
| 37 | + software_info.verify_license_info(self.another_license_version, self.another_license_link) | |
| 38 | + | |
| 39 | + software_info.software = software | |
| 40 | + software.software_info = software_info | |
| 40 | 41 | software.save! |
| 42 | + | |
| 43 | + software.environment = self.environment | |
| 44 | + software.add_admin(self.requestor) | |
| 41 | 45 | end |
| 42 | 46 | |
| 43 | 47 | def title | ... | ... |
src/noosfero-spb/software_communities/lib/software_info.rb
| ... | ... | @@ -123,6 +123,10 @@ class SoftwareInfo < ActiveRecord::Base |
| 123 | 123 | return self.software |
| 124 | 124 | end |
| 125 | 125 | |
| 126 | + def community= community | |
| 127 | + self.software = community.becomes(Software) if community | |
| 128 | + end | |
| 129 | + | |
| 126 | 130 | def license_info |
| 127 | 131 | license = LicenseInfo.find_by_id self.license_info_id |
| 128 | 132 | license_another = LicenseInfo.find_by_version("Another") |
| ... | ... | @@ -196,13 +200,14 @@ class SoftwareInfo < ActiveRecord::Base |
| 196 | 200 | software.template_id = software_template.id |
| 197 | 201 | end |
| 198 | 202 | |
| 199 | - software.save! | |
| 200 | - software.add_admin(requestor) | |
| 201 | - | |
| 202 | 203 | software_info.software = software |
| 203 | 204 | software_info.license_info = license_info |
| 204 | 205 | software_info.verify_license_info(another_license_version, another_license_link) |
| 205 | 206 | software_info.save! |
| 207 | + software.software_info = software_info | |
| 208 | + software.save! | |
| 209 | + software.add_admin(requestor) | |
| 210 | + | |
| 206 | 211 | end |
| 207 | 212 | |
| 208 | 213 | software_info | ... | ... |
src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb
| 1 | 1 | module PluginTestHelper |
| 2 | 2 | |
| 3 | - def create_community name | |
| 4 | - community = fast_create(Community) | |
| 5 | - community.name = name | |
| 6 | - community.identifier = name.to_slug | |
| 7 | - community.save | |
| 8 | - community | |
| 3 | + def create_software name | |
| 4 | + software = Software.new | |
| 5 | + software.name = name | |
| 6 | + software.identifier = name.to_slug | |
| 7 | + software.save | |
| 8 | + software | |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def create_software_info name, finality = "something", acronym = "" |
| 12 | - community = create_community(name) | |
| 12 | + software = create_software(name) | |
| 13 | 13 | software_info = SoftwareInfo.new |
| 14 | - software_info.community = community | |
| 14 | + software_info.software = software | |
| 15 | 15 | software_info.finality = finality |
| 16 | 16 | software_info.acronym = acronym |
| 17 | 17 | software_info.public_software = true |
| 18 | - software_info.save! | |
| 18 | + | |
| 19 | + software.software_info = software_info | |
| 20 | + software.save | |
| 19 | 21 | |
| 20 | 22 | software_info |
| 21 | 23 | end | ... | ... |
src/noosfero-spb/software_communities/test/unit/communities_block_test.rb
| ... | ... | @@ -9,7 +9,7 @@ class CommunitiesBlockTest < ActiveSupport::TestCase |
| 9 | 9 | @software_info = create_software_info("Novo Software") |
| 10 | 10 | @software_info.community.add_member(@person) |
| 11 | 11 | |
| 12 | - @community = create_community("Nova Comunidade") | |
| 12 | + @community = fast_create(Community) | |
| 13 | 13 | @community.add_member(@person) |
| 14 | 14 | |
| 15 | 15 | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb
| ... | ... | @@ -27,7 +27,7 @@ class GovUserPluginPersonTest < ActiveSupport::TestCase |
| 27 | 27 | should 'get a list of softwares of a person' do |
| 28 | 28 | software1 = create_software_info "noosfero" |
| 29 | 29 | software2 = create_software_info "colab" |
| 30 | - community = create_community "simple_community" | |
| 30 | + community = fast_create(Community) | |
| 31 | 31 | |
| 32 | 32 | software1.community.add_member @person |
| 33 | 33 | software1.save! | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb
| ... | ... | @@ -5,12 +5,14 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase |
| 5 | 5 | include PluginTestHelper |
| 6 | 6 | |
| 7 | 7 | def setup |
| 8 | - @community = create_community("A new community") | |
| 8 | + @software = fast_create(Community) | |
| 9 | + @software = create_software_info("a software").software | |
| 10 | + @software.boxes.destroy_all | |
| 9 | 11 | @software_events_block = SoftwareEventsBlock.new |
| 10 | 12 | |
| 11 | 13 | box = Box.new |
| 12 | 14 | box.position = 1 |
| 13 | - box.owner = @community | |
| 15 | + box.owner = @software | |
| 14 | 16 | box.blocks << @software_events_block |
| 15 | 17 | box.save! |
| 16 | 18 | |
| ... | ... | @@ -23,10 +25,10 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase |
| 23 | 25 | @e3 = Event.new :name=>"Event 3", :body=>"Event 3 body", |
| 24 | 26 | :start_date=>(DateTime.now - 20.days), :end_date=>(DateTime.now - 10.days) |
| 25 | 27 | |
| 26 | - @community.events << @e1 | |
| 27 | - @community.events << @e2 | |
| 28 | - @community.events << @e3 | |
| 29 | - @community.save! | |
| 28 | + @software.events << @e1 | |
| 29 | + @software.events << @e2 | |
| 30 | + @software.events << @e3 | |
| 31 | + @software.save! | |
| 30 | 32 | end |
| 31 | 33 | |
| 32 | 34 | should "give community events that have not yet finished ordered by start date" do |
| ... | ... | @@ -46,7 +48,7 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase |
| 46 | 48 | should "tell if there are events to be displayed" do |
| 47 | 49 | assert_equal true, @software_events_block.has_events_to_display? |
| 48 | 50 | |
| 49 | - @community.events.update_all :start_date => (DateTime.now - 2.days), | |
| 51 | + @software.events.update_all :start_date => (DateTime.now - 2.days), | |
| 50 | 52 | :end_date => (DateTime.now - 1.day) |
| 51 | 53 | |
| 52 | 54 | assert_equal false, @software_events_block.has_events_to_display? | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_language_validation.rb
| ... | ... | @@ -46,9 +46,11 @@ class SoftwareLanguageValidationTest < ActiveSupport::TestCase |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | 48 | def create_software_info |
| 49 | + software = Software.new | |
| 50 | + | |
| 49 | 51 | software_info = SoftwareInfo.new |
| 50 | - software_info.community_id = fast_create(Community).id | |
| 51 | - software_info.community.name = 'Noosfero' | |
| 52 | + software_info.software = software | |
| 53 | + software_info.software.name = 'Noosfero' | |
| 52 | 54 | software_info.e_mag = true |
| 53 | 55 | software_info.icp_brasil = true |
| 54 | 56 | software_info.intern = true |
| ... | ... | @@ -57,6 +59,10 @@ class SoftwareLanguageValidationTest < ActiveSupport::TestCase |
| 57 | 59 | software_info.operating_platform = 'GNU/Linux' |
| 58 | 60 | software_info.features = "Do a lot of things" |
| 59 | 61 | software_info.objectives = "All tests should pass !" |
| 62 | + software_info.finality = "Teste" | |
| 63 | + | |
| 64 | + software.software_info = software_info | |
| 65 | + software.save! | |
| 60 | 66 | software_info |
| 61 | 67 | end |
| 62 | 68 | ... | ... |