diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index c042abd..8f3e089 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -57,4 +57,13 @@ class Enterprise < Organization end end + + def default_set_of_blocks + [ + [MainBlock], + [ProfileInfoBlock, ProductsBlock, RecentDocumentsBlock], + [MembersBlock, TagsBlock] + ] + end + end diff --git a/app/models/organization.rb b/app/models/organization.rb index 8ceca84..48e376f 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -54,18 +54,12 @@ class Organization < Profile true end - hacked_after_create :create_default_set_of_blocks_for_organization - def create_default_set_of_blocks_for_organization - # "main" area - self.boxes[0].blocks << MainBlock.new - - # "left" area - self.boxes[1].blocks << ProfileInfoBlock.new - self.boxes[1].blocks << RecentDocumentsBlock.new - - # "right" area - self.boxes[2].blocks << MembersBlock.new - self.boxes[2].blocks << TagsBlock.new + def default_set_of_blocks + [ + [MainBlock], + [ProfileInfoBlock, RecentDocumentsBlock], + [MembersBlock, TagsBlock] + ] end end diff --git a/app/models/person.rb b/app/models/person.rb index 8af262f..81c772d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -70,34 +70,14 @@ class Person < Profile end end - # FIXME this is *weird*, because this class is not inheriting the callback - # from Profile !!! - hacked_after_create :create_default_set_of_boxes_for_person - def create_default_set_of_boxes_for_person - 3.times do - self.boxes << Box.new - end - - # main area - self.boxes.first.blocks << MainBlock.new - - # "left" area - self.boxes[1].blocks << ProfileInfoBlock.new - self.boxes[1].blocks << RecentDocumentsBlock.new - - # right area - self.boxes[2].blocks << TagsBlock.new - self.boxes[2].blocks << FriendsBlock.new - self.boxes[2].blocks << CommunitiesBlock.new - self.boxes[2].blocks << EnterprisesBlock.new - - true + def default_set_of_blocks + [ + [MainBlock], + [ProfileInfoBlock, RecentDocumentsBlock], + [TagsBlock, FriendsBlock, CommunitiesBlock, EnterprisesBlock] + ] end - # FIXME this is *weird*, because this class is not inheriting the callbacks - before_create :set_default_environment - hacked_after_create :insert_default_homepage_and_feed - def name if !self[:name].blank? self[:name] diff --git a/app/models/profile.rb b/app/models/profile.rb index 51334ab..884101c 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -166,7 +166,7 @@ class Profile < ActiveRecord::Base end # registar callback for creating boxes after the object is created. - hacked_after_create :create_default_set_of_boxes + after_create :create_default_set_of_boxes # creates the initial set of boxes when the profile is created. Can be # overriden for each subclass to create a custom set of boxes for its @@ -175,6 +175,15 @@ class Profile < ActiveRecord::Base 3.times do self.boxes << Box.new end + + if self.respond_to?(:default_set_of_blocks) + default_set_of_blocks.each_with_index do |blocks,i| + blocks.each do |block| + self.boxes[i].blocks << block.new + end + end + end + true end @@ -300,7 +309,7 @@ class Profile < ActiveRecord::Base false end - hacked_after_create :insert_default_homepage_and_feed + after_create :insert_default_homepage_and_feed def insert_default_homepage_and_feed hp = TinyMceArticle.new(:name => _("%s's home page") % self.name, :body => _("

This is a default homepage created for %s. It can be changed though the control panel.

") % self.name, :advertise => false) hp.profile = self diff --git a/config/environment.rb b/config/environment.rb index 5c42ff8..ba8a4e4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -101,7 +101,6 @@ require 'acts_as_searchable' require 'acts_as_having_boxes' require 'acts_as_having_settings' require 'acts_as_having_image' -require 'hacked_after_create' require 'sqlite_extension' require 'will_paginate' diff --git a/lib/hacked_after_create.rb b/lib/hacked_after_create.rb deleted file mode 100644 index 60848f2..0000000 --- a/lib/hacked_after_create.rb +++ /dev/null @@ -1,11 +0,0 @@ -class << ActiveRecord::Base - # it seems that in some enviroments after_create hook is not inherited. This - # method calls after_create only if the callback is not already there. - def hacked_after_create(sym) - current = after_create - if !current.include?(sym) - current = after_create(sym) - end - current - end -end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 976b7da..abc65c6 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -68,12 +68,13 @@ class EnterpriseTest < Test::Unit::TestCase assert e.boxes[0].blocks.map(&:class).include?(MainBlock), 'enterprise must have a MainBlock upon creation' assert e.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock), 'enterprise must have a ProfileInfoBlock upon creation' + assert e.boxes[1].blocks.map(&:class).include?(ProductsBlock), 'enterprise must have a ProductsBlock upon creation' assert e.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock), 'enterprise must have a RecentDocumentsBlock upon creation' assert e.boxes[2].blocks.map(&:class).include?(MembersBlock), 'enterprise must have a MembersBlock upon creation' assert e.boxes[2].blocks.map(&:class).include?(TagsBlock), 'enterprise must have a TagsBlock upon creation' - assert_equal 5, e.blocks.size + assert_equal 6, e.blocks.size end should 'be found in search for its product categories' do -- libgit2 0.21.2