Commit 46e64845efff11088cb086f6b312b026e39f5275
1 parent
9bd5e533
Exists in
master
and in
23 other branches
ActionItem93: removing products together with their owners
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1067 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
13 additions
and
1 deletions
Show diff stats
app/models/enterprise.rb
| 1 | # An enterprise is a kind of organization. According to the system concept, | 1 | # An enterprise is a kind of organization. According to the system concept, |
| 2 | # only enterprises can offer products and services. | 2 | # only enterprises can offer products and services. |
| 3 | class Enterprise < Organization | 3 | class Enterprise < Organization |
| 4 | - has_many :products | 4 | + has_many :products, :dependent => :destroy |
| 5 | end | 5 | end |
test/unit/enterprise_test.rb
| @@ -46,4 +46,16 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -46,4 +46,16 @@ class EnterpriseTest < Test::Unit::TestCase | ||
| 46 | end | 46 | end |
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | + should 'remove products when removing enterprise' do | ||
| 50 | + e = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise') | ||
| 51 | + e.products.build(:name => 'One product').save! | ||
| 52 | + e.products.build(:name => 'Another product').save! | ||
| 53 | + | ||
| 54 | + assert_difference Product, :count, -2 do | ||
| 55 | + e.destroy | ||
| 56 | + end | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + end | ||
| 60 | + | ||
| 49 | end | 61 | end |