Commit e381bcc6307ee6b9f11f55ee151c50c5199569b4

Authored by Daniela Feitosa
1 parent 2d698f0b

Destroy roles when environment is destroyed

(ActionItem2987)
app/models/environment.rb
@@ -184,7 +184,7 @@ class Environment < ActiveRecord::Base @@ -184,7 +184,7 @@ class Environment < ActiveRecord::Base
184 has_many :product_categories, :conditions => { :type => 'ProductCategory'} 184 has_many :product_categories, :conditions => { :type => 'ProductCategory'}
185 has_many :regions 185 has_many :regions
186 186
187 - has_many :roles 187 + has_many :roles, :dependent => :destroy
188 188
189 has_many :qualifiers 189 has_many :qualifiers
190 has_many :certifiers 190 has_many :certifiers
test/unit/environment_test.rb
@@ -783,6 +783,18 @@ class EnvironmentTest < ActiveSupport::TestCase @@ -783,6 +783,18 @@ class EnvironmentTest < ActiveSupport::TestCase
783 assert role2.valid? 783 assert role2.valid?
784 end 784 end
785 785
  786 + should 'destroy roles when its environment is destroyed' do
  787 + e1 = fast_create(Environment)
  788 + role1 = Role.create!(:name => 'test_role', :environment => e1, :key => 'a_member')
  789 + e2 = fast_create(Environment)
  790 + role2 = Role.create!(:name => 'test_role', :environment => e2, :key => 'a_member')
  791 +
  792 + e2.destroy
  793 +
  794 + assert_nothing_raised {Role.find(role1.id)}
  795 + assert_raise(ActiveRecord::RecordNotFound) {Role.find(role2.id)}
  796 + end
  797 +
786 should 'have a help_message_to_add_enterprise attribute' do 798 should 'have a help_message_to_add_enterprise attribute' do
787 env = Environment.new 799 env = Environment.new
788 800