Commit 7eff9852851d39b69f040b130d8819653e507dd2
1 parent
47bee664
Exists in
master
and in
23 other branches
container_block: remove need of container_block_array
Showing
7 changed files
with
3 additions
and
65 deletions
Show diff stats
plugins/container_block/lib/container_block_plugin/container_block.rb
| @@ -24,7 +24,7 @@ class ContainerBlockPlugin::ContainerBlock < Block | @@ -24,7 +24,7 @@ class ContainerBlockPlugin::ContainerBlock < Block | ||
| 24 | end | 24 | end |
| 25 | 25 | ||
| 26 | def create_box | 26 | def create_box |
| 27 | - box = Box.create!(:owner => self) | 27 | + box = Box.create!(:owner => owner) |
| 28 | settings[:container_box_id] = box.id | 28 | settings[:container_box_id] = box.id |
| 29 | save! | 29 | save! |
| 30 | end | 30 | end |
| @@ -34,7 +34,7 @@ class ContainerBlockPlugin::ContainerBlock < Block | @@ -34,7 +34,7 @@ class ContainerBlockPlugin::ContainerBlock < Block | ||
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | def container_box | 36 | def container_box |
| 37 | - Box.find(container_box_id) | 37 | + owner.boxes.find(container_box_id) |
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | def block_classes=(classes) | 40 | def block_classes=(classes) |
plugins/container_block/lib/container_block_plugin/container_block_array.rb
| @@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
| 1 | -module ContainerBlockPlugin::ContainerBlockArray | ||
| 2 | - | ||
| 3 | - def blocks_with_container_block_plugin(reload = false) | ||
| 4 | - blocks = blocks_without_container_block_plugin(reload) | ||
| 5 | - blocks.each { |block| blocks.concat(block.blocks) if block.kind_of?(ContainerBlockPlugin::ContainerBlock) } | ||
| 6 | - end | ||
| 7 | - | ||
| 8 | - def self.included(base) | ||
| 9 | - base.class_eval do | ||
| 10 | - alias_method_chain :blocks, :container_block_plugin | ||
| 11 | - end | ||
| 12 | - end | ||
| 13 | - | ||
| 14 | -end |
plugins/container_block/lib/ext/block.rb
| @@ -1,10 +0,0 @@ | @@ -1,10 +0,0 @@ | ||
| 1 | -require_dependency 'block' | ||
| 2 | - | ||
| 3 | -class Block | ||
| 4 | - def owner_with_container_block_plugin | ||
| 5 | - owner = owner_without_container_block_plugin | ||
| 6 | - owner.kind_of?(ContainerBlockPlugin::ContainerBlock) ? owner.owner : owner | ||
| 7 | - end | ||
| 8 | - | ||
| 9 | - alias_method_chain :owner, :container_block_plugin | ||
| 10 | -end |
plugins/container_block/lib/ext/environment.rb
plugins/container_block/lib/ext/profile.rb
plugins/container_block/test/unit/container_block_plugin/container_block_array_test.rb
| @@ -1,29 +0,0 @@ | @@ -1,29 +0,0 @@ | ||
| 1 | -require 'test_helper' | ||
| 2 | - | ||
| 3 | -class ContainerBlockPlugin::ContainerBlockArrayTest < ActiveSupport::TestCase | ||
| 4 | - | ||
| 5 | - attr_reader :blocks | ||
| 6 | - | ||
| 7 | - include ContainerBlockPlugin::ContainerBlockArray | ||
| 8 | - | ||
| 9 | - def setup | ||
| 10 | - @blocks = [] | ||
| 11 | - | ||
| 12 | - @environment = fast_create(Environment) | ||
| 13 | - @container_box = Box.new(:owner => @environment) | ||
| 14 | - @container = ContainerBlockPlugin::ContainerBlock.new(:box => @container_box) | ||
| 15 | - end | ||
| 16 | - | ||
| 17 | - should 'return blocks as usual' do | ||
| 18 | - @blocks << Block.new | ||
| 19 | - assert_equal @blocks, blocks_without_container_block_plugin | ||
| 20 | - end | ||
| 21 | - | ||
| 22 | - should 'return blocks and container block children' do | ||
| 23 | - @container.save! | ||
| 24 | - @container_box.blocks << Block.new | ||
| 25 | - @blocks.concat([Block.new, @container]) | ||
| 26 | - assert_equal @blocks + @container.blocks, blocks_without_container_block_plugin | ||
| 27 | - end | ||
| 28 | - | ||
| 29 | -end |
plugins/container_block/test/unit/container_block_plugin/container_block_test.rb
| @@ -4,6 +4,7 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase | @@ -4,6 +4,7 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase | ||
| 4 | 4 | ||
| 5 | def setup | 5 | def setup |
| 6 | @block = ContainerBlockPlugin::ContainerBlock.new | 6 | @block = ContainerBlockPlugin::ContainerBlock.new |
| 7 | + @block.stubs(:owner).returns(Environment.default) | ||
| 7 | end | 8 | end |
| 8 | 9 | ||
| 9 | should 'describe yourself' do | 10 | should 'describe yourself' do |