Commit d8c5099005524dbc987efcd1ecdabb7199986b09

Authored by Arthur Esposte
1 parent 32a1bf15

software_communities: adequate models with proper namespace

Showing 92 changed files with 1228 additions and 1211 deletions   Show diff stats
src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb
@@ -6,7 +6,7 @@ class SoftwareCommunitiesPluginController < ApplicationController @@ -6,7 +6,7 @@ class SoftwareCommunitiesPluginController < ApplicationController
6 return render :json=>{} if !request.xhr? || params[:query].nil? 6 return render :json=>{} if !request.xhr? || params[:query].nil?
7 7
8 data = LicenseHelper.find_licenses(params[:query]) if params[:query] 8 data = LicenseHelper.find_licenses(params[:query]) if params[:query]
9 - data ||= LicenseInfo.all 9 + data ||= SoftwareCommunitiesPlugin::LicenseInfo.all
10 10
11 render :json=> data.collect { |license| 11 render :json=> data.collect { |license|
12 {:id=>license.id, :label=>license.version} 12 {:id=>license.id, :label=>license.version}
@@ -42,7 +42,7 @@ class SoftwareCommunitiesPluginController < ApplicationController @@ -42,7 +42,7 @@ class SoftwareCommunitiesPluginController < ApplicationController
42 protected 42 protected
43 43
44 def get_model_by_params_field 44 def get_model_by_params_field
45 - return DatabaseDescription unless params[:field] == "software_language"  
46 - return ProgrammingLanguage 45 + return SoftwareCommunitiesPlugin::DatabaseDescription unless params[:field] == "software_language"
  46 + return SoftwareCommunitiesPlugin::ProgrammingLanguage
47 end 47 end
48 end 48 end
src/noosfero-spb/software_communities/controllers/software_communities_plugin_myprofile_controller.rb
@@ -10,10 +10,10 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController @@ -10,10 +10,10 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController
10 @community = Community.new(params[:community]) 10 @community = Community.new(params[:community])
11 @community.environment = environment 11 @community.environment = environment
12 12
13 - @license_info = LicenseInfo.find_by_id(params[:license][:license_infos_id]) if params[:license]  
14 - @license_info ||= LicenseInfo.new 13 + @license_info = SoftwareCommunitiesPlugin::LicenseInfo.find_by_id(params[:license][:license_infos_id]) if params[:license]
  14 + @license_info ||= SoftwareCommunitiesPlugin::LicenseInfo.new
15 15
16 - @software_info = SoftwareInfo.new(params[:software_info]) 16 + @software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(params[:software_info])
17 @software_info.community = @community 17 @software_info.community = @community
18 @software_info.license_info = @license_info 18 @software_info.license_info = @license_info
19 19
@@ -90,7 +90,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController @@ -90,7 +90,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController
90 def create_software 90 def create_software
91 @software_info = @profile.software_info 91 @software_info = @profile.software_info
92 params[:software][:public_software] ||= false unless @software_info.public_software? 92 params[:software][:public_software] ||= false unless @software_info.public_software?
93 - @license = LicenseInfo.find(params[:license][:license_infos_id]) 93 + @license = SoftwareCommunitiesPlugin::LicenseInfo.find(params[:license][:license_infos_id])
94 @software_info.license_info = @license 94 @software_info.license_info = @license
95 @software_info.update_attributes(params[:software]) 95 @software_info.update_attributes(params[:software])
96 96
@@ -122,7 +122,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController @@ -122,7 +122,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController
122 another_license_version = params[:license][:version] 122 another_license_version = params[:license][:version]
123 another_license_link = params[:license][:link] 123 another_license_link = params[:license][:link]
124 end 124 end
125 - @software_info = SoftwareInfo.create_after_moderation(user, 125 + @software_info = SoftwareCommunitiesPlugin::SoftwareInfo.create_after_moderation(user,
126 params[:software_info].merge({ 126 params[:software_info].merge({
127 :environment => environment, 127 :environment => environment,
128 :name => params[:community][:name], 128 :name => params[:community][:name],
@@ -158,7 +158,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController @@ -158,7 +158,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController
158 @another_license_version = "" 158 @another_license_version = ""
159 @another_license_link = "" 159 @another_license_link = ""
160 160
161 - license_another = LicenseInfo.find_by_version("Another") 161 + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another")
162 if license_another && @software_info.license_info_id == license_another.id 162 if license_another && @software_info.license_info_id == license_another.id
163 @license_version = "Another" 163 @license_version = "Another"
164 @another_license_version = @software_info.license_info.version 164 @another_license_version = @software_info.license_info.version
src/noosfero-spb/software_communities/controllers/software_communities_plugin_profile_controller.rb
@@ -9,11 +9,11 @@ class SoftwareCommunitiesPluginProfileController < ProfileController @@ -9,11 +9,11 @@ class SoftwareCommunitiesPluginProfileController < ProfileController
9 } 9 }
10 10
11 def download_file 11 def download_file
12 - download_block = DownloadBlock.find_by_id params[:block] 12 + download_block = SoftwareCommunitiesPlugin::DownloadBlock.find_by_id params[:block]
13 index = params[:download_index].to_i 13 index = params[:download_index].to_i
14 14
15 if download_block and (index < download_block.downloads.size) 15 if download_block and (index < download_block.downloads.size)
16 - download = Download.new(download_block.downloads[index]) 16 + download = SoftwareCommunitiesPlugin::Download.new(download_block.downloads[index])
17 17
18 download.total_downloads += 1 18 download.total_downloads += 1
19 download_block.downloads[index] = download.to_hash 19 download_block.downloads[index] = download.to_hash
src/noosfero-spb/software_communities/db/migrate/20140528193902_create_license_infos_table.rb
@@ -6,7 +6,7 @@ class CreateLicenseInfosTable &lt; ActiveRecord::Migration @@ -6,7 +6,7 @@ class CreateLicenseInfosTable &lt; ActiveRecord::Migration
6 end 6 end
7 7
8 link = "http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" 8 link = "http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
9 - LicenseInfo.create(:version => "CC-GPL-V2", :link => link) 9 + SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "CC-GPL-V2", :link => link)
10 end 10 end
11 11
12 def self.down 12 def self.down
src/noosfero-spb/software_communities/db/migrate/20140528193956_create_programming_languages_table.rb
@@ -4,7 +4,7 @@ class CreateProgrammingLanguagesTable &lt; ActiveRecord::Migration @@ -4,7 +4,7 @@ class CreateProgrammingLanguagesTable &lt; ActiveRecord::Migration
4 t.string :name 4 t.string :name
5 end 5 end
6 6
7 - SoftwareHelper.create_list_with_file("plugins/software_communities/public/static/languages.txt", ProgrammingLanguage) 7 + SoftwareHelper.create_list_with_file("plugins/software_communities/public/static/languages.txt", SoftwareCommunitiesPlugin::ProgrammingLanguage)
8 end 8 end
9 9
10 def self.down 10 def self.down
src/noosfero-spb/software_communities/db/migrate/20140714133901_create_operating_name_table.rb
@@ -5,7 +5,7 @@ class CreateOperatingNameTable &lt; ActiveRecord::Migration @@ -5,7 +5,7 @@ class CreateOperatingNameTable &lt; ActiveRecord::Migration
5 end 5 end
6 6
7 path_to_file = "plugins/software_communities/public/static/operating_systems.txt" 7 path_to_file = "plugins/software_communities/public/static/operating_systems.txt"
8 - SoftwareHelper.create_list_with_file(path_to_file, OperatingSystemName) 8 + SoftwareHelper.create_list_with_file(path_to_file, SoftwareCommunitiesPlugin::OperatingSystemName)
9 end 9 end
10 10
11 def down 11 def down
src/noosfero-spb/software_communities/db/migrate/20150210182519_rename_cc_license.rb
1 class RenameCcLicense < ActiveRecord::Migration 1 class RenameCcLicense < ActiveRecord::Migration
2 def up 2 def up
3 - license = LicenseInfo.find_by_version "CC-GPL-V2" 3 + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version "CC-GPL-V2"
4 license.version = "Creative Commons GPL V2" 4 license.version = "Creative Commons GPL V2"
5 license.save! 5 license.save!
6 end 6 end
7 7
8 def down 8 def down
9 - license = LicenseInfo.find_by_version "Creative Commons GPL V2" 9 + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version "Creative Commons GPL V2"
10 license.version = "CC-GPL-V2" 10 license.version = "CC-GPL-V2"
11 license.save! 11 license.save!
12 end 12 end
src/noosfero-spb/software_communities/db/migrate/20151022175354_rename_tables_with_plugin_namespace.rb 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +class RenameTablesWithPluginNamespace < ActiveRecord::Migration
  2 + def change
  3 + rename_table :license_infos, :software_communities_plugin_license_infos
  4 + rename_table :software_infos, :software_communities_plugin_software_infos
  5 + rename_table :libraries, :software_communities_plugin_libraries
  6 + rename_table :programming_languages, :software_communities_plugin_programming_languages
  7 + rename_table :database_descriptions, :software_communities_plugin_database_descriptions
  8 + rename_table :software_databases, :software_communities_plugin_software_databases
  9 + rename_table :software_languages, :software_communities_plugin_software_languages
  10 + rename_table :operating_systems, :software_communities_plugin_operating_systems
  11 + rename_table :operating_system_names, :software_communities_plugin_operating_system_names
  12 + rename_table :software_categories, :software_communities_plugin_software_categories
  13 + end
  14 +end
src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -class CategoriesAndTagsBlock < Block  
2 -  
3 - attr_accessible :show_name  
4 -  
5 - settings_items :show_name, :type => :boolean, :default => false  
6 -  
7 - def self.description  
8 - _('Categories and Tags')  
9 - end  
10 -  
11 - def help  
12 - _('This block displays the categories and tags of a software.')  
13 - end  
14 -  
15 - def content(args={})  
16 - block = self  
17 - s = show_name  
18 - lambda do |object|  
19 - render(  
20 - :file => 'blocks/categories_and_tags',  
21 - :locals => { :block => block, :show_name => s }  
22 - )  
23 - end  
24 - end  
25 -  
26 - def cacheable?  
27 - false  
28 - end  
29 -end  
src/noosfero-spb/software_communities/lib/categories_software_block.rb
@@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
1 -class CategoriesSoftwareBlock < Block  
2 -  
3 - attr_accessible :show_name  
4 -  
5 - settings_items :show_name, :type => :boolean, :default => false  
6 -  
7 - def self.description  
8 - _('Categories Softwares')  
9 - end  
10 -  
11 - def help  
12 - _('This block displays the categories and the amount of softwares for  
13 - each category.')  
14 - end  
15 -  
16 - def content(args={})  
17 - block = self  
18 - s = show_name  
19 -  
20 - software_category = Category.find_by_name("Software")  
21 - categories = []  
22 - categories = software_category.children.sort if software_category  
23 -  
24 - lambda do |object|  
25 - render(  
26 - :file => 'blocks/categories_software',  
27 - :locals => { :block => block, :show_name => s, :categories => categories }  
28 - )  
29 - end  
30 - end  
31 -  
32 - def cacheable?  
33 - false  
34 - end  
35 -end  
src/noosfero-spb/software_communities/lib/create_software.rb
@@ -1,115 +0,0 @@ @@ -1,115 +0,0 @@
1 -class CreateSoftware < Task  
2 - include Rails.application.routes.url_helpers  
3 -  
4 - validates_presence_of :requestor_id, :target_id  
5 - validates_presence_of :name, :finality  
6 -  
7 - attr_accessible :name, :finality, :repository_link, :requestor, :environment,  
8 - :reject_explanation, :license_info, :identifier, :target  
9 -  
10 - alias :environment :target  
11 - alias :environment= :target=  
12 -  
13 - DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link']  
14 - DATA_FIELDS.each do |field|  
15 - settings_items field.to_sym  
16 - end  
17 -  
18 - def perform  
19 - software_template = SoftwareHelper.software_template  
20 - template_id = software_template.blank? ? nil : software_template.id  
21 -  
22 - identifier = self.identifier  
23 - identifier ||= self.name.to_slug  
24 -  
25 - community = Community.create!(:name => self.name,  
26 - :identifier => identifier,  
27 - :template_id => template_id)  
28 -  
29 - community.environment = self.environment  
30 - community.add_admin(self.requestor)  
31 -  
32 - software = SoftwareInfo.create!(:finality => self.finality,  
33 - :repository_link => self.repository_link, :community_id => community.id,  
34 - :license_info => self.license_info)  
35 - end  
36 -  
37 - def title  
38 - _("New software")  
39 - end  
40 -  
41 - def subject  
42 - name  
43 - end  
44 -  
45 - def information  
46 - message = _('%{requestor} wants to create software %{subject} with')  
47 - if finality.blank?  
48 - { :message => message + _(' no finality.') }  
49 - else  
50 - { :message => message + _(' this finality:<p><em>%{finality}</em></p>'),  
51 - :variables => {:finality => finality} }  
52 - end  
53 - end  
54 -  
55 - def reject_details  
56 - true  
57 - end  
58 -  
59 - # tells if this request was rejected  
60 - def rejected?  
61 - self.status == Task::Status::CANCELLED  
62 - end  
63 -  
64 - # tells if this request was appoved  
65 - def approved?  
66 - self.status == Task::Status::FINISHED  
67 - end  
68 -  
69 - def target_notification_description  
70 - _('%{requestor} wants to create software %{subject}') %  
71 - {:requestor => requestor.name, :subject => subject}  
72 - end  
73 -  
74 - def target_notification_message  
75 - _("User \"%{user}\" just requested to create software %{software}.  
76 - You have to approve or reject it through the \"Pending Validations\"  
77 - section in your control panel.\n") %  
78 - { :user => self.requestor.name, :software => self.name }  
79 - end  
80 -  
81 - def task_created_message  
82 - _("Your request for registering software %{software} at %{environment} was  
83 - just sent. Environment administrator will receive it and will approve or  
84 - reject your request according to his methods and criteria.  
85 -  
86 - You will be notified as soon as environment administrator has a position  
87 - about your request.") %  
88 - { :software => self.name, :environment => self.target }  
89 - end  
90 -  
91 - def task_cancelled_message  
92 - _("Your request for registering software %{software} at %{environment} was  
93 - not approved by the environment administrator. The following explanation  
94 - was given: \n\n%{explanation}") %  
95 - { :software => self.name,  
96 - :environment => self.environment,  
97 - :explanation => self.reject_explanation }  
98 - end  
99 -  
100 - def task_finished_message  
101 - _('Your request for registering the software "%{software}" was approved.  
102 - You can access %{url} and finish the registration of your software.') %  
103 - { :software => self.name, :url => mount_url }  
104 - end  
105 -  
106 - private  
107 -  
108 - def mount_url  
109 - identifier = Community.where(:name => self.name).first.identifier  
110 - # The use of url_for doesn't allow the /social within the Public Software  
111 - # portal. That's why the url is mounted so 'hard coded'  
112 - url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community"  
113 - end  
114 -  
115 -end  
src/noosfero-spb/software_communities/lib/database_description.rb
@@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
1 -class DatabaseDescription < ActiveRecord::Base  
2 -  
3 - SEARCHABLE_SOFTWARE_FIELDS = {  
4 - :name => 1  
5 - }  
6 -  
7 - attr_accessible :name  
8 -  
9 - has_many :software_databases  
10 - has_many :software_infos, :through => :software_databases  
11 -  
12 - validates_presence_of :name  
13 - validates_uniqueness_of :name  
14 -  
15 -end  
src/noosfero-spb/software_communities/lib/database_helper.rb
@@ -5,7 +5,7 @@ class DatabaseHelper &lt; DynamicTableHelper @@ -5,7 +5,7 @@ class DatabaseHelper &lt; DynamicTableHelper
5 def self.valid_database? database 5 def self.valid_database? database
6 return false if SoftwareHelper.all_table_is_empty?(database) 6 return false if SoftwareHelper.all_table_is_empty?(database)
7 7
8 - database_description_id_list = DatabaseDescription.select(:id). 8 + database_description_id_list = SoftwareCommunitiesPlugin::DatabaseDescription.select(:id).
9 collect {|dd| dd.id} 9 collect {|dd| dd.id}
10 10
11 return database_description_id_list.include?( 11 return database_description_id_list.include?(
@@ -19,7 +19,7 @@ class DatabaseHelper &lt; DynamicTableHelper @@ -19,7 +19,7 @@ class DatabaseHelper &lt; DynamicTableHelper
19 19
20 new_databases.each do |new_database| 20 new_databases.each do |new_database|
21 if valid_database? new_database 21 if valid_database? new_database
22 - database = SoftwareDatabase.new 22 + database = SoftwareCommunitiesPlugin::SoftwareDatabase.new
23 23
24 database.database_description_id = 24 database.database_description_id =
25 new_database[:database_description_id] 25 new_database[:database_description_id]
@@ -46,7 +46,7 @@ class DatabaseHelper &lt; DynamicTableHelper @@ -46,7 +46,7 @@ class DatabaseHelper &lt; DynamicTableHelper
46 46
47 def self.database_html_structure(database_data, disabled) 47 def self.database_html_structure(database_data, disabled)
48 database_id = database_data[:database_description_id] 48 database_id = database_data[:database_description_id]
49 - database_name = database_id.blank? ? "" : DatabaseDescription.find( 49 + database_name = database_id.blank? ? "" : SoftwareCommunitiesPlugin::DatabaseDescription.find(
50 database_data[:database_description_id], 50 database_data[:database_description_id],
51 :select=>"name" 51 :select=>"name"
52 ).name 52 ).name
src/noosfero-spb/software_communities/lib/download.rb
@@ -1,51 +0,0 @@ @@ -1,51 +0,0 @@
1 -#FIX ME: Turn this into a proper model(next release)  
2 -class Download  
3 - def initialize data  
4 - @name = data[:name]  
5 - @link = data[:link]  
6 - @software_description = data[:software_description]  
7 - @minimum_requirements = data[:minimum_requirements]  
8 - @size = data[:size]  
9 -  
10 - @total_downloads = if data[:total_downloads]  
11 - data[:total_downloads]  
12 - else  
13 - 0  
14 - end  
15 - end  
16 -  
17 - def self.validate_download_list download_list  
18 - download_list.select! do |download|  
19 - not download[:name].blank?  
20 - end  
21 -  
22 - download_list.map do |download|  
23 - Download.new(download).to_hash  
24 - end  
25 - end  
26 -  
27 - def to_hash  
28 - {  
29 - :name => @name,  
30 - :link => @link,  
31 - :software_description => @software_description,  
32 - :minimum_requirements => @minimum_requirements,  
33 - :size => @size,  
34 - :total_downloads => @total_downloads  
35 - }  
36 - end  
37 -  
38 - def total_downloads= value  
39 - if value.is_a? Integer  
40 - @total_downloads = value  
41 - end  
42 - end  
43 -  
44 - def total_downloads  
45 - @total_downloads  
46 - end  
47 -  
48 - def link  
49 - @link  
50 - end  
51 -end  
src/noosfero-spb/software_communities/lib/download_block.rb
@@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
1 -class DownloadBlock < Block  
2 -  
3 - attr_accessible :show_name, :downloads  
4 -  
5 - settings_items :show_name, :type => :boolean, :default => false  
6 - settings_items :downloads, :type => Array, :default => []  
7 -  
8 - validate :download_values  
9 -  
10 - def download_values  
11 - self.downloads = Download.validate_download_list(self.downloads)  
12 - end  
13 -  
14 - def self.description  
15 - _('Download Stable Version')  
16 - end  
17 -  
18 - def help  
19 - _('This block displays the stable version of a software.')  
20 - end  
21 -  
22 - def content(args={})  
23 - block = self  
24 - s = show_name  
25 - lambda do |object|  
26 - render(  
27 - :file => 'blocks/download',  
28 - :locals => { :block => block, :show_name => s }  
29 - )  
30 - end  
31 - end  
32 -  
33 - def cacheable?  
34 - false  
35 - end  
36 -end  
src/noosfero-spb/software_communities/lib/ext/community.rb
@@ -10,7 +10,7 @@ class Community @@ -10,7 +10,7 @@ class Community
10 10
11 attr_accessible :visible 11 attr_accessible :visible
12 12
13 - has_one :software_info, :dependent=>:destroy 13 + has_one :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :dependent=>:destroy
14 14
15 settings_items :hits, :type => :integer, :default => 0 15 settings_items :hits, :type => :integer, :default => 0
16 16
@@ -57,7 +57,7 @@ class Community @@ -57,7 +57,7 @@ class Community
57 def remove_of_community_search_software? 57 def remove_of_community_search_software?
58 return software? 58 return software?
59 end 59 end
60 - 60 +
61 def hit 61 def hit
62 self.hits += 1 62 self.hits += 1
63 self.save! 63 self.save!
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
@@ -63,11 +63,11 @@ class SearchController @@ -63,11 +63,11 @@ class SearchController
63 params[:query] ||= "" 63 params[:query] ||= ""
64 visible_communities = visible_profiles(Community) 64 visible_communities = visible_profiles(Community)
65 65
66 - filtered_software_list = SoftwareInfo.search_by_query(params[:query]) 66 + filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.search_by_query(params[:query])
67 67
68 if params[:only_softwares] 68 if params[:only_softwares]
69 params[:only_softwares].collect!{ |software_name| software_name.to_slug } 69 params[:only_softwares].collect!{ |software_name| software_name.to_slug }
70 - filtered_software_list = SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) } 70 + filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) }
71 @public_software_selected = false 71 @public_software_selected = false
72 end 72 end
73 73
@@ -117,7 +117,9 @@ class SearchController @@ -117,7 +117,9 @@ class SearchController
117 end 117 end
118 118
119 def prepare_software_infos_params 119 def prepare_software_infos_params
120 - @titles[:software_infos] = _("Result Search") 120 + @asset = "software_communities_plugin/software_infos"
  121 + @assets = [@asset]
  122 + @titles["software_communities_plugin/software_infos"] = _("Result Search")
121 @selected_categories_id = params[:selected_categories_id] 123 @selected_categories_id = params[:selected_categories_id]
122 @selected_categories_id ||= [] 124 @selected_categories_id ||= []
123 @selected_categories_id = @selected_categories_id.map(&:to_i) 125 @selected_categories_id = @selected_categories_id.map(&:to_i)
@@ -130,7 +132,7 @@ class SearchController @@ -130,7 +132,7 @@ class SearchController
130 return 15 if params[:software_display].nil? 132 return 15 if params[:software_display].nil?
131 133
132 if params[:software_display] == "all" 134 if params[:software_display] == "all"
133 - SoftwareInfo.count 135 + SoftwareCommunitiesPlugin::SoftwareInfo.count
134 else 136 else
135 params[:software_display].to_i 137 params[:software_display].to_i
136 end 138 end
src/noosfero-spb/software_communities/lib/library.rb
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -class Library < ActiveRecord::Base  
2 - attr_accessible :name, :version, :license, :software_info_id  
3 -  
4 - validates :name, :version, :license,  
5 - presence: { message: _("can't be blank") },  
6 - length: {  
7 - maximum: 20,  
8 - too_long: _("Too long (maximum is 20 characters)")  
9 - }  
10 -end  
src/noosfero-spb/software_communities/lib/library_helper.rb
@@ -7,7 +7,7 @@ class LibraryHelper &lt; DynamicTableHelper @@ -7,7 +7,7 @@ class LibraryHelper &lt; DynamicTableHelper
7 7
8 new_libraries.each do |new_library| 8 new_libraries.each do |new_library|
9 unless SoftwareHelper.all_table_is_empty? new_library 9 unless SoftwareHelper.all_table_is_empty? new_library
10 - library = Library.new 10 + library = SoftwareCommunitiesPlugin::Library.new
11 library.name = new_library[:name] 11 library.name = new_library[:name]
12 library.version = new_library[:version] 12 library.version = new_library[:version]
13 library.license = new_library[:license] 13 library.license = new_library[:license]
src/noosfero-spb/software_communities/lib/license_helper.rb
1 module LicenseHelper 1 module LicenseHelper
2 def self.find_licenses query 2 def self.find_licenses query
3 - licenses = LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") 3 + licenses = SoftwareCommunitiesPlugin::LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version")
4 licenses.reject!{|license| license.version == "Another"} 4 licenses.reject!{|license| license.version == "Another"}
5 - license_another = LicenseInfo.find_by_version("Another") 5 + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another")
6 licenses << license_another if license_another 6 licenses << license_another if license_another
7 licenses 7 licenses
8 end 8 end
src/noosfero-spb/software_communities/lib/license_info.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -class LicenseInfo < ActiveRecord::Base  
2 - attr_accessible :version, :link  
3 -  
4 - validates_presence_of :version  
5 -  
6 - has_many :software_info  
7 -  
8 -end  
src/noosfero-spb/software_communities/lib/operating_system.rb
@@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
1 -class OperatingSystem < ActiveRecord::Base  
2 - attr_accessible :version  
3 -  
4 - belongs_to :software_info  
5 - belongs_to :operating_system_name  
6 -  
7 - validates :operating_system_name, presence: true  
8 - validates :version,  
9 - presence: true,  
10 - length: {  
11 - maximum: 20,  
12 - too_long: _('too long (maximum is 20 characters)')  
13 - }  
14 -end  
src/noosfero-spb/software_communities/lib/operating_system_helper.rb
@@ -12,8 +12,8 @@ class OperatingSystemHelper &lt; DynamicTableHelper @@ -12,8 +12,8 @@ class OperatingSystemHelper &lt; DynamicTableHelper
12 ["operating_system_name_id"] 12 ["operating_system_name_id"]
13 ) 13 )
14 14
15 - operating_system = OperatingSystem.new  
16 - operating_system.operating_system_name = OperatingSystemName.find( 15 + operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new
  16 + operating_system.operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName.find(
17 new_operating_system[:operating_system_name_id] 17 new_operating_system[:operating_system_name_id]
18 ) 18 )
19 19
@@ -38,7 +38,7 @@ class OperatingSystemHelper &lt; DynamicTableHelper @@ -38,7 +38,7 @@ class OperatingSystemHelper &lt; DynamicTableHelper
38 38
39 def self.operating_system_html_structure (operating_system_data, disabled) 39 def self.operating_system_html_structure (operating_system_data, disabled)
40 select_options = options_for_select( 40 select_options = options_for_select(
41 - OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, 41 + SoftwareCommunitiesPlugin::OperatingSystemName.all.collect {|osn| [osn.name, osn.id]},
42 operating_system_data[:operating_system_name_id] 42 operating_system_data[:operating_system_name_id]
43 ) 43 )
44 44
src/noosfero-spb/software_communities/lib/operating_system_name.rb
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -class OperatingSystemName < ActiveRecord::Base  
2 - attr_accessible :name  
3 -  
4 - validates_presence_of :name  
5 - validates_uniqueness_of :name  
6 -  
7 - has_many :operating_systems  
8 - has_many :software_infos, :through => :operating_systems  
9 -  
10 -end  
src/noosfero-spb/software_communities/lib/programming_language.rb
@@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
1 -class ProgrammingLanguage < ActiveRecord::Base  
2 -  
3 - SEARCHABLE_SOFTWARE_FIELDS = {  
4 - :name => 1  
5 - }  
6 -  
7 - attr_accessible :name  
8 -  
9 - validates_presence_of :name  
10 - validates_uniqueness_of :name  
11 -  
12 - has_many :software_languages  
13 - has_many :software_infos, :through => :software_languages  
14 -  
15 -end  
src/noosfero-spb/software_communities/lib/repository_block.rb
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -class RepositoryBlock < Block  
2 -  
3 - attr_accessible :show_name  
4 -  
5 - settings_items :show_name, :type => :boolean, :default => false  
6 -  
7 - def self.description  
8 - _('Repository Link')  
9 - end  
10 -  
11 - def help  
12 - _('This block displays the repository link of a software.')  
13 - end  
14 -  
15 - def content(args={})  
16 - block = self  
17 - s = show_name  
18 - lambda do |object|  
19 - render(  
20 - :file => 'blocks/repository',  
21 - :locals => { :block => block, :show_name => s }  
22 - )  
23 - end  
24 - end  
25 -  
26 - def cacheable?  
27 - false  
28 - end  
29 -end  
src/noosfero-spb/software_communities/lib/search_catalog_block.rb
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -class SearchCatalogBlock < Block  
2 -  
3 - attr_accessible :show_name  
4 -  
5 - settings_items :show_name, :type => :boolean, :default => false  
6 -  
7 - def self.description  
8 - _('Search Softwares catalog')  
9 - end  
10 -  
11 - def help  
12 - _('This block displays the search categories field ')  
13 - end  
14 -  
15 - def content(args={})  
16 - block = self  
17 - s = show_name  
18 - lambda do |object|  
19 - render(  
20 - :file => 'blocks/search_catalog',  
21 - :locals => { :block => block, :show_name => s }  
22 - )  
23 - end  
24 - end  
25 -  
26 - def cacheable?  
27 - false  
28 - end  
29 -end  
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
@@ -33,17 +33,17 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -33,17 +33,17 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
33 33
34 def self.extra_blocks 34 def self.extra_blocks
35 { 35 {
36 - SoftwaresBlock => { :type => [Environment, Person] },  
37 - SoftwareInformationBlock => { :type => [Community] },  
38 - DownloadBlock => { :type => [Community] },  
39 - RepositoryBlock => { :type => [Community] },  
40 - CategoriesAndTagsBlock => { :type => [Community] },  
41 - CategoriesSoftwareBlock => { :type => [Environment] },  
42 - SearchCatalogBlock => { :type => [Environment] },  
43 - SoftwareHighlightsBlock => { :type => [Environment] },  
44 - SoftwareTabDataBlock => {:type => [Community], :position => 1},  
45 - WikiBlock => {:type => [Community]},  
46 - StatisticBlock => { :type => [Community] } 36 + SoftwareCommunitiesPlugin::SoftwaresBlock => { :type => [Environment, Person] },
  37 + SoftwareCommunitiesPlugin::SoftwareInformationBlock => { :type => [Community] },
  38 + SoftwareCommunitiesPlugin::DownloadBlock => { :type => [Community] },
  39 + SoftwareCommunitiesPlugin::RepositoryBlock => { :type => [Community] },
  40 + SoftwareCommunitiesPlugin::CategoriesAndTagsBlock => { :type => [Community] },
  41 + SoftwareCommunitiesPlugin::CategoriesSoftwareBlock => { :type => [Environment] },
  42 + SoftwareCommunitiesPlugin::SearchCatalogBlock => { :type => [Environment] },
  43 + SoftwareCommunitiesPlugin::SoftwareHighlightsBlock => { :type => [Environment] },
  44 + SoftwareCommunitiesPlugin::SoftwareTabDataBlock => {:type => [Community], :position => 1},
  45 + SoftwareCommunitiesPlugin::WikiBlock => {:type => [Community]},
  46 + SoftwareCommunitiesPlugin::StatisticBlock => { :type => [Community] }
47 } 47 }
48 end 48 end
49 49
@@ -117,7 +117,7 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -117,7 +117,7 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
117 protected 117 protected
118 118
119 def software_info_transaction 119 def software_info_transaction
120 - SoftwareInfo.transaction do 120 + SoftwareCommunitiesPlugin::SoftwareInfo.transaction do
121 context.profile. 121 context.profile.
122 software_info. 122 software_info.
123 update_attributes!(context.params[:software_info]) 123 update_attributes!(context.params[:software_info])
@@ -125,7 +125,7 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -125,7 +125,7 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
125 end 125 end
126 126
127 def license_transaction 127 def license_transaction
128 - license = LicenseInfo.find(context.params[:version]) 128 + license = SoftwareCommunitiesPlugin::LicenseInfo.find(context.params[:version])
129 context.profile.software_info.license_info = license 129 context.profile.software_info.license_info = license
130 context.profile.software_info.save! 130 context.profile.software_info.save!
131 end 131 end
src/noosfero-spb/software_communities/lib/software_database.rb
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -class SoftwareDatabase < ActiveRecord::Base  
2 - attr_accessible :version  
3 -  
4 - belongs_to :software_info  
5 - belongs_to :database_description  
6 -  
7 - validates_presence_of :database_description_id, :version  
8 -  
9 - validates_length_of(  
10 - :version,  
11 - :maximum => 20,  
12 - :too_long => _("Software database is too long (maximum is 20 characters)")  
13 - )  
14 -  
15 - validates(  
16 - :database_description_id,  
17 - :numericality => {:greater_than_or_equal_to => 1}  
18 - )  
19 -  
20 -end  
src/noosfero-spb/software_communities/lib/software_highlights_block.rb
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -class SoftwareHighlightsBlock < HighlightsBlock  
2 -  
3 - def self.description  
4 - _('Software Highlights Block')  
5 - end  
6 -  
7 - def help  
8 - _('This block displays the softwares icon into a highlight')  
9 - end  
10 -  
11 - def content(args={})  
12 - softwares = self.settings[:images].collect {|h| h[:address].split('/').last}  
13 - block = self  
14 - proc do  
15 - render :file => 'blocks/software_highlights', :locals => { :block => block, :softwares => softwares}  
16 - end  
17 - end  
18 -  
19 -  
20 -end  
src/noosfero-spb/software_communities/lib/software_info.rb
@@ -1,263 +0,0 @@ @@ -1,263 +0,0 @@
1 -class SoftwareInfo < ActiveRecord::Base  
2 - acts_as_having_settings :field => :settings  
3 -  
4 - SEARCHABLE_SOFTWARE_FIELDS = {  
5 - :acronym => 1,  
6 - :finality => 2,  
7 - }  
8 -  
9 - SEARCHABLE_SOFTWARE_CLASSES = [  
10 - SoftwareInfo,  
11 - Community,  
12 - ProgrammingLanguage,  
13 - DatabaseDescription  
14 - ]  
15 -  
16 - scope :search_by_query, lambda { |query = ""|  
17 - filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')  
18 - search_fields = SoftwareInfo.pg_search_plugin_fields  
19 -  
20 - if query.empty?  
21 - SoftwareInfo.joins(:community).where("profiles.visible = ?", true)  
22 - else  
23 - searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES)  
24 - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true)  
25 - end  
26 - }  
27 -  
28 - def self.transform_list_in_methods_list list  
29 - methods_list = []  
30 -  
31 - list.each do |element|  
32 - if SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym)  
33 - methods_list << element.to_s.underscore.to_sym  
34 - elsif SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym)  
35 - methods_list << element.to_s.underscore.pluralize.to_sym  
36 - end  
37 - end  
38 -  
39 - methods_list  
40 - end  
41 -  
42 - def self.pg_search_plugin_fields  
43 - SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class|  
44 - self.get_searchable_fields(one_class)  
45 - }.join(" || ' ' || ")  
46 - end  
47 -  
48 - def self.get_searchable_fields one_class  
49 - searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ")  
50 - searchable_fields  
51 - end  
52 -  
53 - SEARCH_FILTERS = {  
54 - :order => %w[],  
55 - :display => %w[full]  
56 - }  
57 -  
58 - def self.default_search_display  
59 - 'full'  
60 - end  
61 -  
62 - attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq,  
63 - :operating_platform  
64 -  
65 - attr_accessible :demonstration_url, :acronym, :objectives, :features,  
66 - :license_info  
67 -  
68 - attr_accessible :community_id, :finality, :repository_link, :public_software,  
69 - :first_edit  
70 -  
71 - has_many :libraries, :dependent => :destroy  
72 - has_many :software_databases  
73 - has_many :database_descriptions, :through => :software_databases  
74 - has_many :software_languages  
75 - has_many :operating_systems  
76 - has_many :programming_languages, :through => :software_languages  
77 - has_many :operating_system_names, :through => :operating_systems  
78 -  
79 - belongs_to :community, :dependent => :destroy  
80 - belongs_to :license_info  
81 -  
82 - has_one :software_categories  
83 -  
84 - validates_length_of :finality, :maximum => 120  
85 - validates_length_of :objectives, :maximum => 4000  
86 - validates_length_of :features, :maximum => 4000  
87 - validates_presence_of :finality, :community  
88 -  
89 - validate :validate_acronym  
90 -  
91 - settings_items :another_license_version, :another_license_link  
92 -  
93 - # used on find_by_contents  
94 - scope :like_search, lambda{ |name|  
95 - joins(:community).where(  
96 - "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?",  
97 - "%#{name}%", "%#{name}%", "%#{name}%"  
98 - )  
99 - }  
100 -  
101 - scope :search, lambda { |name="", database_description_id = "",  
102 - programming_language_id = "", operating_system_name_id = "",  
103 - license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "",  
104 - icp_brasil = "", e_arq = "", software_categories = "" |  
105 -  
106 - like_sql = ""  
107 - values = []  
108 -  
109 - unless name.blank?  
110 - like_sql << "name ILIKE ? OR identifier ILIKE ? AND "  
111 - values << "%#{name}%" << "%#{name}%"  
112 - end  
113 -  
114 - like_sql = like_sql[0..like_sql.length-5]  
115 -  
116 - {  
117 - :joins => [:community],  
118 - :conditions=>[like_sql, *values]  
119 - }  
120 - }  
121 -  
122 - def license_info  
123 - license = LicenseInfo.find_by_id self.license_info_id  
124 - license_another = LicenseInfo.find_by_version("Another")  
125 -  
126 - if license_another && license.id == license_another.id  
127 - LicenseInfo.new(  
128 - :version => self.another_license_version,  
129 - :link => self.another_license_link  
130 - )  
131 - else  
132 - license  
133 - end  
134 - end  
135 -  
136 - def another_license(version, link)  
137 - license_another = LicenseInfo.find_by_version("Another")  
138 -  
139 - if license_another  
140 - self.another_license_version = version  
141 - self.another_license_link = link  
142 - self.license_info = license_another  
143 - self.save!  
144 - end  
145 - end  
146 -  
147 - def validate_name_lenght  
148 - if self.community.name.size > 100  
149 - self.errors.add(  
150 - :base,  
151 - _("Name is too long (maximum is %{count} characters)")  
152 - )  
153 - false  
154 - end  
155 - true  
156 - end  
157 -  
158 - # if create_after_moderation receive a model object, would be possible to reuse core method  
159 - def self.create_after_moderation(requestor, attributes = {})  
160 - environment = attributes.delete(:environment)  
161 - name = attributes.delete(:name)  
162 - identifier = attributes.delete(:identifier)  
163 - image_builder = attributes.delete(:image_builder)  
164 - license_info = attributes.delete(:license_info)  
165 - another_license_version = attributes.delete(:another_license_version)  
166 - another_license_link = attributes.delete(:another_license_link)  
167 -  
168 - software_info = SoftwareInfo.new(attributes)  
169 - unless environment.admins.include? requestor  
170 - CreateSoftware.create!(  
171 - attributes.merge(  
172 - :requestor => requestor,  
173 - :environment => environment,  
174 - :name => name,  
175 - :identifier => identifier,  
176 - :license_info => license_info  
177 - )  
178 - )  
179 - else  
180 - software_template = SoftwareHelper.software_template  
181 -  
182 - community_hash = {:name => name}  
183 - community_hash[:identifier] = identifier  
184 - community_hash[:image_builder] = image_builder if image_builder  
185 -  
186 - community = Community.new(community_hash)  
187 - community.environment = environment  
188 -  
189 - unless software_template.blank?  
190 - community.template_id = software_template.id  
191 - end  
192 -  
193 - community.save!  
194 - community.add_admin(requestor)  
195 -  
196 - software_info.community = community  
197 - software_info.license_info = license_info  
198 - software_info.save!  
199 - end  
200 -  
201 - software_info.verify_license_info(another_license_version, another_license_link)  
202 - software_info.save  
203 - software_info  
204 - end  
205 -  
206 - def verify_license_info another_license_version, another_license_link  
207 - license_another = LicenseInfo.find_by_version("Another")  
208 -  
209 - if license_another && self.license_info_id == license_another.id  
210 - version = another_license_version  
211 - link = another_license_link  
212 -  
213 - self.another_license(version, link)  
214 - end  
215 - end  
216 -  
217 -  
218 - def validate_acronym  
219 - self.acronym = "" if self.acronym.nil?  
220 - if self.acronym.length > 10 && self.errors.messages[:acronym].nil?  
221 - self.errors.add(:acronym, _("can't have more than 10 characteres"))  
222 - false  
223 - elsif self.acronym.match(/\s+/)  
224 - self.errors.add(:acronym, _("can't have whitespaces"))  
225 - false  
226 - end  
227 - true  
228 - end  
229 -  
230 - def valid_operating_systems  
231 - if self.operating_systems.empty?  
232 - self.errors.add(:operating_system, _(": at least one must be filled"))  
233 - end  
234 - end  
235 -  
236 - def valid_software_info  
237 - if self.software_languages.empty?  
238 - self.errors.add(:software_languages, _(": at least one must be filled"))  
239 - end  
240 - end  
241 -  
242 - def valid_databases  
243 - if self.software_databases.empty?  
244 - self.errors.add(:software_databases, _(": at least one must be filled"))  
245 - end  
246 - end  
247 -  
248 - def visible?  
249 - self.community.visible?  
250 - end  
251 -  
252 - def name  
253 - self.community.name  
254 - end  
255 -  
256 - def short_name  
257 - self.community.short_name  
258 - end  
259 -  
260 - def identifier  
261 - self.community.identifier  
262 - end  
263 -end  
src/noosfero-spb/software_communities/lib/software_information_block.rb
@@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
1 -class SoftwareInformationBlock < Block  
2 -  
3 - attr_accessible :show_name  
4 -  
5 - settings_items :show_name, :type => :boolean, :default => false  
6 -  
7 - def self.description  
8 - _('Basic Software Information')  
9 - end  
10 -  
11 - def help  
12 - _('This block displays the basic information of a software profile.')  
13 - end  
14 -  
15 - def content(args={})  
16 - block = self  
17 - s = show_name  
18 -  
19 - lambda do |object|  
20 - render(  
21 - :file => 'blocks/software_information',  
22 - :locals => { :block => block, :show_name => s}  
23 - )  
24 - end  
25 - end  
26 -  
27 - def cacheable?  
28 - false  
29 - end  
30 -  
31 - private  
32 -  
33 - def owner_has_ratings?  
34 - ratings = CommunityRating.where(community_id: block.owner.id)  
35 - !ratings.empty?  
36 - end  
37 -end  
src/noosfero-spb/software_communities/lib/software_language.rb
@@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
1 -class SoftwareLanguage < ActiveRecord::Base  
2 - attr_accessible :version  
3 -  
4 - belongs_to :software_info  
5 - belongs_to :programming_language  
6 -  
7 - validates_length_of(  
8 - :version,  
9 - :maximum => 20,  
10 - :too_long => _("Software language is too long (maximum is 20 characters)")  
11 - )  
12 -  
13 - validates_presence_of :version,:programming_language  
14 -end  
src/noosfero-spb/software_communities/lib/software_language_helper.rb
@@ -5,7 +5,7 @@ class SoftwareLanguageHelper &lt; DynamicTableHelper @@ -5,7 +5,7 @@ class SoftwareLanguageHelper &lt; DynamicTableHelper
5 def self.valid_language? language 5 def self.valid_language? language
6 return false if SoftwareHelper.all_table_is_empty?(language) 6 return false if SoftwareHelper.all_table_is_empty?(language)
7 7
8 - programming_language_id_list = ProgrammingLanguage. 8 + programming_language_id_list = SoftwareCommunitiesPlugin::ProgrammingLanguage.
9 select(:id). 9 select(:id).
10 collect { |dd| dd.id } 10 collect { |dd| dd.id }
11 11
@@ -20,9 +20,9 @@ class SoftwareLanguageHelper &lt; DynamicTableHelper @@ -20,9 +20,9 @@ class SoftwareLanguageHelper &lt; DynamicTableHelper
20 20
21 new_languages.each do |new_language| 21 new_languages.each do |new_language|
22 if valid_language? new_language 22 if valid_language? new_language
23 - language = SoftwareLanguage.new 23 + language = SoftwareCommunitiesPlugin::SoftwareLanguage.new
24 language.programming_language = 24 language.programming_language =
25 - ProgrammingLanguage.find(new_language[:programming_language_id]) 25 + SoftwareCommunitiesPlugin::ProgrammingLanguage.find(new_language[:programming_language_id])
26 language.version = new_language[:version] 26 language.version = new_language[:version]
27 list_languages << language 27 list_languages << language
28 end 28 end
@@ -52,7 +52,7 @@ class SoftwareLanguageHelper &lt; DynamicTableHelper @@ -52,7 +52,7 @@ class SoftwareLanguageHelper &lt; DynamicTableHelper
52 language_id = language_data[:programming_language_id] 52 language_id = language_data[:programming_language_id]
53 language_name = "" 53 language_name = ""
54 unless language_data[:programming_language_id].blank? 54 unless language_data[:programming_language_id].blank?
55 - language_name = ProgrammingLanguage.find( 55 + language_name = SoftwareCommunitiesPlugin::ProgrammingLanguage.find(
56 language_data[:programming_language_id], 56 language_data[:programming_language_id],
57 :select=>"name" 57 :select=>"name"
58 ).name 58 ).name
src/noosfero-spb/software_communities/lib/software_tab_data_block.rb
@@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
1 -class SoftwareTabDataBlock < Block  
2 - attr_accessible :show_name, :displayed_blog  
3 -  
4 - settings_items :show_name, :type => :boolean, :default => false  
5 - settings_items :displayed_blog, :type => :integer, :default => 0  
6 -  
7 - TOTAL_POSTS_DYSPLAYED = 5  
8 -  
9 - def self.description  
10 - _('Software Tab Data')  
11 - end  
12 -  
13 - def help  
14 - _('This block is used by colab to insert data into Noosfero')  
15 - end  
16 -  
17 - def content(args={})  
18 - block = self  
19 -  
20 - lambda do |object|  
21 - render(  
22 - :file => 'blocks/software_tab_data',  
23 - :locals => {  
24 - :block => block  
25 - }  
26 - )  
27 - end  
28 - end  
29 -  
30 - def blogs  
31 - self.owner.blogs  
32 - end  
33 -  
34 - def actual_blog  
35 - # As :displayed_blog default value is 0, it falls to the first one  
36 - blogs.find_by_id(self.displayed_blog) || blogs.first  
37 - end  
38 -  
39 - def posts  
40 - blog = actual_blog  
41 -  
42 - if blog and (not blog.posts.empty?)  
43 - blog.posts.limit(TOTAL_POSTS_DYSPLAYED)  
44 - else  
45 - []  
46 - end  
47 - end  
48 -end  
src/noosfero-spb/software_communities/lib/softwares_block.rb
@@ -1,105 +0,0 @@ @@ -1,105 +0,0 @@
1 -class SoftwaresBlock < CommunitiesBlock  
2 -  
3 - settings_items :software_type, :default => "All"  
4 - attr_accessible :accessor_id, :accessor_type, :role_id,  
5 - :resource_id, :resource_type, :software_type  
6 -  
7 - def self.description  
8 - _('Softwares')  
9 - end  
10 -  
11 - def default_title  
12 - if self.software_type == "Generic"  
13 - return n_('{#} generic software', '{#} generic softwares', profile_count)  
14 - elsif self.software_type == "Public"  
15 - return n_('{#} public software', '{#} public softwares', profile_count)  
16 - else  
17 - return n_('{#} software', '{#} softwares', profile_count)  
18 - end  
19 - end  
20 -  
21 - def help  
22 - _('This block displays the softwares in which the user is a member.')  
23 - end  
24 -  
25 - def footer  
26 - self.software_type ||= "All"  
27 - owner = self.owner  
28 - case owner  
29 - when Profile  
30 - lambda do |context|  
31 - link_to s_('softwares|View all'), :profile => owner.identifier,  
32 - :controller => 'profile', :action => 'communities',  
33 - :type => 'Software'  
34 - end  
35 - when Environment  
36 - lambda do |context|  
37 - link_to s_('softwares|View all'), :controller => 'search',  
38 - :action => 'software_infos'  
39 - end  
40 - else  
41 - ''  
42 - end  
43 - end  
44 -  
45 - def profile_count  
46 - profile_list.count  
47 - end  
48 -  
49 - def profiles  
50 - owner.communities  
51 - end  
52 -  
53 - def profile_list  
54 - profiles = get_visible_profiles  
55 -  
56 - software_profiles = profiles.select do |profile|  
57 - profile.class == Community && profile.software?  
58 - end  
59 -  
60 - block_softwares = if self.software_type == "Public"  
61 - software_profiles.select { |profile| profile.software_info.public_software? }  
62 - elsif self.software_type == "Generic"  
63 - software_profiles.select { |profile| !profile.software_info.public_software? }  
64 - else # All  
65 - software_profiles  
66 - end  
67 -  
68 - block_softwares.slice(0..get_limit-1)  
69 - end  
70 -  
71 - def content(arg={})  
72 - if self.box.owner_type == "Environment" && self.box.position == 1  
73 - block = self  
74 -  
75 - proc do  
76 - render :file => 'blocks/main_area_softwares',  
77 - :locals => {:profiles=> block.profile_list(), :block => block}  
78 - end  
79 - else  
80 - super(arg)  
81 - end  
82 - end  
83 -  
84 - protected  
85 -  
86 - def get_visible_profiles  
87 - profile_include_list = [:image, :domains, :preferred_domain, :environment]  
88 - visible_profiles = profiles.visible.includes(profile_include_list)  
89 -  
90 - if !prioritize_profiles_with_image  
91 - visible_profiles.all( :limit => get_limit,  
92 - :order => 'profiles.updated_at DESC'  
93 - ).sort_by{ rand }  
94 - elsif profiles.visible.with_image.count >= get_limit  
95 - visible_profiles.with_image.all( :limit => get_limit * 5,  
96 - :order => 'profiles.updated_at DESC'  
97 - ).sort_by{ rand }  
98 - else  
99 - visible_profiles.with_image.sort_by{ rand } +  
100 - visible_profiles.without_image.all( :limit => get_limit * 5,  
101 - :order => 'profiles.updated_at DESC'  
102 - ).sort_by{ rand }  
103 - end  
104 - end  
105 -end  
src/noosfero-spb/software_communities/lib/statistic_block.rb
@@ -1,52 +0,0 @@ @@ -1,52 +0,0 @@
1 -class StatisticBlock < Block  
2 -  
3 - settings_items :benefited_people, :type => :integer, :default => 0  
4 - settings_items :saved_resources, :type => :float, :default => 0.0  
5 -  
6 - attr_accessible :benefited_people, :saved_resources  
7 -  
8 - def self.description  
9 - _('Software Statistics')  
10 - end  
11 -  
12 - def help  
13 - _('This block displays software statistics.')  
14 - end  
15 -  
16 - def content(args={})  
17 - download_blocks = get_profile_download_blocks(self.owner)  
18 - downloads = download_blocks.map do |download_block|  
19 - get_downloads_from_block(download_block)  
20 - end  
21 -  
22 - block = self  
23 -  
24 - lambda do |object|  
25 - render(  
26 - :file => 'blocks/software_statistics',  
27 - :locals => {  
28 - :block => block,  
29 - :total_downloads => downloads.sum  
30 - }  
31 - )  
32 - end  
33 - end  
34 -  
35 - def cacheable?  
36 - false  
37 - end  
38 -  
39 - private  
40 -  
41 - def get_profile_download_blocks profile  
42 - DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id)  
43 - end  
44 -  
45 - def get_downloads_from_block download_block  
46 - downloads = download_block.downloads.map do |download|  
47 - download[:total_downloads] unless download[:total_downloads].nil?  
48 - end  
49 - downloads.select! {|value| not value.nil? }  
50 - downloads.sum  
51 - end  
52 -end  
src/noosfero-spb/software_communities/lib/tasks/create_licenses.rake
@@ -16,8 +16,8 @@ namespace :software do @@ -16,8 +16,8 @@ namespace :software do
16 16
17 if data.length != 0 17 if data.length != 0
18 if version_or_link == 'version' 18 if version_or_link == 'version'
19 - can_save = LicenseInfo.find_by_version(data) ? false : true  
20 - licence = LicenseInfo::new :version => data 19 + can_save = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version(data) ? false : true
  20 + licence = SoftwareCommunitiesPlugin::LicenseInfo::new :version => data
21 version_or_link = 'link' 21 version_or_link = 'link'
22 elsif version_or_link == 'link' 22 elsif version_or_link == 'link'
23 licence.link = data 23 licence.link = data
src/noosfero-spb/software_communities/lib/tasks/create_sample_softwares.rake
@@ -53,12 +53,12 @@ end @@ -53,12 +53,12 @@ end
53 53
54 def create_software_info(name, acronym = "", finality = "default") 54 def create_software_info(name, acronym = "", finality = "default")
55 community = create_community(name) 55 community = create_community(name)
56 - software_info = SoftwareInfo.new 56 + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new
57 software_info.community = community 57 software_info.community = community
58 software_info.public_software = true 58 software_info.public_software = true
59 software_info.acronym = acronym 59 software_info.acronym = acronym
60 software_info.finality = finality 60 software_info.finality = finality
61 - software_info.license_info = LicenseInfo.first 61 + software_info.license_info = SoftwareCommunitiesPlugin::LicenseInfo.first
62 62
63 if software_info.community.valid? && software_info.valid? 63 if software_info.community.valid? && software_info.valid?
64 print "." 64 print "."
src/noosfero-spb/software_communities/lib/tasks/export.rake
@@ -37,7 +37,7 @@ namespace :export do @@ -37,7 +37,7 @@ namespace :export do
37 "home_page_published_at" 37 "home_page_published_at"
38 ] 38 ]
39 39
40 - SoftwareInfo.all.each do |software| 40 + SoftwareCommunitiesPlugin::SoftwareInfo.all.each do |software|
41 if software.community 41 if software.community
42 begin 42 begin
43 csv << [ 43 csv << [
@@ -104,7 +104,7 @@ namespace :export do @@ -104,7 +104,7 @@ namespace :export do
104 "category_id" 104 "category_id"
105 ] 105 ]
106 106
107 - SoftwareInfo.all.each do |software| 107 + SoftwareCommunitiesPlugin::SoftwareInfo.all.each do |software|
108 if software.community 108 if software.community
109 software.community.categories.each do |category| 109 software.community.categories.each do |category|
110 begin 110 begin
src/noosfero-spb/software_communities/lib/wiki_block.rb
@@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
1 -class WikiBlock < Block  
2 -  
3 - attr_accessible :show_name, :wiki_link  
4 - settings_items :show_name, :type => :boolean, :default => false  
5 - settings_items :wiki_link, :type => :string, :default => ""  
6 -  
7 - def self.description  
8 - _('Wiki Link')  
9 - end  
10 -  
11 - def help  
12 - _('This block displays a link to the software wiki.')  
13 - end  
14 -  
15 - def content(args={})  
16 - block = self  
17 - s = show_name  
18 -  
19 - lambda do |object|  
20 - render(  
21 - :file => 'blocks/wiki',  
22 - :locals => { :block => block, :show_name => s }  
23 - )  
24 - end  
25 - end  
26 -  
27 - def cacheable?  
28 - true  
29 - end  
30 -end  
src/noosfero-spb/software_communities/models/software_communities_plugin/categories_and_tags_block.rb 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +class SoftwareCommunitiesPlugin::CategoriesAndTagsBlock < Block
  2 +
  3 + attr_accessible :show_name
  4 +
  5 + settings_items :show_name, :type => :boolean, :default => false
  6 +
  7 + def self.description
  8 + _('Categories and Tags')
  9 + end
  10 +
  11 + def help
  12 + _('This block displays the categories and tags of a software.')
  13 + end
  14 +
  15 + def content(args={})
  16 + block = self
  17 + s = show_name
  18 + lambda do |object|
  19 + render(
  20 + :file => 'blocks/categories_and_tags',
  21 + :locals => { :block => block, :show_name => s }
  22 + )
  23 + end
  24 + end
  25 +
  26 + def cacheable?
  27 + false
  28 + end
  29 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/categories_software_block.rb 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +class SoftwareCommunitiesPlugin::CategoriesSoftwareBlock < Block
  2 +
  3 + attr_accessible :show_name
  4 +
  5 + settings_items :show_name, :type => :boolean, :default => false
  6 +
  7 + def self.description
  8 + _('Categories Softwares')
  9 + end
  10 +
  11 + def help
  12 + _('This block displays the categories and the amount of softwares for
  13 + each category.')
  14 + end
  15 +
  16 + def content(args={})
  17 + block = self
  18 + s = show_name
  19 +
  20 + software_category = Category.find_by_name("Software")
  21 + categories = []
  22 + categories = software_category.children.sort if software_category
  23 +
  24 + lambda do |object|
  25 + render(
  26 + :file => 'blocks/categories_software',
  27 + :locals => { :block => block, :show_name => s, :categories => categories }
  28 + )
  29 + end
  30 + end
  31 +
  32 + def cacheable?
  33 + false
  34 + end
  35 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/create_software.rb 0 → 100644
@@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
  1 +class SoftwareCommunitiesPlugin::CreateSoftware < Task
  2 + include Rails.application.routes.url_helpers
  3 +
  4 + validates_presence_of :requestor_id, :target_id
  5 + validates_presence_of :name, :finality
  6 +
  7 + attr_accessible :name, :finality, :repository_link, :requestor, :environment,
  8 + :reject_explanation, :license_info, :identifier, :target
  9 +
  10 + alias :environment :target
  11 + alias :environment= :target=
  12 +
  13 + DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link']
  14 + DATA_FIELDS.each do |field|
  15 + settings_items field.to_sym
  16 + end
  17 +
  18 + def perform
  19 + software_template = SoftwareHelper.software_template
  20 + template_id = software_template.blank? ? nil : software_template.id
  21 +
  22 + identifier = self.identifier
  23 + identifier ||= self.name.to_slug
  24 +
  25 + community = Community.create!(:name => self.name,
  26 + :identifier => identifier,
  27 + :template_id => template_id)
  28 +
  29 + community.environment = self.environment
  30 + community.add_admin(self.requestor)
  31 +
  32 + software = SoftwareCommunitiesPlugin::SoftwareInfo.create!(:finality => self.finality,
  33 + :repository_link => self.repository_link, :community_id => community.id,
  34 + :license_info => self.license_info)
  35 + end
  36 +
  37 + def title
  38 + _("New software")
  39 + end
  40 +
  41 + def subject
  42 + name
  43 + end
  44 +
  45 + def information
  46 + message = _('%{requestor} wants to create software %{subject} with')
  47 + if finality.blank?
  48 + { :message => message + _(' no finality.') }
  49 + else
  50 + { :message => message + _(' this finality:<p><em>%{finality}</em></p>'),
  51 + :variables => {:finality => finality} }
  52 + end
  53 + end
  54 +
  55 + def reject_details
  56 + true
  57 + end
  58 +
  59 + # tells if this request was rejected
  60 + def rejected?
  61 + self.status == Task::Status::CANCELLED
  62 + end
  63 +
  64 + # tells if this request was appoved
  65 + def approved?
  66 + self.status == Task::Status::FINISHED
  67 + end
  68 +
  69 + def target_notification_description
  70 + _('%{requestor} wants to create software %{subject}') %
  71 + {:requestor => requestor.name, :subject => subject}
  72 + end
  73 +
  74 + def target_notification_message
  75 + _("User \"%{user}\" just requested to create software %{software}.
  76 + You have to approve or reject it through the \"Pending Validations\"
  77 + section in your control panel.\n") %
  78 + { :user => self.requestor.name, :software => self.name }
  79 + end
  80 +
  81 + def task_created_message
  82 + _("Your request for registering software %{software} at %{environment} was
  83 + just sent. Environment administrator will receive it and will approve or
  84 + reject your request according to his methods and criteria.
  85 +
  86 + You will be notified as soon as environment administrator has a position
  87 + about your request.") %
  88 + { :software => self.name, :environment => self.target }
  89 + end
  90 +
  91 + def task_cancelled_message
  92 + _("Your request for registering software %{software} at %{environment} was
  93 + not approved by the environment administrator. The following explanation
  94 + was given: \n\n%{explanation}") %
  95 + { :software => self.name,
  96 + :environment => self.environment,
  97 + :explanation => self.reject_explanation }
  98 + end
  99 +
  100 + def task_finished_message
  101 + _('Your request for registering the software "%{software}" was approved.
  102 + You can access %{url} and finish the registration of your software.') %
  103 + { :software => self.name, :url => mount_url }
  104 + end
  105 +
  106 + private
  107 +
  108 + def mount_url
  109 + identifier = Community.where(:name => self.name).first.identifier
  110 + # The use of url_for doesn't allow the /social within the Public Software
  111 + # portal. That's why the url is mounted so 'hard coded'
  112 + url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community"
  113 + end
  114 +
  115 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/database_description.rb 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +class SoftwareCommunitiesPlugin::DatabaseDescription < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_SOFTWARE_FIELDS = {
  4 + :name => 1
  5 + }
  6 +
  7 + attr_accessible :name
  8 +
  9 + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase'
  10 + has_many :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :through => :software_databases
  11 +
  12 + validates_presence_of :name
  13 + validates_uniqueness_of :name
  14 +
  15 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/download.rb 0 → 100644
@@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
  1 +#FIX ME: Turn this into a proper model(next release)
  2 +class SoftwareCommunitiesPlugin::Download
  3 + def initialize data
  4 + @name = data[:name]
  5 + @link = data[:link]
  6 + @software_description = data[:software_description]
  7 + @minimum_requirements = data[:minimum_requirements]
  8 + @size = data[:size]
  9 +
  10 + @total_downloads = if data[:total_downloads]
  11 + data[:total_downloads]
  12 + else
  13 + 0
  14 + end
  15 + end
  16 +
  17 + def self.validate_download_list download_list
  18 + download_list.select! do |download|
  19 + not download[:name].blank?
  20 + end
  21 +
  22 + download_list.map do |download|
  23 + SoftwareCommunitiesPlugin::Download.new(download).to_hash
  24 + end
  25 + end
  26 +
  27 + def to_hash
  28 + {
  29 + :name => @name,
  30 + :link => @link,
  31 + :software_description => @software_description,
  32 + :minimum_requirements => @minimum_requirements,
  33 + :size => @size,
  34 + :total_downloads => @total_downloads
  35 + }
  36 + end
  37 +
  38 + def total_downloads= value
  39 + if value.is_a? Integer
  40 + @total_downloads = value
  41 + end
  42 + end
  43 +
  44 + def total_downloads
  45 + @total_downloads
  46 + end
  47 +
  48 + def link
  49 + @link
  50 + end
  51 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/download_block.rb 0 → 100644
@@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
  1 +class SoftwareCommunitiesPlugin::DownloadBlock < Block
  2 +
  3 + attr_accessible :show_name, :downloads
  4 +
  5 + settings_items :show_name, :type => :boolean, :default => false
  6 + settings_items :downloads, :type => Array, :default => []
  7 +
  8 + validate :download_values
  9 +
  10 + def download_values
  11 + self.downloads = SoftwareCommunitiesPlugin::Download.validate_download_list(self.downloads)
  12 + end
  13 +
  14 + def self.description
  15 + _('Download Stable Version')
  16 + end
  17 +
  18 + def help
  19 + _('This block displays the stable version of a software.')
  20 + end
  21 +
  22 + def content(args={})
  23 + block = self
  24 + s = show_name
  25 + lambda do |object|
  26 + render(
  27 + :file => 'blocks/download',
  28 + :locals => { :block => block, :show_name => s }
  29 + )
  30 + end
  31 + end
  32 +
  33 + def cacheable?
  34 + false
  35 + end
  36 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/library.rb 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +class SoftwareCommunitiesPlugin::Library < ActiveRecord::Base
  2 + attr_accessible :name, :version, :license, :software_info_id
  3 +
  4 + validates :name, :version, :license,
  5 + presence: { message: _("can't be blank") },
  6 + length: {
  7 + maximum: 20,
  8 + too_long: _("Too long (maximum is 20 characters)")
  9 + }
  10 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/license_info.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +class SoftwareCommunitiesPlugin::LicenseInfo < ActiveRecord::Base
  2 + attr_accessible :version, :link
  3 +
  4 + validates_presence_of :version
  5 +
  6 + has_many :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo'
  7 +
  8 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system.rb 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +class SoftwareCommunitiesPlugin::OperatingSystem < ActiveRecord::Base
  2 + attr_accessible :version
  3 +
  4 + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo'
  5 + belongs_to :operating_system_name, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName'
  6 +
  7 + validates :operating_system_name, presence: true
  8 + validates :version,
  9 + presence: true,
  10 + length: {
  11 + maximum: 20,
  12 + too_long: _('too long (maximum is 20 characters)')
  13 + }
  14 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system_name.rb 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +class SoftwareCommunitiesPlugin::OperatingSystemName < ActiveRecord::Base
  2 + attr_accessible :name
  3 +
  4 + validates_presence_of :name
  5 + validates_uniqueness_of :name
  6 +
  7 + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem'
  8 + has_many :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :through => :operating_systems
  9 +
  10 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/programming_language.rb 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +class SoftwareCommunitiesPlugin::ProgrammingLanguage < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_SOFTWARE_FIELDS = {
  4 + :name => 1
  5 + }
  6 +
  7 + attr_accessible :name
  8 +
  9 + validates_presence_of :name
  10 + validates_uniqueness_of :name
  11 +
  12 + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguages'
  13 + has_many :software_infos, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :through => :software_languages
  14 +
  15 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/repository_block.rb 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +class SoftwareCommunitiesPlugin::RepositoryBlock < Block
  2 +
  3 + attr_accessible :show_name
  4 +
  5 + settings_items :show_name, :type => :boolean, :default => false
  6 +
  7 + def self.description
  8 + _('Repository Link')
  9 + end
  10 +
  11 + def help
  12 + _('This block displays the repository link of a software.')
  13 + end
  14 +
  15 + def content(args={})
  16 + block = self
  17 + s = show_name
  18 + lambda do |object|
  19 + render(
  20 + :file => 'blocks/repository',
  21 + :locals => { :block => block, :show_name => s }
  22 + )
  23 + end
  24 + end
  25 +
  26 + def cacheable?
  27 + false
  28 + end
  29 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/search_catalog_block.rb 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +class SoftwareCommunitiesPlugin::SearchCatalogBlock < Block
  2 +
  3 + attr_accessible :show_name
  4 +
  5 + settings_items :show_name, :type => :boolean, :default => false
  6 +
  7 + def self.description
  8 + _('Search Softwares catalog')
  9 + end
  10 +
  11 + def help
  12 + _('This block displays the search categories field ')
  13 + end
  14 +
  15 + def content(args={})
  16 + block = self
  17 + s = show_name
  18 + lambda do |object|
  19 + render(
  20 + :file => 'blocks/search_catalog',
  21 + :locals => { :block => block, :show_name => s }
  22 + )
  23 + end
  24 + end
  25 +
  26 + def cacheable?
  27 + false
  28 + end
  29 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/software_database.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +class SoftwareCommunitiesPlugin::SoftwareDatabase < ActiveRecord::Base
  2 + attr_accessible :version
  3 +
  4 + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo'
  5 + belongs_to :database_description, :class_name => 'SoftwareCommunitiesPlugin::DatabaseDescription'
  6 +
  7 + validates_presence_of :database_description_id, :version
  8 +
  9 + validates_length_of(
  10 + :version,
  11 + :maximum => 20,
  12 + :too_long => _("Software database is too long (maximum is 20 characters)")
  13 + )
  14 +
  15 + validates(
  16 + :database_description_id,
  17 + :numericality => {:greater_than_or_equal_to => 1}
  18 + )
  19 +
  20 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/software_highlights_block.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +class SoftwareCommunitiesPlugin::SoftwareHighlightsBlock < HighlightsBlock
  2 +
  3 + def self.description
  4 + _('Software Highlights Block')
  5 + end
  6 +
  7 + def help
  8 + _('This block displays the softwares icon into a highlight')
  9 + end
  10 +
  11 + def content(args={})
  12 + softwares = self.settings[:images].collect {|h| h[:address].split('/').last}
  13 + block = self
  14 + proc do
  15 + render :file => 'blocks/software_highlights', :locals => { :block => block, :softwares => softwares}
  16 + end
  17 + end
  18 +
  19 +
  20 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/software_info.rb 0 → 100644
@@ -0,0 +1,263 @@ @@ -0,0 +1,263 @@
  1 +class SoftwareCommunitiesPlugin::SoftwareInfo < ActiveRecord::Base
  2 + acts_as_having_settings :field => :settings
  3 +
  4 + SEARCHABLE_SOFTWARE_FIELDS = {
  5 + :acronym => 1,
  6 + :finality => 2,
  7 + }
  8 +
  9 + SEARCHABLE_SOFTWARE_CLASSES = [
  10 + SoftwareCommunitiesPlugin::SoftwareInfo,
  11 + Community,
  12 + SoftwareCommunitiesPlugin::ProgrammingLanguage,
  13 + SoftwareCommunitiesPlugin::DatabaseDescription
  14 + ]
  15 +
  16 + scope :search_by_query, lambda { |query = ""|
  17 + filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')
  18 + search_fields = SoftwareCommunitiesPlugin::SoftwareInfo.pg_search_plugin_fields
  19 +
  20 + if query.empty?
  21 + SoftwareCommunitiesPlugin::SoftwareInfo.joins(:community).where("profiles.visible = ?", true)
  22 + else
  23 + searchable_software_objects = SoftwareCommunitiesPlugin::SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES)
  24 + includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true)
  25 + end
  26 + }
  27 +
  28 + def self.transform_list_in_methods_list list
  29 + methods_list = []
  30 +
  31 + list.each do |element|
  32 + if SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym)
  33 + methods_list << element.to_s.underscore.to_sym
  34 + elsif SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym)
  35 + methods_list << element.to_s.underscore.pluralize.to_sym
  36 + end
  37 + end
  38 +
  39 + methods_list
  40 + end
  41 +
  42 + def self.pg_search_plugin_fields
  43 + SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class|
  44 + self.get_searchable_fields(one_class)
  45 + }.join(" || ' ' || ")
  46 + end
  47 +
  48 + def self.get_searchable_fields one_class
  49 + searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ")
  50 + searchable_fields
  51 + end
  52 +
  53 + SEARCH_FILTERS = {
  54 + :order => %w[],
  55 + :display => %w[full]
  56 + }
  57 +
  58 + def self.default_search_display
  59 + 'full'
  60 + end
  61 +
  62 + attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq,
  63 + :operating_platform
  64 +
  65 + attr_accessible :demonstration_url, :acronym, :objectives, :features,
  66 + :license_info
  67 +
  68 + attr_accessible :community_id, :finality, :repository_link, :public_software,
  69 + :first_edit
  70 +
  71 + has_many :libraries, :dependent => :destroy, :class_name => 'SoftwareCommunitiesPlugin::Library'
  72 + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase'
  73 + has_many :database_descriptions, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabaseDescription', :through => :software_databases
  74 + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguage'
  75 + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem'
  76 + has_many :programming_languages, :class_name => 'SoftwareCommunitiesPlugin::ProgrammingLanguage', :through => :software_languages
  77 + has_many :operating_system_names, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName', :through => :operating_systems
  78 +
  79 + belongs_to :community, :dependent => :destroy
  80 + belongs_to :license_info, :class_name => 'SoftwareCommunitiesPlugin::LicenseInfo'
  81 +
  82 + has_one :software_categories
  83 +
  84 + validates_length_of :finality, :maximum => 120
  85 + validates_length_of :objectives, :maximum => 4000
  86 + validates_length_of :features, :maximum => 4000
  87 + validates_presence_of :finality, :community
  88 +
  89 + validate :validate_acronym
  90 +
  91 + settings_items :another_license_version, :another_license_link
  92 +
  93 + # used on find_by_contents
  94 + scope :like_search, lambda{ |name|
  95 + joins(:community).where(
  96 + "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?",
  97 + "%#{name}%", "%#{name}%", "%#{name}%"
  98 + )
  99 + }
  100 +
  101 + scope :search, lambda { |name="", database_description_id = "",
  102 + programming_language_id = "", operating_system_name_id = "",
  103 + license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "",
  104 + icp_brasil = "", e_arq = "", software_categories = "" |
  105 +
  106 + like_sql = ""
  107 + values = []
  108 +
  109 + unless name.blank?
  110 + like_sql << "name ILIKE ? OR identifier ILIKE ? AND "
  111 + values << "%#{name}%" << "%#{name}%"
  112 + end
  113 +
  114 + like_sql = like_sql[0..like_sql.length-5]
  115 +
  116 + {
  117 + :joins => [:community],
  118 + :conditions=>[like_sql, *values]
  119 + }
  120 + }
  121 +
  122 + def license_info
  123 + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_id self.license_info_id
  124 + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another")
  125 +
  126 + if license_another && license.id == license_another.id
  127 + SoftwareCommunitiesPlugin::LicenseInfo.new(
  128 + :version => self.another_license_version,
  129 + :link => self.another_license_link
  130 + )
  131 + else
  132 + license
  133 + end
  134 + end
  135 +
  136 + def another_license(version, link)
  137 + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another")
  138 +
  139 + if license_another
  140 + self.another_license_version = version
  141 + self.another_license_link = link
  142 + self.license_info = license_another
  143 + self.save!
  144 + end
  145 + end
  146 +
  147 + def validate_name_lenght
  148 + if self.community.name.size > 100
  149 + self.errors.add(
  150 + :base,
  151 + _("Name is too long (maximum is %{count} characters)")
  152 + )
  153 + false
  154 + end
  155 + true
  156 + end
  157 +
  158 + # if create_after_moderation receive a model object, would be possible to reuse core method
  159 + def self.create_after_moderation(requestor, attributes = {})
  160 + environment = attributes.delete(:environment)
  161 + name = attributes.delete(:name)
  162 + identifier = attributes.delete(:identifier)
  163 + image_builder = attributes.delete(:image_builder)
  164 + license_info = attributes.delete(:license_info)
  165 + another_license_version = attributes.delete(:another_license_version)
  166 + another_license_link = attributes.delete(:another_license_link)
  167 +
  168 + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(attributes)
  169 + unless environment.admins.include? requestor
  170 + CreateSoftware.create!(
  171 + attributes.merge(
  172 + :requestor => requestor,
  173 + :environment => environment,
  174 + :name => name,
  175 + :identifier => identifier,
  176 + :license_info => license_info
  177 + )
  178 + )
  179 + else
  180 + software_template = SoftwareHelper.software_template
  181 +
  182 + community_hash = {:name => name}
  183 + community_hash[:identifier] = identifier
  184 + community_hash[:image_builder] = image_builder if image_builder
  185 +
  186 + community = Community.new(community_hash)
  187 + community.environment = environment
  188 +
  189 + unless software_template.blank?
  190 + community.template_id = software_template.id
  191 + end
  192 +
  193 + community.save!
  194 + community.add_admin(requestor)
  195 +
  196 + software_info.community = community
  197 + software_info.license_info = license_info
  198 + software_info.save!
  199 + end
  200 +
  201 + software_info.verify_license_info(another_license_version, another_license_link)
  202 + software_info.save
  203 + software_info
  204 + end
  205 +
  206 + def verify_license_info another_license_version, another_license_link
  207 + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another")
  208 +
  209 + if license_another && self.license_info_id == license_another.id
  210 + version = another_license_version
  211 + link = another_license_link
  212 +
  213 + self.another_license(version, link)
  214 + end
  215 + end
  216 +
  217 +
  218 + def validate_acronym
  219 + self.acronym = "" if self.acronym.nil?
  220 + if self.acronym.length > 10 && self.errors.messages[:acronym].nil?
  221 + self.errors.add(:acronym, _("can't have more than 10 characteres"))
  222 + false
  223 + elsif self.acronym.match(/\s+/)
  224 + self.errors.add(:acronym, _("can't have whitespaces"))
  225 + false
  226 + end
  227 + true
  228 + end
  229 +
  230 + def valid_operating_systems
  231 + if self.operating_systems.empty?
  232 + self.errors.add(:operating_system, _(": at least one must be filled"))
  233 + end
  234 + end
  235 +
  236 + def valid_software_info
  237 + if self.software_languages.empty?
  238 + self.errors.add(:software_languages, _(": at least one must be filled"))
  239 + end
  240 + end
  241 +
  242 + def valid_databases
  243 + if self.software_databases.empty?
  244 + self.errors.add(:software_databases, _(": at least one must be filled"))
  245 + end
  246 + end
  247 +
  248 + def visible?
  249 + self.community.visible?
  250 + end
  251 +
  252 + def name
  253 + self.community.name
  254 + end
  255 +
  256 + def short_name
  257 + self.community.short_name
  258 + end
  259 +
  260 + def identifier
  261 + self.community.identifier
  262 + end
  263 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/software_information_block.rb 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +class SoftwareCommunitiesPlugin::SoftwareInformationBlock < Block
  2 +
  3 + attr_accessible :show_name
  4 +
  5 + settings_items :show_name, :type => :boolean, :default => false
  6 +
  7 + def self.description
  8 + _('Basic Software Information')
  9 + end
  10 +
  11 + def help
  12 + _('This block displays the basic information of a software profile.')
  13 + end
  14 +
  15 + def content(args={})
  16 + block = self
  17 + s = show_name
  18 +
  19 + lambda do |object|
  20 + render(
  21 + :file => 'blocks/software_information',
  22 + :locals => { :block => block, :show_name => s}
  23 + )
  24 + end
  25 + end
  26 +
  27 + def cacheable?
  28 + false
  29 + end
  30 +
  31 + private
  32 +
  33 + def owner_has_ratings?
  34 + ratings = CommunityRating.where(community_id: block.owner.id)
  35 + !ratings.empty?
  36 + end
  37 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/software_language.rb 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +class SoftwareCommunitiesPlugin::SoftwareLanguage < ActiveRecord::Base
  2 + attr_accessible :version
  3 +
  4 + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo'
  5 + belongs_to :programming_language, :class_name => 'SoftwareCommunitiesPlugin::ProgrammingLanguage'
  6 +
  7 + validates_length_of(
  8 + :version,
  9 + :maximum => 20,
  10 + :too_long => _("Software language is too long (maximum is 20 characters)")
  11 + )
  12 +
  13 + validates_presence_of :version,:programming_language
  14 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/software_tab_data_block.rb 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  1 +class SoftwareCommunitiesPlugin::SoftwareTabDataBlock < Block
  2 + attr_accessible :show_name, :displayed_blog
  3 +
  4 + settings_items :show_name, :type => :boolean, :default => false
  5 + settings_items :displayed_blog, :type => :integer, :default => 0
  6 +
  7 + TOTAL_POSTS_DYSPLAYED = 5
  8 +
  9 + def self.description
  10 + _('Software Tab Data')
  11 + end
  12 +
  13 + def help
  14 + _('This block is used by colab to insert data into Noosfero')
  15 + end
  16 +
  17 + def content(args={})
  18 + block = self
  19 +
  20 + lambda do |object|
  21 + render(
  22 + :file => 'blocks/software_tab_data',
  23 + :locals => {
  24 + :block => block
  25 + }
  26 + )
  27 + end
  28 + end
  29 +
  30 + def blogs
  31 + self.owner.blogs
  32 + end
  33 +
  34 + def actual_blog
  35 + # As :displayed_blog default value is 0, it falls to the first one
  36 + blogs.find_by_id(self.displayed_blog) || blogs.first
  37 + end
  38 +
  39 + def posts
  40 + blog = actual_blog
  41 +
  42 + if blog and (not blog.posts.empty?)
  43 + blog.posts.limit(TOTAL_POSTS_DYSPLAYED)
  44 + else
  45 + []
  46 + end
  47 + end
  48 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/softwares_block.rb 0 → 100644
@@ -0,0 +1,105 @@ @@ -0,0 +1,105 @@
  1 +class SoftwareCommunitiesPlugin::SoftwaresBlock < CommunitiesBlock
  2 +
  3 + settings_items :software_type, :default => "All"
  4 + attr_accessible :accessor_id, :accessor_type, :role_id,
  5 + :resource_id, :resource_type, :software_type
  6 +
  7 + def self.description
  8 + _('Softwares')
  9 + end
  10 +
  11 + def default_title
  12 + if self.software_type == "Generic"
  13 + return n_('{#} generic software', '{#} generic softwares', profile_count)
  14 + elsif self.software_type == "Public"
  15 + return n_('{#} public software', '{#} public softwares', profile_count)
  16 + else
  17 + return n_('{#} software', '{#} softwares', profile_count)
  18 + end
  19 + end
  20 +
  21 + def help
  22 + _('This block displays the softwares in which the user is a member.')
  23 + end
  24 +
  25 + def footer
  26 + self.software_type ||= "All"
  27 + owner = self.owner
  28 + case owner
  29 + when Profile
  30 + lambda do |context|
  31 + link_to s_('softwares|View all'), :profile => owner.identifier,
  32 + :controller => 'profile', :action => 'communities',
  33 + :type => 'Software'
  34 + end
  35 + when Environment
  36 + lambda do |context|
  37 + link_to s_('softwares|View all'), :controller => 'search',
  38 + :action => 'software_infos'
  39 + end
  40 + else
  41 + ''
  42 + end
  43 + end
  44 +
  45 + def profile_count
  46 + profile_list.count
  47 + end
  48 +
  49 + def profiles
  50 + owner.communities
  51 + end
  52 +
  53 + def profile_list
  54 + profiles = get_visible_profiles
  55 +
  56 + software_profiles = profiles.select do |profile|
  57 + profile.class == Community && profile.software?
  58 + end
  59 +
  60 + block_softwares = if self.software_type == "Public"
  61 + software_profiles.select { |profile| profile.software_info.public_software? }
  62 + elsif self.software_type == "Generic"
  63 + software_profiles.select { |profile| !profile.software_info.public_software? }
  64 + else # All
  65 + software_profiles
  66 + end
  67 +
  68 + block_softwares.slice(0..get_limit-1)
  69 + end
  70 +
  71 + def content(arg={})
  72 + if self.box.owner_type == "Environment" && self.box.position == 1
  73 + block = self
  74 +
  75 + proc do
  76 + render :file => 'blocks/main_area_softwares',
  77 + :locals => {:profiles=> block.profile_list(), :block => block}
  78 + end
  79 + else
  80 + super(arg)
  81 + end
  82 + end
  83 +
  84 + protected
  85 +
  86 + def get_visible_profiles
  87 + profile_include_list = [:image, :domains, :preferred_domain, :environment]
  88 + visible_profiles = profiles.visible.includes(profile_include_list)
  89 +
  90 + if !prioritize_profiles_with_image
  91 + visible_profiles.all( :limit => get_limit,
  92 + :order => 'profiles.updated_at DESC'
  93 + ).sort_by{ rand }
  94 + elsif profiles.visible.with_image.count >= get_limit
  95 + visible_profiles.with_image.all( :limit => get_limit * 5,
  96 + :order => 'profiles.updated_at DESC'
  97 + ).sort_by{ rand }
  98 + else
  99 + visible_profiles.with_image.sort_by{ rand } +
  100 + visible_profiles.without_image.all( :limit => get_limit * 5,
  101 + :order => 'profiles.updated_at DESC'
  102 + ).sort_by{ rand }
  103 + end
  104 + end
  105 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/statistic_block.rb 0 → 100644
@@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
  1 +class SoftwareCommunitiesPlugin::StatisticBlock < Block
  2 +
  3 + settings_items :benefited_people, :type => :integer, :default => 0
  4 + settings_items :saved_resources, :type => :float, :default => 0.0
  5 +
  6 + attr_accessible :benefited_people, :saved_resources
  7 +
  8 + def self.description
  9 + _('Software Statistics')
  10 + end
  11 +
  12 + def help
  13 + _('This block displays software statistics.')
  14 + end
  15 +
  16 + def content(args={})
  17 + download_blocks = get_profile_download_blocks(self.owner)
  18 + downloads = download_blocks.map do |download_block|
  19 + get_downloads_from_block(download_block)
  20 + end
  21 +
  22 + block = self
  23 +
  24 + lambda do |object|
  25 + render(
  26 + :file => 'blocks/software_statistics',
  27 + :locals => {
  28 + :block => block,
  29 + :total_downloads => downloads.sum
  30 + }
  31 + )
  32 + end
  33 + end
  34 +
  35 + def cacheable?
  36 + false
  37 + end
  38 +
  39 + private
  40 +
  41 + def get_profile_download_blocks profile
  42 + SoftwareCommunitiesPlugin::DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id)
  43 + end
  44 +
  45 + def get_downloads_from_block download_block
  46 + downloads = download_block.downloads.map do |download|
  47 + download[:total_downloads] unless download[:total_downloads].nil?
  48 + end
  49 + downloads.select! {|value| not value.nil? }
  50 + downloads.sum
  51 + end
  52 +end
src/noosfero-spb/software_communities/models/software_communities_plugin/wiki_block.rb 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +class SoftwareCommunitiesPlugin::WikiBlock < Block
  2 +
  3 + attr_accessible :show_name, :wiki_link
  4 + settings_items :show_name, :type => :boolean, :default => false
  5 + settings_items :wiki_link, :type => :string, :default => ""
  6 +
  7 + def self.description
  8 + _('Wiki Link')
  9 + end
  10 +
  11 + def help
  12 + _('This block displays a link to the software wiki.')
  13 + end
  14 +
  15 + def content(args={})
  16 + block = self
  17 + s = show_name
  18 +
  19 + lambda do |object|
  20 + render(
  21 + :file => 'blocks/wiki',
  22 + :locals => { :block => block, :show_name => s }
  23 + )
  24 + end
  25 + end
  26 +
  27 + def cacheable?
  28 + true
  29 + end
  30 +end
src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb
@@ -58,7 +58,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -58,7 +58,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
58 58
59 def create_software_info name, finality = "something", acronym = "" 59 def create_software_info name, finality = "something", acronym = ""
60 community = create_community(name) 60 community = create_community(name)
61 - software_info = SoftwareInfo.new 61 + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new
62 software_info.community = community 62 software_info.community = community
63 software_info.finality = finality 63 software_info.finality = finality
64 software_info.acronym = acronym 64 software_info.acronym = acronym
src/noosfero-spb/software_communities/test/functional/search_controller_test.rb
@@ -21,8 +21,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -21,8 +21,8 @@ class SearchControllerTest &lt; ActionController::TestCase
21 @response = ActionController::TestResponse.new 21 @response = ActionController::TestResponse.new
22 22
23 @licenses = [ 23 @licenses = [
24 - LicenseInfo.create(:version => "GPL - 1"),  
25 - LicenseInfo.create(:version => "GPL - 2") 24 + SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "GPL - 1"),
  25 + SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "GPL - 2")
26 ] 26 ]
27 27
28 create_software_categories 28 create_software_categories
@@ -145,7 +145,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -145,7 +145,7 @@ class SearchControllerTest &lt; ActionController::TestCase
145 145
146 should "software_infos search by relevance" do 146 should "software_infos search by relevance" do
147 @softwares << create_software_info("Software Three", :acronym => "SFW", :finality => "Java") 147 @softwares << create_software_info("Software Three", :acronym => "SFW", :finality => "Java")
148 - @softwares.last.license_info = LicenseInfo.create :version => "GPL - 3.0" 148 + @softwares.last.license_info = SoftwareCommunitiesPlugin::LicenseInfo.create :version => "GPL - 3.0"
149 149
150 150
151 @softwares.first.software_languages << create_software_language("Java", "8.0") 151 @softwares.first.software_languages << create_software_language("Java", "8.0")
@@ -215,8 +215,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -215,8 +215,8 @@ class SearchControllerTest &lt; ActionController::TestCase
215 end 215 end
216 216
217 should "software_infos search return only enabled softwares" do 217 should "software_infos search return only enabled softwares" do
218 - s1 = SoftwareInfo.first  
219 - s2 = SoftwareInfo.last 218 + s1 = SoftwareCommunitiesPlugin::SoftwareInfo.first
  219 + s2 = SoftwareCommunitiesPlugin::SoftwareInfo.last
220 220
221 # First get them all normally 221 # First get them all normally
222 get( 222 get(
@@ -276,12 +276,12 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -276,12 +276,12 @@ class SearchControllerTest &lt; ActionController::TestCase
276 end 276 end
277 277
278 def create_software_language(name, version) 278 def create_software_language(name, version)
279 - unless ProgrammingLanguage.find_by_name(name)  
280 - ProgrammingLanguage.create(:name => name) 279 + unless SoftwareCommunitiesPlugin::ProgrammingLanguage.find_by_name(name)
  280 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name => name)
281 end 281 end
282 282
283 - software_language = SoftwareLanguage.new  
284 - software_language.programming_language = ProgrammingLanguage.find_by_name(name) 283 + software_language = SoftwareCommunitiesPlugin::SoftwareLanguage.new
  284 + software_language.programming_language = SoftwareCommunitiesPlugin::ProgrammingLanguage.find_by_name(name)
285 software_language.version = version 285 software_language.version = version
286 software_language.save! 286 software_language.save!
287 287
@@ -289,12 +289,12 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -289,12 +289,12 @@ class SearchControllerTest &lt; ActionController::TestCase
289 end 289 end
290 290
291 def create_software_database(name, version) 291 def create_software_database(name, version)
292 - unless DatabaseDescription.find_by_name(name)  
293 - DatabaseDescription.create(:name => name) 292 + unless SoftwareCommunitiesPlugin::DatabaseDescription.find_by_name(name)
  293 + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => name)
294 end 294 end
295 295
296 - software_database = SoftwareDatabase.new  
297 - software_database.database_description = DatabaseDescription.find_by_name(name) 296 + software_database = SoftwareCommunitiesPlugin::SoftwareDatabase.new
  297 + software_database.database_description = SoftwareCommunitiesPlugin::DatabaseDescription.find_by_name(name)
298 software_database.version = version 298 software_database.version = version
299 software_database.save! 299 software_database.save!
300 300
src/noosfero-spb/software_communities/test/functional/software_communities_plugin_controller_test.rb
@@ -14,20 +14,20 @@ class SoftwareCommunitiesPluginControllerTest &lt; ActionController::TestCase @@ -14,20 +14,20 @@ class SoftwareCommunitiesPluginControllerTest &lt; ActionController::TestCase
14 @environment.add_admin(@admin) 14 @environment.add_admin(@admin)
15 @environment.save 15 @environment.save
16 16
17 - LicenseInfo.create(:version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt")  
18 - LicenseInfo.create(:version=>"Academic Free License 3.0 (AFL-3.0)", :link=>"http://www.openfoundry.org/en/licenses/753-academic-free-license-version-30-afl")  
19 - LicenseInfo.create(:version=>"Apache License 2.0 (Apache-2.0)", :link=>"http://www.apache.org/licenses/LICENSE-2.0")  
20 - LicenseInfo.create(:version=>'BSD 2-Clause "Simplified" or "FreeBSD" License (BSD-2-Clause)', :link=>"http://opensource.org/licenses/BSD-2-Clause")  
21 -  
22 - ProgrammingLanguage.create(:name =>"Java")  
23 - ProgrammingLanguage.create(:name =>"Ruby")  
24 - ProgrammingLanguage.create(:name =>"C")  
25 - ProgrammingLanguage.create(:name =>"C++")  
26 - DatabaseDescription.create(:name => "PostgreSQL")  
27 - DatabaseDescription.create(:name => "MySQL")  
28 - DatabaseDescription.create(:name => "MongoDB")  
29 - DatabaseDescription.create(:name => "Oracle")  
30 - OperatingSystemName.create(:name=>"Debian") 17 + SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt")
  18 + SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>"Academic Free License 3.0 (AFL-3.0)", :link=>"http://www.openfoundry.org/en/licenses/753-academic-free-license-version-30-afl")
  19 + SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>"Apache License 2.0 (Apache-2.0)", :link=>"http://www.apache.org/licenses/LICENSE-2.0")
  20 + SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>'BSD 2-Clause "Simplified" or "FreeBSD" License (BSD-2-Clause)', :link=>"http://opensource.org/licenses/BSD-2-Clause")
  21 +
  22 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"Java")
  23 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"Ruby")
  24 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"C")
  25 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"C++")
  26 + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "PostgreSQL")
  27 + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "MySQL")
  28 + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "MongoDB")
  29 + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "Oracle")
  30 + SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Debian")
31 31
32 @response = ActionController::TestResponse.new 32 @response = ActionController::TestResponse.new
33 end 33 end
src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb
@@ -19,14 +19,14 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -19,14 +19,14 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
19 @offer_1 = create_user('Ana de Souza') 19 @offer_1 = create_user('Ana de Souza')
20 @offer_2 = create_user('Angelo Roberto') 20 @offer_2 = create_user('Angelo Roberto')
21 21
22 - LicenseInfo.create( 22 + SoftwareCommunitiesPlugin::LicenseInfo.create(
23 :version=>"CC-GPL-V2", 23 :version=>"CC-GPL-V2",
24 :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" 24 :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
25 ) 25 )
26 26
27 - ProgrammingLanguage.create(:name =>"language")  
28 - DatabaseDescription.create(:name => "database")  
29 - OperatingSystemName.create(:name=>"Debian") 27 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"language")
  28 + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "database")
  29 + SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Debian")
30 30
31 login_as(@person.user_login) 31 login_as(@person.user_login)
32 @environment = Environment.default 32 @environment = Environment.default
@@ -54,7 +54,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -54,7 +54,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
54 :license => fields[0], 54 :license => fields[0],
55 :software_info => fields[2] 55 :software_info => fields[2]
56 ) 56 )
57 - assert_equal SoftwareInfo.last.community.name, "Debian" 57 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.community.name, "Debian"
58 end 58 end
59 59
60 should 'edit a new software adding basic information' do 60 should 'edit a new software adding basic information' do
@@ -72,7 +72,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -72,7 +72,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
72 :language => {}, 72 :language => {},
73 :database => {} 73 :database => {}
74 ) 74 )
75 - assert_equal SoftwareInfo.last.repository_link, "www.github.com/test" 75 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.repository_link, "www.github.com/test"
76 end 76 end
77 77
78 should 'edit a new software adding specific information' do 78 should 'edit a new software adding specific information' do
@@ -90,7 +90,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -90,7 +90,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
90 :software => fields[4], 90 :software => fields[4],
91 :license => fields[5] 91 :license => fields[5]
92 ) 92 )
93 - assert_equal SoftwareInfo.last.acronym, "test" 93 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.acronym, "test"
94 end 94 end
95 95
96 should 'upgrade a generic software to a public software' do 96 should 'upgrade a generic software to a public software' do
@@ -111,7 +111,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -111,7 +111,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
111 :license => fields[5] 111 :license => fields[5]
112 ) 112 )
113 113
114 - assert_equal true, SoftwareInfo.last.public_software? 114 + assert_equal true, SoftwareCommunitiesPlugin::SoftwareInfo.last.public_software?
115 end 115 end
116 116
117 should "create software_info with existing license_info" do 117 should "create software_info with existing license_info" do
@@ -121,15 +121,15 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -121,15 +121,15 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
121 :new_software, 121 :new_software,
122 :community => {:name =>"New Software", :identifier => "new-software"}, 122 :community => {:name =>"New Software", :identifier => "new-software"},
123 :software_info => {:finality => "something", :repository_link => ""}, 123 :software_info => {:finality => "something", :repository_link => ""},
124 - :license =>{:license_infos_id => LicenseInfo.last.id}, 124 + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id},
125 :profile => @person.identifier 125 :profile => @person.identifier
126 ) 126 )
127 127
128 - assert_equal SoftwareInfo.last.license_info, LicenseInfo.last 128 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info, SoftwareCommunitiesPlugin::LicenseInfo.last
129 end 129 end
130 130
131 should "create software_info with 'Another' license_info" do 131 should "create software_info with 'Another' license_info" do
132 - license_another = LicenseInfo.create(:version => "Another", :link => "#") 132 + license_another = SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "Another", :link => "#")
133 @environment.add_admin(@person) 133 @environment.add_admin(@person)
134 134
135 another_license_version = "Different License" 135 another_license_version = "Different License"
@@ -146,10 +146,10 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -146,10 +146,10 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
146 :profile => @person.identifier 146 :profile => @person.identifier
147 ) 147 )
148 148
149 - assert_equal SoftwareInfo.last.license_info_id, license_another.id  
150 - assert_equal SoftwareInfo.last.license_info.id, nil  
151 - assert_equal SoftwareInfo.last.license_info.version, another_license_version  
152 - assert_equal SoftwareInfo.last.license_info.link, another_license_link 149 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info_id, license_another.id
  150 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info.id, nil
  151 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info.version, another_license_version
  152 + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info.link, another_license_link
153 end 153 end
154 154
155 should "show error messages on create software_info" do 155 should "show error messages on create software_info" do
@@ -173,14 +173,14 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -173,14 +173,14 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
173 :new_software, 173 :new_software,
174 :community => {:name =>"New Software", :identifier => "new-software"}, 174 :community => {:name =>"New Software", :identifier => "new-software"},
175 :software_info => {:finality => "something", :repository_link => ""}, 175 :software_info => {:finality => "something", :repository_link => ""},
176 - :license =>{:license_infos_id => LicenseInfo.last.id}, 176 + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id},
177 :profile => @person.identifier 177 :profile => @person.identifier
178 ) 178 )
179 post( 179 post(
180 :new_software, 180 :new_software,
181 :community => {:name =>"New Software", :identifier => "new-software"}, 181 :community => {:name =>"New Software", :identifier => "new-software"},
182 :software_info => {:finality => "something", :repository_link => ""}, 182 :software_info => {:finality => "something", :repository_link => ""},
183 - :license =>{:license_infos_id => LicenseInfo.last.id}, 183 + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id},
184 :profile => @person.identifier 184 :profile => @person.identifier
185 ) 185 )
186 186
@@ -194,7 +194,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -194,7 +194,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
194 :new_software, 194 :new_software,
195 :community => {:name =>"New Software", :identifier => "new-software"}, 195 :community => {:name =>"New Software", :identifier => "new-software"},
196 :software_info => {:finality => "something", :repository_link => ""}, 196 :software_info => {:finality => "something", :repository_link => ""},
197 - :license =>{:license_infos_id => LicenseInfo.last.id}, 197 + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id},
198 :profile => @person.identifier 198 :profile => @person.identifier
199 ) 199 )
200 200
@@ -202,6 +202,6 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC @@ -202,6 +202,6 @@ class SoftwareCommunitiesPluginMyprofileControllerTest &lt; ActionController::TestC
202 Task.last.send('finish', @person) 202 Task.last.send('finish', @person)
203 203
204 assert_equal "New Software", Task.last.data[:name] 204 assert_equal "New Software", Task.last.data[:name]
205 - assert_equal "New Software", SoftwareInfo.last.community.name 205 + assert_equal "New Software", SoftwareCommunitiesPlugin::SoftwareInfo.last.community.name
206 end 206 end
207 end 207 end
src/noosfero-spb/software_communities/test/functional/software_communities_plugin_profile_controller_test.rb
@@ -16,7 +16,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas @@ -16,7 +16,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas
16 @environment.enable_plugin('SoftwareCommunitiesPlugin') 16 @environment.enable_plugin('SoftwareCommunitiesPlugin')
17 @environment.save! 17 @environment.save!
18 18
19 - LicenseInfo.create( 19 + SoftwareCommunitiesPlugin::LicenseInfo.create(
20 :version=>"CC-GPL-V2", 20 :version=>"CC-GPL-V2",
21 :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" 21 :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
22 ) 22 )
@@ -32,8 +32,8 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas @@ -32,8 +32,8 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas
32 @software = create_software(software_fields) 32 @software = create_software(software_fields)
33 @software.save! 33 @software.save!
34 34
35 - download_block = DownloadBlock.new  
36 - download_block.downloads = Download.validate_download_list([@download_data]) 35 + download_block = SoftwareCommunitiesPlugin::DownloadBlock.new
  36 + download_block.downloads = SoftwareCommunitiesPlugin::Download.validate_download_list([@download_data])
37 download_block.save! 37 download_block.save!
38 38
39 @software.community.blocks << download_block 39 @software.community.blocks << download_block
@@ -41,7 +41,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas @@ -41,7 +41,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas
41 end 41 end
42 42
43 should 'redirect to download link with correct params' do 43 should 'redirect to download link with correct params' do
44 - download_block = DownloadBlock.last 44 + download_block = SoftwareCommunitiesPlugin::DownloadBlock.last
45 get :download_file, :profile=>@software.community.identifier, 45 get :download_file, :profile=>@software.community.identifier,
46 :block => download_block.id, :download_index => 0 46 :block => download_block.id, :download_index => 0
47 47
@@ -50,7 +50,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas @@ -50,7 +50,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas
50 end 50 end
51 51
52 should "notice when the download was not found" do 52 should "notice when the download was not found" do
53 - download_block = DownloadBlock.last 53 + download_block = SoftwareCommunitiesPlugin::DownloadBlock.last
54 get :download_file, :profile=>@software.community.identifier, 54 get :download_file, :profile=>@software.community.identifier,
55 :block => 123, :download_index => 0 55 :block => 123, :download_index => 0
56 56
@@ -58,7 +58,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas @@ -58,7 +58,7 @@ class SoftwareCommunitiesPluginProfileControllerTest &lt; ActionController::TestCas
58 end 58 end
59 59
60 should "notice when given invalid download params" do 60 should "notice when given invalid download params" do
61 - download_block = DownloadBlock.last 61 + download_block = SoftwareCommunitiesPlugin::DownloadBlock.last
62 get :download_file, :profile=>@software.community.identifier, 62 get :download_file, :profile=>@software.community.identifier,
63 :block => download_block.id, :download_index => -5 63 :block => download_block.id, :download_index => -5
64 64
src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb
@@ -10,7 +10,7 @@ module PluginTestHelper @@ -10,7 +10,7 @@ module PluginTestHelper
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 community = create_community(name)
13 - software_info = SoftwareInfo.new 13 + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new
14 software_info.community = community 14 software_info.community = community
15 software_info.finality = finality 15 software_info.finality = finality
16 software_info.acronym = acronym 16 software_info.acronym = acronym
@@ -55,7 +55,7 @@ module PluginTestHelper @@ -55,7 +55,7 @@ module PluginTestHelper
55 end 55 end
56 56
57 def create_license_info version, link = "" 57 def create_license_info version, link = ""
58 - license = LicenseInfo.create(:version => version) 58 + license = SoftwareCommunitiesPlugin::LicenseInfo.create(:version => version)
59 license.link = link 59 license.link = link
60 license.save 60 license.save
61 61
src/noosfero-spb/software_communities/test/helpers/software_test_helper.rb
1 module SoftwareTestHelper 1 module SoftwareTestHelper
2 2
3 def create_language language_fields 3 def create_language language_fields
4 - language = SoftwareLanguage.new 4 + language = SoftwareCommunitiesPlugin::SoftwareLanguage.new
5 5
6 language_fields[0].each do |k,v| 6 language_fields[0].each do |k,v|
7 language[k] = v 7 language[k] = v
@@ -12,7 +12,7 @@ module SoftwareTestHelper @@ -12,7 +12,7 @@ module SoftwareTestHelper
12 12
13 def create_database database_fields 13 def create_database database_fields
14 14
15 - database = SoftwareDatabase.new 15 + database = SoftwareCommunitiesPlugin::SoftwareDatabase.new
16 16
17 database_fields[0].each do |k,v| 17 database_fields[0].each do |k,v|
18 database[k] = v 18 database[k] = v
@@ -23,7 +23,7 @@ module SoftwareTestHelper @@ -23,7 +23,7 @@ module SoftwareTestHelper
23 end 23 end
24 24
25 def create_library library_fields 25 def create_library library_fields
26 - library = Library.new 26 + library = SoftwareCommunitiesPlugin::Library.new
27 27
28 library_fields[0].each do |k,v| 28 library_fields[0].each do |k,v|
29 library[k] = v 29 library[k] = v
@@ -33,7 +33,7 @@ module SoftwareTestHelper @@ -33,7 +33,7 @@ module SoftwareTestHelper
33 end 33 end
34 34
35 def create_operating_system operating_system_hash 35 def create_operating_system operating_system_hash
36 - operating_system = OperatingSystem.new 36 + operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new
37 37
38 operating_system_hash[0].each do |k,v| 38 operating_system_hash[0].each do |k,v|
39 operating_system[k] = v 39 operating_system[k] = v
@@ -43,7 +43,7 @@ module SoftwareTestHelper @@ -43,7 +43,7 @@ module SoftwareTestHelper
43 end 43 end
44 44
45 def create_license license_hash 45 def create_license license_hash
46 - license_info = LicenseInfo.new 46 + license_info = SoftwareCommunitiesPlugin::LicenseInfo.new
47 47
48 license_hash.each do |k,v| 48 license_hash.each do |k,v|
49 license_info[k] = v 49 license_info[k] = v
@@ -64,7 +64,7 @@ module SoftwareTestHelper @@ -64,7 +64,7 @@ module SoftwareTestHelper
64 64
65 def create_software fields 65 def create_software fields
66 66
67 - software = SoftwareInfo.new 67 + software = SoftwareCommunitiesPlugin::SoftwareInfo.new
68 community = Community.new 68 community = Community.new
69 software_hash = fields[2] 69 software_hash = fields[2]
70 license_system_hash = fields[0] 70 license_system_hash = fields[0]
@@ -97,7 +97,7 @@ module SoftwareTestHelper @@ -97,7 +97,7 @@ module SoftwareTestHelper
97 hash_list << fields 97 hash_list << fields
98 98
99 #Fields for license info 99 #Fields for license info
100 - fields_license['license_infos_id'] = LicenseInfo.last.id 100 + fields_license['license_infos_id'] = SoftwareCommunitiesPlugin::LicenseInfo.last.id
101 hash_list << fields_license 101 hash_list << fields_license
102 102
103 hash_list 103 hash_list
@@ -128,7 +128,7 @@ module SoftwareTestHelper @@ -128,7 +128,7 @@ module SoftwareTestHelper
128 128
129 #Fields for software language 129 #Fields for software language
130 fields_language['version'] = 'test' 130 fields_language['version'] = 'test'
131 - fields_language['programming_language_id'] = ProgrammingLanguage.last.id 131 + fields_language['programming_language_id'] = SoftwareCommunitiesPlugin::ProgrammingLanguage.last.id
132 fields_language['operating_system'] = 'test' 132 fields_language['operating_system'] = 'test'
133 list_language << fields_language 133 list_language << fields_language
134 list_language << {} 134 list_language << {}
@@ -136,7 +136,7 @@ module SoftwareTestHelper @@ -136,7 +136,7 @@ module SoftwareTestHelper
136 136
137 #Fields for database 137 #Fields for database
138 fields_database['version'] = 'test' 138 fields_database['version'] = 'test'
139 - fields_database['database_description_id'] = DatabaseDescription.last.id 139 + fields_database['database_description_id'] = SoftwareCommunitiesPlugin::DatabaseDescription.last.id
140 fields_database['operating_system'] = 'test' 140 fields_database['operating_system'] = 'test'
141 list_database << fields_database 141 list_database << fields_database
142 list_database << {} 142 list_database << {}
@@ -144,7 +144,7 @@ module SoftwareTestHelper @@ -144,7 +144,7 @@ module SoftwareTestHelper
144 144
145 #Fields for operating system 145 #Fields for operating system
146 fields_operating_system['version'] = 'version' 146 fields_operating_system['version'] = 'version'
147 - fields_operating_system['operating_system_name_id'] = OperatingSystemName.last.id 147 + fields_operating_system['operating_system_name_id'] = SoftwareCommunitiesPlugin::OperatingSystemName.last.id
148 list_operating_system << fields_operating_system 148 list_operating_system << fields_operating_system
149 list_operating_system << {} 149 list_operating_system << {}
150 hash_list << list_operating_system 150 hash_list << list_operating_system
@@ -158,7 +158,7 @@ module SoftwareTestHelper @@ -158,7 +158,7 @@ module SoftwareTestHelper
158 hash_list << fields_software 158 hash_list << fields_software
159 159
160 #Fields for license 160 #Fields for license
161 - fields_license['license_infos_id'] = LicenseInfo.last.id 161 + fields_license['license_infos_id'] = SoftwareCommunitiesPlugin::LicenseInfo.last.id
162 hash_list << fields_license 162 hash_list << fields_license
163 163
164 hash_list 164 hash_list
@@ -169,7 +169,7 @@ module SoftwareTestHelper @@ -169,7 +169,7 @@ module SoftwareTestHelper
169 169
170 #Fields for license info 170 #Fields for license info
171 fields_license = { 171 fields_license = {
172 - license_infos_id: LicenseInfo.last.id 172 + license_infos_id: SoftwareCommunitiesPlugin::LicenseInfo.last.id
173 } 173 }
174 hash_list << fields_license 174 hash_list << fields_license
175 175
@@ -189,5 +189,5 @@ module SoftwareTestHelper @@ -189,5 +189,5 @@ module SoftwareTestHelper
189 hash_list 189 hash_list
190 end 190 end
191 end 191 end
192 -#version: LicenseInfo.last.version,  
193 -#id: LicenseInfo.last.id  
194 \ No newline at end of file 192 \ No newline at end of file
  193 +#version: SoftwareCommunitiesPlugin::LicenseInfo.last.version,
  194 +#id: SoftwareCommunitiesPlugin::LicenseInfo.last.id
195 \ No newline at end of file 195 \ No newline at end of file
src/noosfero-spb/software_communities/test/unit/categories_and_tags_block_test.rb
@@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39; @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39;
4 class CategoriesAndTagsBlockTest < ActiveSupport::TestCase 4 class CategoriesAndTagsBlockTest < ActiveSupport::TestCase
5 include PluginTestHelper 5 include PluginTestHelper
6 should 'inherit from Block' do 6 should 'inherit from Block' do
7 - assert_kind_of Block, CategoriesAndTagsBlock.new 7 + assert_kind_of Block, SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.new
8 end 8 end
9 9
10 should 'declare its default title' do 10 should 'declare its default title' do
11 - CategoriesAndTagsBlock.any_instance.stubs(:profile_count).returns(0)  
12 - assert_equal Block.new.default_title, CategoriesAndTagsBlock.new.default_title 11 + SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.any_instance.stubs(:profile_count).returns(0)
  12 + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.new.default_title
13 end 13 end
14 14
15 should 'describe itself' do 15 should 'describe itself' do
16 - assert_not_equal Block.description, CategoriesAndTagsBlock.description 16 + assert_not_equal Block.description, SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.description
17 end 17 end
18 18
19 end 19 end
src/noosfero-spb/software_communities/test/unit/categories_software_block_test.rb
@@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39; @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39;
4 class CategoriesSoftwareBlockTest < ActiveSupport::TestCase 4 class CategoriesSoftwareBlockTest < ActiveSupport::TestCase
5 include PluginTestHelper 5 include PluginTestHelper
6 should 'inherit from Block' do 6 should 'inherit from Block' do
7 - assert_kind_of Block, CategoriesSoftwareBlock.new 7 + assert_kind_of Block, SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.new
8 end 8 end
9 9
10 should 'declare its default title' do 10 should 'declare its default title' do
11 - CategoriesSoftwareBlock.any_instance.stubs(:profile_count).returns(0)  
12 - assert_equal Block.new.default_title, CategoriesSoftwareBlock.new.default_title 11 + SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.any_instance.stubs(:profile_count).returns(0)
  12 + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.new.default_title
13 end 13 end
14 14
15 should 'describe itself' do 15 should 'describe itself' do
16 - assert_not_equal Block.description, CategoriesSoftwareBlock.description 16 + assert_not_equal Block.description, SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.description
17 end 17 end
18 18
19 end 19 end
src/noosfero-spb/software_communities/test/unit/create_software_test.rb
@@ -7,11 +7,11 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase @@ -7,11 +7,11 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase
7 end 7 end
8 8
9 should 'be a task' do 9 should 'be a task' do
10 - ok { CreateSoftware.new.kind_of?(Task) } 10 + ok { SoftwareCommunitiesPlugin::CreateSoftware.new.kind_of?(Task) }
11 end 11 end
12 12
13 should 'require a requestor' do 13 should 'require a requestor' do
14 - task = CreateSoftware.new(:name => 'Software Test', :target => Environment.default) 14 + task = SoftwareCommunitiesPlugin::CreateSoftware.new(:name => 'Software Test', :target => Environment.default)
15 task.valid? 15 task.valid?
16 16
17 assert task.errors[:requestor_id.to_s].present? 17 assert task.errors[:requestor_id.to_s].present?
@@ -24,9 +24,9 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase @@ -24,9 +24,9 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase
24 end 24 end
25 25
26 should 'actually create new software community when confirmed' do 26 should 'actually create new software community when confirmed' do
27 - task = CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any") 27 + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any")
28 28
29 - assert_difference 'SoftwareInfo.count' do 29 + assert_difference 'SoftwareCommunitiesPlugin::SoftwareInfo.count' do
30 assert_difference 'Community.count' do 30 assert_difference 'Community.count' do
31 task.finish 31 task.finish
32 end 32 end
@@ -36,7 +36,7 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase @@ -36,7 +36,7 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase
36 end 36 end
37 37
38 should 'create new software community with all informed data when confirmed' do 38 should 'create new software community with all informed data when confirmed' do
39 - task = CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any", :repository_link => "#", ) 39 + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any", :repository_link => "#", )
40 40
41 task.finish 41 task.finish
42 software = Community["software-test"].software_info 42 software = Community["software-test"].software_info
@@ -47,7 +47,7 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase @@ -47,7 +47,7 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase
47 end 47 end
48 48
49 should 'override message methods from Task' do 49 should 'override message methods from Task' do
50 - task = CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any") 50 + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any")
51 51
52 task.finish 52 task.finish
53 53
@@ -59,13 +59,13 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase @@ -59,13 +59,13 @@ class CreateSoftwareTest &lt; ActiveSupport::TestCase
59 end 59 end
60 60
61 should 'report as approved when approved' do 61 should 'report as approved when approved' do
62 - request = CreateSoftware.new 62 + request = SoftwareCommunitiesPlugin::CreateSoftware.new
63 request.stubs(:status).returns(Task::Status::FINISHED) 63 request.stubs(:status).returns(Task::Status::FINISHED)
64 assert request.approved? 64 assert request.approved?
65 end 65 end
66 66
67 should 'report as rejected when rejected' do 67 should 'report as rejected when rejected' do
68 - request = CreateSoftware.new 68 + request = SoftwareCommunitiesPlugin::CreateSoftware.new
69 request.stubs(:status).returns(Task::Status::CANCELLED) 69 request.stubs(:status).returns(Task::Status::CANCELLED)
70 assert request.rejected? 70 assert request.rejected?
71 end 71 end
src/noosfero-spb/software_communities/test/unit/database_helper_test.rb
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
3 class DatabaseHelperTest < ActiveSupport::TestCase 3 class DatabaseHelperTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - dd1 = DatabaseDescription.create(:name => "Oracle")  
7 - dd2 = DatabaseDescription.create!(:name => "MySQL") 6 + dd1 = SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "Oracle")
  7 + dd2 = SoftwareCommunitiesPlugin::DatabaseDescription.create!(:name => "MySQL")
8 8
9 @database_objects = [ 9 @database_objects = [
10 {:database_description_id => dd1.id.to_s ,:version => "2.0"}, 10 {:database_description_id => dd1.id.to_s ,:version => "2.0"},
@@ -14,8 +14,8 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase @@ -14,8 +14,8 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase
14 14
15 def teardown 15 def teardown
16 @database_objects = nil 16 @database_objects = nil
17 - SoftwareDatabase.destroy_all  
18 - DatabaseDescription.destroy_all 17 + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all
  18 + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all
19 end 19 end
20 20
21 should "return an empty list" do 21 should "return an empty list" do
src/noosfero-spb/software_communities/test/unit/database_validation_test.rb
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
3 class DatabaseValidationTest < ActiveSupport::TestCase 3 class DatabaseValidationTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - @database_desc = DatabaseDescription.create(:name => "ABC")  
7 - @database = SoftwareDatabase.new 6 + @database_desc = SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "ABC")
  7 + @database = SoftwareCommunitiesPlugin::SoftwareDatabase.new
8 @database.database_description = @database_desc 8 @database.database_description = @database_desc
9 @database.version = "MYSQL" 9 @database.version = "MYSQL"
10 @database 10 @database
@@ -12,8 +12,8 @@ class DatabaseValidationTest &lt; ActiveSupport::TestCase @@ -12,8 +12,8 @@ class DatabaseValidationTest &lt; ActiveSupport::TestCase
12 12
13 def teardown 13 def teardown
14 @database = nil 14 @database = nil
15 - DatabaseDescription.destroy_all  
16 - SoftwareDatabase.destroy_all 15 + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all
  16 + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all
17 end 17 end
18 18
19 should "Save database if all fields are filled" do 19 should "Save database if all fields are filled" do
src/noosfero-spb/software_communities/test/unit/download_block_test.rb
@@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39; @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39;
4 class DownloadBlockTest < ActiveSupport::TestCase 4 class DownloadBlockTest < ActiveSupport::TestCase
5 include PluginTestHelper 5 include PluginTestHelper
6 should 'inherit from Block' do 6 should 'inherit from Block' do
7 - assert_kind_of Block, DownloadBlock.new 7 + assert_kind_of Block, SoftwareCommunitiesPlugin::DownloadBlock.new
8 end 8 end
9 9
10 should 'declare its default title' do 10 should 'declare its default title' do
11 - DownloadBlock.any_instance.stubs(:profile_count).returns(0)  
12 - assert_equal Block.new.default_title, DownloadBlock.new.default_title 11 + SoftwareCommunitiesPlugin::DownloadBlock.any_instance.stubs(:profile_count).returns(0)
  12 + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::DownloadBlock.new.default_title
13 end 13 end
14 14
15 should 'describe itself' do 15 should 'describe itself' do
16 - assert_not_equal Block.description, DownloadBlock.description 16 + assert_not_equal Block.description, SoftwareCommunitiesPlugin::DownloadBlock.description
17 end 17 end
18 18
19 should 'have software info to download it' do 19 should 'have software info to download it' do
@@ -24,7 +24,7 @@ class DownloadBlockTest &lt; ActiveSupport::TestCase @@ -24,7 +24,7 @@ class DownloadBlockTest &lt; ActiveSupport::TestCase
24 link2 = "gitlab.com/teste/2" 24 link2 = "gitlab.com/teste/2"
25 name2 = "Test Software2" 25 name2 = "Test Software2"
26 26
27 - block = DownloadBlock.create(:downloads => [{:name => name1, :link => link1}, {:name => name2, :link => link2}]) 27 + block = SoftwareCommunitiesPlugin::DownloadBlock.create(:downloads => [{:name => name1, :link => link1}, {:name => name2, :link => link2}])
28 28
29 assert_equal block.downloads[0][:link], link1, "Link should not be empty" 29 assert_equal block.downloads[0][:link], link1, "Link should not be empty"
30 assert_equal block.downloads[0][:name], name1, "Name should not be empty" 30 assert_equal block.downloads[0][:name], name1, "Name should not be empty"
src/noosfero-spb/software_communities/test/unit/download_test.rb
@@ -26,8 +26,8 @@ class DownloadTest &lt; ActiveSupport::TestCase @@ -26,8 +26,8 @@ class DownloadTest &lt; ActiveSupport::TestCase
26 end 26 end
27 27
28 should "Set as 0(zero) total_downloads if it is not given" do 28 should "Set as 0(zero) total_downloads if it is not given" do
29 - without_total_downloads = Download.new({})  
30 - with_total_downloads = Download.new(@downloads_sample_data.last) 29 + without_total_downloads = SoftwareCommunitiesPlugin::Download.new({})
  30 + with_total_downloads = SoftwareCommunitiesPlugin::Download.new(@downloads_sample_data.last)
31 31
32 assert_equal 0, without_total_downloads.total_downloads 32 assert_equal 0, without_total_downloads.total_downloads
33 assert_equal @downloads_sample_data.last[:total_downloads], with_total_downloads.total_downloads 33 assert_equal @downloads_sample_data.last[:total_downloads], with_total_downloads.total_downloads
@@ -35,14 +35,14 @@ class DownloadTest &lt; ActiveSupport::TestCase @@ -35,14 +35,14 @@ class DownloadTest &lt; ActiveSupport::TestCase
35 35
36 should "Remove downloads without a name" do 36 should "Remove downloads without a name" do
37 @downloads_sample_data[1] = @downloads_sample_data[1].slice! :name 37 @downloads_sample_data[1] = @downloads_sample_data[1].slice! :name
38 - downloads = Download.validate_download_list @downloads_sample_data 38 + downloads = SoftwareCommunitiesPlugin::Download.validate_download_list @downloads_sample_data
39 39
40 assert_equal 1, downloads.size 40 assert_equal 1, downloads.size
41 assert_equal @downloads_sample_data[0][:name], downloads[0][:name] 41 assert_equal @downloads_sample_data[0][:name], downloads[0][:name]
42 end 42 end
43 43
44 should "Only set total_downloads if the value is integer" do 44 should "Only set total_downloads if the value is integer" do
45 - download = Download.new(@downloads_sample_data.last) 45 + download = SoftwareCommunitiesPlugin::Download.new(@downloads_sample_data.last)
46 46
47 download.total_downloads = "456" 47 download.total_downloads = "456"
48 assert_not_equal 456, download.total_downloads 48 assert_not_equal 456, download.total_downloads
src/noosfero-spb/software_communities/test/unit/library_helper_test.rb
@@ -42,7 +42,7 @@ class LibraryHelperTest &lt; ActiveSupport::TestCase @@ -42,7 +42,7 @@ class LibraryHelperTest &lt; ActiveSupport::TestCase
42 should "return a html text with license name equals to linux" do 42 should "return a html text with license name equals to linux" do
43 libraries = [] 43 libraries = []
44 44
45 - library_description = Library.new 45 + library_description = SoftwareCommunitiesPlugin::Library.new
46 library_description.name = "Lib" 46 library_description.name = "Lib"
47 47
48 libraries << library_description 48 libraries << library_description
src/noosfero-spb/software_communities/test/unit/library_validation_test.rb
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
3 class LibraryValidationTest < ActiveSupport::TestCase 3 class LibraryValidationTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - @library = Library.new 6 + @library = SoftwareCommunitiesPlugin::Library.new
7 @library.name = "name" 7 @library.name = "name"
8 @library.version = "version" 8 @library.version = "version"
9 @library.license = "license" 9 @library.license = "license"
src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2
3 -OperatingSystemName.create(:name=>"Debina")  
4 -OperatingSystemName.create(:name=>"Fedora")  
5 -OperatingSystemName.create(:name=>"CentOS") 3 +SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Debina")
  4 +SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Fedora")
  5 +SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"CentOS")
6 6
7 class OperatingSystemHelperTest < ActiveSupport::TestCase 7 class OperatingSystemHelperTest < ActiveSupport::TestCase
8 8
@@ -49,16 +49,16 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase @@ -49,16 +49,16 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase
49 should "return a html text with operating system" do 49 should "return a html text with operating system" do
50 operating_systems = [] 50 operating_systems = []
51 51
52 - operating_system = OperatingSystemName.new 52 + operating_system = SoftwareCommunitiesPlugin::OperatingSystemName.new
53 operating_system.name = "teste" 53 operating_system.name = "teste"
54 54
55 - software_operating_system = OperatingSystem.new 55 + software_operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new
56 software_operating_system.version = 2 56 software_operating_system.version = 2
57 software_operating_system.operating_system_name = operating_system 57 software_operating_system.operating_system_name = operating_system
58 58
59 operating_systems << software_operating_system 59 operating_systems << software_operating_system
60 op_table = OperatingSystemHelper.operating_system_as_tables(operating_systems) 60 op_table = OperatingSystemHelper.operating_system_as_tables(operating_systems)
61 61
62 - assert_not_nil op_table.first.call.index(OperatingSystemName.first.name) 62 + assert_not_nil op_table.first.call.index(SoftwareCommunitiesPlugin::OperatingSystemName.first.name)
63 end 63 end
64 end 64 end
src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
3 class OperatingSystemValidationTest < ActiveSupport::TestCase 3 class OperatingSystemValidationTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - operating_system_name = OperatingSystemName::new :name=>"Linux"  
7 - @operating_system = OperatingSystem::new :version=>"3.0" 6 + operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName::new :name=>"Linux"
  7 + @operating_system = SoftwareCommunitiesPlugin::OperatingSystem::new :version=>"3.0"
8 @operating_system.operating_system_name = operating_system_name 8 @operating_system.operating_system_name = operating_system_name
9 @operating_system 9 @operating_system
10 end 10 end
src/noosfero-spb/software_communities/test/unit/repository_block_test.rb
@@ -5,15 +5,15 @@ class RepositoryBlockTest &lt; ActiveSupport::TestCase @@ -5,15 +5,15 @@ class RepositoryBlockTest &lt; ActiveSupport::TestCase
5 include PluginTestHelper 5 include PluginTestHelper
6 6
7 should 'inherit from Block' do 7 should 'inherit from Block' do
8 - assert_kind_of Block, RepositoryBlock.new 8 + assert_kind_of Block, SoftwareCommunitiesPlugin::RepositoryBlock.new
9 end 9 end
10 10
11 should 'declare its default title' do 11 should 'declare its default title' do
12 - RepositoryBlock.any_instance.stubs(:profile_count).returns(0)  
13 - assert_equal Block.new.default_title, RepositoryBlock.new.default_title 12 + SoftwareCommunitiesPlugin::RepositoryBlock.any_instance.stubs(:profile_count).returns(0)
  13 + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::RepositoryBlock.new.default_title
14 end 14 end
15 15
16 should 'describe itself' do 16 should 'describe itself' do
17 - assert_not_equal Block.description, RepositoryBlock.description 17 + assert_not_equal Block.description, SoftwareCommunitiesPlugin::RepositoryBlock.description
18 end 18 end
19 end 19 end
src/noosfero-spb/software_communities/test/unit/search_catalog_block_test.rb
@@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39; @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39;
4 class SearchCatalogBlockTest < ActiveSupport::TestCase 4 class SearchCatalogBlockTest < ActiveSupport::TestCase
5 include PluginTestHelper 5 include PluginTestHelper
6 should 'inherit from Block' do 6 should 'inherit from Block' do
7 - assert_kind_of Block, SearchCatalogBlock.new 7 + assert_kind_of Block, SoftwareCommunitiesPlugin::SearchCatalogBlock.new
8 end 8 end
9 9
10 should 'declare its default title' do 10 should 'declare its default title' do
11 - SearchCatalogBlock.any_instance.stubs(:profile_count).returns(0)  
12 - assert_equal Block.new.default_title, SearchCatalogBlock.new.default_title 11 + SoftwareCommunitiesPlugin::SearchCatalogBlock.any_instance.stubs(:profile_count).returns(0)
  12 + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::SearchCatalogBlock.new.default_title
13 end 13 end
14 14
15 should 'describe itself' do 15 should 'describe itself' do
16 - assert_not_equal Block.description, SearchCatalogBlock.description 16 + assert_not_equal Block.description, SoftwareCommunitiesPlugin::SearchCatalogBlock.description
17 end 17 end
18 18
19 end 19 end
src/noosfero-spb/software_communities/test/unit/software_database_test.rb
@@ -2,16 +2,16 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -2,16 +2,16 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
2 2
3 class SoftwareDatabaseTest < ActiveSupport::TestCase 3 class SoftwareDatabaseTest < ActiveSupport::TestCase
4 def setup 4 def setup
5 - DatabaseDescription.create!(name: "PostgreSQL")  
6 - @software_database = SoftwareDatabase.new( 5 + SoftwareCommunitiesPlugin::DatabaseDescription.create!(name: "PostgreSQL")
  6 + @software_database = SoftwareCommunitiesPlugin::SoftwareDatabase.new(
7 :version => "1.0" 7 :version => "1.0"
8 ) 8 )
9 @software_database.database_description_id = 1 9 @software_database.database_description_id = 1
10 end 10 end
11 11
12 def teardown 12 def teardown
13 - DatabaseDescription.destroy_all  
14 - SoftwareDatabase.destroy_all 13 + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all
  14 + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all
15 end 15 end
16 16
17 should "save if all informations of @software_database are filled" do 17 should "save if all informations of @software_database are filled" do
src/noosfero-spb/software_communities/test/unit/software_helper_test.rb
@@ -5,16 +5,16 @@ class SoftwareHelperTest &lt; ActiveSupport::TestCase @@ -5,16 +5,16 @@ class SoftwareHelperTest &lt; ActiveSupport::TestCase
5 include SoftwareHelper 5 include SoftwareHelper
6 6
7 should "Create ProgrammingLanguages based on file with languages names" do 7 should "Create ProgrammingLanguages based on file with languages names" do
8 - ProgrammingLanguage.delete_all 8 + SoftwareCommunitiesPlugin::ProgrammingLanguage.delete_all
9 PATH_TO_FILE = "plugins/software_communities/public/static/languages.txt" 9 PATH_TO_FILE = "plugins/software_communities/public/static/languages.txt"
10 10
11 - SoftwareHelper.create_list_with_file(PATH_TO_FILE, ProgrammingLanguage) 11 + SoftwareHelper.create_list_with_file(PATH_TO_FILE, SoftwareCommunitiesPlugin::ProgrammingLanguage)
12 12
13 list = File.open(PATH_TO_FILE, "r") 13 list = File.open(PATH_TO_FILE, "r")
14 count = list.readlines.count 14 count = list.readlines.count
15 list.close 15 list.close
16 16
17 - assert(ProgrammingLanguage.count == count) 17 + assert(SoftwareCommunitiesPlugin::ProgrammingLanguage.count == count)
18 end 18 end
19 19
20 should "return the software template specified in config.yml file" do 20 should "return the software template specified in config.yml file" do
src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb
@@ -9,29 +9,29 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase @@ -9,29 +9,29 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase
9 :name => 'New Software' 9 :name => 'New Software'
10 ) 10 )
11 11
12 - @language = ProgrammingLanguage.new(:name => 'C++') 12 + @language = SoftwareCommunitiesPlugin::ProgrammingLanguage.new(:name => 'C++')
13 @language.save 13 @language.save
14 - @software_language = SoftwareLanguage.new( 14 + @software_language = SoftwareCommunitiesPlugin::SoftwareLanguage.new(
15 :version => '1' 15 :version => '1'
16 ) 16 )
17 @software_language.programming_language = @language 17 @software_language.programming_language = @language
18 @software_language.save 18 @software_language.save
19 19
20 - @database = DatabaseDescription.new(:name => 'Oracle') 20 + @database = SoftwareCommunitiesPlugin::DatabaseDescription.new(:name => 'Oracle')
21 @database.save 21 @database.save
22 - @software_database = SoftwareDatabase.new( 22 + @software_database = SoftwareCommunitiesPlugin::SoftwareDatabase.new(
23 :version => '2' 23 :version => '2'
24 ) 24 )
25 @software_database.database_description = @database 25 @software_database.database_description = @database
26 @software_database.save 26 @software_database.save
27 27
28 - @operating_system_name = OperatingSystemName.new(:name => 'Debian') 28 + @operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName.new(:name => 'Debian')
29 @operating_system_name.save 29 @operating_system_name.save
30 - @operating_system = OperatingSystem.new(:version => '1.0') 30 + @operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new(:version => '1.0')
31 @operating_system.operating_system_name = @operating_system_name 31 @operating_system.operating_system_name = @operating_system_name
32 @operating_system.save 32 @operating_system.save
33 33
34 - @software_info = SoftwareInfo.new( 34 + @software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(
35 :acronym => "SFTW", 35 :acronym => "SFTW",
36 :e_mag => true, 36 :e_mag => true,
37 :icp_brasil => true, 37 :icp_brasil => true,
@@ -53,13 +53,13 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase @@ -53,13 +53,13 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase
53 end 53 end
54 54
55 def teardown 55 def teardown
56 - ProgrammingLanguage.destroy_all  
57 - SoftwareLanguage.destroy_all  
58 - DatabaseDescription.destroy_all  
59 - SoftwareDatabase.destroy_all  
60 - OperatingSystem.destroy_all  
61 - OperatingSystemName.destroy_all  
62 - SoftwareInfo.destroy_all 56 + SoftwareCommunitiesPlugin::ProgrammingLanguage.destroy_all
  57 + SoftwareCommunitiesPlugin::SoftwareLanguage.destroy_all
  58 + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all
  59 + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all
  60 + SoftwareCommunitiesPlugin::OperatingSystem.destroy_all
  61 + SoftwareCommunitiesPlugin::OperatingSystemName.destroy_all
  62 + SoftwareCommunitiesPlugin::SoftwareInfo.destroy_all
63 end 63 end
64 64
65 should 'Save SoftwareInfo if all fields are filled' do 65 should 'Save SoftwareInfo if all fields are filled' do
src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
3 class SoftwareLanguageHelperTest < ActiveSupport::TestCase 3 class SoftwareLanguageHelperTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - pl1 = ProgrammingLanguage.create(:name => "Python")  
7 - pl2 = ProgrammingLanguage.create(:name => "Java") 6 + pl1 = SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name => "Python")
  7 + pl2 = SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name => "Java")
8 8
9 @software_language_objects = [ 9 @software_language_objects = [
10 {:programming_language_id => pl1.id.to_s ,:version => "2.0"}, 10 {:programming_language_id => pl1.id.to_s ,:version => "2.0"},
@@ -15,7 +15,7 @@ class SoftwareLanguageHelperTest &lt; ActiveSupport::TestCase @@ -15,7 +15,7 @@ class SoftwareLanguageHelperTest &lt; ActiveSupport::TestCase
15 15
16 def teardown 16 def teardown
17 @software_language_objects = nil 17 @software_language_objects = nil
18 - ProgrammingLanguage.destroy_all 18 + SoftwareCommunitiesPlugin::ProgrammingLanguage.destroy_all
19 end 19 end
20 20
21 should "return an empty list" do 21 should "return an empty list" do
src/noosfero-spb/software_communities/test/unit/software_language_validation.rb
@@ -9,7 +9,7 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase @@ -9,7 +9,7 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase
9 9
10 def teardown 10 def teardown
11 @software_info = nil 11 @software_info = nil
12 - SoftwareInfo.destroy_all 12 + SoftwareCommunitiesPlugin::SoftwareInfo.destroy_all
13 end 13 end
14 14
15 should "Save SoftwareLanguage if version and prog_language are filled" do 15 should "Save SoftwareLanguage if version and prog_language are filled" do
@@ -38,15 +38,15 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase @@ -38,15 +38,15 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase
38 private 38 private
39 39
40 def create_software_language 40 def create_software_language
41 - software_language = SoftwareLanguage.new 41 + software_language = SoftwareCommunitiesPlugin::SoftwareLanguage.new
42 software_language.software_info = @software_info 42 software_language.software_info = @software_info
43 - software_language.programming_language = ProgrammingLanguage.last 43 + software_language.programming_language = SoftwareCommunitiesPlugin::ProgrammingLanguage.last
44 software_language.version = "version" 44 software_language.version = "version"
45 software_language 45 software_language
46 end 46 end
47 47
48 def create_software_info 48 def create_software_info
49 - software_info = SoftwareInfo.new 49 + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new
50 software_info.community_id = fast_create(Community).id 50 software_info.community_id = fast_create(Community).id
51 software_info.community.name = 'Noosfero' 51 software_info.community.name = 'Noosfero'
52 software_info.e_mag = true 52 software_info.e_mag = true
@@ -61,9 +61,9 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase @@ -61,9 +61,9 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase
61 end 61 end
62 62
63 def create_programming_language 63 def create_programming_language
64 - ProgrammingLanguage.create(:name=>"C")  
65 - ProgrammingLanguage.create(:name=>"C++")  
66 - ProgrammingLanguage.create(:name=>"Ruby")  
67 - ProgrammingLanguage.create(:name=>"Python") 64 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"C")
  65 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"C++")
  66 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"Ruby")
  67 + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"Python")
68 end 68 end
69 end 69 end
src/noosfero-spb/software_communities/test/unit/software_license_info_test.rb
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
3 class SoftwareDatabaseTest < ActiveSupport::TestCase 3 class SoftwareDatabaseTest < ActiveSupport::TestCase
4 4
5 should "save if all informations are filled" do 5 should "save if all informations are filled" do
6 - @software_license_info = LicenseInfo.create( 6 + @software_license_info = SoftwareCommunitiesPlugin::LicenseInfo.create(
7 :version => "GPL", 7 :version => "GPL",
8 :link => "www.gpl2.com" 8 :link => "www.gpl2.com"
9 ) 9 )
@@ -11,7 +11,7 @@ class SoftwareDatabaseTest &lt; ActiveSupport::TestCase @@ -11,7 +11,7 @@ class SoftwareDatabaseTest &lt; ActiveSupport::TestCase
11 end 11 end
12 12
13 should "not save if license info version is empty" do 13 should "not save if license info version is empty" do
14 - @software_license_info = LicenseInfo.create( 14 + @software_license_info = SoftwareCommunitiesPlugin::LicenseInfo.create(
15 :version => "GPL", 15 :version => "GPL",
16 :link => "www.gpl2.com" 16 :link => "www.gpl2.com"
17 ) 17 )
@@ -20,7 +20,7 @@ class SoftwareDatabaseTest &lt; ActiveSupport::TestCase @@ -20,7 +20,7 @@ class SoftwareDatabaseTest &lt; ActiveSupport::TestCase
20 end 20 end
21 21
22 should "save if link is empty" do 22 should "save if link is empty" do
23 - @software_license_info = LicenseInfo.create( 23 + @software_license_info = SoftwareCommunitiesPlugin::LicenseInfo.create(
24 :version => "GPL", 24 :version => "GPL",
25 :link => "www.gpl2.com") 25 :link => "www.gpl2.com")
26 @software_license_info.link = nil 26 @software_license_info.link = nil
src/noosfero-spb/software_communities/test/unit/software_registration_test.rb
@@ -9,17 +9,18 @@ class SoftwareRegistrationTest &lt; ActiveSupport::TestCase @@ -9,17 +9,18 @@ class SoftwareRegistrationTest &lt; ActiveSupport::TestCase
9 9
10 def teardown 10 def teardown
11 Community.destroy_all 11 Community.destroy_all
12 - SoftwareInfo.destroy_all 12 + SoftwareCommunitiesPlugin::SoftwareInfo.destroy_all
13 Task.destroy_all 13 Task.destroy_all
14 end 14 end
15 15
16 should 'include software registration task if is admin' do 16 should 'include software registration task if is admin' do
17 person = create_user('molly').person 17 person = create_user('molly').person
18 @environment.add_admin(person) 18 @environment.add_admin(person)
19 - task = CreateSoftware.create!( 19 + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(
20 :name => "Teste One", 20 :name => "Teste One",
21 :requestor => person, 21 :requestor => person,
22 - :environment => @environment 22 + :environment => @environment,
  23 + :finality => "something"
23 ) 24 )
24 assert_equal [task], Task.to(person).pending 25 assert_equal [task], Task.to(person).pending
25 end 26 end
@@ -27,16 +28,16 @@ class SoftwareRegistrationTest &lt; ActiveSupport::TestCase @@ -27,16 +28,16 @@ class SoftwareRegistrationTest &lt; ActiveSupport::TestCase
27 should 'create software when admin accept software create task' do 28 should 'create software when admin accept software create task' do
28 person = create_user('Pedro').person 29 person = create_user('Pedro').person
29 @environment.add_admin(person) 30 @environment.add_admin(person)
30 - task = CreateSoftware.create!( 31 + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(
31 :name => "Teste Two", 32 :name => "Teste Two",
32 :requestor => person, 33 :requestor => person,
33 :environment => @environment, 34 :environment => @environment,
34 :finality => "something" 35 :finality => "something"
35 ) 36 )
36 37
37 - software_count = SoftwareInfo.count 38 + software_count = SoftwareCommunitiesPlugin::SoftwareInfo.count
38 task.finish 39 task.finish
39 40
40 - assert_equal software_count+1, SoftwareInfo.count 41 + assert_equal software_count+1, SoftwareCommunitiesPlugin::SoftwareInfo.count
41 end 42 end
42 end 43 end
src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb
@@ -14,15 +14,15 @@ class SoftwareTabDataBlockTest &lt; ActiveSupport::TestCase @@ -14,15 +14,15 @@ class SoftwareTabDataBlockTest &lt; ActiveSupport::TestCase
14 @soft_community.blogs << Blog.new(:name=>"Second blog") 14 @soft_community.blogs << Blog.new(:name=>"Second blog")
15 @soft_community.save! 15 @soft_community.save!
16 16
17 - SoftwareTabDataBlock.any_instance.stubs(:owner).returns(@soft_community) 17 + SoftwareCommunitiesPlugin::SoftwareTabDataBlock.any_instance.stubs(:owner).returns(@soft_community)
18 end 18 end
19 19
20 should "get its owner blogs" do 20 should "get its owner blogs" do
21 - assert_equal @soft_community.blogs, SoftwareTabDataBlock.new.blogs 21 + assert_equal @soft_community.blogs, SoftwareCommunitiesPlugin::SoftwareTabDataBlock.new.blogs
22 end 22 end
23 23
24 should "actual_blog get the first blog if it is not defined" do 24 should "actual_blog get the first blog if it is not defined" do
25 - assert_equal @soft_community.blogs.first, SoftwareTabDataBlock.new.actual_blog 25 + assert_equal @soft_community.blogs.first, SoftwareCommunitiesPlugin::SoftwareTabDataBlock.new.actual_blog
26 end 26 end
27 27
28 should "actual_blog get the defined community blog" do 28 should "actual_blog get the defined community blog" do
@@ -46,13 +46,13 @@ class SoftwareTabDataBlockTest &lt; ActiveSupport::TestCase @@ -46,13 +46,13 @@ class SoftwareTabDataBlockTest &lt; ActiveSupport::TestCase
46 soft_tab_data = create_software_tab_data_block(last_blog) 46 soft_tab_data = create_software_tab_data_block(last_blog)
47 craete_sample_posts(last_blog, 6) 47 craete_sample_posts(last_blog, 6)
48 48
49 - assert_equal SoftwareTabDataBlock::TOTAL_POSTS_DYSPLAYED, soft_tab_data.posts.count 49 + assert_equal SoftwareCommunitiesPlugin::SoftwareTabDataBlock::TOTAL_POSTS_DYSPLAYED, soft_tab_data.posts.count
50 end 50 end
51 51
52 private 52 private
53 53
54 def create_software_tab_data_block blog 54 def create_software_tab_data_block blog
55 - soft_tab_data = SoftwareTabDataBlock.new 55 + soft_tab_data = SoftwareCommunitiesPlugin::SoftwareTabDataBlock.new
56 soft_tab_data.displayed_blog = blog.id 56 soft_tab_data.displayed_blog = blog.id
57 soft_tab_data 57 soft_tab_data
58 end 58 end
src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb
@@ -4,20 +4,20 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39; @@ -4,20 +4,20 @@ require File.dirname(__FILE__) + &#39;/../helpers/plugin_test_helper&#39;
4 class SoftwaresBlockTest < ActiveSupport::TestCase 4 class SoftwaresBlockTest < ActiveSupport::TestCase
5 include PluginTestHelper 5 include PluginTestHelper
6 should 'inherit from ProfileListBlock' do 6 should 'inherit from ProfileListBlock' do
7 - assert_kind_of ProfileListBlock, SoftwaresBlock.new 7 + assert_kind_of ProfileListBlock, SoftwareCommunitiesPlugin::SoftwaresBlock.new
8 end 8 end
9 9
10 should 'declare its default title' do 10 should 'declare its default title' do
11 - SoftwaresBlock.any_instance.stubs(:profile_count).returns(0)  
12 - assert_not_equal ProfileListBlock.new.default_title, SoftwaresBlock.new.default_title 11 + SoftwareCommunitiesPlugin::SoftwaresBlock.any_instance.stubs(:profile_count).returns(0)
  12 + assert_not_equal ProfileListBlock.new.default_title, SoftwareCommunitiesPlugin::SoftwaresBlock.new.default_title
13 end 13 end
14 14
15 should 'describe itself' do 15 should 'describe itself' do
16 - assert_not_equal ProfileListBlock.description, SoftwaresBlock.description 16 + assert_not_equal ProfileListBlock.description, SoftwareCommunitiesPlugin::SoftwaresBlock.description
17 end 17 end
18 18
19 should 'give empty footer on unsupported owner type' do 19 should 'give empty footer on unsupported owner type' do
20 - block = SoftwaresBlock.new 20 + block = SoftwareCommunitiesPlugin::SoftwaresBlock.new
21 block.expects(:owner).returns(1) 21 block.expects(:owner).returns(1)
22 assert_equal '', block.footer 22 assert_equal '', block.footer
23 end 23 end
@@ -34,7 +34,7 @@ class SoftwaresBlockTest &lt; ActiveSupport::TestCase @@ -34,7 +34,7 @@ class SoftwaresBlockTest &lt; ActiveSupport::TestCase
34 software_info = create_software_info("new software") 34 software_info = create_software_info("new software")
35 software_info.community.add_member(user) 35 software_info.community.add_member(user)
36 36
37 - block = SoftwaresBlock.new 37 + block = SoftwareCommunitiesPlugin::SoftwaresBlock.new
38 block.expects(:owner).at_least_once.returns(user) 38 block.expects(:owner).at_least_once.returns(user)
39 39
40 assert_equivalent [software_info.community], block.profiles 40 assert_equivalent [software_info.community], block.profiles