Commit 4324e6fcba0f04cf9f779014e99e58a1739b2f50
1 parent
b1ce5ed3
Exists in
master
and in
28 other branches
r228@sede: terceiro | 2007-07-28 16:57:19 -0300
ActionItem0: bringing Block from old flexible_template git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@232 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
93 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +module Design | |
| 2 | + | |
| 3 | + # Box ix the base class for most of the content elements. A Box is contaied | |
| 4 | + # by a Block, which may contain several blocks. | |
| 5 | + class Block < ActiveRecord::Base | |
| 6 | + | |
| 7 | + set_table_name 'design_blocks' | |
| 8 | + | |
| 9 | + belongs_to :box | |
| 10 | + | |
| 11 | + #<tt>position</tt> codl not be nil and must be an integer | |
| 12 | + validates_numericality_of :position, :only_integer => true | |
| 13 | + #TODO see the internationalization | |
| 14 | + #, :message => _('%{fn} must be composed only of integers') | |
| 15 | + | |
| 16 | + # A block must be associated to a box | |
| 17 | + validates_presence_of :box_id | |
| 18 | + | |
| 19 | + # This method always return false excepted when redefined by the MainBlock class. It mean the current block it's not the result of a | |
| 20 | + # controller action. | |
| 21 | + # | |
| 22 | + # The child class MainBlock subscribes this method returning true. | |
| 23 | + def main? | |
| 24 | + false | |
| 25 | + end | |
| 26 | + | |
| 27 | + # Method that define the content code displayed in the box. | |
| 28 | + # This method cannot be used directly it will be redefined by the children classes | |
| 29 | + def content | |
| 30 | + raise "This is a main class, don't use it" | |
| 31 | + end | |
| 32 | + | |
| 33 | + #TODO see if this method is needed | |
| 34 | + def self.children | |
| 35 | + @@block_children | |
| 36 | + end | |
| 37 | + | |
| 38 | + private | |
| 39 | + @@block_children = Array.new | |
| 40 | + | |
| 41 | + def self.inherited(subclass) | |
| 42 | + @@block_children.push(subclass.to_s) unless @@block_children.include? subclass.to_s | |
| 43 | + end | |
| 44 | + | |
| 45 | + end | |
| 46 | + | |
| 47 | +end # END OF module Design | ... | ... |
| ... | ... | @@ -0,0 +1,46 @@ |
| 1 | +require File.dirname(__FILE__) + '/test_helper' | |
| 2 | + | |
| 3 | +class BlockTest < Test::Unit::TestCase | |
| 4 | + | |
| 5 | + include Design | |
| 6 | + | |
| 7 | + def test_position_validation | |
| 8 | + b = Block.new | |
| 9 | + u = DesignTestUser.new | |
| 10 | + assert u.save | |
| 11 | + box = Box.new | |
| 12 | + box.owner = u | |
| 13 | + box.number = 1000 | |
| 14 | + assert box.save | |
| 15 | + b.box = box | |
| 16 | + assert !b.valid? | |
| 17 | + assert b.errors.invalid?(:position) | |
| 18 | + assert_equal 1, b.errors.length | |
| 19 | + end | |
| 20 | + | |
| 21 | + def test_box_validation | |
| 22 | + b = Block.new | |
| 23 | + b.position=1 | |
| 24 | + | |
| 25 | + assert !b.valid? | |
| 26 | + assert b.errors.invalid?(:box_id) | |
| 27 | + assert_equal 1, b.errors.length | |
| 28 | + | |
| 29 | + end | |
| 30 | + | |
| 31 | + def test_save | |
| 32 | + b = Block.new | |
| 33 | + b.position = 1000 | |
| 34 | + | |
| 35 | + u = DesignTestUser.new | |
| 36 | + assert u.save | |
| 37 | + box = Box.new | |
| 38 | + box.owner = u | |
| 39 | + box.number = 1000 | |
| 40 | + assert box.save | |
| 41 | + b.box = box | |
| 42 | + assert b.valid? | |
| 43 | + | |
| 44 | + end | |
| 45 | + | |
| 46 | +end | ... | ... |