Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ad177410
Commit
ad177410
authored
May 21, 2016
by
Long Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove todos when destroy project member and specs
parent
ed9b6497
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
2 deletions
+47
-2
app/models/members/project_member.rb
app/models/members/project_member.rb
+3
-1
app/models/user.rb
app/models/user.rb
+1
-1
spec/models/members/project_member_spec.rb
spec/models/members/project_member_spec.rb
+43
-0
No files found.
app/models/members/project_member.rb
View file @
ad177410
...
...
@@ -3,9 +3,9 @@ class ProjectMember < Member
include
Gitlab
::
ShellAdapter
has_many
:todos
,
through: :user
belongs_to
:project
,
class_name:
'Project'
,
foreign_key:
'source_id'
# Make sure project member points only to project as it source
default_value_for
:source_type
,
SOURCE_TYPE
validates_format_of
:source_type
,
with:
/\AProject\z/
...
...
@@ -15,6 +15,8 @@ class ProjectMember < Member
scope
:in_projects
,
->
(
projects
)
{
where
(
source_id:
projects
.
pluck
(
:id
))
}
scope
:with_user
,
->
(
user
)
{
where
(
user_id:
user
.
id
)
}
before_destroy
{
todos
.
each
(
&
:destroy
)
}
class
<<
self
# Add users to project teams with passed access option
...
...
app/models/user.rb
View file @
ad177410
...
...
@@ -77,7 +77,7 @@ class User < ActiveRecord::Base
has_one
:abuse_report
,
dependent: :destroy
has_many
:spam_logs
,
dependent: :destroy
has_many
:builds
,
dependent: :nullify
,
class_name:
'Ci::Build'
has_many
:todos
,
->
{
joins
(
"join members on members.source_id = todos.project_id and members.user_id = todos.user_id"
)
},
dependent: :destroy
has_many
:todos
,
dependent: :destroy
has_many
:notification_settings
,
dependent: :destroy
#
...
...
spec/models/members/project_member_spec.rb
View file @
ad177410
...
...
@@ -20,6 +20,49 @@
require
'spec_helper'
describe
ProjectMember
,
models:
true
do
describe
'associations'
do
it
{
is_expected
.
to
have_many
(
:todos
).
through
(
:user
)
}
it
{
is_expected
.
to
belong_to
(
:project
).
class_name
(
'Project'
).
with_foreign_key
(
:source_id
)
}
end
describe
'validations'
do
it
{
is_expected
.
to
allow_value
(
'Project'
).
for
(
:source_type
)
}
it
{
is_expected
.
not_to
allow_value
(
'project'
).
for
(
:source_type
)
}
end
describe
'modules'
do
it
{
is_expected
.
to
include_module
(
Gitlab
::
ShellAdapter
)
}
end
describe
"#destroy"
do
let
(
:owner
)
{
create
(
:project_member
,
access_level:
ProjectMember
::
OWNER
)
}
let
(
:project
)
{
owner
.
project
}
let
(
:master
)
{
create
(
:project_member
,
project:
project
)
}
let
(
:owner_todos
)
{
(
0
...
2
).
map
{
create
(
:todo
,
user:
owner
.
user
,
project:
project
)
}
}
let
(
:master_todos
)
{
(
0
...
3
).
map
{
create
(
:todo
,
user:
master
.
user
,
project:
project
)
}
}
before
do
owner_todos
master_todos
end
it
"destroy itself and delete associated todos"
do
expect
(
owner
.
todos
.
size
).
to
eq
(
2
)
expect
(
master
.
todos
.
size
).
to
eq
(
3
)
expect
(
Todo
.
count
).
to
eq
(
5
)
master_todo_ids
=
master_todos
.
map
(
&
:id
)
master
.
destroy
expect
(
owner
.
todos
.
size
).
to
eq
(
2
)
expect
(
Todo
.
count
).
to
eq
(
2
)
master_todo_ids
.
each
do
|
id
|
expect
(
Todo
.
exists?
(
id
)).
to
eq
(
false
)
end
end
end
describe
:import_team
do
before
do
@abilities
=
Six
.
new
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment