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
5b35000f
Commit
5b35000f
authored
Mar 24, 2013
by
Andrew8xx8
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Snippets feature refactored. Tests now use spinach
parent
bc7c5f87
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
183 additions
and
228 deletions
+183
-228
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+7
-7
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+1
-1
app/models/ability.rb
app/models/ability.rb
+2
-1
app/models/project.rb
app/models/project.rb
+1
-1
app/views/projects/snippets/_form.html.haml
app/views/projects/snippets/_form.html.haml
+2
-2
app/views/projects/snippets/edit.html.haml
app/views/projects/snippets/edit.html.haml
+1
-1
app/views/projects/snippets/index.html.haml
app/views/projects/snippets/index.html.haml
+1
-1
app/views/projects/snippets/new.html.haml
app/views/projects/snippets/new.html.haml
+1
-1
app/views/projects/snippets/show.html.haml
app/views/projects/snippets/show.html.haml
+1
-1
config/routes.rb
config/routes.rb
+8
-9
db/migrate/20130324172327_change_project_id_to_null_in_snipepts.rb
...e/20130324172327_change_project_id_to_null_in_snipepts.rb
+9
-0
db/schema.rb
db/schema.rb
+2
-2
features/project/snippets.feature
features/project/snippets.feature
+35
-0
features/steps/project/project_snippets.rb
features/steps/project/project_snippets.rb
+100
-0
features/steps/shared/paths.rb
features/steps/shared/paths.rb
+4
-0
spec/factories.rb
spec/factories.rb
+8
-1
spec/features/projects/snippets_spec.rb
spec/features/projects/snippets_spec.rb
+0
-101
spec/features/snippets_spec.rb
spec/features/snippets_spec.rb
+0
-99
No files found.
app/controllers/projects/snippets_controller.rb
View file @
5b35000f
...
...
@@ -27,12 +27,12 @@ class Projects::SnippetsController < Projects::ApplicationController
end
def
create
@snippet
=
@project
.
snippets
.
new
(
params
[
:snippet
])
@snippet
=
@project
.
snippets
.
new
(
params
[
:
project_
snippet
])
@snippet
.
author
=
current_user
@snippet
.
save
if
@snippet
.
valid?
redirect_to
[
@project
,
@snippet
]
redirect_to
project_snippet_path
(
@project
,
@snippet
)
else
respond_with
(
@snippet
)
end
...
...
@@ -42,10 +42,10 @@ class Projects::SnippetsController < Projects::ApplicationController
end
def
update
@snippet
.
update_attributes
(
params
[
:snippet
])
@snippet
.
update_attributes
(
params
[
:
project_
snippet
])
if
@snippet
.
valid?
redirect_to
[
@project
,
@snippet
]
redirect_to
project_snippet_path
(
@project
,
@snippet
)
else
respond_with
(
@snippet
)
end
...
...
@@ -58,7 +58,7 @@ class Projects::SnippetsController < Projects::ApplicationController
end
def
destroy
return
access_denied!
unless
can?
(
current_user
,
:admin_snippet
,
@snippet
)
return
access_denied!
unless
can?
(
current_user
,
:admin_
project_
snippet
,
@snippet
)
@snippet
.
destroy
...
...
@@ -81,11 +81,11 @@ class Projects::SnippetsController < Projects::ApplicationController
end
def
authorize_modify_snippet!
return
render_404
unless
can?
(
current_user
,
:modify_snippet
,
@snippet
)
return
render_404
unless
can?
(
current_user
,
:modify_
project_
snippet
,
@snippet
)
end
def
authorize_admin_snippet!
return
render_404
unless
can?
(
current_user
,
:admin_snippet
,
@snippet
)
return
render_404
unless
can?
(
current_user
,
:admin_
project_
snippet
,
@snippet
)
end
def
module_enabled
...
...
app/controllers/snippets_controller.rb
View file @
5b35000f
...
...
@@ -60,7 +60,7 @@ class SnippetsController < ProjectResourceController
@snippet
.
destroy
redirect_to
project_snippet
s
_path
(
@project
)
redirect_to
project_snippet_path
(
@project
)
end
def
raw
...
...
app/models/ability.rb
View file @
5b35000f
...
...
@@ -7,6 +7,7 @@ class Ability
when
"Project"
then
project_abilities
(
user
,
subject
)
when
"Issue"
then
issue_abilities
(
user
,
subject
)
when
"Note"
then
note_abilities
(
user
,
subject
)
when
"ProjectSnippet"
then
project_snippet_abilities
(
user
,
subject
)
when
"Snippet"
then
snippet_abilities
(
user
,
subject
)
when
"MergeRequest"
then
merge_request_abilities
(
user
,
subject
)
when
"Group"
,
"Namespace"
then
group_abilities
(
user
,
subject
)
...
...
@@ -135,7 +136,7 @@ class Ability
end
[
:issue
,
:note
,
:snippet
,
:merge_request
].
each
do
|
name
|
[
:issue
,
:note
,
:
project_snippet
,
:
snippet
,
:merge_request
].
each
do
|
name
|
define_method
"
#{
name
}
_abilities"
do
|
user
,
subject
|
if
subject
.
author
==
user
[
...
...
app/models/project.rb
View file @
5b35000f
...
...
@@ -50,7 +50,7 @@ class Project < ActiveRecord::Base
has_many
:milestones
,
dependent: :destroy
has_many
:users_projects
,
dependent: :destroy
has_many
:notes
,
dependent: :destroy
has_many
:snippets
,
dependent: :destroy
has_many
:snippets
,
dependent: :destroy
,
class_name:
"ProjectSnippet"
has_many
:deploy_keys
,
dependent: :destroy
,
class_name:
"Key"
,
foreign_key:
"project_id"
has_many
:hooks
,
dependent: :destroy
,
class_name:
"ProjectHook"
has_many
:wikis
,
dependent: :destroy
...
...
app/views/projects/snippets/_form.html.haml
View file @
5b35000f
...
...
@@ -2,7 +2,7 @@
=
@snippet
.
new_record?
?
"New Snippet"
:
"Edit Snippet #
#{
@snippet
.
id
}
"
%hr
.snippet-form-holder
=
form_for
[
@project
,
@snippet
]
do
|
f
|
=
form_for
[
@project
,
@snippet
]
,
as: :project_snippet
,
url:
url
do
|
f
|
-
if
@snippet
.
errors
.
any?
.alert.alert-error
%ul
...
...
@@ -30,7 +30,7 @@
=
f
.
submit
'Save'
,
class:
"btn-save btn"
=
link_to
"Cancel"
,
project_snippets_path
(
@project
),
class:
" btn"
-
unless
@snippet
.
new_record?
.pull-right
=
link_to
'Destroy'
,
[
@project
,
@snippet
]
,
confirm:
'Are you sure?'
,
method: :delete
,
class:
"btn pull-right danger delete-snippet"
,
id:
"destroy_snippet_
#{
@snippet
.
id
}
"
.pull-right
=
link_to
'Destroy'
,
project_snippet_path
(
@project
,
@snippet
)
,
confirm:
'Are you sure?'
,
method: :delete
,
class:
"btn pull-right danger delete-snippet"
,
id:
"destroy_snippet_
#{
@snippet
.
id
}
"
:javascript
...
...
app/views/projects/snippets/edit.html.haml
View file @
5b35000f
=
render
"
snippets/form"
=
render
"
projects/snippets/form"
,
url:
project_snippet_path
(
@project
,
@snippet
)
app/views/projects/snippets/index.html.haml
View file @
5b35000f
...
...
@@ -12,7 +12,7 @@
%th
Title
%th
File Name
%th
Expires At
=
render
@snippets
=
render
partial:
"projects/snippets/snippet"
,
collection:
@snippets
-
if
@snippets
.
empty?
%tr
%td
{
colspan:
3
}
...
...
app/views/projects/snippets/new.html.haml
View file @
5b35000f
=
render
"
snippets/form"
=
render
"
projects/snippets/form"
,
url:
project_snippets_path
(
@project
,
@snippet
)
app/views/projects/snippets/show.html.haml
View file @
5b35000f
...
...
@@ -5,5 +5,5 @@
=
link_to
"Edit"
,
edit_project_snippet_path
(
@project
,
@snippet
),
class:
"btn btn-small pull-right"
,
title:
'Edit Snippet'
%br
%div
=
render
'blob'
%div
=
render
'
projects/snippets/
blob'
%div
#notes
=
render
"notes/notes_with_form"
config/routes.rb
View file @
5b35000f
...
...
@@ -177,6 +177,14 @@ Gitlab::Application.routes.draw do
match
"/compare/:from...:to"
=>
"compare#show"
,
as:
"compare"
,
:via
=>
[
:get
,
:post
],
constraints:
{
from:
/.+/
,
to:
/.+/
}
scope
module: :projects
do
resources
:snippets
do
member
do
get
"raw"
end
end
end
resources
:wikis
,
only:
[
:show
,
:edit
,
:destroy
,
:create
]
do
collection
do
get
:pages
...
...
@@ -244,21 +252,12 @@ Gitlab::Application.routes.draw do
end
end
scope
module: :projects
do
resources
:snippets
do
member
do
get
"raw"
end
end
end
resources
:hooks
,
only:
[
:index
,
:create
,
:destroy
]
do
member
do
get
:test
end
end
resources
:team
,
controller:
'team_members'
,
only:
[
:index
]
resources
:milestones
,
except:
[
:destroy
]
resources
:labels
,
only:
[
:index
]
...
...
db/migrate/20130324172327_change_project_id_to_null_in_snipepts.rb
0 → 100644
View file @
5b35000f
class
ChangeProjectIdToNullInSnipepts
<
ActiveRecord
::
Migration
def
up
change_column
:snippets
,
:project_id
,
:integer
,
:null
=>
true
end
def
down
change_column
:snippets
,
:project_id
,
:integer
,
:null
=>
false
end
end
db/schema.rb
View file @
5b35000f
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
:version
=>
201303241
51736
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
201303241
72327
)
do
create_table
"events"
,
:force
=>
true
do
|
t
|
t
.
string
"target_type"
...
...
@@ -185,7 +185,7 @@ ActiveRecord::Schema.define(:version => 20130324151736) do
t
.
string
"title"
t
.
text
"content"
t
.
integer
"author_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
string
"file_name"
...
...
features/project/snippets.feature
0 → 100644
View file @
5b35000f
Feature
:
Project Snippets
Background
:
Given
I sign in as a user
And
I own project
"Shop"
And
project
"Shop"
have
"Snippet one"
snippet
And
project
"Shop"
have no
"Snippet two"
snippet
And
I visit project
"Shop"
snippets page
Scenario
:
I
should see snippets
Given
I visit project
"Shop"
snippets page
Then
I should see
"Snippet one"
in snippets
And
I should not see
"Snippet two"
in snippets
Scenario
:
I
create new project snippet
Given
I click link
"New Snippet"
And
I submit new snippet
"Snippet three"
Then
I should see snippet
"Snippet three"
@javascript
Scenario
:
I
comment on a snippet
"Snippet one"
Given
I visit snippet page
"Snippet one"
And
I leave a comment like
"Good snippet!"
Then
I should see comment
"Good snippet!"
Scenario
:
I
update
"Snippet one"
Given
I visit snippet page
"Snippet one"
And
I click link
"Edit"
And
I submit new title
"Snippet new title"
Then
I should see
"Snippet new title"
Scenario
:
I
destroy
"Snippet one"
Given
I visit snippet page
"Snippet one"
And
I click link
"Edit"
And
I click link
"Destroy"
Then
I should not see
"Snippet one"
in snippets
features/steps/project/project_snippets.rb
0 → 100644
View file @
5b35000f
class
ProjectSnippets
<
Spinach
::
FeatureSteps
include
SharedAuthentication
include
SharedProject
include
SharedNote
include
SharedPaths
And
'project "Shop" have "Snippet one" snippet'
do
create
(
:project_snippet
,
title:
"Snippet one"
,
content:
"Test content"
,
file_name:
"snippet.rb"
,
project:
project
,
author:
project
.
users
.
first
)
end
And
'project "Shop" have no "Snippet two" snippet'
do
create
(
:snippet
,
title:
"Snippet two"
,
content:
"Test content"
,
file_name:
"snippet.rb"
,
author:
project
.
users
.
first
)
end
Given
'I click link "New Snippet"'
do
click_link
"Add new snippet"
end
Given
'I click link "Snippet one"'
do
click_link
"Snippet one"
end
Then
'I should see "Snippet one" in snippets'
do
page
.
should
have_content
"Snippet one"
end
And
'I should not see "Snippet two" in snippets'
do
page
.
should_not
have_content
"Snippet two"
end
And
'I should not see "Snippet one" in snippets'
do
page
.
should_not
have_content
"Snippet one"
end
And
'I click link "Edit"'
do
within
".page_title"
do
click_link
"Edit"
end
end
And
'I click link "Destroy"'
do
click_link
"Destroy"
end
And
'I submit new snippet "Snippet three"'
do
fill_in
"project_snippet_title"
,
:with
=>
"Snippet three"
select
"forever"
,
:from
=>
"project_snippet_expires_at"
fill_in
"project_snippet_file_name"
,
:with
=>
"my_snippet.rb"
within
(
'.file-editor'
)
do
find
(
:xpath
,
"//input[@id='project_snippet_content']"
).
set
'Content of snippet three'
end
click_button
"Save"
end
Then
'I should see snippet "Snippet three"'
do
page
.
should
have_content
"Snippet three"
page
.
should
have_content
"Content of snippet three"
end
And
'I submit new title "Snippet new title"'
do
fill_in
"project_snippet_title"
,
:with
=>
"Snippet new title"
click_button
"Save"
end
Then
'I should see "Snippet new title"'
do
page
.
should
have_content
"Snippet new title"
end
And
'I leave a comment like "Good snippet!"'
do
within
(
'.js-main-target-form'
)
do
fill_in
"note_note"
,
with:
"Good snippet!"
click_button
"Add Comment"
end
end
Then
'I should see comment "Good snippet!"'
do
page
.
should
have_content
"Good snippet!"
end
And
'I visit snippet page "Snippet one"'
do
visit
project_snippet_path
(
project
,
project_snippet
)
end
def
project
@project
||=
Project
.
find_by_name!
(
"Shop"
)
end
def
project_snippet
@project_snippet
||=
ProjectSnippet
.
find_by_title!
(
"Snippet One"
)
end
end
features/steps/shared/paths.rb
View file @
5b35000f
...
...
@@ -263,6 +263,10 @@ module SharedPaths
visit
project_wiki_path
(
@project
,
:home
)
end
Given
'I visit project "Shop" snippets page'
do
visit
project_snippets_path
(
project
)
end
def
root_ref
@project
.
repository
.
root_ref
end
...
...
spec/factories.rb
View file @
5b35000f
...
...
@@ -196,7 +196,7 @@ FactoryGirl.define do
user
end
factory
:snippet
do
factory
:
project_
snippet
do
project
author
title
...
...
@@ -204,6 +204,13 @@ FactoryGirl.define do
file_name
end
factory
:snippet
do
author
title
content
file_name
end
factory
:protected_branch
do
name
project
...
...
spec/features/projects/snippets_spec.rb
deleted
100644 → 0
View file @
bc7c5f87
require
'spec_helper'
describe
"Project::Snippets"
do
let
(
:project
)
{
create
(
:project
)
}
before
do
login_as
:user
project
.
team
<<
[
@user
,
:developer
]
end
describe
"GET /:project/snippets"
do
before
do
@snippet
=
create
(
:snippet
,
author:
@user
,
project:
project
)
visit
project_snippets_path
(
project
)
p
project_snippets_path
(
project
)
end
subject
{
page
}
it
{
should
have_content
(
@snippet
.
title
[
0
..
10
])
}
it
{
should
have_content
(
@snippet
.
project
.
name
)
}
describe
"Destroy"
do
before
do
# admin access to remove snippet
@user
.
users_projects
.
destroy_all
project
.
team
<<
[
@user
,
:master
]
visit
edit_project_snippet_path
(
project
,
@snippet
)
end
it
"should remove entry"
do
expect
{
click_link
"destroy_snippet_
#{
@snippet
.
id
}
"
}.
to
change
{
Snippet
.
count
}.
by
(
-
1
)
end
end
end
describe
"New project snippet"
do
before
do
visit
project_snippets_path
(
project
)
click_link
"New Snippet"
end
it
"should open new snippet popup"
do
page
.
current_path
.
should
==
new_project_snippet_path
(
project
)
end
describe
"fill in"
,
js:
true
do
before
do
fill_in
"snippet_title"
,
with:
"login function"
fill_in
"snippet_file_name"
,
with:
"test.rb"
page
.
execute_script
(
"editor.insert('def login; end');"
)
end
it
{
expect
{
click_button
"Save"
}.
to
change
{
Snippet
.
count
}.
by
(
1
)
}
it
"should add new snippet to table"
do
click_button
"Save"
page
.
current_path
.
should
==
project_snippet_path
(
project
,
Snippet
.
last
)
page
.
should
have_content
"login function"
page
.
should
have_content
"test.rb"
end
end
end
describe
"Edit project snippet"
do
before
do
@snippet
=
create
(
:snippet
,
author:
@user
,
project:
project
)
visit
project_snippet_path
(
project
,
@snippet
)
click_link
"Edit Snippet"
end
it
"should open edit page"
do
page
.
current_path
.
should
==
edit_project_snippet_path
(
project
,
@snippet
)
end
describe
"fill in"
do
before
do
fill_in
"snippet_title"
,
with:
"login function"
fill_in
"snippet_file_name"
,
with:
"test.rb"
end
it
{
expect
{
click_button
"Save"
}.
to_not
change
{
Snippet
.
count
}
}
it
"should update snippet fields"
do
click_button
"Save"
page
.
current_path
.
should
==
project_snippet_path
(
project
,
@snippet
)
page
.
should
have_content
"login function"
page
.
should
have_content
"test.rb"
end
end
end
end
spec/features/snippets_spec.rb
deleted
100644 → 0
View file @
bc7c5f87
require
'spec_helper'
describe
"Snippets"
do
let
(
:project
)
{
create
(
:project
)
}
before
do
login_as
:user
project
.
team
<<
[
@user
,
:developer
]
end
describe
"GET /snippets"
do
before
do
@snippet
=
create
(
:snippet
,
author:
@user
,
project:
project
)
visit
project_snippets_path
(
project
)
end
subject
{
page
}
it
{
should
have_content
(
@snippet
.
title
[
0
..
10
])
}
it
{
should
have_content
(
@snippet
.
project
.
name
)
}
describe
"Destroy"
do
before
do
# admin access to remove snippet
@user
.
users_projects
.
destroy_all
project
.
team
<<
[
@user
,
:master
]
visit
edit_project_snippet_path
(
project
,
@snippet
)
end
it
"should remove entry"
do
expect
{
click_link
"destroy_snippet_
#{
@snippet
.
id
}
"
}.
to
change
{
Snippet
.
count
}.
by
(
-
1
)
end
end
end
describe
"New snippet"
do
before
do
visit
project_snippets_path
(
project
)
click_link
"New Snippet"
end
it
"should open new snippet popup"
do
page
.
current_path
.
should
==
new_project_snippet_path
(
project
)
end
describe
"fill in"
,
js:
true
do
before
do
fill_in
"snippet_title"
,
with:
"login function"
fill_in
"snippet_file_name"
,
with:
"test.rb"
page
.
execute_script
(
"editor.insert('def login; end');"
)
end
it
{
expect
{
click_button
"Save"
}.
to
change
{
Snippet
.
count
}.
by
(
1
)
}
it
"should add new snippet to table"
do
click_button
"Save"
page
.
current_path
.
should
==
project_snippet_path
(
project
,
Snippet
.
last
)
page
.
should
have_content
"login function"
page
.
should
have_content
"test.rb"
end
end
end
describe
"Edit snippet"
do
before
do
@snippet
=
create
(
:snippet
,
author:
@user
,
project:
project
)
visit
project_snippet_path
(
project
,
@snippet
)
click_link
"Edit Snippet"
end
it
"should open edit page"
do
page
.
current_path
.
should
==
edit_project_snippet_path
(
project
,
@snippet
)
end
describe
"fill in"
do
before
do
fill_in
"snippet_title"
,
with:
"login function"
fill_in
"snippet_file_name"
,
with:
"test.rb"
end
it
{
expect
{
click_button
"Save"
}.
to_not
change
{
Snippet
.
count
}
}
it
"should update snippet fields"
do
click_button
"Save"
page
.
current_path
.
should
==
project_snippet_path
(
project
,
@snippet
)
page
.
should
have_content
"login function"
page
.
should
have_content
"test.rb"
end
end
end
end
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