Commit 9a5f328313a85142af669b6745825e3e2c7b3005
1 parent
eb96336d
Exists in
master
and in
4 other branches
notes should depends on user when destroy
Showing
2 changed files
with
19 additions
and
0 deletions
Show diff stats
app/models/user.rb
... | ... | @@ -16,6 +16,10 @@ class User < ActiveRecord::Base |
16 | 16 | :foreign_key => :author_id, |
17 | 17 | :dependent => :destroy |
18 | 18 | |
19 | + has_many :notes, | |
20 | + :foreign_key => :author_id, | |
21 | + :dependent => :destroy | |
22 | + | |
19 | 23 | has_many :assigned_issues, |
20 | 24 | :class_name => "Issue", |
21 | 25 | :foreign_key => :assignee_id, | ... | ... |
spec/models/user_spec.rb
... | ... | @@ -18,6 +18,21 @@ describe User do |
18 | 18 | user = User.new(:email => "test@mail.com") |
19 | 19 | user.identifier.should == "test_mail.com" |
20 | 20 | end |
21 | + | |
22 | + describe "dependent" do | |
23 | + before do | |
24 | + @user = Factory :user | |
25 | + @note = Factory :note, | |
26 | + :author => @user, | |
27 | + :project => Factory(:project) | |
28 | + end | |
29 | + | |
30 | + it "should destroy all notes with user" do | |
31 | + Note.find_by_id(@note.id).should_not be_nil | |
32 | + @user.destroy | |
33 | + Note.find_by_id(@note.id).should be_nil | |
34 | + end | |
35 | + end | |
21 | 36 | end |
22 | 37 | # == Schema Information |
23 | 38 | # | ... | ... |