Commit e381bcc6307ee6b9f11f55ee151c50c5199569b4
1 parent
2d698f0b
Exists in
master
and in
29 other branches
Destroy roles when environment is destroyed
(ActionItem2987)
Showing
2 changed files
with
13 additions
and
1 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -184,7 +184,7 @@ class Environment < ActiveRecord::Base |
184 | 184 | has_many :product_categories, :conditions => { :type => 'ProductCategory'} |
185 | 185 | has_many :regions |
186 | 186 | |
187 | - has_many :roles | |
187 | + has_many :roles, :dependent => :destroy | |
188 | 188 | |
189 | 189 | has_many :qualifiers |
190 | 190 | has_many :certifiers | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -783,6 +783,18 @@ class EnvironmentTest < ActiveSupport::TestCase |
783 | 783 | assert role2.valid? |
784 | 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 | 798 | should 'have a help_message_to_add_enterprise attribute' do |
787 | 799 | env = Environment.new |
788 | 800 | ... | ... |