Commit 01d3165e52c24c0e94a588f370599f3ea04c0bd3

Authored by Luciano Prestes
1 parent 228e43c2

fix unit tests of softare community

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