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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
41d8f564
Commit
41d8f564
authored
Feb 12, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add task model
parent
040ae7e3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
1 deletion
+95
-1
app/models/task.rb
app/models/task.rb
+29
-0
app/models/user.rb
app/models/user.rb
+1
-1
db/migrate/20160212123307_create_tasks.rb
db/migrate/20160212123307_create_tasks.rb
+14
-0
db/schema.rb
db/schema.rb
+18
-0
spec/models/task_spec.rb
spec/models/task_spec.rb
+32
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-0
No files found.
app/models/task.rb
0 → 100644
View file @
41d8f564
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# user_id :integer not null
# project_id :integer not null
# target_id :integer not null
# target_type :string not null
# author_id :integer
# action :integer
# state :string not null
# created_at :datetime
# updated_at :datetime
#
class
Task
<
ActiveRecord
::
Base
belongs_to
:author
,
class_name:
"User"
belongs_to
:project
belongs_to
:target
,
polymorphic:
true
,
touch:
true
belongs_to
:user
validates
:action
,
:project
,
:target
,
:user
,
presence:
true
state_machine
:state
,
initial: :pending
do
state
:pending
state
:done
end
end
app/models/user.rb
View file @
41d8f564
...
...
@@ -140,7 +140,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
:tasks
,
dependent: :destroy
#
# Validations
...
...
db/migrate/20160212123307_create_tasks.rb
0 → 100644
View file @
41d8f564
class
CreateTasks
<
ActiveRecord
::
Migration
def
change
create_table
:tasks
do
|
t
|
t
.
references
:user
,
null:
false
,
index:
true
t
.
references
:project
,
null:
false
,
index:
true
t
.
references
:target
,
polymorphic:
true
,
null:
false
,
index:
true
t
.
integer
:author_id
,
index:
true
t
.
integer
:action
,
null:
false
t
.
string
:state
,
null:
false
,
index:
true
t
.
timestamps
end
end
end
db/schema.rb
View file @
41d8f564
...
...
@@ -824,6 +824,24 @@ ActiveRecord::Schema.define(version: 20160217100506) do
add_index
"tags"
,
[
"name"
],
name:
"index_tags_on_name"
,
unique:
true
,
using: :btree
create_table
"tasks"
,
force: :cascade
do
|
t
|
t
.
integer
"user_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
integer
"target_id"
,
null:
false
t
.
string
"target_type"
,
null:
false
t
.
integer
"author_id"
t
.
integer
"action"
,
null:
false
t
.
string
"state"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
add_index
"tasks"
,
[
"author_id"
],
name:
"index_tasks_on_author_id"
,
using: :btree
add_index
"tasks"
,
[
"project_id"
],
name:
"index_tasks_on_project_id"
,
using: :btree
add_index
"tasks"
,
[
"state"
],
name:
"index_tasks_on_state"
,
using: :btree
add_index
"tasks"
,
[
"target_type"
,
"target_id"
],
name:
"index_tasks_on_target_type_and_target_id"
,
using: :btree
add_index
"tasks"
,
[
"user_id"
],
name:
"index_tasks_on_user_id"
,
using: :btree
create_table
"users"
,
force: :cascade
do
|
t
|
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
...
...
spec/models/task_spec.rb
0 → 100644
View file @
41d8f564
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# user_id :integer not null
# project_id :integer not null
# target_id :integer not null
# target_type :string not null
# author_id :integer
# action :integer
# state :string not null
# created_at :datetime
# updated_at :datetime
#
require
'spec_helper'
describe
Task
,
models:
true
do
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:author
).
class_name
(
"User"
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:target
).
touch
(
true
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
end
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:action
)
}
it
{
is_expected
.
to
validate_presence_of
(
:target
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
end
end
spec/models/user_spec.rb
View file @
41d8f564
...
...
@@ -92,6 +92,7 @@ describe User, models: true do
it
{
is_expected
.
to
have_many
(
:identities
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_one
(
:abuse_report
)
}
it
{
is_expected
.
to
have_many
(
:spam_logs
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:tasks
).
dependent
(
:destroy
)
}
end
describe
'validations'
do
...
...
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