diff --git a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb index 0d59ad8..1814f26 100644 --- a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb +++ b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb @@ -6,7 +6,7 @@ class SoftwareCommunitiesPluginController < ApplicationController return render :json=>{} if !request.xhr? || params[:query].nil? data = LicenseHelper.find_licenses(params[:query]) if params[:query] - data ||= LicenseInfo.all + data ||= SoftwareCommunitiesPlugin::LicenseInfo.all render :json=> data.collect { |license| {:id=>license.id, :label=>license.version} @@ -42,7 +42,7 @@ class SoftwareCommunitiesPluginController < ApplicationController protected def get_model_by_params_field - return DatabaseDescription unless params[:field] == "software_language" - return ProgrammingLanguage + return SoftwareCommunitiesPlugin::DatabaseDescription unless params[:field] == "software_language" + return SoftwareCommunitiesPlugin::ProgrammingLanguage end end diff --git a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_myprofile_controller.rb b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_myprofile_controller.rb index f51b5ff..34c9f42 100644 --- a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_myprofile_controller.rb +++ b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_myprofile_controller.rb @@ -10,10 +10,10 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController @community = Community.new(params[:community]) @community.environment = environment - @license_info = LicenseInfo.find_by_id(params[:license][:license_infos_id]) if params[:license] - @license_info ||= LicenseInfo.new + @license_info = SoftwareCommunitiesPlugin::LicenseInfo.find_by_id(params[:license][:license_infos_id]) if params[:license] + @license_info ||= SoftwareCommunitiesPlugin::LicenseInfo.new - @software_info = SoftwareInfo.new(params[:software_info]) + @software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(params[:software_info]) @software_info.community = @community @software_info.license_info = @license_info @@ -90,7 +90,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController def create_software @software_info = @profile.software_info params[:software][:public_software] ||= false unless @software_info.public_software? - @license = LicenseInfo.find(params[:license][:license_infos_id]) + @license = SoftwareCommunitiesPlugin::LicenseInfo.find(params[:license][:license_infos_id]) @software_info.license_info = @license @software_info.update_attributes(params[:software]) @@ -122,7 +122,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController another_license_version = params[:license][:version] another_license_link = params[:license][:link] end - @software_info = SoftwareInfo.create_after_moderation(user, + @software_info = SoftwareCommunitiesPlugin::SoftwareInfo.create_after_moderation(user, params[:software_info].merge({ :environment => environment, :name => params[:community][:name], @@ -158,7 +158,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController @another_license_version = "" @another_license_link = "" - license_another = LicenseInfo.find_by_version("Another") + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") if license_another && @software_info.license_info_id == license_another.id @license_version = "Another" @another_license_version = @software_info.license_info.version diff --git a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_profile_controller.rb b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_profile_controller.rb index 9f80e73..b76db27 100644 --- a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_profile_controller.rb +++ b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_profile_controller.rb @@ -9,11 +9,11 @@ class SoftwareCommunitiesPluginProfileController < ProfileController } def download_file - download_block = DownloadBlock.find_by_id params[:block] + download_block = SoftwareCommunitiesPlugin::DownloadBlock.find_by_id params[:block] index = params[:download_index].to_i if download_block and (index < download_block.downloads.size) - download = Download.new(download_block.downloads[index]) + download = SoftwareCommunitiesPlugin::Download.new(download_block.downloads[index]) download.total_downloads += 1 download_block.downloads[index] = download.to_hash diff --git a/src/noosfero-spb/software_communities/db/migrate/20140528193902_create_license_infos_table.rb b/src/noosfero-spb/software_communities/db/migrate/20140528193902_create_license_infos_table.rb index 0024f7d..fe38a6e 100644 --- a/src/noosfero-spb/software_communities/db/migrate/20140528193902_create_license_infos_table.rb +++ b/src/noosfero-spb/software_communities/db/migrate/20140528193902_create_license_infos_table.rb @@ -6,7 +6,7 @@ class CreateLicenseInfosTable < ActiveRecord::Migration end link = "http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" - LicenseInfo.create(:version => "CC-GPL-V2", :link => link) + SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "CC-GPL-V2", :link => link) end def self.down diff --git a/src/noosfero-spb/software_communities/db/migrate/20140528193956_create_programming_languages_table.rb b/src/noosfero-spb/software_communities/db/migrate/20140528193956_create_programming_languages_table.rb index 2c939eb..3c42b83 100644 --- a/src/noosfero-spb/software_communities/db/migrate/20140528193956_create_programming_languages_table.rb +++ b/src/noosfero-spb/software_communities/db/migrate/20140528193956_create_programming_languages_table.rb @@ -4,7 +4,7 @@ class CreateProgrammingLanguagesTable < ActiveRecord::Migration t.string :name end - SoftwareHelper.create_list_with_file("plugins/software_communities/public/static/languages.txt", ProgrammingLanguage) + SoftwareHelper.create_list_with_file("plugins/software_communities/public/static/languages.txt", SoftwareCommunitiesPlugin::ProgrammingLanguage) end def self.down diff --git a/src/noosfero-spb/software_communities/db/migrate/20140714133901_create_operating_name_table.rb b/src/noosfero-spb/software_communities/db/migrate/20140714133901_create_operating_name_table.rb index 610bcec..1db3bcf 100644 --- a/src/noosfero-spb/software_communities/db/migrate/20140714133901_create_operating_name_table.rb +++ b/src/noosfero-spb/software_communities/db/migrate/20140714133901_create_operating_name_table.rb @@ -5,7 +5,7 @@ class CreateOperatingNameTable < ActiveRecord::Migration end path_to_file = "plugins/software_communities/public/static/operating_systems.txt" - SoftwareHelper.create_list_with_file(path_to_file, OperatingSystemName) + SoftwareHelper.create_list_with_file(path_to_file, SoftwareCommunitiesPlugin::OperatingSystemName) end def down diff --git a/src/noosfero-spb/software_communities/db/migrate/20150210182519_rename_cc_license.rb b/src/noosfero-spb/software_communities/db/migrate/20150210182519_rename_cc_license.rb index 9cc7fc8..f618b5f 100644 --- a/src/noosfero-spb/software_communities/db/migrate/20150210182519_rename_cc_license.rb +++ b/src/noosfero-spb/software_communities/db/migrate/20150210182519_rename_cc_license.rb @@ -1,12 +1,12 @@ class RenameCcLicense < ActiveRecord::Migration def up - license = LicenseInfo.find_by_version "CC-GPL-V2" + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version "CC-GPL-V2" license.version = "Creative Commons GPL V2" license.save! end def down - license = LicenseInfo.find_by_version "Creative Commons GPL V2" + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version "Creative Commons GPL V2" license.version = "CC-GPL-V2" license.save! end diff --git a/src/noosfero-spb/software_communities/db/migrate/20151022175354_rename_tables_with_plugin_namespace.rb b/src/noosfero-spb/software_communities/db/migrate/20151022175354_rename_tables_with_plugin_namespace.rb new file mode 100644 index 0000000..d8119d1 --- /dev/null +++ b/src/noosfero-spb/software_communities/db/migrate/20151022175354_rename_tables_with_plugin_namespace.rb @@ -0,0 +1,14 @@ +class RenameTablesWithPluginNamespace < ActiveRecord::Migration + def change + rename_table :license_infos, :software_communities_plugin_license_infos + rename_table :software_infos, :software_communities_plugin_software_infos + rename_table :libraries, :software_communities_plugin_libraries + rename_table :programming_languages, :software_communities_plugin_programming_languages + rename_table :database_descriptions, :software_communities_plugin_database_descriptions + rename_table :software_databases, :software_communities_plugin_software_databases + rename_table :software_languages, :software_communities_plugin_software_languages + rename_table :operating_systems, :software_communities_plugin_operating_systems + rename_table :operating_system_names, :software_communities_plugin_operating_system_names + rename_table :software_categories, :software_communities_plugin_software_categories + end +end diff --git a/src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb b/src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb deleted file mode 100644 index e50f9c4..0000000 --- a/src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb +++ /dev/null @@ -1,29 +0,0 @@ -class CategoriesAndTagsBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Categories and Tags') - end - - def help - _('This block displays the categories and tags of a software.') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/categories_and_tags', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/categories_software_block.rb b/src/noosfero-spb/software_communities/lib/categories_software_block.rb deleted file mode 100644 index 97e1fda..0000000 --- a/src/noosfero-spb/software_communities/lib/categories_software_block.rb +++ /dev/null @@ -1,35 +0,0 @@ -class CategoriesSoftwareBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Categories Softwares') - end - - def help - _('This block displays the categories and the amount of softwares for - each category.') - end - - def content(args={}) - block = self - s = show_name - - software_category = Category.find_by_name("Software") - categories = [] - categories = software_category.children.sort if software_category - - lambda do |object| - render( - :file => 'blocks/categories_software', - :locals => { :block => block, :show_name => s, :categories => categories } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/create_software.rb b/src/noosfero-spb/software_communities/lib/create_software.rb deleted file mode 100644 index d43a21b..0000000 --- a/src/noosfero-spb/software_communities/lib/create_software.rb +++ /dev/null @@ -1,115 +0,0 @@ -class CreateSoftware < Task - include Rails.application.routes.url_helpers - - validates_presence_of :requestor_id, :target_id - validates_presence_of :name, :finality - - attr_accessible :name, :finality, :repository_link, :requestor, :environment, - :reject_explanation, :license_info, :identifier, :target - - alias :environment :target - alias :environment= :target= - - DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link'] - DATA_FIELDS.each do |field| - settings_items field.to_sym - end - - def perform - software_template = SoftwareHelper.software_template - template_id = software_template.blank? ? nil : software_template.id - - identifier = self.identifier - identifier ||= self.name.to_slug - - community = Community.create!(:name => self.name, - :identifier => identifier, - :template_id => template_id) - - community.environment = self.environment - community.add_admin(self.requestor) - - software = SoftwareInfo.create!(:finality => self.finality, - :repository_link => self.repository_link, :community_id => community.id, - :license_info => self.license_info) - end - - def title - _("New software") - end - - def subject - name - end - - def information - message = _('%{requestor} wants to create software %{subject} with') - if finality.blank? - { :message => message + _(' no finality.') } - else - { :message => message + _(' this finality:
%{finality}
'), - :variables => {:finality => finality} } - end - end - - def reject_details - true - end - - # tells if this request was rejected - def rejected? - self.status == Task::Status::CANCELLED - end - - # tells if this request was appoved - def approved? - self.status == Task::Status::FINISHED - end - - def target_notification_description - _('%{requestor} wants to create software %{subject}') % - {:requestor => requestor.name, :subject => subject} - end - - def target_notification_message - _("User \"%{user}\" just requested to create software %{software}. - You have to approve or reject it through the \"Pending Validations\" - section in your control panel.\n") % - { :user => self.requestor.name, :software => self.name } - end - - def task_created_message - _("Your request for registering software %{software} at %{environment} was - just sent. Environment administrator will receive it and will approve or - reject your request according to his methods and criteria. - - You will be notified as soon as environment administrator has a position - about your request.") % - { :software => self.name, :environment => self.target } - end - - def task_cancelled_message - _("Your request for registering software %{software} at %{environment} was - not approved by the environment administrator. The following explanation - was given: \n\n%{explanation}") % - { :software => self.name, - :environment => self.environment, - :explanation => self.reject_explanation } - end - - def task_finished_message - _('Your request for registering the software "%{software}" was approved. - You can access %{url} and finish the registration of your software.') % - { :software => self.name, :url => mount_url } - end - - private - - def mount_url - identifier = Community.where(:name => self.name).first.identifier - # The use of url_for doesn't allow the /social within the Public Software - # portal. That's why the url is mounted so 'hard coded' - url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community" - end - -end diff --git a/src/noosfero-spb/software_communities/lib/database_description.rb b/src/noosfero-spb/software_communities/lib/database_description.rb deleted file mode 100644 index ff1e641..0000000 --- a/src/noosfero-spb/software_communities/lib/database_description.rb +++ /dev/null @@ -1,15 +0,0 @@ -class DatabaseDescription < ActiveRecord::Base - - SEARCHABLE_SOFTWARE_FIELDS = { - :name => 1 - } - - attr_accessible :name - - has_many :software_databases - has_many :software_infos, :through => :software_databases - - validates_presence_of :name - validates_uniqueness_of :name - -end diff --git a/src/noosfero-spb/software_communities/lib/database_helper.rb b/src/noosfero-spb/software_communities/lib/database_helper.rb index 94bf652..daafcbe 100644 --- a/src/noosfero-spb/software_communities/lib/database_helper.rb +++ b/src/noosfero-spb/software_communities/lib/database_helper.rb @@ -5,7 +5,7 @@ class DatabaseHelper < DynamicTableHelper def self.valid_database? database return false if SoftwareHelper.all_table_is_empty?(database) - database_description_id_list = DatabaseDescription.select(:id). + database_description_id_list = SoftwareCommunitiesPlugin::DatabaseDescription.select(:id). collect {|dd| dd.id} return database_description_id_list.include?( @@ -19,7 +19,7 @@ class DatabaseHelper < DynamicTableHelper new_databases.each do |new_database| if valid_database? new_database - database = SoftwareDatabase.new + database = SoftwareCommunitiesPlugin::SoftwareDatabase.new database.database_description_id = new_database[:database_description_id] @@ -46,7 +46,7 @@ class DatabaseHelper < DynamicTableHelper def self.database_html_structure(database_data, disabled) database_id = database_data[:database_description_id] - database_name = database_id.blank? ? "" : DatabaseDescription.find( + database_name = database_id.blank? ? "" : SoftwareCommunitiesPlugin::DatabaseDescription.find( database_data[:database_description_id], :select=>"name" ).name diff --git a/src/noosfero-spb/software_communities/lib/download.rb b/src/noosfero-spb/software_communities/lib/download.rb deleted file mode 100644 index 0b63fed..0000000 --- a/src/noosfero-spb/software_communities/lib/download.rb +++ /dev/null @@ -1,51 +0,0 @@ -#FIX ME: Turn this into a proper model(next release) -class Download - def initialize data - @name = data[:name] - @link = data[:link] - @software_description = data[:software_description] - @minimum_requirements = data[:minimum_requirements] - @size = data[:size] - - @total_downloads = if data[:total_downloads] - data[:total_downloads] - else - 0 - end - end - - def self.validate_download_list download_list - download_list.select! do |download| - not download[:name].blank? - end - - download_list.map do |download| - Download.new(download).to_hash - end - end - - def to_hash - { - :name => @name, - :link => @link, - :software_description => @software_description, - :minimum_requirements => @minimum_requirements, - :size => @size, - :total_downloads => @total_downloads - } - end - - def total_downloads= value - if value.is_a? Integer - @total_downloads = value - end - end - - def total_downloads - @total_downloads - end - - def link - @link - end -end diff --git a/src/noosfero-spb/software_communities/lib/download_block.rb b/src/noosfero-spb/software_communities/lib/download_block.rb deleted file mode 100644 index 58048b7..0000000 --- a/src/noosfero-spb/software_communities/lib/download_block.rb +++ /dev/null @@ -1,36 +0,0 @@ -class DownloadBlock < Block - - attr_accessible :show_name, :downloads - - settings_items :show_name, :type => :boolean, :default => false - settings_items :downloads, :type => Array, :default => [] - - validate :download_values - - def download_values - self.downloads = Download.validate_download_list(self.downloads) - end - - def self.description - _('Download Stable Version') - end - - def help - _('This block displays the stable version of a software.') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/download', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/ext/community.rb b/src/noosfero-spb/software_communities/lib/ext/community.rb index 6f8602f..fd40f7a 100644 --- a/src/noosfero-spb/software_communities/lib/ext/community.rb +++ b/src/noosfero-spb/software_communities/lib/ext/community.rb @@ -10,7 +10,7 @@ class Community attr_accessible :visible - has_one :software_info, :dependent=>:destroy + has_one :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :dependent=>:destroy settings_items :hits, :type => :integer, :default => 0 @@ -57,7 +57,7 @@ class Community def remove_of_community_search_software? return software? end - + def hit self.hits += 1 self.save! diff --git a/src/noosfero-spb/software_communities/lib/ext/search_controller.rb b/src/noosfero-spb/software_communities/lib/ext/search_controller.rb index e96cd63..37d5bf6 100644 --- a/src/noosfero-spb/software_communities/lib/ext/search_controller.rb +++ b/src/noosfero-spb/software_communities/lib/ext/search_controller.rb @@ -63,11 +63,11 @@ class SearchController params[:query] ||= "" visible_communities = visible_profiles(Community) - filtered_software_list = SoftwareInfo.search_by_query(params[:query]) + filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.search_by_query(params[:query]) if params[:only_softwares] params[:only_softwares].collect!{ |software_name| software_name.to_slug } - filtered_software_list = SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) } + filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) } @public_software_selected = false end @@ -117,7 +117,9 @@ class SearchController end def prepare_software_infos_params - @titles[:software_infos] = _("Result Search") + @asset = "software_communities_plugin/software_infos" + @assets = [@asset] + @titles["software_communities_plugin/software_infos"] = _("Result Search") @selected_categories_id = params[:selected_categories_id] @selected_categories_id ||= [] @selected_categories_id = @selected_categories_id.map(&:to_i) @@ -130,7 +132,7 @@ class SearchController return 15 if params[:software_display].nil? if params[:software_display] == "all" - SoftwareInfo.count + SoftwareCommunitiesPlugin::SoftwareInfo.count else params[:software_display].to_i end diff --git a/src/noosfero-spb/software_communities/lib/library.rb b/src/noosfero-spb/software_communities/lib/library.rb deleted file mode 100644 index d4b2b56..0000000 --- a/src/noosfero-spb/software_communities/lib/library.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Library < ActiveRecord::Base - attr_accessible :name, :version, :license, :software_info_id - - validates :name, :version, :license, - presence: { message: _("can't be blank") }, - length: { - maximum: 20, - too_long: _("Too long (maximum is 20 characters)") - } -end diff --git a/src/noosfero-spb/software_communities/lib/library_helper.rb b/src/noosfero-spb/software_communities/lib/library_helper.rb index 579ebb7..af27c42 100644 --- a/src/noosfero-spb/software_communities/lib/library_helper.rb +++ b/src/noosfero-spb/software_communities/lib/library_helper.rb @@ -7,7 +7,7 @@ class LibraryHelper < DynamicTableHelper new_libraries.each do |new_library| unless SoftwareHelper.all_table_is_empty? new_library - library = Library.new + library = SoftwareCommunitiesPlugin::Library.new library.name = new_library[:name] library.version = new_library[:version] library.license = new_library[:license] diff --git a/src/noosfero-spb/software_communities/lib/license_helper.rb b/src/noosfero-spb/software_communities/lib/license_helper.rb index 8a21a2b..1d17c71 100644 --- a/src/noosfero-spb/software_communities/lib/license_helper.rb +++ b/src/noosfero-spb/software_communities/lib/license_helper.rb @@ -1,8 +1,8 @@ module LicenseHelper def self.find_licenses query - licenses = LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") + licenses = SoftwareCommunitiesPlugin::LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") licenses.reject!{|license| license.version == "Another"} - license_another = LicenseInfo.find_by_version("Another") + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") licenses << license_another if license_another licenses end diff --git a/src/noosfero-spb/software_communities/lib/license_info.rb b/src/noosfero-spb/software_communities/lib/license_info.rb deleted file mode 100644 index 6f9bfe7..0000000 --- a/src/noosfero-spb/software_communities/lib/license_info.rb +++ /dev/null @@ -1,8 +0,0 @@ -class LicenseInfo < ActiveRecord::Base - attr_accessible :version, :link - - validates_presence_of :version - - has_many :software_info - -end diff --git a/src/noosfero-spb/software_communities/lib/operating_system.rb b/src/noosfero-spb/software_communities/lib/operating_system.rb deleted file mode 100644 index b2763e9..0000000 --- a/src/noosfero-spb/software_communities/lib/operating_system.rb +++ /dev/null @@ -1,14 +0,0 @@ -class OperatingSystem < ActiveRecord::Base - attr_accessible :version - - belongs_to :software_info - belongs_to :operating_system_name - - validates :operating_system_name, presence: true - validates :version, - presence: true, - length: { - maximum: 20, - too_long: _('too long (maximum is 20 characters)') - } -end diff --git a/src/noosfero-spb/software_communities/lib/operating_system_helper.rb b/src/noosfero-spb/software_communities/lib/operating_system_helper.rb index 201ac05..4851732 100644 --- a/src/noosfero-spb/software_communities/lib/operating_system_helper.rb +++ b/src/noosfero-spb/software_communities/lib/operating_system_helper.rb @@ -12,8 +12,8 @@ class OperatingSystemHelper < DynamicTableHelper ["operating_system_name_id"] ) - operating_system = OperatingSystem.new - operating_system.operating_system_name = OperatingSystemName.find( + operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new + operating_system.operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName.find( new_operating_system[:operating_system_name_id] ) @@ -38,7 +38,7 @@ class OperatingSystemHelper < DynamicTableHelper def self.operating_system_html_structure (operating_system_data, disabled) select_options = options_for_select( - OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, + SoftwareCommunitiesPlugin::OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, operating_system_data[:operating_system_name_id] ) diff --git a/src/noosfero-spb/software_communities/lib/operating_system_name.rb b/src/noosfero-spb/software_communities/lib/operating_system_name.rb deleted file mode 100644 index cc59602..0000000 --- a/src/noosfero-spb/software_communities/lib/operating_system_name.rb +++ /dev/null @@ -1,10 +0,0 @@ -class OperatingSystemName < ActiveRecord::Base - attr_accessible :name - - validates_presence_of :name - validates_uniqueness_of :name - - has_many :operating_systems - has_many :software_infos, :through => :operating_systems - -end diff --git a/src/noosfero-spb/software_communities/lib/programming_language.rb b/src/noosfero-spb/software_communities/lib/programming_language.rb deleted file mode 100644 index 193225c..0000000 --- a/src/noosfero-spb/software_communities/lib/programming_language.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ProgrammingLanguage < ActiveRecord::Base - - SEARCHABLE_SOFTWARE_FIELDS = { - :name => 1 - } - - attr_accessible :name - - validates_presence_of :name - validates_uniqueness_of :name - - has_many :software_languages - has_many :software_infos, :through => :software_languages - -end diff --git a/src/noosfero-spb/software_communities/lib/repository_block.rb b/src/noosfero-spb/software_communities/lib/repository_block.rb deleted file mode 100644 index 483da7a..0000000 --- a/src/noosfero-spb/software_communities/lib/repository_block.rb +++ /dev/null @@ -1,29 +0,0 @@ -class RepositoryBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Repository Link') - end - - def help - _('This block displays the repository link of a software.') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/repository', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/search_catalog_block.rb b/src/noosfero-spb/software_communities/lib/search_catalog_block.rb deleted file mode 100644 index 4f7b517..0000000 --- a/src/noosfero-spb/software_communities/lib/search_catalog_block.rb +++ /dev/null @@ -1,29 +0,0 @@ -class SearchCatalogBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Search Softwares catalog') - end - - def help - _('This block displays the search categories field ') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/search_catalog', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb index b78d762..e2d2c2d 100644 --- a/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb @@ -33,17 +33,17 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin def self.extra_blocks { - SoftwaresBlock => { :type => [Environment, Person] }, - SoftwareInformationBlock => { :type => [Community] }, - DownloadBlock => { :type => [Community] }, - RepositoryBlock => { :type => [Community] }, - CategoriesAndTagsBlock => { :type => [Community] }, - CategoriesSoftwareBlock => { :type => [Environment] }, - SearchCatalogBlock => { :type => [Environment] }, - SoftwareHighlightsBlock => { :type => [Environment] }, - SoftwareTabDataBlock => {:type => [Community], :position => 1}, - WikiBlock => {:type => [Community]}, - StatisticBlock => { :type => [Community] } + SoftwareCommunitiesPlugin::SoftwaresBlock => { :type => [Environment, Person] }, + SoftwareCommunitiesPlugin::SoftwareInformationBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::DownloadBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::RepositoryBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::CategoriesAndTagsBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::CategoriesSoftwareBlock => { :type => [Environment] }, + SoftwareCommunitiesPlugin::SearchCatalogBlock => { :type => [Environment] }, + SoftwareCommunitiesPlugin::SoftwareHighlightsBlock => { :type => [Environment] }, + SoftwareCommunitiesPlugin::SoftwareTabDataBlock => {:type => [Community], :position => 1}, + SoftwareCommunitiesPlugin::WikiBlock => {:type => [Community]}, + SoftwareCommunitiesPlugin::StatisticBlock => { :type => [Community] } } end @@ -117,7 +117,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin protected def software_info_transaction - SoftwareInfo.transaction do + SoftwareCommunitiesPlugin::SoftwareInfo.transaction do context.profile. software_info. update_attributes!(context.params[:software_info]) @@ -125,7 +125,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin end def license_transaction - license = LicenseInfo.find(context.params[:version]) + license = SoftwareCommunitiesPlugin::LicenseInfo.find(context.params[:version]) context.profile.software_info.license_info = license context.profile.software_info.save! end diff --git a/src/noosfero-spb/software_communities/lib/software_database.rb b/src/noosfero-spb/software_communities/lib/software_database.rb deleted file mode 100644 index 6c7911f..0000000 --- a/src/noosfero-spb/software_communities/lib/software_database.rb +++ /dev/null @@ -1,20 +0,0 @@ -class SoftwareDatabase < ActiveRecord::Base - attr_accessible :version - - belongs_to :software_info - belongs_to :database_description - - validates_presence_of :database_description_id, :version - - validates_length_of( - :version, - :maximum => 20, - :too_long => _("Software database is too long (maximum is 20 characters)") - ) - - validates( - :database_description_id, - :numericality => {:greater_than_or_equal_to => 1} - ) - -end diff --git a/src/noosfero-spb/software_communities/lib/software_highlights_block.rb b/src/noosfero-spb/software_communities/lib/software_highlights_block.rb deleted file mode 100644 index a8b2a1c..0000000 --- a/src/noosfero-spb/software_communities/lib/software_highlights_block.rb +++ /dev/null @@ -1,20 +0,0 @@ -class SoftwareHighlightsBlock < HighlightsBlock - - def self.description - _('Software Highlights Block') - end - - def help - _('This block displays the softwares icon into a highlight') - end - - def content(args={}) - softwares = self.settings[:images].collect {|h| h[:address].split('/').last} - block = self - proc do - render :file => 'blocks/software_highlights', :locals => { :block => block, :softwares => softwares} - end - end - - -end diff --git a/src/noosfero-spb/software_communities/lib/software_info.rb b/src/noosfero-spb/software_communities/lib/software_info.rb deleted file mode 100644 index fa82ccc..0000000 --- a/src/noosfero-spb/software_communities/lib/software_info.rb +++ /dev/null @@ -1,263 +0,0 @@ -class SoftwareInfo < ActiveRecord::Base - acts_as_having_settings :field => :settings - - SEARCHABLE_SOFTWARE_FIELDS = { - :acronym => 1, - :finality => 2, - } - - SEARCHABLE_SOFTWARE_CLASSES = [ - SoftwareInfo, - Community, - ProgrammingLanguage, - DatabaseDescription - ] - - scope :search_by_query, lambda { |query = ""| - filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') - search_fields = SoftwareInfo.pg_search_plugin_fields - - if query.empty? - SoftwareInfo.joins(:community).where("profiles.visible = ?", true) - else - searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) - end - } - - def self.transform_list_in_methods_list list - methods_list = [] - - list.each do |element| - if SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym) - methods_list << element.to_s.underscore.to_sym - elsif SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym) - methods_list << element.to_s.underscore.pluralize.to_sym - end - end - - methods_list - end - - def self.pg_search_plugin_fields - SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class| - self.get_searchable_fields(one_class) - }.join(" || ' ' || ") - end - - def self.get_searchable_fields one_class - searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ") - searchable_fields - end - - SEARCH_FILTERS = { - :order => %w[], - :display => %w[full] - } - - def self.default_search_display - 'full' - end - - attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, - :operating_platform - - attr_accessible :demonstration_url, :acronym, :objectives, :features, - :license_info - - attr_accessible :community_id, :finality, :repository_link, :public_software, - :first_edit - - has_many :libraries, :dependent => :destroy - has_many :software_databases - has_many :database_descriptions, :through => :software_databases - has_many :software_languages - has_many :operating_systems - has_many :programming_languages, :through => :software_languages - has_many :operating_system_names, :through => :operating_systems - - belongs_to :community, :dependent => :destroy - belongs_to :license_info - - has_one :software_categories - - validates_length_of :finality, :maximum => 120 - validates_length_of :objectives, :maximum => 4000 - validates_length_of :features, :maximum => 4000 - validates_presence_of :finality, :community - - validate :validate_acronym - - settings_items :another_license_version, :another_license_link - - # used on find_by_contents - scope :like_search, lambda{ |name| - joins(:community).where( - "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", - "%#{name}%", "%#{name}%", "%#{name}%" - ) - } - - scope :search, lambda { |name="", database_description_id = "", - programming_language_id = "", operating_system_name_id = "", - license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "", - icp_brasil = "", e_arq = "", software_categories = "" | - - like_sql = "" - values = [] - - unless name.blank? - like_sql << "name ILIKE ? OR identifier ILIKE ? AND " - values << "%#{name}%" << "%#{name}%" - end - - like_sql = like_sql[0..like_sql.length-5] - - { - :joins => [:community], - :conditions=>[like_sql, *values] - } - } - - def license_info - license = LicenseInfo.find_by_id self.license_info_id - license_another = LicenseInfo.find_by_version("Another") - - if license_another && license.id == license_another.id - LicenseInfo.new( - :version => self.another_license_version, - :link => self.another_license_link - ) - else - license - end - end - - def another_license(version, link) - license_another = LicenseInfo.find_by_version("Another") - - if license_another - self.another_license_version = version - self.another_license_link = link - self.license_info = license_another - self.save! - end - end - - def validate_name_lenght - if self.community.name.size > 100 - self.errors.add( - :base, - _("Name is too long (maximum is %{count} characters)") - ) - false - end - true - end - - # if create_after_moderation receive a model object, would be possible to reuse core method - def self.create_after_moderation(requestor, attributes = {}) - environment = attributes.delete(:environment) - name = attributes.delete(:name) - identifier = attributes.delete(:identifier) - image_builder = attributes.delete(:image_builder) - license_info = attributes.delete(:license_info) - another_license_version = attributes.delete(:another_license_version) - another_license_link = attributes.delete(:another_license_link) - - software_info = SoftwareInfo.new(attributes) - unless environment.admins.include? requestor - CreateSoftware.create!( - attributes.merge( - :requestor => requestor, - :environment => environment, - :name => name, - :identifier => identifier, - :license_info => license_info - ) - ) - else - software_template = SoftwareHelper.software_template - - community_hash = {:name => name} - community_hash[:identifier] = identifier - community_hash[:image_builder] = image_builder if image_builder - - community = Community.new(community_hash) - community.environment = environment - - unless software_template.blank? - community.template_id = software_template.id - end - - community.save! - community.add_admin(requestor) - - software_info.community = community - software_info.license_info = license_info - software_info.save! - end - - software_info.verify_license_info(another_license_version, another_license_link) - software_info.save - software_info - end - - def verify_license_info another_license_version, another_license_link - license_another = LicenseInfo.find_by_version("Another") - - if license_another && self.license_info_id == license_another.id - version = another_license_version - link = another_license_link - - self.another_license(version, link) - end - end - - - def validate_acronym - self.acronym = "" if self.acronym.nil? - if self.acronym.length > 10 && self.errors.messages[:acronym].nil? - self.errors.add(:acronym, _("can't have more than 10 characteres")) - false - elsif self.acronym.match(/\s+/) - self.errors.add(:acronym, _("can't have whitespaces")) - false - end - true - end - - def valid_operating_systems - if self.operating_systems.empty? - self.errors.add(:operating_system, _(": at least one must be filled")) - end - end - - def valid_software_info - if self.software_languages.empty? - self.errors.add(:software_languages, _(": at least one must be filled")) - end - end - - def valid_databases - if self.software_databases.empty? - self.errors.add(:software_databases, _(": at least one must be filled")) - end - end - - def visible? - self.community.visible? - end - - def name - self.community.name - end - - def short_name - self.community.short_name - end - - def identifier - self.community.identifier - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_information_block.rb b/src/noosfero-spb/software_communities/lib/software_information_block.rb deleted file mode 100644 index a398c96..0000000 --- a/src/noosfero-spb/software_communities/lib/software_information_block.rb +++ /dev/null @@ -1,37 +0,0 @@ -class SoftwareInformationBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Basic Software Information') - end - - def help - _('This block displays the basic information of a software profile.') - end - - def content(args={}) - block = self - s = show_name - - lambda do |object| - render( - :file => 'blocks/software_information', - :locals => { :block => block, :show_name => s} - ) - end - end - - def cacheable? - false - end - - private - - def owner_has_ratings? - ratings = CommunityRating.where(community_id: block.owner.id) - !ratings.empty? - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_language.rb b/src/noosfero-spb/software_communities/lib/software_language.rb deleted file mode 100644 index 29f23c4..0000000 --- a/src/noosfero-spb/software_communities/lib/software_language.rb +++ /dev/null @@ -1,14 +0,0 @@ -class SoftwareLanguage < ActiveRecord::Base - attr_accessible :version - - belongs_to :software_info - belongs_to :programming_language - - validates_length_of( - :version, - :maximum => 20, - :too_long => _("Software language is too long (maximum is 20 characters)") - ) - - validates_presence_of :version,:programming_language -end diff --git a/src/noosfero-spb/software_communities/lib/software_language_helper.rb b/src/noosfero-spb/software_communities/lib/software_language_helper.rb index 38ba6e1..b1aeb48 100644 --- a/src/noosfero-spb/software_communities/lib/software_language_helper.rb +++ b/src/noosfero-spb/software_communities/lib/software_language_helper.rb @@ -5,7 +5,7 @@ class SoftwareLanguageHelper < DynamicTableHelper def self.valid_language? language return false if SoftwareHelper.all_table_is_empty?(language) - programming_language_id_list = ProgrammingLanguage. + programming_language_id_list = SoftwareCommunitiesPlugin::ProgrammingLanguage. select(:id). collect { |dd| dd.id } @@ -20,9 +20,9 @@ class SoftwareLanguageHelper < DynamicTableHelper new_languages.each do |new_language| if valid_language? new_language - language = SoftwareLanguage.new + language = SoftwareCommunitiesPlugin::SoftwareLanguage.new language.programming_language = - ProgrammingLanguage.find(new_language[:programming_language_id]) + SoftwareCommunitiesPlugin::ProgrammingLanguage.find(new_language[:programming_language_id]) language.version = new_language[:version] list_languages << language end @@ -52,7 +52,7 @@ class SoftwareLanguageHelper < DynamicTableHelper language_id = language_data[:programming_language_id] language_name = "" unless language_data[:programming_language_id].blank? - language_name = ProgrammingLanguage.find( + language_name = SoftwareCommunitiesPlugin::ProgrammingLanguage.find( language_data[:programming_language_id], :select=>"name" ).name diff --git a/src/noosfero-spb/software_communities/lib/software_tab_data_block.rb b/src/noosfero-spb/software_communities/lib/software_tab_data_block.rb deleted file mode 100644 index b32eeb5..0000000 --- a/src/noosfero-spb/software_communities/lib/software_tab_data_block.rb +++ /dev/null @@ -1,48 +0,0 @@ -class SoftwareTabDataBlock < Block - attr_accessible :show_name, :displayed_blog - - settings_items :show_name, :type => :boolean, :default => false - settings_items :displayed_blog, :type => :integer, :default => 0 - - TOTAL_POSTS_DYSPLAYED = 5 - - def self.description - _('Software Tab Data') - end - - def help - _('This block is used by colab to insert data into Noosfero') - end - - def content(args={}) - block = self - - lambda do |object| - render( - :file => 'blocks/software_tab_data', - :locals => { - :block => block - } - ) - end - end - - def blogs - self.owner.blogs - end - - def actual_blog - # As :displayed_blog default value is 0, it falls to the first one - blogs.find_by_id(self.displayed_blog) || blogs.first - end - - def posts - blog = actual_blog - - if blog and (not blog.posts.empty?) - blog.posts.limit(TOTAL_POSTS_DYSPLAYED) - else - [] - end - end -end diff --git a/src/noosfero-spb/software_communities/lib/softwares_block.rb b/src/noosfero-spb/software_communities/lib/softwares_block.rb deleted file mode 100644 index 067345a..0000000 --- a/src/noosfero-spb/software_communities/lib/softwares_block.rb +++ /dev/null @@ -1,105 +0,0 @@ -class SoftwaresBlock < CommunitiesBlock - - settings_items :software_type, :default => "All" - attr_accessible :accessor_id, :accessor_type, :role_id, - :resource_id, :resource_type, :software_type - - def self.description - _('Softwares') - end - - def default_title - if self.software_type == "Generic" - return n_('{#} generic software', '{#} generic softwares', profile_count) - elsif self.software_type == "Public" - return n_('{#} public software', '{#} public softwares', profile_count) - else - return n_('{#} software', '{#} softwares', profile_count) - end - end - - def help - _('This block displays the softwares in which the user is a member.') - end - - def footer - self.software_type ||= "All" - owner = self.owner - case owner - when Profile - lambda do |context| - link_to s_('softwares|View all'), :profile => owner.identifier, - :controller => 'profile', :action => 'communities', - :type => 'Software' - end - when Environment - lambda do |context| - link_to s_('softwares|View all'), :controller => 'search', - :action => 'software_infos' - end - else - '' - end - end - - def profile_count - profile_list.count - end - - def profiles - owner.communities - end - - def profile_list - profiles = get_visible_profiles - - software_profiles = profiles.select do |profile| - profile.class == Community && profile.software? - end - - block_softwares = if self.software_type == "Public" - software_profiles.select { |profile| profile.software_info.public_software? } - elsif self.software_type == "Generic" - software_profiles.select { |profile| !profile.software_info.public_software? } - else # All - software_profiles - end - - block_softwares.slice(0..get_limit-1) - end - - def content(arg={}) - if self.box.owner_type == "Environment" && self.box.position == 1 - block = self - - proc do - render :file => 'blocks/main_area_softwares', - :locals => {:profiles=> block.profile_list(), :block => block} - end - else - super(arg) - end - end - - protected - - def get_visible_profiles - profile_include_list = [:image, :domains, :preferred_domain, :environment] - visible_profiles = profiles.visible.includes(profile_include_list) - - if !prioritize_profiles_with_image - visible_profiles.all( :limit => get_limit, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - elsif profiles.visible.with_image.count >= get_limit - visible_profiles.with_image.all( :limit => get_limit * 5, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - else - visible_profiles.with_image.sort_by{ rand } + - visible_profiles.without_image.all( :limit => get_limit * 5, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - end - end -end diff --git a/src/noosfero-spb/software_communities/lib/statistic_block.rb b/src/noosfero-spb/software_communities/lib/statistic_block.rb deleted file mode 100644 index fd45f4f..0000000 --- a/src/noosfero-spb/software_communities/lib/statistic_block.rb +++ /dev/null @@ -1,52 +0,0 @@ -class StatisticBlock < Block - - settings_items :benefited_people, :type => :integer, :default => 0 - settings_items :saved_resources, :type => :float, :default => 0.0 - - attr_accessible :benefited_people, :saved_resources - - def self.description - _('Software Statistics') - end - - def help - _('This block displays software statistics.') - end - - def content(args={}) - download_blocks = get_profile_download_blocks(self.owner) - downloads = download_blocks.map do |download_block| - get_downloads_from_block(download_block) - end - - block = self - - lambda do |object| - render( - :file => 'blocks/software_statistics', - :locals => { - :block => block, - :total_downloads => downloads.sum - } - ) - end - end - - def cacheable? - false - end - - private - - def get_profile_download_blocks profile - DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id) - end - - def get_downloads_from_block download_block - downloads = download_block.downloads.map do |download| - download[:total_downloads] unless download[:total_downloads].nil? - end - downloads.select! {|value| not value.nil? } - downloads.sum - end -end diff --git a/src/noosfero-spb/software_communities/lib/tasks/create_licenses.rake b/src/noosfero-spb/software_communities/lib/tasks/create_licenses.rake index 3df7c30..bcb59ad 100644 --- a/src/noosfero-spb/software_communities/lib/tasks/create_licenses.rake +++ b/src/noosfero-spb/software_communities/lib/tasks/create_licenses.rake @@ -16,8 +16,8 @@ namespace :software do if data.length != 0 if version_or_link == 'version' - can_save = LicenseInfo.find_by_version(data) ? false : true - licence = LicenseInfo::new :version => data + can_save = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version(data) ? false : true + licence = SoftwareCommunitiesPlugin::LicenseInfo::new :version => data version_or_link = 'link' elsif version_or_link == 'link' licence.link = data diff --git a/src/noosfero-spb/software_communities/lib/tasks/create_sample_softwares.rake b/src/noosfero-spb/software_communities/lib/tasks/create_sample_softwares.rake index 1cd00cf..0259895 100644 --- a/src/noosfero-spb/software_communities/lib/tasks/create_sample_softwares.rake +++ b/src/noosfero-spb/software_communities/lib/tasks/create_sample_softwares.rake @@ -53,12 +53,12 @@ end def create_software_info(name, acronym = "", finality = "default") community = create_community(name) - software_info = SoftwareInfo.new + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new software_info.community = community software_info.public_software = true software_info.acronym = acronym software_info.finality = finality - software_info.license_info = LicenseInfo.first + software_info.license_info = SoftwareCommunitiesPlugin::LicenseInfo.first if software_info.community.valid? && software_info.valid? print "." diff --git a/src/noosfero-spb/software_communities/lib/tasks/export.rake b/src/noosfero-spb/software_communities/lib/tasks/export.rake index 224ae25..24d9523 100644 --- a/src/noosfero-spb/software_communities/lib/tasks/export.rake +++ b/src/noosfero-spb/software_communities/lib/tasks/export.rake @@ -37,7 +37,7 @@ namespace :export do "home_page_published_at" ] - SoftwareInfo.all.each do |software| + SoftwareCommunitiesPlugin::SoftwareInfo.all.each do |software| if software.community begin csv << [ @@ -104,7 +104,7 @@ namespace :export do "category_id" ] - SoftwareInfo.all.each do |software| + SoftwareCommunitiesPlugin::SoftwareInfo.all.each do |software| if software.community software.community.categories.each do |category| begin diff --git a/src/noosfero-spb/software_communities/lib/wiki_block.rb b/src/noosfero-spb/software_communities/lib/wiki_block.rb deleted file mode 100644 index 3d7da90..0000000 --- a/src/noosfero-spb/software_communities/lib/wiki_block.rb +++ /dev/null @@ -1,30 +0,0 @@ -class WikiBlock < Block - - attr_accessible :show_name, :wiki_link - settings_items :show_name, :type => :boolean, :default => false - settings_items :wiki_link, :type => :string, :default => "" - - def self.description - _('Wiki Link') - end - - def help - _('This block displays a link to the software wiki.') - end - - def content(args={}) - block = self - s = show_name - - lambda do |object| - render( - :file => 'blocks/wiki', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - true - end -end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/categories_and_tags_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/categories_and_tags_block.rb new file mode 100644 index 0000000..2b3f4e7 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/categories_and_tags_block.rb @@ -0,0 +1,29 @@ +class SoftwareCommunitiesPlugin::CategoriesAndTagsBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Categories and Tags') + end + + def help + _('This block displays the categories and tags of a software.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/categories_and_tags', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/categories_software_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/categories_software_block.rb new file mode 100644 index 0000000..cf55556 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/categories_software_block.rb @@ -0,0 +1,35 @@ +class SoftwareCommunitiesPlugin::CategoriesSoftwareBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Categories Softwares') + end + + def help + _('This block displays the categories and the amount of softwares for + each category.') + end + + def content(args={}) + block = self + s = show_name + + software_category = Category.find_by_name("Software") + categories = [] + categories = software_category.children.sort if software_category + + lambda do |object| + render( + :file => 'blocks/categories_software', + :locals => { :block => block, :show_name => s, :categories => categories } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/create_software.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/create_software.rb new file mode 100644 index 0000000..73831e4 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/create_software.rb @@ -0,0 +1,115 @@ +class SoftwareCommunitiesPlugin::CreateSoftware < Task + include Rails.application.routes.url_helpers + + validates_presence_of :requestor_id, :target_id + validates_presence_of :name, :finality + + attr_accessible :name, :finality, :repository_link, :requestor, :environment, + :reject_explanation, :license_info, :identifier, :target + + alias :environment :target + alias :environment= :target= + + DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link'] + DATA_FIELDS.each do |field| + settings_items field.to_sym + end + + def perform + software_template = SoftwareHelper.software_template + template_id = software_template.blank? ? nil : software_template.id + + identifier = self.identifier + identifier ||= self.name.to_slug + + community = Community.create!(:name => self.name, + :identifier => identifier, + :template_id => template_id) + + community.environment = self.environment + community.add_admin(self.requestor) + + software = SoftwareCommunitiesPlugin::SoftwareInfo.create!(:finality => self.finality, + :repository_link => self.repository_link, :community_id => community.id, + :license_info => self.license_info) + end + + def title + _("New software") + end + + def subject + name + end + + def information + message = _('%{requestor} wants to create software %{subject} with') + if finality.blank? + { :message => message + _(' no finality.') } + else + { :message => message + _(' this finality:%{finality}
'), + :variables => {:finality => finality} } + end + end + + def reject_details + true + end + + # tells if this request was rejected + def rejected? + self.status == Task::Status::CANCELLED + end + + # tells if this request was appoved + def approved? + self.status == Task::Status::FINISHED + end + + def target_notification_description + _('%{requestor} wants to create software %{subject}') % + {:requestor => requestor.name, :subject => subject} + end + + def target_notification_message + _("User \"%{user}\" just requested to create software %{software}. + You have to approve or reject it through the \"Pending Validations\" + section in your control panel.\n") % + { :user => self.requestor.name, :software => self.name } + end + + def task_created_message + _("Your request for registering software %{software} at %{environment} was + just sent. Environment administrator will receive it and will approve or + reject your request according to his methods and criteria. + + You will be notified as soon as environment administrator has a position + about your request.") % + { :software => self.name, :environment => self.target } + end + + def task_cancelled_message + _("Your request for registering software %{software} at %{environment} was + not approved by the environment administrator. The following explanation + was given: \n\n%{explanation}") % + { :software => self.name, + :environment => self.environment, + :explanation => self.reject_explanation } + end + + def task_finished_message + _('Your request for registering the software "%{software}" was approved. + You can access %{url} and finish the registration of your software.') % + { :software => self.name, :url => mount_url } + end + + private + + def mount_url + identifier = Community.where(:name => self.name).first.identifier + # The use of url_for doesn't allow the /social within the Public Software + # portal. That's why the url is mounted so 'hard coded' + url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community" + end + +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/database_description.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/database_description.rb new file mode 100644 index 0000000..f46fa5f --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/database_description.rb @@ -0,0 +1,15 @@ +class SoftwareCommunitiesPlugin::DatabaseDescription < ActiveRecord::Base + + SEARCHABLE_SOFTWARE_FIELDS = { + :name => 1 + } + + attr_accessible :name + + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase' + has_many :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :through => :software_databases + + validates_presence_of :name + validates_uniqueness_of :name + +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/download.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/download.rb new file mode 100644 index 0000000..de000d1 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/download.rb @@ -0,0 +1,51 @@ +#FIX ME: Turn this into a proper model(next release) +class SoftwareCommunitiesPlugin::Download + def initialize data + @name = data[:name] + @link = data[:link] + @software_description = data[:software_description] + @minimum_requirements = data[:minimum_requirements] + @size = data[:size] + + @total_downloads = if data[:total_downloads] + data[:total_downloads] + else + 0 + end + end + + def self.validate_download_list download_list + download_list.select! do |download| + not download[:name].blank? + end + + download_list.map do |download| + SoftwareCommunitiesPlugin::Download.new(download).to_hash + end + end + + def to_hash + { + :name => @name, + :link => @link, + :software_description => @software_description, + :minimum_requirements => @minimum_requirements, + :size => @size, + :total_downloads => @total_downloads + } + end + + def total_downloads= value + if value.is_a? Integer + @total_downloads = value + end + end + + def total_downloads + @total_downloads + end + + def link + @link + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/download_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/download_block.rb new file mode 100644 index 0000000..49f5239 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/download_block.rb @@ -0,0 +1,36 @@ +class SoftwareCommunitiesPlugin::DownloadBlock < Block + + attr_accessible :show_name, :downloads + + settings_items :show_name, :type => :boolean, :default => false + settings_items :downloads, :type => Array, :default => [] + + validate :download_values + + def download_values + self.downloads = SoftwareCommunitiesPlugin::Download.validate_download_list(self.downloads) + end + + def self.description + _('Download Stable Version') + end + + def help + _('This block displays the stable version of a software.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/download', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/library.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/library.rb new file mode 100644 index 0000000..126ea2a --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/library.rb @@ -0,0 +1,10 @@ +class SoftwareCommunitiesPlugin::Library < ActiveRecord::Base + attr_accessible :name, :version, :license, :software_info_id + + validates :name, :version, :license, + presence: { message: _("can't be blank") }, + length: { + maximum: 20, + too_long: _("Too long (maximum is 20 characters)") + } +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/license_info.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/license_info.rb new file mode 100644 index 0000000..2031603 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/license_info.rb @@ -0,0 +1,8 @@ +class SoftwareCommunitiesPlugin::LicenseInfo < ActiveRecord::Base + attr_accessible :version, :link + + validates_presence_of :version + + has_many :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system.rb new file mode 100644 index 0000000..ad28daa --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system.rb @@ -0,0 +1,14 @@ +class SoftwareCommunitiesPlugin::OperatingSystem < ActiveRecord::Base + attr_accessible :version + + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + belongs_to :operating_system_name, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName' + + validates :operating_system_name, presence: true + validates :version, + presence: true, + length: { + maximum: 20, + too_long: _('too long (maximum is 20 characters)') + } +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system_name.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system_name.rb new file mode 100644 index 0000000..2fcb052 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/operating_system_name.rb @@ -0,0 +1,10 @@ +class SoftwareCommunitiesPlugin::OperatingSystemName < ActiveRecord::Base + attr_accessible :name + + validates_presence_of :name + validates_uniqueness_of :name + + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem' + has_many :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :through => :operating_systems + +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/programming_language.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/programming_language.rb new file mode 100644 index 0000000..828e2d0 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/programming_language.rb @@ -0,0 +1,15 @@ +class SoftwareCommunitiesPlugin::ProgrammingLanguage < ActiveRecord::Base + + SEARCHABLE_SOFTWARE_FIELDS = { + :name => 1 + } + + attr_accessible :name + + validates_presence_of :name + validates_uniqueness_of :name + + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguages' + has_many :software_infos, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo', :through => :software_languages + +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/repository_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/repository_block.rb new file mode 100644 index 0000000..5420e0e --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/repository_block.rb @@ -0,0 +1,29 @@ +class SoftwareCommunitiesPlugin::RepositoryBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Repository Link') + end + + def help + _('This block displays the repository link of a software.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/repository', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/search_catalog_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/search_catalog_block.rb new file mode 100644 index 0000000..006cdf2 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/search_catalog_block.rb @@ -0,0 +1,29 @@ +class SoftwareCommunitiesPlugin::SearchCatalogBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Search Softwares catalog') + end + + def help + _('This block displays the search categories field ') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/search_catalog', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/software_database.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_database.rb new file mode 100644 index 0000000..a30c942 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_database.rb @@ -0,0 +1,20 @@ +class SoftwareCommunitiesPlugin::SoftwareDatabase < ActiveRecord::Base + attr_accessible :version + + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + belongs_to :database_description, :class_name => 'SoftwareCommunitiesPlugin::DatabaseDescription' + + validates_presence_of :database_description_id, :version + + validates_length_of( + :version, + :maximum => 20, + :too_long => _("Software database is too long (maximum is 20 characters)") + ) + + validates( + :database_description_id, + :numericality => {:greater_than_or_equal_to => 1} + ) + +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/software_highlights_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_highlights_block.rb new file mode 100644 index 0000000..d96b38a --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_highlights_block.rb @@ -0,0 +1,20 @@ +class SoftwareCommunitiesPlugin::SoftwareHighlightsBlock < HighlightsBlock + + def self.description + _('Software Highlights Block') + end + + def help + _('This block displays the softwares icon into a highlight') + end + + def content(args={}) + softwares = self.settings[:images].collect {|h| h[:address].split('/').last} + block = self + proc do + render :file => 'blocks/software_highlights', :locals => { :block => block, :softwares => softwares} + end + end + + +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/software_info.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_info.rb new file mode 100644 index 0000000..67a9b9e --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_info.rb @@ -0,0 +1,263 @@ +class SoftwareCommunitiesPlugin::SoftwareInfo < ActiveRecord::Base + acts_as_having_settings :field => :settings + + SEARCHABLE_SOFTWARE_FIELDS = { + :acronym => 1, + :finality => 2, + } + + SEARCHABLE_SOFTWARE_CLASSES = [ + SoftwareCommunitiesPlugin::SoftwareInfo, + Community, + SoftwareCommunitiesPlugin::ProgrammingLanguage, + SoftwareCommunitiesPlugin::DatabaseDescription + ] + + scope :search_by_query, lambda { |query = ""| + filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') + search_fields = SoftwareCommunitiesPlugin::SoftwareInfo.pg_search_plugin_fields + + if query.empty? + SoftwareCommunitiesPlugin::SoftwareInfo.joins(:community).where("profiles.visible = ?", true) + else + searchable_software_objects = SoftwareCommunitiesPlugin::SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) + includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) + end + } + + def self.transform_list_in_methods_list list + methods_list = [] + + list.each do |element| + if SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym) + methods_list << element.to_s.underscore.to_sym + elsif SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym) + methods_list << element.to_s.underscore.pluralize.to_sym + end + end + + methods_list + end + + def self.pg_search_plugin_fields + SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class| + self.get_searchable_fields(one_class) + }.join(" || ' ' || ") + end + + def self.get_searchable_fields one_class + searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ") + searchable_fields + end + + SEARCH_FILTERS = { + :order => %w[], + :display => %w[full] + } + + def self.default_search_display + 'full' + end + + attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, + :operating_platform + + attr_accessible :demonstration_url, :acronym, :objectives, :features, + :license_info + + attr_accessible :community_id, :finality, :repository_link, :public_software, + :first_edit + + has_many :libraries, :dependent => :destroy, :class_name => 'SoftwareCommunitiesPlugin::Library' + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase' + has_many :database_descriptions, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabaseDescription', :through => :software_databases + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguage' + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem' + has_many :programming_languages, :class_name => 'SoftwareCommunitiesPlugin::ProgrammingLanguage', :through => :software_languages + has_many :operating_system_names, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName', :through => :operating_systems + + belongs_to :community, :dependent => :destroy + belongs_to :license_info, :class_name => 'SoftwareCommunitiesPlugin::LicenseInfo' + + has_one :software_categories + + validates_length_of :finality, :maximum => 120 + validates_length_of :objectives, :maximum => 4000 + validates_length_of :features, :maximum => 4000 + validates_presence_of :finality, :community + + validate :validate_acronym + + settings_items :another_license_version, :another_license_link + + # used on find_by_contents + scope :like_search, lambda{ |name| + joins(:community).where( + "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", + "%#{name}%", "%#{name}%", "%#{name}%" + ) + } + + scope :search, lambda { |name="", database_description_id = "", + programming_language_id = "", operating_system_name_id = "", + license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "", + icp_brasil = "", e_arq = "", software_categories = "" | + + like_sql = "" + values = [] + + unless name.blank? + like_sql << "name ILIKE ? OR identifier ILIKE ? AND " + values << "%#{name}%" << "%#{name}%" + end + + like_sql = like_sql[0..like_sql.length-5] + + { + :joins => [:community], + :conditions=>[like_sql, *values] + } + } + + def license_info + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_id self.license_info_id + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") + + if license_another && license.id == license_another.id + SoftwareCommunitiesPlugin::LicenseInfo.new( + :version => self.another_license_version, + :link => self.another_license_link + ) + else + license + end + end + + def another_license(version, link) + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") + + if license_another + self.another_license_version = version + self.another_license_link = link + self.license_info = license_another + self.save! + end + end + + def validate_name_lenght + if self.community.name.size > 100 + self.errors.add( + :base, + _("Name is too long (maximum is %{count} characters)") + ) + false + end + true + end + + # if create_after_moderation receive a model object, would be possible to reuse core method + def self.create_after_moderation(requestor, attributes = {}) + environment = attributes.delete(:environment) + name = attributes.delete(:name) + identifier = attributes.delete(:identifier) + image_builder = attributes.delete(:image_builder) + license_info = attributes.delete(:license_info) + another_license_version = attributes.delete(:another_license_version) + another_license_link = attributes.delete(:another_license_link) + + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(attributes) + unless environment.admins.include? requestor + CreateSoftware.create!( + attributes.merge( + :requestor => requestor, + :environment => environment, + :name => name, + :identifier => identifier, + :license_info => license_info + ) + ) + else + software_template = SoftwareHelper.software_template + + community_hash = {:name => name} + community_hash[:identifier] = identifier + community_hash[:image_builder] = image_builder if image_builder + + community = Community.new(community_hash) + community.environment = environment + + unless software_template.blank? + community.template_id = software_template.id + end + + community.save! + community.add_admin(requestor) + + software_info.community = community + software_info.license_info = license_info + software_info.save! + end + + software_info.verify_license_info(another_license_version, another_license_link) + software_info.save + software_info + end + + def verify_license_info another_license_version, another_license_link + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") + + if license_another && self.license_info_id == license_another.id + version = another_license_version + link = another_license_link + + self.another_license(version, link) + end + end + + + def validate_acronym + self.acronym = "" if self.acronym.nil? + if self.acronym.length > 10 && self.errors.messages[:acronym].nil? + self.errors.add(:acronym, _("can't have more than 10 characteres")) + false + elsif self.acronym.match(/\s+/) + self.errors.add(:acronym, _("can't have whitespaces")) + false + end + true + end + + def valid_operating_systems + if self.operating_systems.empty? + self.errors.add(:operating_system, _(": at least one must be filled")) + end + end + + def valid_software_info + if self.software_languages.empty? + self.errors.add(:software_languages, _(": at least one must be filled")) + end + end + + def valid_databases + if self.software_databases.empty? + self.errors.add(:software_databases, _(": at least one must be filled")) + end + end + + def visible? + self.community.visible? + end + + def name + self.community.name + end + + def short_name + self.community.short_name + end + + def identifier + self.community.identifier + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/software_information_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_information_block.rb new file mode 100644 index 0000000..64ce2bb --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_information_block.rb @@ -0,0 +1,37 @@ +class SoftwareCommunitiesPlugin::SoftwareInformationBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Basic Software Information') + end + + def help + _('This block displays the basic information of a software profile.') + end + + def content(args={}) + block = self + s = show_name + + lambda do |object| + render( + :file => 'blocks/software_information', + :locals => { :block => block, :show_name => s} + ) + end + end + + def cacheable? + false + end + + private + + def owner_has_ratings? + ratings = CommunityRating.where(community_id: block.owner.id) + !ratings.empty? + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/software_language.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_language.rb new file mode 100644 index 0000000..1db2e11 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_language.rb @@ -0,0 +1,14 @@ +class SoftwareCommunitiesPlugin::SoftwareLanguage < ActiveRecord::Base + attr_accessible :version + + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + belongs_to :programming_language, :class_name => 'SoftwareCommunitiesPlugin::ProgrammingLanguage' + + validates_length_of( + :version, + :maximum => 20, + :too_long => _("Software language is too long (maximum is 20 characters)") + ) + + validates_presence_of :version,:programming_language +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/software_tab_data_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_tab_data_block.rb new file mode 100644 index 0000000..cc4eeb1 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/software_tab_data_block.rb @@ -0,0 +1,48 @@ +class SoftwareCommunitiesPlugin::SoftwareTabDataBlock < Block + attr_accessible :show_name, :displayed_blog + + settings_items :show_name, :type => :boolean, :default => false + settings_items :displayed_blog, :type => :integer, :default => 0 + + TOTAL_POSTS_DYSPLAYED = 5 + + def self.description + _('Software Tab Data') + end + + def help + _('This block is used by colab to insert data into Noosfero') + end + + def content(args={}) + block = self + + lambda do |object| + render( + :file => 'blocks/software_tab_data', + :locals => { + :block => block + } + ) + end + end + + def blogs + self.owner.blogs + end + + def actual_blog + # As :displayed_blog default value is 0, it falls to the first one + blogs.find_by_id(self.displayed_blog) || blogs.first + end + + def posts + blog = actual_blog + + if blog and (not blog.posts.empty?) + blog.posts.limit(TOTAL_POSTS_DYSPLAYED) + else + [] + end + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/softwares_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/softwares_block.rb new file mode 100644 index 0000000..0c0a910 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/softwares_block.rb @@ -0,0 +1,105 @@ +class SoftwareCommunitiesPlugin::SoftwaresBlock < CommunitiesBlock + + settings_items :software_type, :default => "All" + attr_accessible :accessor_id, :accessor_type, :role_id, + :resource_id, :resource_type, :software_type + + def self.description + _('Softwares') + end + + def default_title + if self.software_type == "Generic" + return n_('{#} generic software', '{#} generic softwares', profile_count) + elsif self.software_type == "Public" + return n_('{#} public software', '{#} public softwares', profile_count) + else + return n_('{#} software', '{#} softwares', profile_count) + end + end + + def help + _('This block displays the softwares in which the user is a member.') + end + + def footer + self.software_type ||= "All" + owner = self.owner + case owner + when Profile + lambda do |context| + link_to s_('softwares|View all'), :profile => owner.identifier, + :controller => 'profile', :action => 'communities', + :type => 'Software' + end + when Environment + lambda do |context| + link_to s_('softwares|View all'), :controller => 'search', + :action => 'software_infos' + end + else + '' + end + end + + def profile_count + profile_list.count + end + + def profiles + owner.communities + end + + def profile_list + profiles = get_visible_profiles + + software_profiles = profiles.select do |profile| + profile.class == Community && profile.software? + end + + block_softwares = if self.software_type == "Public" + software_profiles.select { |profile| profile.software_info.public_software? } + elsif self.software_type == "Generic" + software_profiles.select { |profile| !profile.software_info.public_software? } + else # All + software_profiles + end + + block_softwares.slice(0..get_limit-1) + end + + def content(arg={}) + if self.box.owner_type == "Environment" && self.box.position == 1 + block = self + + proc do + render :file => 'blocks/main_area_softwares', + :locals => {:profiles=> block.profile_list(), :block => block} + end + else + super(arg) + end + end + + protected + + def get_visible_profiles + profile_include_list = [:image, :domains, :preferred_domain, :environment] + visible_profiles = profiles.visible.includes(profile_include_list) + + if !prioritize_profiles_with_image + visible_profiles.all( :limit => get_limit, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + elsif profiles.visible.with_image.count >= get_limit + visible_profiles.with_image.all( :limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + else + visible_profiles.with_image.sort_by{ rand } + + visible_profiles.without_image.all( :limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + end + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/statistic_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/statistic_block.rb new file mode 100644 index 0000000..73a0dcd --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/statistic_block.rb @@ -0,0 +1,52 @@ +class SoftwareCommunitiesPlugin::StatisticBlock < Block + + settings_items :benefited_people, :type => :integer, :default => 0 + settings_items :saved_resources, :type => :float, :default => 0.0 + + attr_accessible :benefited_people, :saved_resources + + def self.description + _('Software Statistics') + end + + def help + _('This block displays software statistics.') + end + + def content(args={}) + download_blocks = get_profile_download_blocks(self.owner) + downloads = download_blocks.map do |download_block| + get_downloads_from_block(download_block) + end + + block = self + + lambda do |object| + render( + :file => 'blocks/software_statistics', + :locals => { + :block => block, + :total_downloads => downloads.sum + } + ) + end + end + + def cacheable? + false + end + + private + + def get_profile_download_blocks profile + SoftwareCommunitiesPlugin::DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id) + end + + def get_downloads_from_block download_block + downloads = download_block.downloads.map do |download| + download[:total_downloads] unless download[:total_downloads].nil? + end + downloads.select! {|value| not value.nil? } + downloads.sum + end +end diff --git a/src/noosfero-spb/software_communities/models/software_communities_plugin/wiki_block.rb b/src/noosfero-spb/software_communities/models/software_communities_plugin/wiki_block.rb new file mode 100644 index 0000000..9b55083 --- /dev/null +++ b/src/noosfero-spb/software_communities/models/software_communities_plugin/wiki_block.rb @@ -0,0 +1,30 @@ +class SoftwareCommunitiesPlugin::WikiBlock < Block + + attr_accessible :show_name, :wiki_link + settings_items :show_name, :type => :boolean, :default => false + settings_items :wiki_link, :type => :string, :default => "" + + def self.description + _('Wiki Link') + end + + def help + _('This block displays a link to the software wiki.') + end + + def content(args={}) + block = self + s = show_name + + lambda do |object| + render( + :file => 'blocks/wiki', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + true + end +end diff --git a/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb index b677a1d..d05d7a0 100644 --- a/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb @@ -58,7 +58,7 @@ class ProfileEditorControllerTest < ActionController::TestCase def create_software_info name, finality = "something", acronym = "" community = create_community(name) - software_info = SoftwareInfo.new + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new software_info.community = community software_info.finality = finality software_info.acronym = acronym diff --git a/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb index 606337d..1141158 100644 --- a/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb @@ -21,8 +21,8 @@ class SearchControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new @licenses = [ - LicenseInfo.create(:version => "GPL - 1"), - LicenseInfo.create(:version => "GPL - 2") + SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "GPL - 1"), + SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "GPL - 2") ] create_software_categories @@ -145,7 +145,7 @@ class SearchControllerTest < ActionController::TestCase should "software_infos search by relevance" do @softwares << create_software_info("Software Three", :acronym => "SFW", :finality => "Java") - @softwares.last.license_info = LicenseInfo.create :version => "GPL - 3.0" + @softwares.last.license_info = SoftwareCommunitiesPlugin::LicenseInfo.create :version => "GPL - 3.0" @softwares.first.software_languages << create_software_language("Java", "8.0") @@ -215,8 +215,8 @@ class SearchControllerTest < ActionController::TestCase end should "software_infos search return only enabled softwares" do - s1 = SoftwareInfo.first - s2 = SoftwareInfo.last + s1 = SoftwareCommunitiesPlugin::SoftwareInfo.first + s2 = SoftwareCommunitiesPlugin::SoftwareInfo.last # First get them all normally get( @@ -276,12 +276,12 @@ class SearchControllerTest < ActionController::TestCase end def create_software_language(name, version) - unless ProgrammingLanguage.find_by_name(name) - ProgrammingLanguage.create(:name => name) + unless SoftwareCommunitiesPlugin::ProgrammingLanguage.find_by_name(name) + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name => name) end - software_language = SoftwareLanguage.new - software_language.programming_language = ProgrammingLanguage.find_by_name(name) + software_language = SoftwareCommunitiesPlugin::SoftwareLanguage.new + software_language.programming_language = SoftwareCommunitiesPlugin::ProgrammingLanguage.find_by_name(name) software_language.version = version software_language.save! @@ -289,12 +289,12 @@ class SearchControllerTest < ActionController::TestCase end def create_software_database(name, version) - unless DatabaseDescription.find_by_name(name) - DatabaseDescription.create(:name => name) + unless SoftwareCommunitiesPlugin::DatabaseDescription.find_by_name(name) + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => name) end - software_database = SoftwareDatabase.new - software_database.database_description = DatabaseDescription.find_by_name(name) + software_database = SoftwareCommunitiesPlugin::SoftwareDatabase.new + software_database.database_description = SoftwareCommunitiesPlugin::DatabaseDescription.find_by_name(name) software_database.version = version software_database.save! diff --git a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_controller_test.rb index 78ae2e0..043b74d 100644 --- a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_controller_test.rb @@ -14,20 +14,20 @@ class SoftwareCommunitiesPluginControllerTest < ActionController::TestCase @environment.add_admin(@admin) @environment.save - LicenseInfo.create(:version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt") - 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") - LicenseInfo.create(:version=>"Apache License 2.0 (Apache-2.0)", :link=>"http://www.apache.org/licenses/LICENSE-2.0") - LicenseInfo.create(:version=>'BSD 2-Clause "Simplified" or "FreeBSD" License (BSD-2-Clause)', :link=>"http://opensource.org/licenses/BSD-2-Clause") - - ProgrammingLanguage.create(:name =>"Java") - ProgrammingLanguage.create(:name =>"Ruby") - ProgrammingLanguage.create(:name =>"C") - ProgrammingLanguage.create(:name =>"C++") - DatabaseDescription.create(:name => "PostgreSQL") - DatabaseDescription.create(:name => "MySQL") - DatabaseDescription.create(:name => "MongoDB") - DatabaseDescription.create(:name => "Oracle") - OperatingSystemName.create(:name=>"Debian") + SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt") + 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") + SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>"Apache License 2.0 (Apache-2.0)", :link=>"http://www.apache.org/licenses/LICENSE-2.0") + SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>'BSD 2-Clause "Simplified" or "FreeBSD" License (BSD-2-Clause)', :link=>"http://opensource.org/licenses/BSD-2-Clause") + + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"Java") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"Ruby") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"C") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"C++") + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "PostgreSQL") + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "MySQL") + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "MongoDB") + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "Oracle") + SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Debian") @response = ActionController::TestResponse.new end diff --git a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb index f6e2e8e..4cafe32 100644 --- a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb @@ -19,14 +19,14 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC @offer_1 = create_user('Ana de Souza') @offer_2 = create_user('Angelo Roberto') - LicenseInfo.create( + SoftwareCommunitiesPlugin::LicenseInfo.create( :version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" ) - ProgrammingLanguage.create(:name =>"language") - DatabaseDescription.create(:name => "database") - OperatingSystemName.create(:name=>"Debian") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name =>"language") + SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "database") + SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Debian") login_as(@person.user_login) @environment = Environment.default @@ -54,7 +54,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :license => fields[0], :software_info => fields[2] ) - assert_equal SoftwareInfo.last.community.name, "Debian" + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.community.name, "Debian" end should 'edit a new software adding basic information' do @@ -72,7 +72,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :language => {}, :database => {} ) - assert_equal SoftwareInfo.last.repository_link, "www.github.com/test" + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.repository_link, "www.github.com/test" end should 'edit a new software adding specific information' do @@ -90,7 +90,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :software => fields[4], :license => fields[5] ) - assert_equal SoftwareInfo.last.acronym, "test" + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.acronym, "test" end should 'upgrade a generic software to a public software' do @@ -111,7 +111,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :license => fields[5] ) - assert_equal true, SoftwareInfo.last.public_software? + assert_equal true, SoftwareCommunitiesPlugin::SoftwareInfo.last.public_software? end should "create software_info with existing license_info" do @@ -121,15 +121,15 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :new_software, :community => {:name =>"New Software", :identifier => "new-software"}, :software_info => {:finality => "something", :repository_link => ""}, - :license =>{:license_infos_id => LicenseInfo.last.id}, + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id}, :profile => @person.identifier ) - assert_equal SoftwareInfo.last.license_info, LicenseInfo.last + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info, SoftwareCommunitiesPlugin::LicenseInfo.last end should "create software_info with 'Another' license_info" do - license_another = LicenseInfo.create(:version => "Another", :link => "#") + license_another = SoftwareCommunitiesPlugin::LicenseInfo.create(:version => "Another", :link => "#") @environment.add_admin(@person) another_license_version = "Different License" @@ -146,10 +146,10 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :profile => @person.identifier ) - assert_equal SoftwareInfo.last.license_info_id, license_another.id - assert_equal SoftwareInfo.last.license_info.id, nil - assert_equal SoftwareInfo.last.license_info.version, another_license_version - assert_equal SoftwareInfo.last.license_info.link, another_license_link + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info_id, license_another.id + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info.id, nil + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info.version, another_license_version + assert_equal SoftwareCommunitiesPlugin::SoftwareInfo.last.license_info.link, another_license_link end should "show error messages on create software_info" do @@ -173,14 +173,14 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :new_software, :community => {:name =>"New Software", :identifier => "new-software"}, :software_info => {:finality => "something", :repository_link => ""}, - :license =>{:license_infos_id => LicenseInfo.last.id}, + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id}, :profile => @person.identifier ) post( :new_software, :community => {:name =>"New Software", :identifier => "new-software"}, :software_info => {:finality => "something", :repository_link => ""}, - :license =>{:license_infos_id => LicenseInfo.last.id}, + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id}, :profile => @person.identifier ) @@ -194,7 +194,7 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC :new_software, :community => {:name =>"New Software", :identifier => "new-software"}, :software_info => {:finality => "something", :repository_link => ""}, - :license =>{:license_infos_id => LicenseInfo.last.id}, + :license =>{:license_infos_id => SoftwareCommunitiesPlugin::LicenseInfo.last.id}, :profile => @person.identifier ) @@ -202,6 +202,6 @@ class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestC Task.last.send('finish', @person) assert_equal "New Software", Task.last.data[:name] - assert_equal "New Software", SoftwareInfo.last.community.name + assert_equal "New Software", SoftwareCommunitiesPlugin::SoftwareInfo.last.community.name end end diff --git a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_profile_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_profile_controller_test.rb index 00c715e..936b5b6 100644 --- a/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_profile_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/software_communities_plugin_profile_controller_test.rb @@ -16,7 +16,7 @@ class SoftwareCommunitiesPluginProfileControllerTest < ActionController::TestCas @environment.enable_plugin('SoftwareCommunitiesPlugin') @environment.save! - LicenseInfo.create( + SoftwareCommunitiesPlugin::LicenseInfo.create( :version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" ) @@ -32,8 +32,8 @@ class SoftwareCommunitiesPluginProfileControllerTest < ActionController::TestCas @software = create_software(software_fields) @software.save! - download_block = DownloadBlock.new - download_block.downloads = Download.validate_download_list([@download_data]) + download_block = SoftwareCommunitiesPlugin::DownloadBlock.new + download_block.downloads = SoftwareCommunitiesPlugin::Download.validate_download_list([@download_data]) download_block.save! @software.community.blocks << download_block @@ -41,7 +41,7 @@ class SoftwareCommunitiesPluginProfileControllerTest < ActionController::TestCas end should 'redirect to download link with correct params' do - download_block = DownloadBlock.last + download_block = SoftwareCommunitiesPlugin::DownloadBlock.last get :download_file, :profile=>@software.community.identifier, :block => download_block.id, :download_index => 0 @@ -50,7 +50,7 @@ class SoftwareCommunitiesPluginProfileControllerTest < ActionController::TestCas end should "notice when the download was not found" do - download_block = DownloadBlock.last + download_block = SoftwareCommunitiesPlugin::DownloadBlock.last get :download_file, :profile=>@software.community.identifier, :block => 123, :download_index => 0 @@ -58,7 +58,7 @@ class SoftwareCommunitiesPluginProfileControllerTest < ActionController::TestCas end should "notice when given invalid download params" do - download_block = DownloadBlock.last + download_block = SoftwareCommunitiesPlugin::DownloadBlock.last get :download_file, :profile=>@software.community.identifier, :block => download_block.id, :download_index => -5 diff --git a/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb b/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb index d7458ce..4770a2c 100644 --- a/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb +++ b/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb @@ -10,7 +10,7 @@ module PluginTestHelper def create_software_info name, finality = "something", acronym = "" community = create_community(name) - software_info = SoftwareInfo.new + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new software_info.community = community software_info.finality = finality software_info.acronym = acronym @@ -55,7 +55,7 @@ module PluginTestHelper end def create_license_info version, link = "" - license = LicenseInfo.create(:version => version) + license = SoftwareCommunitiesPlugin::LicenseInfo.create(:version => version) license.link = link license.save diff --git a/src/noosfero-spb/software_communities/test/helpers/software_test_helper.rb b/src/noosfero-spb/software_communities/test/helpers/software_test_helper.rb index 285fd27..724645e 100644 --- a/src/noosfero-spb/software_communities/test/helpers/software_test_helper.rb +++ b/src/noosfero-spb/software_communities/test/helpers/software_test_helper.rb @@ -1,7 +1,7 @@ module SoftwareTestHelper def create_language language_fields - language = SoftwareLanguage.new + language = SoftwareCommunitiesPlugin::SoftwareLanguage.new language_fields[0].each do |k,v| language[k] = v @@ -12,7 +12,7 @@ module SoftwareTestHelper def create_database database_fields - database = SoftwareDatabase.new + database = SoftwareCommunitiesPlugin::SoftwareDatabase.new database_fields[0].each do |k,v| database[k] = v @@ -23,7 +23,7 @@ module SoftwareTestHelper end def create_library library_fields - library = Library.new + library = SoftwareCommunitiesPlugin::Library.new library_fields[0].each do |k,v| library[k] = v @@ -33,7 +33,7 @@ module SoftwareTestHelper end def create_operating_system operating_system_hash - operating_system = OperatingSystem.new + operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new operating_system_hash[0].each do |k,v| operating_system[k] = v @@ -43,7 +43,7 @@ module SoftwareTestHelper end def create_license license_hash - license_info = LicenseInfo.new + license_info = SoftwareCommunitiesPlugin::LicenseInfo.new license_hash.each do |k,v| license_info[k] = v @@ -64,7 +64,7 @@ module SoftwareTestHelper def create_software fields - software = SoftwareInfo.new + software = SoftwareCommunitiesPlugin::SoftwareInfo.new community = Community.new software_hash = fields[2] license_system_hash = fields[0] @@ -97,7 +97,7 @@ module SoftwareTestHelper hash_list << fields #Fields for license info - fields_license['license_infos_id'] = LicenseInfo.last.id + fields_license['license_infos_id'] = SoftwareCommunitiesPlugin::LicenseInfo.last.id hash_list << fields_license hash_list @@ -128,7 +128,7 @@ module SoftwareTestHelper #Fields for software language fields_language['version'] = 'test' - fields_language['programming_language_id'] = ProgrammingLanguage.last.id + fields_language['programming_language_id'] = SoftwareCommunitiesPlugin::ProgrammingLanguage.last.id fields_language['operating_system'] = 'test' list_language << fields_language list_language << {} @@ -136,7 +136,7 @@ module SoftwareTestHelper #Fields for database fields_database['version'] = 'test' - fields_database['database_description_id'] = DatabaseDescription.last.id + fields_database['database_description_id'] = SoftwareCommunitiesPlugin::DatabaseDescription.last.id fields_database['operating_system'] = 'test' list_database << fields_database list_database << {} @@ -144,7 +144,7 @@ module SoftwareTestHelper #Fields for operating system fields_operating_system['version'] = 'version' - fields_operating_system['operating_system_name_id'] = OperatingSystemName.last.id + fields_operating_system['operating_system_name_id'] = SoftwareCommunitiesPlugin::OperatingSystemName.last.id list_operating_system << fields_operating_system list_operating_system << {} hash_list << list_operating_system @@ -158,7 +158,7 @@ module SoftwareTestHelper hash_list << fields_software #Fields for license - fields_license['license_infos_id'] = LicenseInfo.last.id + fields_license['license_infos_id'] = SoftwareCommunitiesPlugin::LicenseInfo.last.id hash_list << fields_license hash_list @@ -169,7 +169,7 @@ module SoftwareTestHelper #Fields for license info fields_license = { - license_infos_id: LicenseInfo.last.id + license_infos_id: SoftwareCommunitiesPlugin::LicenseInfo.last.id } hash_list << fields_license @@ -189,5 +189,5 @@ module SoftwareTestHelper hash_list end end -#version: LicenseInfo.last.version, -#id: LicenseInfo.last.id \ No newline at end of file +#version: SoftwareCommunitiesPlugin::LicenseInfo.last.version, +#id: SoftwareCommunitiesPlugin::LicenseInfo.last.id \ No newline at end of file diff --git a/src/noosfero-spb/software_communities/test/unit/categories_and_tags_block_test.rb b/src/noosfero-spb/software_communities/test/unit/categories_and_tags_block_test.rb index a7e0bef..2359ad9 100644 --- a/src/noosfero-spb/software_communities/test/unit/categories_and_tags_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/categories_and_tags_block_test.rb @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' class CategoriesAndTagsBlockTest < ActiveSupport::TestCase include PluginTestHelper should 'inherit from Block' do - assert_kind_of Block, CategoriesAndTagsBlock.new + assert_kind_of Block, SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.new end should 'declare its default title' do - CategoriesAndTagsBlock.any_instance.stubs(:profile_count).returns(0) - assert_equal Block.new.default_title, CategoriesAndTagsBlock.new.default_title + SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.any_instance.stubs(:profile_count).returns(0) + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.new.default_title end should 'describe itself' do - assert_not_equal Block.description, CategoriesAndTagsBlock.description + assert_not_equal Block.description, SoftwareCommunitiesPlugin::CategoriesAndTagsBlock.description end end diff --git a/src/noosfero-spb/software_communities/test/unit/categories_software_block_test.rb b/src/noosfero-spb/software_communities/test/unit/categories_software_block_test.rb index b02f9b4..979ee52 100644 --- a/src/noosfero-spb/software_communities/test/unit/categories_software_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/categories_software_block_test.rb @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' class CategoriesSoftwareBlockTest < ActiveSupport::TestCase include PluginTestHelper should 'inherit from Block' do - assert_kind_of Block, CategoriesSoftwareBlock.new + assert_kind_of Block, SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.new end should 'declare its default title' do - CategoriesSoftwareBlock.any_instance.stubs(:profile_count).returns(0) - assert_equal Block.new.default_title, CategoriesSoftwareBlock.new.default_title + SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.any_instance.stubs(:profile_count).returns(0) + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.new.default_title end should 'describe itself' do - assert_not_equal Block.description, CategoriesSoftwareBlock.description + assert_not_equal Block.description, SoftwareCommunitiesPlugin::CategoriesSoftwareBlock.description end end diff --git a/src/noosfero-spb/software_communities/test/unit/create_software_test.rb b/src/noosfero-spb/software_communities/test/unit/create_software_test.rb index 75e8af6..460018b 100644 --- a/src/noosfero-spb/software_communities/test/unit/create_software_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/create_software_test.rb @@ -7,11 +7,11 @@ class CreateSoftwareTest < ActiveSupport::TestCase end should 'be a task' do - ok { CreateSoftware.new.kind_of?(Task) } + ok { SoftwareCommunitiesPlugin::CreateSoftware.new.kind_of?(Task) } end should 'require a requestor' do - task = CreateSoftware.new(:name => 'Software Test', :target => Environment.default) + task = SoftwareCommunitiesPlugin::CreateSoftware.new(:name => 'Software Test', :target => Environment.default) task.valid? assert task.errors[:requestor_id.to_s].present? @@ -24,9 +24,9 @@ class CreateSoftwareTest < ActiveSupport::TestCase end should 'actually create new software community when confirmed' do - task = CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any") + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any") - assert_difference 'SoftwareInfo.count' do + assert_difference 'SoftwareCommunitiesPlugin::SoftwareInfo.count' do assert_difference 'Community.count' do task.finish end @@ -36,7 +36,7 @@ class CreateSoftwareTest < ActiveSupport::TestCase end should 'create new software community with all informed data when confirmed' do - task = CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any", :repository_link => "#", ) + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any", :repository_link => "#", ) task.finish software = Community["software-test"].software_info @@ -47,7 +47,7 @@ class CreateSoftwareTest < ActiveSupport::TestCase end should 'override message methods from Task' do - task = CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any") + task = SoftwareCommunitiesPlugin::CreateSoftware.create!(:name => 'Software Test', :target => Environment.default, :requestor => @requestor, :finality => "Any") task.finish @@ -59,13 +59,13 @@ class CreateSoftwareTest < ActiveSupport::TestCase end should 'report as approved when approved' do - request = CreateSoftware.new + request = SoftwareCommunitiesPlugin::CreateSoftware.new request.stubs(:status).returns(Task::Status::FINISHED) assert request.approved? end should 'report as rejected when rejected' do - request = CreateSoftware.new + request = SoftwareCommunitiesPlugin::CreateSoftware.new request.stubs(:status).returns(Task::Status::CANCELLED) assert request.rejected? end diff --git a/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb index d7f2444..7a90900 100644 --- a/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class DatabaseHelperTest < ActiveSupport::TestCase def setup - dd1 = DatabaseDescription.create(:name => "Oracle") - dd2 = DatabaseDescription.create!(:name => "MySQL") + dd1 = SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "Oracle") + dd2 = SoftwareCommunitiesPlugin::DatabaseDescription.create!(:name => "MySQL") @database_objects = [ {:database_description_id => dd1.id.to_s ,:version => "2.0"}, @@ -14,8 +14,8 @@ class DatabaseHelperTest < ActiveSupport::TestCase def teardown @database_objects = nil - SoftwareDatabase.destroy_all - DatabaseDescription.destroy_all + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all end should "return an empty list" do diff --git a/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb index 5466779..abfa634 100644 --- a/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class DatabaseValidationTest < ActiveSupport::TestCase def setup - @database_desc = DatabaseDescription.create(:name => "ABC") - @database = SoftwareDatabase.new + @database_desc = SoftwareCommunitiesPlugin::DatabaseDescription.create(:name => "ABC") + @database = SoftwareCommunitiesPlugin::SoftwareDatabase.new @database.database_description = @database_desc @database.version = "MYSQL" @database @@ -12,8 +12,8 @@ class DatabaseValidationTest < ActiveSupport::TestCase def teardown @database = nil - DatabaseDescription.destroy_all - SoftwareDatabase.destroy_all + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all end should "Save database if all fields are filled" do diff --git a/src/noosfero-spb/software_communities/test/unit/download_block_test.rb b/src/noosfero-spb/software_communities/test/unit/download_block_test.rb index adfcdd3..846d213 100644 --- a/src/noosfero-spb/software_communities/test/unit/download_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/download_block_test.rb @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' class DownloadBlockTest < ActiveSupport::TestCase include PluginTestHelper should 'inherit from Block' do - assert_kind_of Block, DownloadBlock.new + assert_kind_of Block, SoftwareCommunitiesPlugin::DownloadBlock.new end should 'declare its default title' do - DownloadBlock.any_instance.stubs(:profile_count).returns(0) - assert_equal Block.new.default_title, DownloadBlock.new.default_title + SoftwareCommunitiesPlugin::DownloadBlock.any_instance.stubs(:profile_count).returns(0) + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::DownloadBlock.new.default_title end should 'describe itself' do - assert_not_equal Block.description, DownloadBlock.description + assert_not_equal Block.description, SoftwareCommunitiesPlugin::DownloadBlock.description end should 'have software info to download it' do @@ -24,7 +24,7 @@ class DownloadBlockTest < ActiveSupport::TestCase link2 = "gitlab.com/teste/2" name2 = "Test Software2" - block = DownloadBlock.create(:downloads => [{:name => name1, :link => link1}, {:name => name2, :link => link2}]) + block = SoftwareCommunitiesPlugin::DownloadBlock.create(:downloads => [{:name => name1, :link => link1}, {:name => name2, :link => link2}]) assert_equal block.downloads[0][:link], link1, "Link should not be empty" assert_equal block.downloads[0][:name], name1, "Name should not be empty" diff --git a/src/noosfero-spb/software_communities/test/unit/download_test.rb b/src/noosfero-spb/software_communities/test/unit/download_test.rb index 4b301fd..570e0cc 100644 --- a/src/noosfero-spb/software_communities/test/unit/download_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/download_test.rb @@ -26,8 +26,8 @@ class DownloadTest < ActiveSupport::TestCase end should "Set as 0(zero) total_downloads if it is not given" do - without_total_downloads = Download.new({}) - with_total_downloads = Download.new(@downloads_sample_data.last) + without_total_downloads = SoftwareCommunitiesPlugin::Download.new({}) + with_total_downloads = SoftwareCommunitiesPlugin::Download.new(@downloads_sample_data.last) assert_equal 0, without_total_downloads.total_downloads assert_equal @downloads_sample_data.last[:total_downloads], with_total_downloads.total_downloads @@ -35,14 +35,14 @@ class DownloadTest < ActiveSupport::TestCase should "Remove downloads without a name" do @downloads_sample_data[1] = @downloads_sample_data[1].slice! :name - downloads = Download.validate_download_list @downloads_sample_data + downloads = SoftwareCommunitiesPlugin::Download.validate_download_list @downloads_sample_data assert_equal 1, downloads.size assert_equal @downloads_sample_data[0][:name], downloads[0][:name] end should "Only set total_downloads if the value is integer" do - download = Download.new(@downloads_sample_data.last) + download = SoftwareCommunitiesPlugin::Download.new(@downloads_sample_data.last) download.total_downloads = "456" assert_not_equal 456, download.total_downloads diff --git a/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb index 28e58e3..d4d5e9f 100644 --- a/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb @@ -42,7 +42,7 @@ class LibraryHelperTest < ActiveSupport::TestCase should "return a html text with license name equals to linux" do libraries = [] - library_description = Library.new + library_description = SoftwareCommunitiesPlugin::Library.new library_description.name = "Lib" libraries << library_description diff --git a/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb index f45cc9e..d56da08 100644 --- a/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class LibraryValidationTest < ActiveSupport::TestCase def setup - @library = Library.new + @library = SoftwareCommunitiesPlugin::Library.new @library.name = "name" @library.version = "version" @library.license = "license" diff --git a/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb index 8b2e506..62ad432 100644 --- a/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb @@ -1,8 +1,8 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' -OperatingSystemName.create(:name=>"Debina") -OperatingSystemName.create(:name=>"Fedora") -OperatingSystemName.create(:name=>"CentOS") +SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Debina") +SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"Fedora") +SoftwareCommunitiesPlugin::OperatingSystemName.create(:name=>"CentOS") class OperatingSystemHelperTest < ActiveSupport::TestCase @@ -49,16 +49,16 @@ class OperatingSystemHelperTest < ActiveSupport::TestCase should "return a html text with operating system" do operating_systems = [] - operating_system = OperatingSystemName.new + operating_system = SoftwareCommunitiesPlugin::OperatingSystemName.new operating_system.name = "teste" - software_operating_system = OperatingSystem.new + software_operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new software_operating_system.version = 2 software_operating_system.operating_system_name = operating_system operating_systems << software_operating_system op_table = OperatingSystemHelper.operating_system_as_tables(operating_systems) - assert_not_nil op_table.first.call.index(OperatingSystemName.first.name) + assert_not_nil op_table.first.call.index(SoftwareCommunitiesPlugin::OperatingSystemName.first.name) end end diff --git a/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb index 1f4a42b..f3ec475 100644 --- a/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class OperatingSystemValidationTest < ActiveSupport::TestCase def setup - operating_system_name = OperatingSystemName::new :name=>"Linux" - @operating_system = OperatingSystem::new :version=>"3.0" + operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName::new :name=>"Linux" + @operating_system = SoftwareCommunitiesPlugin::OperatingSystem::new :version=>"3.0" @operating_system.operating_system_name = operating_system_name @operating_system end diff --git a/src/noosfero-spb/software_communities/test/unit/repository_block_test.rb b/src/noosfero-spb/software_communities/test/unit/repository_block_test.rb index 2580e79..73c67cc 100644 --- a/src/noosfero-spb/software_communities/test/unit/repository_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/repository_block_test.rb @@ -5,15 +5,15 @@ class RepositoryBlockTest < ActiveSupport::TestCase include PluginTestHelper should 'inherit from Block' do - assert_kind_of Block, RepositoryBlock.new + assert_kind_of Block, SoftwareCommunitiesPlugin::RepositoryBlock.new end should 'declare its default title' do - RepositoryBlock.any_instance.stubs(:profile_count).returns(0) - assert_equal Block.new.default_title, RepositoryBlock.new.default_title + SoftwareCommunitiesPlugin::RepositoryBlock.any_instance.stubs(:profile_count).returns(0) + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::RepositoryBlock.new.default_title end should 'describe itself' do - assert_not_equal Block.description, RepositoryBlock.description + assert_not_equal Block.description, SoftwareCommunitiesPlugin::RepositoryBlock.description end end diff --git a/src/noosfero-spb/software_communities/test/unit/search_catalog_block_test.rb b/src/noosfero-spb/software_communities/test/unit/search_catalog_block_test.rb index 64376ef..cc8dca4 100644 --- a/src/noosfero-spb/software_communities/test/unit/search_catalog_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/search_catalog_block_test.rb @@ -4,16 +4,16 @@ require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' class SearchCatalogBlockTest < ActiveSupport::TestCase include PluginTestHelper should 'inherit from Block' do - assert_kind_of Block, SearchCatalogBlock.new + assert_kind_of Block, SoftwareCommunitiesPlugin::SearchCatalogBlock.new end should 'declare its default title' do - SearchCatalogBlock.any_instance.stubs(:profile_count).returns(0) - assert_equal Block.new.default_title, SearchCatalogBlock.new.default_title + SoftwareCommunitiesPlugin::SearchCatalogBlock.any_instance.stubs(:profile_count).returns(0) + assert_equal Block.new.default_title, SoftwareCommunitiesPlugin::SearchCatalogBlock.new.default_title end should 'describe itself' do - assert_not_equal Block.description, SearchCatalogBlock.description + assert_not_equal Block.description, SoftwareCommunitiesPlugin::SearchCatalogBlock.description end end diff --git a/src/noosfero-spb/software_communities/test/unit/software_database_test.rb b/src/noosfero-spb/software_communities/test/unit/software_database_test.rb index c73a359..447cfc4 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_database_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_database_test.rb @@ -2,16 +2,16 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class SoftwareDatabaseTest < ActiveSupport::TestCase def setup - DatabaseDescription.create!(name: "PostgreSQL") - @software_database = SoftwareDatabase.new( + SoftwareCommunitiesPlugin::DatabaseDescription.create!(name: "PostgreSQL") + @software_database = SoftwareCommunitiesPlugin::SoftwareDatabase.new( :version => "1.0" ) @software_database.database_description_id = 1 end def teardown - DatabaseDescription.destroy_all - SoftwareDatabase.destroy_all + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all end should "save if all informations of @software_database are filled" do diff --git a/src/noosfero-spb/software_communities/test/unit/software_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/software_helper_test.rb index fc88cc4..3484cb6 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_helper_test.rb @@ -5,16 +5,16 @@ class SoftwareHelperTest < ActiveSupport::TestCase include SoftwareHelper should "Create ProgrammingLanguages based on file with languages names" do - ProgrammingLanguage.delete_all + SoftwareCommunitiesPlugin::ProgrammingLanguage.delete_all PATH_TO_FILE = "plugins/software_communities/public/static/languages.txt" - SoftwareHelper.create_list_with_file(PATH_TO_FILE, ProgrammingLanguage) + SoftwareHelper.create_list_with_file(PATH_TO_FILE, SoftwareCommunitiesPlugin::ProgrammingLanguage) list = File.open(PATH_TO_FILE, "r") count = list.readlines.count list.close - assert(ProgrammingLanguage.count == count) + assert(SoftwareCommunitiesPlugin::ProgrammingLanguage.count == count) end should "return the software template specified in config.yml file" do diff --git a/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb index b5324a6..6006547 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb @@ -9,29 +9,29 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase :name => 'New Software' ) - @language = ProgrammingLanguage.new(:name => 'C++') + @language = SoftwareCommunitiesPlugin::ProgrammingLanguage.new(:name => 'C++') @language.save - @software_language = SoftwareLanguage.new( + @software_language = SoftwareCommunitiesPlugin::SoftwareLanguage.new( :version => '1' ) @software_language.programming_language = @language @software_language.save - @database = DatabaseDescription.new(:name => 'Oracle') + @database = SoftwareCommunitiesPlugin::DatabaseDescription.new(:name => 'Oracle') @database.save - @software_database = SoftwareDatabase.new( + @software_database = SoftwareCommunitiesPlugin::SoftwareDatabase.new( :version => '2' ) @software_database.database_description = @database @software_database.save - @operating_system_name = OperatingSystemName.new(:name => 'Debian') + @operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName.new(:name => 'Debian') @operating_system_name.save - @operating_system = OperatingSystem.new(:version => '1.0') + @operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new(:version => '1.0') @operating_system.operating_system_name = @operating_system_name @operating_system.save - @software_info = SoftwareInfo.new( + @software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new( :acronym => "SFTW", :e_mag => true, :icp_brasil => true, @@ -53,13 +53,13 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase end def teardown - ProgrammingLanguage.destroy_all - SoftwareLanguage.destroy_all - DatabaseDescription.destroy_all - SoftwareDatabase.destroy_all - OperatingSystem.destroy_all - OperatingSystemName.destroy_all - SoftwareInfo.destroy_all + SoftwareCommunitiesPlugin::ProgrammingLanguage.destroy_all + SoftwareCommunitiesPlugin::SoftwareLanguage.destroy_all + SoftwareCommunitiesPlugin::DatabaseDescription.destroy_all + SoftwareCommunitiesPlugin::SoftwareDatabase.destroy_all + SoftwareCommunitiesPlugin::OperatingSystem.destroy_all + SoftwareCommunitiesPlugin::OperatingSystemName.destroy_all + SoftwareCommunitiesPlugin::SoftwareInfo.destroy_all end should 'Save SoftwareInfo if all fields are filled' do diff --git a/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb index 9465f91..4fcd83e 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class SoftwareLanguageHelperTest < ActiveSupport::TestCase def setup - pl1 = ProgrammingLanguage.create(:name => "Python") - pl2 = ProgrammingLanguage.create(:name => "Java") + pl1 = SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name => "Python") + pl2 = SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name => "Java") @software_language_objects = [ {:programming_language_id => pl1.id.to_s ,:version => "2.0"}, @@ -15,7 +15,7 @@ class SoftwareLanguageHelperTest < ActiveSupport::TestCase def teardown @software_language_objects = nil - ProgrammingLanguage.destroy_all + SoftwareCommunitiesPlugin::ProgrammingLanguage.destroy_all end should "return an empty list" do diff --git a/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb b/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb index 8a1b21d..107b6af 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb @@ -9,7 +9,7 @@ class SoftwareLanguageValidationTest < ActiveSupport::TestCase def teardown @software_info = nil - SoftwareInfo.destroy_all + SoftwareCommunitiesPlugin::SoftwareInfo.destroy_all end should "Save SoftwareLanguage if version and prog_language are filled" do @@ -38,15 +38,15 @@ class SoftwareLanguageValidationTest < ActiveSupport::TestCase private def create_software_language - software_language = SoftwareLanguage.new + software_language = SoftwareCommunitiesPlugin::SoftwareLanguage.new software_language.software_info = @software_info - software_language.programming_language = ProgrammingLanguage.last + software_language.programming_language = SoftwareCommunitiesPlugin::ProgrammingLanguage.last software_language.version = "version" software_language end def create_software_info - software_info = SoftwareInfo.new + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new software_info.community_id = fast_create(Community).id software_info.community.name = 'Noosfero' software_info.e_mag = true @@ -61,9 +61,9 @@ class SoftwareLanguageValidationTest < ActiveSupport::TestCase end def create_programming_language - ProgrammingLanguage.create(:name=>"C") - ProgrammingLanguage.create(:name=>"C++") - ProgrammingLanguage.create(:name=>"Ruby") - ProgrammingLanguage.create(:name=>"Python") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"C") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"C++") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"Ruby") + SoftwareCommunitiesPlugin::ProgrammingLanguage.create(:name=>"Python") end end diff --git a/src/noosfero-spb/software_communities/test/unit/software_license_info_test.rb b/src/noosfero-spb/software_communities/test/unit/software_license_info_test.rb index 81ab2ee..fc1929f 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_license_info_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_license_info_test.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class SoftwareDatabaseTest < ActiveSupport::TestCase should "save if all informations are filled" do - @software_license_info = LicenseInfo.create( + @software_license_info = SoftwareCommunitiesPlugin::LicenseInfo.create( :version => "GPL", :link => "www.gpl2.com" ) @@ -11,7 +11,7 @@ class SoftwareDatabaseTest < ActiveSupport::TestCase end should "not save if license info version is empty" do - @software_license_info = LicenseInfo.create( + @software_license_info = SoftwareCommunitiesPlugin::LicenseInfo.create( :version => "GPL", :link => "www.gpl2.com" ) @@ -20,7 +20,7 @@ class SoftwareDatabaseTest < ActiveSupport::TestCase end should "save if link is empty" do - @software_license_info = LicenseInfo.create( + @software_license_info = SoftwareCommunitiesPlugin::LicenseInfo.create( :version => "GPL", :link => "www.gpl2.com") @software_license_info.link = nil diff --git a/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb b/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb index 397adf7..1da606a 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb @@ -9,17 +9,18 @@ class SoftwareRegistrationTest < ActiveSupport::TestCase def teardown Community.destroy_all - SoftwareInfo.destroy_all + SoftwareCommunitiesPlugin::SoftwareInfo.destroy_all Task.destroy_all end should 'include software registration task if is admin' do person = create_user('molly').person @environment.add_admin(person) - task = CreateSoftware.create!( + task = SoftwareCommunitiesPlugin::CreateSoftware.create!( :name => "Teste One", :requestor => person, - :environment => @environment + :environment => @environment, + :finality => "something" ) assert_equal [task], Task.to(person).pending end @@ -27,16 +28,16 @@ class SoftwareRegistrationTest < ActiveSupport::TestCase should 'create software when admin accept software create task' do person = create_user('Pedro').person @environment.add_admin(person) - task = CreateSoftware.create!( + task = SoftwareCommunitiesPlugin::CreateSoftware.create!( :name => "Teste Two", :requestor => person, :environment => @environment, :finality => "something" ) - software_count = SoftwareInfo.count + software_count = SoftwareCommunitiesPlugin::SoftwareInfo.count task.finish - assert_equal software_count+1, SoftwareInfo.count + assert_equal software_count+1, SoftwareCommunitiesPlugin::SoftwareInfo.count end end diff --git a/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb b/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb index aad8c8c..520760e 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb @@ -14,15 +14,15 @@ class SoftwareTabDataBlockTest < ActiveSupport::TestCase @soft_community.blogs << Blog.new(:name=>"Second blog") @soft_community.save! - SoftwareTabDataBlock.any_instance.stubs(:owner).returns(@soft_community) + SoftwareCommunitiesPlugin::SoftwareTabDataBlock.any_instance.stubs(:owner).returns(@soft_community) end should "get its owner blogs" do - assert_equal @soft_community.blogs, SoftwareTabDataBlock.new.blogs + assert_equal @soft_community.blogs, SoftwareCommunitiesPlugin::SoftwareTabDataBlock.new.blogs end should "actual_blog get the first blog if it is not defined" do - assert_equal @soft_community.blogs.first, SoftwareTabDataBlock.new.actual_blog + assert_equal @soft_community.blogs.first, SoftwareCommunitiesPlugin::SoftwareTabDataBlock.new.actual_blog end should "actual_blog get the defined community blog" do @@ -46,13 +46,13 @@ class SoftwareTabDataBlockTest < ActiveSupport::TestCase soft_tab_data = create_software_tab_data_block(last_blog) craete_sample_posts(last_blog, 6) - assert_equal SoftwareTabDataBlock::TOTAL_POSTS_DYSPLAYED, soft_tab_data.posts.count + assert_equal SoftwareCommunitiesPlugin::SoftwareTabDataBlock::TOTAL_POSTS_DYSPLAYED, soft_tab_data.posts.count end private def create_software_tab_data_block blog - soft_tab_data = SoftwareTabDataBlock.new + soft_tab_data = SoftwareCommunitiesPlugin::SoftwareTabDataBlock.new soft_tab_data.displayed_blog = blog.id soft_tab_data end diff --git a/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb b/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb index 44b5064..955086a 100644 --- a/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb @@ -4,20 +4,20 @@ require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' class SoftwaresBlockTest < ActiveSupport::TestCase include PluginTestHelper should 'inherit from ProfileListBlock' do - assert_kind_of ProfileListBlock, SoftwaresBlock.new + assert_kind_of ProfileListBlock, SoftwareCommunitiesPlugin::SoftwaresBlock.new end should 'declare its default title' do - SoftwaresBlock.any_instance.stubs(:profile_count).returns(0) - assert_not_equal ProfileListBlock.new.default_title, SoftwaresBlock.new.default_title + SoftwareCommunitiesPlugin::SoftwaresBlock.any_instance.stubs(:profile_count).returns(0) + assert_not_equal ProfileListBlock.new.default_title, SoftwareCommunitiesPlugin::SoftwaresBlock.new.default_title end should 'describe itself' do - assert_not_equal ProfileListBlock.description, SoftwaresBlock.description + assert_not_equal ProfileListBlock.description, SoftwareCommunitiesPlugin::SoftwaresBlock.description end should 'give empty footer on unsupported owner type' do - block = SoftwaresBlock.new + block = SoftwareCommunitiesPlugin::SoftwaresBlock.new block.expects(:owner).returns(1) assert_equal '', block.footer end @@ -34,7 +34,7 @@ class SoftwaresBlockTest < ActiveSupport::TestCase software_info = create_software_info("new software") software_info.community.add_member(user) - block = SoftwaresBlock.new + block = SoftwareCommunitiesPlugin::SoftwaresBlock.new block.expects(:owner).at_least_once.returns(user) assert_equivalent [software_info.community], block.profiles -- libgit2 0.21.2