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
iv
gitlab-ce
Commits
bc7c5f87
Commit
bc7c5f87
authored
Mar 24, 2013
by
Andrew8xx8
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Project snippet moved to separate model
parent
7d2fbe6b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
7 deletions
+66
-7
app/models/project_snippet.rb
app/models/project_snippet.rb
+27
-0
app/models/snippet.rb
app/models/snippet.rb
+2
-3
db/migrate/20130324151736_add_type_to_snippets.rb
db/migrate/20130324151736_add_type_to_snippets.rb
+5
-0
db/schema.rb
db/schema.rb
+2
-1
spec/models/project_snippet_spec.rb
spec/models/project_snippet_spec.rb
+30
-0
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+0
-3
No files found.
app/models/project_snippet.rb
0 → 100644
View file @
bc7c5f87
# == Schema Information
#
# Table name: snippets
#
# id :integer not null, primary key
# title :string(255)
# content :text
# author_id :integer not null
# project_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# file_name :string(255)
# expires_at :datetime
# type :string(255)
# private :boolean
class
ProjectSnippet
<
Snippet
belongs_to
:project
belongs_to
:author
,
class_name:
"User"
validates
:project
,
presence:
true
# Scopes
scope
:fresh
,
->
{
order
(
"created_at DESC"
)
}
scope
:non_expired
,
->
{
where
([
"expires_at IS NULL OR expires_at > ?"
,
Time
.
current
])
}
scope
:expired
,
->
{
where
([
"expires_at IS NOT NULL AND expires_at < ?"
,
Time
.
current
])
}
end
app/models/snippet.rb
View file @
bc7c5f87
...
@@ -11,21 +11,20 @@
...
@@ -11,21 +11,20 @@
# updated_at :datetime not null
# updated_at :datetime not null
# file_name :string(255)
# file_name :string(255)
# expires_at :datetime
# expires_at :datetime
#
# type :string(255)
# private :boolean
class
Snippet
<
ActiveRecord
::
Base
class
Snippet
<
ActiveRecord
::
Base
include
Linguist
::
BlobHelper
include
Linguist
::
BlobHelper
attr_accessible
:title
,
:content
,
:file_name
,
:expires_at
attr_accessible
:title
,
:content
,
:file_name
,
:expires_at
belongs_to
:project
belongs_to
:author
,
class_name:
"User"
belongs_to
:author
,
class_name:
"User"
has_many
:notes
,
as: :noteable
,
dependent: :destroy
has_many
:notes
,
as: :noteable
,
dependent: :destroy
delegate
:name
,
:email
,
to: :author
,
prefix:
true
,
allow_nil:
true
delegate
:name
,
:email
,
to: :author
,
prefix:
true
,
allow_nil:
true
validates
:author
,
presence:
true
validates
:author
,
presence:
true
validates
:project
,
presence:
true
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:file_name
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:file_name
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:content
,
presence:
true
validates
:content
,
presence:
true
...
...
db/migrate/20130324151736_add_type_to_snippets.rb
0 → 100644
View file @
bc7c5f87
class
AddTypeToSnippets
<
ActiveRecord
::
Migration
def
change
add_column
:snippets
,
:type
,
:string
end
end
db/schema.rb
View file @
bc7c5f87
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended to check this file into your version control system.
# It's strongly recommended to check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
:version
=>
2013032
3174317
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
2013032
4151736
)
do
create_table
"events"
,
:force
=>
true
do
|
t
|
create_table
"events"
,
:force
=>
true
do
|
t
|
t
.
string
"target_type"
t
.
string
"target_type"
...
@@ -191,6 +191,7 @@ ActiveRecord::Schema.define(:version => 20130323174317) do
...
@@ -191,6 +191,7 @@ ActiveRecord::Schema.define(:version => 20130323174317) do
t
.
string
"file_name"
t
.
string
"file_name"
t
.
datetime
"expires_at"
t
.
datetime
"expires_at"
t
.
boolean
"private"
t
.
boolean
"private"
t
.
string
"type"
end
end
add_index
"snippets"
,
[
"created_at"
],
:name
=>
"index_snippets_on_created_at"
add_index
"snippets"
,
[
"created_at"
],
:name
=>
"index_snippets_on_created_at"
...
...
spec/models/project_snippet_spec.rb
0 → 100644
View file @
bc7c5f87
# == Schema Information
#
# Table name: snippets
#
# id :integer not null, primary key
# title :string(255)
# content :text
# author_id :integer not null
# project_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# file_name :string(255)
# expires_at :datetime
#
require
'spec_helper'
describe
ProjectSnippet
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
end
describe
"Mass assignment"
do
it
{
should_not
allow_mass_assignment_of
(
:project_id
)
}
end
describe
"Validation"
do
it
{
should
validate_presence_of
(
:project
)
}
end
end
spec/models/snippet_spec.rb
View file @
bc7c5f87
...
@@ -17,19 +17,16 @@ require 'spec_helper'
...
@@ -17,19 +17,16 @@ require 'spec_helper'
describe
Snippet
do
describe
Snippet
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:author
).
class_name
(
'User'
)
}
it
{
should
belong_to
(
:author
).
class_name
(
'User'
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
end
end
describe
"Mass assignment"
do
describe
"Mass assignment"
do
it
{
should_not
allow_mass_assignment_of
(
:author_id
)
}
it
{
should_not
allow_mass_assignment_of
(
:author_id
)
}
it
{
should_not
allow_mass_assignment_of
(
:project_id
)
}
end
end
describe
"Validation"
do
describe
"Validation"
do
it
{
should
validate_presence_of
(
:author
)
}
it
{
should
validate_presence_of
(
:author
)
}
it
{
should
validate_presence_of
(
:project
)
}
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
ensure_length_of
(
:title
).
is_within
(
0
..
255
)
}
it
{
should
ensure_length_of
(
:title
).
is_within
(
0
..
255
)
}
...
...
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