Commit f37d4b1e6ffa05acc281177791409ab4bec60dae

Authored by AntonioTerceiro
1 parent f869a551

ActionItem501: removed hacks, it seems to work with Rails 2.0.2

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2162 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/enterprise.rb
@@ -57,4 +57,13 @@ class Enterprise < Organization @@ -57,4 +57,13 @@ class Enterprise < Organization
57 end 57 end
58 end 58 end
59 59
  60 +
  61 + def default_set_of_blocks
  62 + [
  63 + [MainBlock],
  64 + [ProfileInfoBlock, ProductsBlock, RecentDocumentsBlock],
  65 + [MembersBlock, TagsBlock]
  66 + ]
  67 + end
  68 +
60 end 69 end
app/models/organization.rb
@@ -54,18 +54,12 @@ class Organization < Profile @@ -54,18 +54,12 @@ class Organization < Profile
54 true 54 true
55 end 55 end
56 56
57 - hacked_after_create :create_default_set_of_blocks_for_organization  
58 - def create_default_set_of_blocks_for_organization  
59 - # "main" area  
60 - self.boxes[0].blocks << MainBlock.new  
61 -  
62 - # "left" area  
63 - self.boxes[1].blocks << ProfileInfoBlock.new  
64 - self.boxes[1].blocks << RecentDocumentsBlock.new  
65 -  
66 - # "right" area  
67 - self.boxes[2].blocks << MembersBlock.new  
68 - self.boxes[2].blocks << TagsBlock.new 57 + def default_set_of_blocks
  58 + [
  59 + [MainBlock],
  60 + [ProfileInfoBlock, RecentDocumentsBlock],
  61 + [MembersBlock, TagsBlock]
  62 + ]
69 end 63 end
70 64
71 end 65 end
app/models/person.rb
@@ -70,34 +70,14 @@ class Person &lt; Profile @@ -70,34 +70,14 @@ class Person &lt; Profile
70 end 70 end
71 end 71 end
72 72
73 - # FIXME this is *weird*, because this class is not inheriting the callback  
74 - # from Profile !!!  
75 - hacked_after_create :create_default_set_of_boxes_for_person  
76 - def create_default_set_of_boxes_for_person  
77 - 3.times do  
78 - self.boxes << Box.new  
79 - end  
80 -  
81 - # main area  
82 - self.boxes.first.blocks << MainBlock.new  
83 -  
84 - # "left" area  
85 - self.boxes[1].blocks << ProfileInfoBlock.new  
86 - self.boxes[1].blocks << RecentDocumentsBlock.new  
87 -  
88 - # right area  
89 - self.boxes[2].blocks << TagsBlock.new  
90 - self.boxes[2].blocks << FriendsBlock.new  
91 - self.boxes[2].blocks << CommunitiesBlock.new  
92 - self.boxes[2].blocks << EnterprisesBlock.new  
93 -  
94 - true 73 + def default_set_of_blocks
  74 + [
  75 + [MainBlock],
  76 + [ProfileInfoBlock, RecentDocumentsBlock],
  77 + [TagsBlock, FriendsBlock, CommunitiesBlock, EnterprisesBlock]
  78 + ]
95 end 79 end
96 80
97 - # FIXME this is *weird*, because this class is not inheriting the callbacks  
98 - before_create :set_default_environment  
99 - hacked_after_create :insert_default_homepage_and_feed  
100 -  
101 def name 81 def name
102 if !self[:name].blank? 82 if !self[:name].blank?
103 self[:name] 83 self[:name]
app/models/profile.rb
@@ -166,7 +166,7 @@ class Profile &lt; ActiveRecord::Base @@ -166,7 +166,7 @@ class Profile &lt; ActiveRecord::Base
166 end 166 end
167 167
168 # registar callback for creating boxes after the object is created. 168 # registar callback for creating boxes after the object is created.
169 - hacked_after_create :create_default_set_of_boxes 169 + after_create :create_default_set_of_boxes
170 170
171 # creates the initial set of boxes when the profile is created. Can be 171 # creates the initial set of boxes when the profile is created. Can be
172 # overriden for each subclass to create a custom set of boxes for its 172 # overriden for each subclass to create a custom set of boxes for its
@@ -175,6 +175,15 @@ class Profile &lt; ActiveRecord::Base @@ -175,6 +175,15 @@ class Profile &lt; ActiveRecord::Base
175 3.times do 175 3.times do
176 self.boxes << Box.new 176 self.boxes << Box.new
177 end 177 end
  178 +
  179 + if self.respond_to?(:default_set_of_blocks)
  180 + default_set_of_blocks.each_with_index do |blocks,i|
  181 + blocks.each do |block|
  182 + self.boxes[i].blocks << block.new
  183 + end
  184 + end
  185 + end
  186 +
178 true 187 true
179 end 188 end
180 189
@@ -300,7 +309,7 @@ class Profile &lt; ActiveRecord::Base @@ -300,7 +309,7 @@ class Profile &lt; ActiveRecord::Base
300 false 309 false
301 end 310 end
302 311
303 - hacked_after_create :insert_default_homepage_and_feed 312 + after_create :insert_default_homepage_and_feed
304 def insert_default_homepage_and_feed 313 def insert_default_homepage_and_feed
305 hp = TinyMceArticle.new(:name => _("%s's home page") % self.name, :body => _("<p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % self.name, :advertise => false) 314 hp = TinyMceArticle.new(:name => _("%s's home page") % self.name, :body => _("<p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % self.name, :advertise => false)
306 hp.profile = self 315 hp.profile = self
config/environment.rb
@@ -101,7 +101,6 @@ require &#39;acts_as_searchable&#39; @@ -101,7 +101,6 @@ require &#39;acts_as_searchable&#39;
101 require 'acts_as_having_boxes' 101 require 'acts_as_having_boxes'
102 require 'acts_as_having_settings' 102 require 'acts_as_having_settings'
103 require 'acts_as_having_image' 103 require 'acts_as_having_image'
104 -require 'hacked_after_create'  
105 require 'sqlite_extension' 104 require 'sqlite_extension'
106 require 'will_paginate' 105 require 'will_paginate'
107 106
lib/hacked_after_create.rb
@@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
1 -class << ActiveRecord::Base  
2 - # it seems that in some enviroments after_create hook is not inherited. This  
3 - # method calls after_create only if the callback is not already there.  
4 - def hacked_after_create(sym)  
5 - current = after_create  
6 - if !current.include?(sym)  
7 - current = after_create(sym)  
8 - end  
9 - current  
10 - end  
11 -end  
test/unit/enterprise_test.rb
@@ -68,12 +68,13 @@ class EnterpriseTest &lt; Test::Unit::TestCase @@ -68,12 +68,13 @@ class EnterpriseTest &lt; Test::Unit::TestCase
68 assert e.boxes[0].blocks.map(&:class).include?(MainBlock), 'enterprise must have a MainBlock upon creation' 68 assert e.boxes[0].blocks.map(&:class).include?(MainBlock), 'enterprise must have a MainBlock upon creation'
69 69
70 assert e.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock), 'enterprise must have a ProfileInfoBlock upon creation' 70 assert e.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock), 'enterprise must have a ProfileInfoBlock upon creation'
  71 + assert e.boxes[1].blocks.map(&:class).include?(ProductsBlock), 'enterprise must have a ProductsBlock upon creation'
71 assert e.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock), 'enterprise must have a RecentDocumentsBlock upon creation' 72 assert e.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock), 'enterprise must have a RecentDocumentsBlock upon creation'
72 73
73 assert e.boxes[2].blocks.map(&:class).include?(MembersBlock), 'enterprise must have a MembersBlock upon creation' 74 assert e.boxes[2].blocks.map(&:class).include?(MembersBlock), 'enterprise must have a MembersBlock upon creation'
74 assert e.boxes[2].blocks.map(&:class).include?(TagsBlock), 'enterprise must have a TagsBlock upon creation' 75 assert e.boxes[2].blocks.map(&:class).include?(TagsBlock), 'enterprise must have a TagsBlock upon creation'
75 76
76 - assert_equal 5, e.blocks.size 77 + assert_equal 6, e.blocks.size
77 end 78 end
78 79
79 should 'be found in search for its product categories' do 80 should 'be found in search for its product categories' do