Commit e0e2d8e52e3fa8e44e731221c6c0b2c431f04c2e

Authored by Diego Camarinha
2 parents cc382578 4e642a56

Merge pull request #279 from mezuro/fix_user_dependant_destroy

Cascade user destroy to its attributes
Showing 2 changed files with 8 additions and 8 deletions   Show diff stats
app/models/user.rb
@@ -8,10 +8,10 @@ class User < ActiveRecord::Base @@ -8,10 +8,10 @@ class User < ActiveRecord::Base
8 validates :email, presence: true 8 validates :email, presence: true
9 validates :email, uniqueness: true 9 validates :email, uniqueness: true
10 10
11 - has_many :project_attributes, class_name: 'ProjectAttributes'  
12 - has_many :reading_group_attributes, class_name: 'ReadingGroupAttributes'  
13 - has_many :repository_attributes, class_name: 'RepositoryAttributes'  
14 - has_many :kalibro_configuration_attributes, class_name: 'KalibroConfigurationAttributes' 11 + has_many :project_attributes, class_name: 'ProjectAttributes', dependent: :destroy
  12 + has_many :reading_group_attributes, class_name: 'ReadingGroupAttributes', dependent: :destroy
  13 + has_many :repository_attributes, class_name: 'RepositoryAttributes', dependent: :destroy
  14 + has_many :kalibro_configuration_attributes, class_name: 'KalibroConfigurationAttributes', dependent: :destroy
15 # Alert: when adding new parameters to this model, they should also be added to registrations_controller 15 # Alert: when adding new parameters to this model, they should also be added to registrations_controller
16 16
17 def projects 17 def projects
spec/models/user_spec.rb
@@ -10,10 +10,10 @@ describe User, :type => :model do @@ -10,10 +10,10 @@ describe User, :type => :model do
10 end 10 end
11 11
12 describe 'associations' do 12 describe 'associations' do
13 - it { is_expected.to have_many(:project_attributes) }  
14 - it { is_expected.to have_many(:reading_group_attributes) }  
15 - it { is_expected.to have_many(:kalibro_configuration_attributes) }  
16 - it { is_expected.to have_many(:repository_attributes) } 13 + it { is_expected.to have_many(:project_attributes).dependent(:destroy) }
  14 + it { is_expected.to have_many(:reading_group_attributes).dependent(:destroy) }
  15 + it { is_expected.to have_many(:kalibro_configuration_attributes).dependent(:destroy) }
  16 + it { is_expected.to have_many(:repository_attributes).dependent(:destroy) }
17 end 17 end
18 18
19 describe 'methods' do 19 describe 'methods' do