Commit fd983d96da8ef7f90dedbe1ee09ba8d75e9df22a
1 parent
976dd94a
Exists in
master
and in
28 other branches
ActionItem152: blocks can declare settings items
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1261 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
30 additions
and
0 deletions
Show diff stats
app/models/block.rb
... | ... | @@ -11,6 +11,17 @@ class Block < ActiveRecord::Base |
11 | 11 | self[:settings] ||= Hash.new |
12 | 12 | end |
13 | 13 | |
14 | + def self.settings_item(name) | |
15 | + class_eval <<-CODE | |
16 | + def #{name} | |
17 | + settings[:#{name}] | |
18 | + end | |
19 | + def #{name}=(value) | |
20 | + settings[:#{name}] = value | |
21 | + end | |
22 | + CODE | |
23 | + end | |
24 | + | |
14 | 25 | def self.description |
15 | 26 | _('A dummy block.') |
16 | 27 | end | ... | ... |
test/unit/block_test.rb
... | ... | @@ -32,4 +32,23 @@ class BlockTest < Test::Unit::TestCase |
32 | 32 | assert_nil Block.new.owner |
33 | 33 | end |
34 | 34 | |
35 | + should 'be able to declare settings items' do | |
36 | + block_class = Class.new(Block) | |
37 | + | |
38 | + block = block_class.new | |
39 | + assert !block.respond_to?(:limit) | |
40 | + assert !block.respond_to?(:limit=) | |
41 | + | |
42 | + block_class.settings_item :limit | |
43 | + | |
44 | + assert_respond_to block, :limit | |
45 | + assert_respond_to block, :limit= | |
46 | + | |
47 | + assert_nil block.limit | |
48 | + block.limit = 10 | |
49 | + assert_equal 10, block.limit | |
50 | + | |
51 | + assert_equal({ :limit => 10}, block.settings) | |
52 | + end | |
53 | + | |
35 | 54 | end | ... | ... |