From 4324e6fcba0f04cf9f779014e99e58a1739b2f50 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Tue, 31 Jul 2007 13:03:18 +0000 Subject: [PATCH] r228@sede: terceiro | 2007-07-28 16:57:19 -0300 ActionItem0: bringing Block from old flexible_template --- vendor/plugins/design/lib/design/block.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vendor/plugins/design/test/block_test.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 0 deletions(-) create mode 100644 vendor/plugins/design/lib/design/block.rb create mode 100644 vendor/plugins/design/test/block_test.rb diff --git a/vendor/plugins/design/lib/design/block.rb b/vendor/plugins/design/lib/design/block.rb new file mode 100644 index 0000000..44607e7 --- /dev/null +++ b/vendor/plugins/design/lib/design/block.rb @@ -0,0 +1,47 @@ +module Design + + # Box ix the base class for most of the content elements. A Box is contaied + # by a Block, which may contain several blocks. + class Block < ActiveRecord::Base + + set_table_name 'design_blocks' + + belongs_to :box + + #position codl not be nil and must be an integer + validates_numericality_of :position, :only_integer => true + #TODO see the internationalization + #, :message => _('%{fn} must be composed only of integers') + + # A block must be associated to a box + validates_presence_of :box_id + + # This method always return false excepted when redefined by the MainBlock class. It mean the current block it's not the result of a + # controller action. + # + # The child class MainBlock subscribes this method returning true. + def main? + false + end + + # Method that define the content code displayed in the box. + # This method cannot be used directly it will be redefined by the children classes + def content + raise "This is a main class, don't use it" + end + + #TODO see if this method is needed + def self.children + @@block_children + end + + private + @@block_children = Array.new + + def self.inherited(subclass) + @@block_children.push(subclass.to_s) unless @@block_children.include? subclass.to_s + end + + end + +end # END OF module Design diff --git a/vendor/plugins/design/test/block_test.rb b/vendor/plugins/design/test/block_test.rb new file mode 100644 index 0000000..d2cf98d --- /dev/null +++ b/vendor/plugins/design/test/block_test.rb @@ -0,0 +1,46 @@ +require File.dirname(__FILE__) + '/test_helper' + +class BlockTest < Test::Unit::TestCase + + include Design + + def test_position_validation + b = Block.new + u = DesignTestUser.new + assert u.save + box = Box.new + box.owner = u + box.number = 1000 + assert box.save + b.box = box + assert !b.valid? + assert b.errors.invalid?(:position) + assert_equal 1, b.errors.length + end + + def test_box_validation + b = Block.new + b.position=1 + + assert !b.valid? + assert b.errors.invalid?(:box_id) + assert_equal 1, b.errors.length + + end + + def test_save + b = Block.new + b.position = 1000 + + u = DesignTestUser.new + assert u.save + box = Box.new + box.owner = u + box.number = 1000 + assert box.save + b.box = box + assert b.valid? + + end + +end -- libgit2 0.21.2