diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index 4e62d33..52468bc 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -17,7 +17,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @list_libraries = LibraryHelper.list_libraries(params[:library]) @list_languages = SoftwareLanguageHelper.list_language(params[:language]) @list_databases = DatabaseHelper.list_database(params[:database]) - @controlled_vocabulary = ControlledVocabulary::new params[:controlled_vocabulary] + @software_categories = SoftwareCategories::new params[:software_categories] @list_operating_systems = OperatingSystemHelper.list_operating_system(params[:operating_system]) @license_info = if params[:license_info].nil? LicenseInfo::new @@ -58,7 +58,8 @@ class MpogSoftwarePluginMyprofileController < MyProfileController valid_operating_system = OperatingSystemHelper.valid_list_operating_system?(@list_operating_systems) if valid_software_info && valid_community && valid_libraries && valid_license && valid_language && valid_database && valid_operating_system - @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]), @software_info, @license_info, @controlled_vocabulary) + + @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]), @software_info, @license_info, @software_categories) unless params[:q].nil? admins = params[:q].split(/,/).map{|n| environment.people.find n.to_i} diff --git a/db/migrate/20140909185547_rename_controlled_vocabulary_to_software_categories.rb b/db/migrate/20140909185547_rename_controlled_vocabulary_to_software_categories.rb new file mode 100644 index 0000000..0d9a7b1 --- /dev/null +++ b/db/migrate/20140909185547_rename_controlled_vocabulary_to_software_categories.rb @@ -0,0 +1,9 @@ +class RenameControlledVocabularyToSoftwareCategories < ActiveRecord::Migration + def up + rename_table :controlled_vocabulary, :software_categories + end + + def down + rename_table :software_categories, :controlled_vocabulary + end +end diff --git a/lib/controlled_vocabulary_helper.rb b/lib/controlled_vocabulary_helper.rb deleted file mode 100644 index 57f012c..0000000 --- a/lib/controlled_vocabulary_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -module ControlledVocabularyHelper - - def self.get_categories_as_options - categories = ["".html_safe] - value = 1 - - ControlledVocabulary.attribute_names.each do |attribute| - if attribute.to_s != "id" && attribute.to_s != "software_info_id" then - categories << "".html_safe - value+=1 - end - end - categories - end -end diff --git a/lib/ext/community.rb b/lib/ext/community.rb index acbdd6e..c24f659 100644 --- a/lib/ext/community.rb +++ b/lib/ext/community.rb @@ -7,17 +7,17 @@ class Community has_one :software_info, :dependent=>:delete has_one :institution, :dependent=>:delete - def self.create_after_moderation(requestor, attributes = {}, software_info = nil, license_info = nil, controlled_vocabulary = nil) + def self.create_after_moderation(requestor, attributes = {}, software_info = nil, license_info = nil, software_categories = nil) community = Community.new(attributes) if not software_info.nil? - if not license_info.nil? - software_info.license_info = license_info - end + if not license_info.nil? + software_info.license_info = license_info + end - if not controlled_vocabulary.nil? - software_info.controlled_vocabulary = controlled_vocabulary - end + if not software_categories.nil? + software_info.software_categories = software_categories + end software_info.save end diff --git a/lib/ext/controlled_vocabulary.rb b/lib/ext/controlled_vocabulary.rb deleted file mode 100644 index 3afc6f8..0000000 --- a/lib/ext/controlled_vocabulary.rb +++ /dev/null @@ -1,12 +0,0 @@ -class ControlledVocabulary < ActiveRecord::Base - self.table_name = "controlled_vocabulary" - - attr_accessible :administration , :agriculture , :business_and_services , :communication , - :culture , :national_defense , :economy_and_finances , :education , - :energy , :sports , :habitation , :industry , :environment , - :research_and_development , :social_security , :social_protection , - :international_relations , :sanitation , :health , - :security_public_order , :work , :transportation , :urbanism - - belongs_to :software_info -end \ No newline at end of file diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index bad9496..8a8a798 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -100,8 +100,8 @@ class MpogSoftwarePlugin < Noosfero::Plugin institution_transaction end - if context.params.has_key?(:controlled_vocabulary) - controlled_vocabulary_transaction + if context.params.has_key?(:software_categories) + software_categories_transaction end elsif context.profile.respond_to?(:user) if context.params.has_key?(:user) @@ -137,7 +137,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin softwares = SoftwareInfo.search(params[:name], params[:database_description][:id], params[:programming_language][:id], params[:operating_system][:id], params[:license_info][:id], params[:e_ping], params[:e_mag], params[:internacionalizable], - params[:icp_brasil], params[:e_arq], params[:controlled_vocabulary]) + params[:icp_brasil], params[:e_arq], params[:software_categories]) communities = [] softwares.each do |s| @@ -416,9 +416,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin end end - def controlled_vocabulary_transaction + def software_categories_transaction ControlledVocabulary.transaction do - context.profile.software_info.controlled_vocabulary.update_attributes!(context.params[:controlled_vocabulary]) + context.profile.software_info.software_categories.update_attributes!(context.params[:software_categories]) end end diff --git a/lib/software_categories.rb b/lib/software_categories.rb new file mode 100644 index 0000000..2ced887 --- /dev/null +++ b/lib/software_categories.rb @@ -0,0 +1,10 @@ +class SoftwareCategories < ActiveRecord::Base + attr_accessible :administration , :agriculture , :business_and_services , :communication , + :culture , :national_defense , :economy_and_finances , :education , + :energy , :sports , :habitation , :industry , :environment , + :research_and_development , :social_security , :social_protection , + :international_relations , :sanitation , :health , + :security_public_order , :work , :transportation , :urbanism + + belongs_to :software_info +end \ No newline at end of file diff --git a/lib/software_categories_helper.rb b/lib/software_categories_helper.rb new file mode 100644 index 0000000..4540847 --- /dev/null +++ b/lib/software_categories_helper.rb @@ -0,0 +1,15 @@ +module SoftwareCategoriesHelper + + def self.get_categories_as_options + categories = ["".html_safe] + value = 1 + + SoftwareCategories.attribute_names.each do |attribute| + if attribute.to_s != "id" && attribute.to_s != "software_info_id" then + categories << "".html_safe + value+=1 + end + end + categories + end +end diff --git a/lib/software_info.rb b/lib/software_info.rb index 3c4ba78..18384bf 100644 --- a/lib/software_info.rb +++ b/lib/software_info.rb @@ -12,7 +12,9 @@ class SoftwareInfo < ActiveRecord::Base belongs_to :community belongs_to :license_info - has_one :controlled_vocabulary + has_one :software_categories + + validates :software_categories, :presence=>true validates :features, :objectives, :presence=>true, @@ -31,7 +33,7 @@ class SoftwareInfo < ActiveRecord::Base 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 = "", controlled_vocabulary = "" | + icp_brasil = "", e_arq = "", software_categories = "" | like_sql = "" values = [] @@ -86,9 +88,9 @@ class SoftwareInfo < ActiveRecord::Base values << "#{e_arq}" end - unless controlled_vocabulary.blank? - controlled_vocabulary = controlled_vocabulary.gsub(' ', '').underscore - like_sql << "controlled_vocabulary.#{controlled_vocabulary} = ? AND " + unless software_categories.blank? + software_categories = software_categories.gsub(' ', '').underscore + like_sql << "software_categories.#{software_categories} = ? AND " values << "true" end @@ -96,7 +98,7 @@ class SoftwareInfo < ActiveRecord::Base { :joins => [:community, :software_databases, :software_languages, - :operating_systems, :controlled_vocabulary], + :operating_systems, :software_categories], :conditions=>[like_sql, *values] } } diff --git a/test/unit/controlled_vocabulary_test.rb b/test/unit/controlled_vocabulary_test.rb deleted file mode 100644 index 753df0e..0000000 --- a/test/unit/controlled_vocabulary_test.rb +++ /dev/null @@ -1,59 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' - -class ControlledVocabularyTest < ActiveSupport::TestCase - - def setup - @community = fast_create(Community, :identifier => 'new-software', :name => 'New Software') - - @language = ProgrammingLanguage.new(:name => 'C++') - @language.save - @software_language = SoftwareLanguage.new(:version => '1', :operating_system => 'os') - @software_language.programming_language = @language - @software_language.save - - @database = DatabaseDescription.new(:name => 'Oracle') - @database.save - @software_database = SoftwareDatabase.new(:version => '2', :operating_system => 'os2') - @software_database.database_description = @database - @software_database.save - - @operating_system_name = OperatingSystemName.new(:name => 'Debian') - @operating_system_name.save - @operating_system = OperatingSystem.new(:version => '1.0') - @operating_system.operating_system_name = @operating_system_name - @operating_system.save - - @software_info = SoftwareInfo.new(:acronym => "SFTW", :e_mag => true,:icp_brasil => true,:intern => true,:e_ping => true, - :e_arq => true, :operating_platform => true, :objectives => "", :features => "") - @software_info.software_languages << @software_language - @software_info.software_databases << @software_database - @software_info.operating_systems << @operating_system - - @controlled_language = ControlledVocabulary.new() - @controlled_vocabulary = ControlledVocabulary.new(:administration => true, :agriculture => true, :business_and_services => true, :communication => true, - :culture => true, :national_defense => true, :economy_and_finances => true, :education => true, - :energy => true, :sports => false , :habitation => true, :industry => true, :environment => true, - :research_and_development => true, :social_security => false , :social_protection => true, - :international_relations => true, :sanitation => true, :health => false, - :security_public_order => true, :work => true, :transportation => true, :urbanism => true) - @software_info.controlled_vocabulary = @controlled_vocabulary - end - - should "save software correctly with ControlledVocabulary filds" do - assert @software_info.save - end - - should "set in software_info a reference to controlled_vocabulary" do - @software_info.save - @controlled_vocabulary.save - assert_equal SoftwareInfo.last.controlled_vocabulary, ControlledVocabulary.last - end - - should "return a valid value from database" do - @software_info.save - @controlled_vocabulary.save - software_info = SoftwareInfo.find(@software_info.id) - controlled_vocabulary = ControlledVocabulary.find(software_info.controlled_vocabulary) - assert_equal true, controlled_vocabulary.education - end -end diff --git a/test/unit/software_categories_test.rb b/test/unit/software_categories_test.rb new file mode 100644 index 0000000..ee75642 --- /dev/null +++ b/test/unit/software_categories_test.rb @@ -0,0 +1,61 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class SoftwareCategoriesTest < ActiveSupport::TestCase + + def setup + @community = fast_create(Community, :identifier => 'new-software', :name => 'New Software') + + @language = ProgrammingLanguage.new(:name => 'C++') + @language.save + @software_language = SoftwareLanguage.new(:version => '1', :operating_system => 'os') + @software_language.programming_language = @language + @software_language.save + + @database = DatabaseDescription.new(:name => 'Oracle') + @database.save + @software_database = SoftwareDatabase.new(:version => '2', :operating_system => 'os2') + @software_database.database_description = @database + @software_database.save + + @operating_system_name = OperatingSystemName.new(:name => 'Debian') + @operating_system_name.save + @operating_system = OperatingSystem.new(:version => '1.0') + @operating_system.operating_system_name = @operating_system_name + @operating_system.save + + @software_info = SoftwareInfo.new(:acronym => "SFTW", :e_mag => true,:icp_brasil => true,:intern => true,:e_ping => true, + :e_arq => true, :operating_platform => true, :objectives => "", :features => "") + @software_info.software_languages << @software_language + @software_info.software_databases << @software_database + @software_info.operating_systems << @operating_system + + @software_info.features = "Do a lot of things" + @software_info.objectives = "All tests should pass !" + + @software_categories = SoftwareCategories.new(:administration => true, :agriculture => true, :business_and_services => true, :communication => true, + :culture => true, :national_defense => true, :economy_and_finances => true, :education => true, + :energy => true, :sports => false , :habitation => true, :industry => true, :environment => true, + :research_and_development => true, :social_security => false , :social_protection => true, + :international_relations => true, :sanitation => true, :health => false, + :security_public_order => true, :work => true, :transportation => true, :urbanism => true) + @software_info.software_categories = @software_categories + end + + should "save software correctly with SoftwareCategories filds" do + assert @software_info.save + end + + should "set in software_info a reference to software_categories" do + @software_info.save + @software_categories.save + assert_equal SoftwareInfo.last.software_categories, SoftwareCategories.last + end + + should "return a valid value from database" do + @software_info.save + @software_categories.save + software_info = SoftwareInfo.find(@software_info.id) + software_categories = SoftwareCategories.find(software_info.software_categories) + assert_equal true, software_categories.education + end +end diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index 1d8819e..921fb77 100644 --- a/views/mpog_software_plugin_myprofile/new_software.html.erb +++ b/views/mpog_software_plugin_myprofile/new_software.html.erb @@ -151,9 +151,9 @@ offerers'), :pre_populate => @tokenized_children}) %> <%= render :partial => 'database_fields', :locals => { :f => f, :object_name => 'community', :profile => @community, :database => @list_databases } %> - <%= fields_for @controlled_vocabulary do |cv| %> -