Commit f37d4b1e6ffa05acc281177791409ab4bec60dae
1 parent
f869a551
Exists in
master
and in
28 other branches
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
Showing
7 changed files
with
34 additions
and
53 deletions
Show diff stats
app/models/enterprise.rb
app/models/organization.rb
... | ... | @@ -54,18 +54,12 @@ class Organization < Profile |
54 | 54 | true |
55 | 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 | 63 | end |
70 | 64 | |
71 | 65 | end | ... | ... |
app/models/person.rb
... | ... | @@ -70,34 +70,14 @@ class Person < Profile |
70 | 70 | end |
71 | 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 | 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 | 81 | def name |
102 | 82 | if !self[:name].blank? |
103 | 83 | self[:name] | ... | ... |
app/models/profile.rb
... | ... | @@ -166,7 +166,7 @@ class Profile < ActiveRecord::Base |
166 | 166 | end |
167 | 167 | |
168 | 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 | 171 | # creates the initial set of boxes when the profile is created. Can be |
172 | 172 | # overriden for each subclass to create a custom set of boxes for its |
... | ... | @@ -175,6 +175,15 @@ class Profile < ActiveRecord::Base |
175 | 175 | 3.times do |
176 | 176 | self.boxes << Box.new |
177 | 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 | 187 | true |
179 | 188 | end |
180 | 189 | |
... | ... | @@ -300,7 +309,7 @@ class Profile < ActiveRecord::Base |
300 | 309 | false |
301 | 310 | end |
302 | 311 | |
303 | - hacked_after_create :insert_default_homepage_and_feed | |
312 | + after_create :insert_default_homepage_and_feed | |
304 | 313 | def insert_default_homepage_and_feed |
305 | 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 | 315 | hp.profile = self | ... | ... |
config/environment.rb
... | ... | @@ -101,7 +101,6 @@ require 'acts_as_searchable' |
101 | 101 | require 'acts_as_having_boxes' |
102 | 102 | require 'acts_as_having_settings' |
103 | 103 | require 'acts_as_having_image' |
104 | -require 'hacked_after_create' | |
105 | 104 | require 'sqlite_extension' |
106 | 105 | require 'will_paginate' |
107 | 106 | ... | ... |
lib/hacked_after_create.rb
... | ... | @@ -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 < Test::Unit::TestCase |
68 | 68 | assert e.boxes[0].blocks.map(&:class).include?(MainBlock), 'enterprise must have a MainBlock upon creation' |
69 | 69 | |
70 | 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 | 72 | assert e.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock), 'enterprise must have a RecentDocumentsBlock upon creation' |
72 | 73 | |
73 | 74 | assert e.boxes[2].blocks.map(&:class).include?(MembersBlock), 'enterprise must have a MembersBlock upon creation' |
74 | 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 | 78 | end |
78 | 79 | |
79 | 80 | should 'be found in search for its product categories' do | ... | ... |