From 358c5f33d297f68b01aa1ad83fe853db61ed1689 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 23 Jan 2008 22:52:01 +0000 Subject: [PATCH] ActionItem154: making blocks refer to their owner trough their box --- app/models/block.rb | 4 ++++ test/unit/block_test.rb | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/app/models/block.rb b/app/models/block.rb index 061d9ce..eee9e24 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -23,4 +23,8 @@ class Block < ActiveRecord::Base false end + def owner + box ? box.owner : nil + end + end diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index d552813..7f67654 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -14,5 +14,22 @@ class BlockTest < Test::Unit::TestCase assert_kind_of Hash, Block.find(block.id).settings end + + + should 'access owner through box' do + user = create_user('testinguser').person + + box = Box.create!(:owner => user) + + block = Block.new + block.box = box + block.save! + + assert_equal user, block.owner + end + + should 'have no owner when there is no box' do + assert_nil Block.new.owner + end end -- libgit2 0.21.2