Commit 6df2a631184c197e0e29adcbdb15270f0bcfbc17
Committed by
Daniela Feitosa
1 parent
0d4a8d98
Exists in
refactor_software_communities
Remove hard coded software templates' references
Showing
8 changed files
with
50 additions
and
7 deletions
Show diff stats
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +software_template: software | ... | ... |
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +software_template: software | ... | ... |
src/noosfero-spb/software_communities/controllers/software_communities_plugin_myprofile_controller.rb
| ... | ... | @@ -167,8 +167,8 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
| 167 | 167 | end |
| 168 | 168 | |
| 169 | 169 | def set_software_as_template |
| 170 | - software_template = Community['software'] | |
| 171 | - software_valid = !software_template.blank? && software_template.is_template && !params['community'].blank? | |
| 170 | + software_template = SoftwareHelper.software_template | |
| 171 | + software_valid = !software_template.blank? && !params['community'].blank? | |
| 172 | 172 | if software_valid |
| 173 | 173 | params['community']['template_id'] = software_template.id if software_valid |
| 174 | 174 | end | ... | ... |
src/noosfero-spb/software_communities/lib/create_software.rb
| ... | ... | @@ -16,7 +16,7 @@ class CreateSoftware < Task |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | def perform |
| 19 | - software_template = Community["software"] | |
| 19 | + software_template = SoftwareHelper.software_template | |
| 20 | 20 | if (!software_template.blank? && software_template.is_template) |
| 21 | 21 | template_id = software_template.id |
| 22 | 22 | end | ... | ... |
src/noosfero-spb/software_communities/lib/software_helper.rb
| ... | ... | @@ -25,4 +25,19 @@ module SoftwareHelper |
| 25 | 25 | def self.all_table_is_empty? table, ignored_fields=[] |
| 26 | 26 | return !table.keys.any?{|key| ignored_fields.include?(key) ? false : !table[key].empty?} |
| 27 | 27 | end |
| 28 | + | |
| 29 | + def self.software_template | |
| 30 | + identifier = SoftwareHelper.software_template_identifier | |
| 31 | + | |
| 32 | + software_template = Community[identifier] | |
| 33 | + if !software_template.blank? && software_template.is_template | |
| 34 | + software_template | |
| 35 | + else | |
| 36 | + nil | |
| 37 | + end | |
| 38 | + end | |
| 39 | + | |
| 40 | + def self.software_template_identifier | |
| 41 | + identifier = YAML::load(File.open(SoftwareCommunitiesPlugin.root_path + 'config.yml'))['software_template'] | |
| 42 | + end | |
| 28 | 43 | end | ... | ... |
src/noosfero-spb/software_communities/lib/software_info.rb
| ... | ... | @@ -177,7 +177,7 @@ class SoftwareInfo < ActiveRecord::Base |
| 177 | 177 | ) |
| 178 | 178 | ) |
| 179 | 179 | else |
| 180 | - software_template = Community["software"] | |
| 180 | + software_template = SoftwareHelper.software_template | |
| 181 | 181 | |
| 182 | 182 | community_hash = {:name => name} |
| 183 | 183 | community_hash[:identifier] = identifier |
| ... | ... | @@ -186,7 +186,7 @@ class SoftwareInfo < ActiveRecord::Base |
| 186 | 186 | community = Community.new(community_hash) |
| 187 | 187 | community.environment = environment |
| 188 | 188 | |
| 189 | - if (!software_template.blank? && software_template.is_template) | |
| 189 | + unless software_template.blank? | |
| 190 | 190 | community.template_id = software_template.id |
| 191 | 191 | end |
| 192 | 192 | ... | ... |
src/noosfero-spb/software_communities/lib/tasks/templates.rake
| ... | ... | @@ -13,10 +13,11 @@ namespace :templates do |
| 13 | 13 | task :software => :environment do |
| 14 | 14 | Environment.all.each do |env| |
| 15 | 15 | if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("SoftwareCommunitiesPlugin") |
| 16 | - software = Community["software"] | |
| 16 | + software = SoftwareHelper.software_template | |
| 17 | 17 | |
| 18 | 18 | if software.nil? |
| 19 | - software = Community.create!(:name => "Software", :identifier => "software") | |
| 19 | + identifier = YAML::load(File.open(SoftwareCommunitiesPlugin.root_path + 'config.yml'))['software_template'] | |
| 20 | + software = Community.create!(:name => "Software", :identifier => identifier) | |
| 20 | 21 | end |
| 21 | 22 | |
| 22 | 23 | software.layout_template = "default" | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_helper_test.rb
| ... | ... | @@ -17,4 +17,29 @@ class SoftwareHelperTest < ActiveSupport::TestCase |
| 17 | 17 | assert(ProgrammingLanguage.count == count) |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | + should "return the software template specified in config.yml file" do | |
| 21 | + template_community = Community.create!(:name => "Software", :identifier => "software_template", :is_template => true) | |
| 22 | + | |
| 23 | + parsed_yaml = {"software_template" => "software_template"} | |
| 24 | + | |
| 25 | + SoftwareHelper.stubs(:software_template_identifier).returns("software_template") | |
| 26 | + | |
| 27 | + software_template = SoftwareHelper.software_template | |
| 28 | + assert !software_template.blank? | |
| 29 | + assert software_template.is_template | |
| 30 | + end | |
| 31 | + | |
| 32 | + should "not return the software template if there is not software template" do | |
| 33 | + parsed_yaml = {"software_template" => "software_template"} | |
| 34 | + | |
| 35 | + SoftwareHelper.stubs(:software_template_identifier).returns("software_template") | |
| 36 | + | |
| 37 | + software_template = SoftwareHelper.software_template | |
| 38 | + assert software_template.blank? | |
| 39 | + | |
| 40 | + template_community = Community.create!(:name => "Software", :identifier => "software_template") | |
| 41 | + | |
| 42 | + software_template = SoftwareHelper.software_template | |
| 43 | + assert software_template.blank? | |
| 44 | + end | |
| 20 | 45 | end | ... | ... |