diff --git a/src/noosfero-spb/software_communities/lib/ext/communities_block.rb b/src/noosfero-spb/software_communities/lib/ext/communities_block.rb index 4a5fcaa..6d3488b 100644 --- a/src/noosfero-spb/software_communities/lib/ext/communities_block.rb +++ b/src/noosfero-spb/software_communities/lib/ext/communities_block.rb @@ -1,45 +1,17 @@ require_dependency 'communities_block' class CommunitiesBlock - def profile_list result = get_visible_profiles + puts "*"*80 + puts result.count + result = result.select { |community| !community.is_a? SoftwareCommunitiesPlugin::Software } + puts "*"*80 + puts result.count result.slice(0..get_limit-1) end def profile_count profile_list.count end - - private - - def get_visible_profiles - visible_profiles = profiles.visible.includes( - [:image,:domains,:preferred_domain,:environment] - ) - - delete_communities = [] - valid_communities_string = Community.get_valid_communities_string - Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} - - visible_profiles = visible_profiles.where(["profiles.id NOT IN (?)", delete_communities]) unless delete_communities.empty? - - if !prioritize_profiles_with_image - return visible_profiles.all( - :limit => get_limit, - :order => 'profiles.updated_at DESC' - ).sort_by {rand} - elsif profiles.visible.with_image.count >= get_limit - return visible_profiles.with_image.all( - :limit => get_limit * 5, - :order => 'profiles.updated_at DESC' - ).sort_by {rand} - else - visible_profiles = visible_profiles.with_image.sort_by {rand} + - visible_profiles.without_image.all( - :limit => get_limit * 5, :order => 'profiles.updated_at DESC' - ).sort_by {rand} - return visible_profiles - end - end end diff --git a/src/noosfero-spb/software_communities/lib/ext/person.rb b/src/noosfero-spb/software_communities/lib/ext/person.rb index 2ccb9a2..cf9529c 100644 --- a/src/noosfero-spb/software_communities/lib/ext/person.rb +++ b/src/noosfero-spb/software_communities/lib/ext/person.rb @@ -6,19 +6,17 @@ class Person delegate :login, :to => :user, :prefix => true - def software? - false - end - + alias :old_communities :communities def softwares - softwares = [] - self.communities.each do |community| - if community.software? - softwares << community - end + self.old_communities.select do |community| + community.is_a?(SoftwareCommunitiesPlugin::Software) end + end - softwares + def communities + self.old_communities.select do |community| + !community.is_a?(SoftwareCommunitiesPlugin::Software) + end end end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/api.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/api.rb index bb3ebe7..3d5e4c0 100644 --- a/src/noosfero-spb/software_communities/lib/software_communities_plugin/api.rb +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/api.rb @@ -8,7 +8,7 @@ class SoftwareCommunitiesPlugin::API < Grape::API resource :software_communities do get do authenticate! - softwares = select_filtered_collection_of(environment,'communities',params).joins(:software_info) + softwares = select_filtered_collection_of(environment,'softwares',params).joins(:software_info) softwares = softwares.visible_for_person(current_person) present softwares.map{|o|o.software_info}, :with => Entities::SoftwareInfo end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/api_entities.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/api_entities.rb index 557c1a6..3b63684 100644 --- a/src/noosfero-spb/software_communities/lib/software_communities_plugin/api_entities.rb +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/api_entities.rb @@ -20,8 +20,8 @@ module Entities expose :operating_system_names expose :created_at, :format_with => :timestamp expose :updated_at, :format_with => :timestamp - expose :community_id do |software_info,options| - software_info.community.id + expose :software_id do |software_info,options| + software_info.software.id end end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb index 0081a00..a830ab1 100644 --- a/src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb @@ -24,17 +24,19 @@ class SoftwareCommunitiesPlugin::CreateSoftware < Task identifier = self.identifier identifier ||= self.name.to_slug - community = Community.create!(:name => self.name, + software = SoftwareCommunitiesPlugin::Software.new(:name => self.name, :identifier => identifier, :template_id => template_id) - community.environment = self.environment - community.add_admin(self.requestor) + software.environment = self.environment + software.add_admin(self.requestor) - software = SoftwareCommunitiesPlugin::SoftwareInfo.create!(:finality => self.finality, - :repository_link => self.repository_link, :community_id => community.id, - :license_info => self.license_info) - software.verify_license_info(self.another_license_version, self.another_license_link) + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(:finality => self.finality, + :repository_link => self.repository_link, :license_info => self.license_info) + + software.software_info = software_info + + software_info.verify_license_info(self.another_license_version, self.another_license_link) software.save! end @@ -110,7 +112,7 @@ class SoftwareCommunitiesPlugin::CreateSoftware < Task private def mount_url - identifier = Community.where(:name => self.name).first.identifier + identifier = SoftwareCommunitiesPlugin::Software.where(:name => self.name).first.identifier # The use of url_for doesn't allow the /social within the Public Software # portal. That's why the url is mounted so 'hard coded' url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community" diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software.rb index 38077bf..e1d2af2 100644 --- a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software.rb +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software.rb @@ -1,15 +1,19 @@ -class SoftwareCommunitiesPlugin::Software < Organization - +class SoftwareCommunitiesPlugin::Software < Community SEARCHABLE_SOFTWARE_FIELDS = { :name => 1, :identifier => 2, :nickname => 3 } - attr_accessible :visible - has_one :software_info, :dependent=>:destroy, :class_name => "SoftwareCommunitiesPlugin::SoftwareInfo" + delegate :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, + :operating_platform, :demonstration_url, :acronym, + :objectives, :features, :license_info, + :finality, :repository_link, :public_software, :first_edit, + :to => :software_info + + settings_items :hits, :type => :integer, :default => 0 def self.create_after_moderation(requestor, attributes = {}) 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 4ad26db..066a4cb 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 @@ -1,10 +1,10 @@ module PluginTestHelper def create_software name - software = fast_create(SoftwareCommunitiesPlugin::Software) + software = SoftwareCommunitiesPlugin::Software.new software.name = name software.identifier = name.to_slug - software.save + software end diff --git a/src/noosfero-spb/software_communities/test/unit/api_test.rb b/src/noosfero-spb/software_communities/test/unit/api_test.rb index 7075db5..c32c757 100644 --- a/src/noosfero-spb/software_communities/test/unit/api_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/api_test.rb @@ -29,12 +29,12 @@ class SoftwareCommunitiesApiTest < ActiveSupport::TestCase assert_equal @software_info.id, json["software_info"]["id"] end - should 'list only softwares with visible community' do + should 'list only softwares with visible software' do @software_info = create_software_info("software_test") @software_info2 = create_software_info("software_test2") - @software_info2.community.visible = false - @software_info2.community.save! + @software_info2.software.visible = false + @software_info2.software.save! get "/api/v1/software_communities?#{params.to_query}" json = JSON.parse(last_response.body) diff --git a/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb b/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb index 7c7640e..a8f2b4e 100644 --- a/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb @@ -6,27 +6,26 @@ class CommunitiesBlockTest < ActiveSupport::TestCase def setup @person = create_person("My Name", "user@email.com", "123456", "123456", "Any State", "Some City") - @software_info = create_software_info("Novo Software") - @software_info.community.add_member(@person) + @software = create_software_info("New Software").software + @software.add_member(@person) - @community = create_community("Nova Comunidade") + @community = create_community("New Community") @community.add_member(@person) - - @comminities_block = CommunitiesBlock.new - @comminities_block.expects(:owner).at_least_once.returns(@person) - end - - def teardown - CommunitiesBlock.destroy_all - @person = nil - @community = nil - @software_info = nil + @communities_block = CommunitiesBlock.new + @communities_block.expects(:owner).at_least_once.returns(@person) end - should "not have community of software or institution in block" do - assert_includes @comminities_block.profile_list, @community - assert_not_includes @comminities_block.profile_list, @software_info.community + should "not have software community in block" do + puts "="*80 + puts "Softwares" + puts @person.softwares + puts "="*80 + puts "Communities" + puts @person.communities + puts "*"*80 + assert_includes @communities_block.profile_list, @community + assert_not_includes @communities_block.profile_list, @software end end diff --git a/src/noosfero-spb/software_communities/test/unit/create_software_test.rb b/src/noosfero-spb/software_communities/test/unit/create_software_test.rb index 0e59244..6128599 100644 --- a/src/noosfero-spb/software_communities/test/unit/create_software_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/create_software_test.rb @@ -28,23 +28,23 @@ class CreateSoftwareTest < ActiveSupport::TestCase task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any", :license_info => @license_info) assert_difference 'SoftwareCommunitiesPlugin::SoftwareInfo.count' do - assert_difference 'Community.count' do + assert_difference 'SoftwareCommunitiesPlugin::Software.count' do task.finish end end - assert_equal @requestor, Community['software-test'].admins.first + assert_equal @requestor, SoftwareCommunitiesPlugin::Software['software-test'].admins.first end should 'create new software community with all informed data when confirmed' do task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any", :repository_link => "#", :license_info => @license_info) task.finish - software = Community["software-test"].software_info + software = SoftwareCommunitiesPlugin::Software["software-test"] assert_equal "Any", software.finality assert_equal "#", software.repository_link - assert_equal "Software Test", software.community.name + assert_equal "Software Test", software.name end should 'override message methods from Task' do diff --git a/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb b/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb index 2217fdb..ccda3a4 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb @@ -20,12 +20,12 @@ class GovUserPluginPersonTest < ActiveSupport::TestCase should 'get a list of softwares of a person' do software1 = create_software_info "noosfero" software2 = create_software_info "colab" - software = create_software "simple_community" + community = fast_create Community software1.software.add_member @user.person software1.save! - software.add_member @user.person - software.save! + community.add_member @user.person + community.save! assert_equal 1, @user.person.softwares.count end diff --git a/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb b/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb index 26b0343..ebd04b9 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb @@ -5,12 +5,12 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase include PluginTestHelper def setup - @community = create_community("A new community") + @software = create_software_info("A new software").software @software_events_block = SoftwareCommunitiesPlugin::SoftwareEventsBlock.new box = Box.new box.position = 1 - box.owner = @community + box.owner = @software box.blocks << @software_events_block box.save! @@ -32,13 +32,13 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase @e6 = Event.new :name=>"Event 6", :body=>"Event 5 body", :start_date=>(DateTime.now) - @community.events << @e1 - @community.events << @e2 - @community.events << @e3 - @community.events << @e4 - @community.events << @e5 - @community.events << @e6 - @community.save! + @software.events << @e1 + @software.events << @e2 + @software.events << @e3 + @software.events << @e4 + @software.events << @e5 + @software.events << @e6 + @software.save! end should "get events with start date equals or bigger than current day ordered by start date" do @@ -56,14 +56,14 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase assert_equal @e5, events.last end - should "include community events that have no end date" do + should "include software events that have no end date" do events = @software_events_block.get_events assert_equal true, events.include?(@e5) assert_equal true, events.include?(@e6) end - should "give community events except by a event with a given slug" do + should "give software events except by a event with a given slug" do events = @software_events_block.get_events_except(@e1.slug) assert_equal false, events.include?(@e1) @@ -82,7 +82,7 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase assert_equal false, @software_events_block.has_events_to_display? - last_event = @community.events.last + last_event = @software.events.last last_event.start_date = DateTime.now last_event.end_date = DateTime.now + 1.day last_event.save! @@ -103,6 +103,6 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase private def update_all_events start_date, end_date - @community.events.update_all :start_date => start_date, :end_date => end_date + @software.events.update_all :start_date => start_date, :end_date => end_date end end 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 d15a6ee..9551859 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 @@ -33,7 +33,7 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase software_info = create_software_info("soft1") another_software_info = create_software_info("soft2") other_env = Environment.create!(name: "sisp") - another_soft_profile = another_software_info.community + another_soft_profile = another_software_info.software another_soft_profile.environment_id = other_env.id another_soft_profile.save 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 2c0f922..a5ee15f 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 @@ -3,8 +3,8 @@ require 'test_helper' class SoftwareInfoValidationTest < ActiveSupport::TestCase def setup - @community = fast_create( - Community, + @software = fast_create( + SoftwareCommunitiesPlugin::Software, :identifier => 'new-software', :name => 'New Software' ) @@ -52,7 +52,7 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase @software_info.features = "Do a lot of things" @software_info.objectives = "All tests should pass !" - @software_info.community = @community + @software_info.software = @software end should 'Save SoftwareInfo if all fields are filled' do diff --git a/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb b/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb index 59a6ba8..07c7214 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb @@ -1,17 +1,23 @@ require 'test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' class SoftwareLanguageValidationTest < ActiveSupport::TestCase + include PluginTestHelper + def setup create_programming_language - @software_info = create_software_info + @software_info = create_software_info('Noosfero') + @software_info.e_mag = true + @software_info.icp_brasil = true + @software_info.intern = true + @software_info.e_ping = true + @software_info.e_arq = true + @software_info.operating_platform = 'GNU/Linux' + @software_info.features = "Do a lot of things" + @software_info.objectives = "All tests should pass !" @software_info.save end - def teardown - @software_info = nil - SoftwareCommunitiesPlugin::SoftwareInfo.destroy_all - end - should "Save SoftwareLanguage if version and prog_language are filled" do @software_language = create_software_language assert_equal true, @software_language.save @@ -45,21 +51,6 @@ class SoftwareLanguageValidationTest < ActiveSupport::TestCase software_language end - def create_software_info - software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new - software_info.community_id = fast_create(Community).id - software_info.community.name = 'Noosfero' - software_info.e_mag = true - software_info.icp_brasil = true - software_info.intern = true - software_info.e_ping = true - software_info.e_arq = true - software_info.operating_platform = 'GNU/Linux' - software_info.features = "Do a lot of things" - software_info.objectives = "All tests should pass !" - software_info - end - def create_programming_language SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"C") SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"C++") diff --git a/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb b/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb index 3055d30..95db7be 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb @@ -8,7 +8,7 @@ class SoftwareTabDataBlockTest < ActiveSupport::TestCase @software_info = create_software_info("A new Software") @software_info.save! - @soft_community = @software_info.community + @soft_community = @software_info.software @soft_community.blogs << Blog.new(:name=>"First blog") @soft_community.blogs << Blog.new(:name=>"Second blog") @@ -25,7 +25,7 @@ class SoftwareTabDataBlockTest < ActiveSupport::TestCase assert_equal @soft_community.blogs.first, SoftwareCommunitiesPlugin::SoftwareTabDataBlock.new.actual_blog end - should "actual_blog get the defined community blog" do + should "actual_blog get the defined software blog" do last_blog = @soft_community.blogs.last soft_tab_data = create_software_tab_data_block(last_blog) diff --git a/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb b/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb index ab3f57c..f42be97 100644 --- a/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb @@ -32,12 +32,12 @@ class SoftwaresBlockTest < ActiveSupport::TestCase ) software_info = create_software_info("new software") - software_info.community.add_member(user) + software_info.software.add_member(user) block = SoftwareCommunitiesPlugin::SoftwaresBlock.new block.expects(:owner).at_least_once.returns(user) - assert_equivalent [software_info.community], block.profiles + assert_equivalent [software_info.software], block.profiles end end -- libgit2 0.21.2