Commit 46e64845efff11088cb086f6b312b026e39f5275

Authored by AntonioTerceiro
1 parent 9bd5e533

ActionItem93: removing products together with their owners



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1067 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/enterprise.rb
1 1 # An enterprise is a kind of organization. According to the system concept,
2 2 # only enterprises can offer products and services.
3 3 class Enterprise < Organization
4   - has_many :products
  4 + has_many :products, :dependent => :destroy
5 5 end
... ...
test/unit/enterprise_test.rb
... ... @@ -46,4 +46,16 @@ class EnterpriseTest &lt; Test::Unit::TestCase
46 46 end
47 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 61 end
... ...