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
Léo-Paul Géneau
gitlab-ce
Commits
8bec6b0b
Commit
8bec6b0b
authored
May 26, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make existing tests test something, return correct errors.
parent
2a8aa742
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
14 deletions
+24
-14
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+14
-5
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+1
-1
spec/controllers/projects_controller_spec.rb
spec/controllers/projects_controller_spec.rb
+9
-8
No files found.
app/controllers/projects_controller.rb
View file @
8bec6b0b
...
...
@@ -164,12 +164,21 @@ class ProjectsController < ApplicationController
def
upload_image
uploader
=
FileUploader
.
new
(
'uploads'
,
upload_path
,
accepted_images
)
alt
=
params
[
'markdown_img'
].
original_filename
uploader
.
store!
(
params
[
'markdown_img'
])
image
=
params
[
'markdown_img'
]
if
image
&&
accepted_images
.
map
{
|
format
|
image
.
content_type
.
include?
format
}.
any?
alt
=
image
.
original_filename
uploader
.
store!
(
image
)
link
=
{
'alt'
=>
File
.
basename
(
alt
,
'.*'
),
'url'
=>
File
.
join
(
root_url
,
uploader
.
url
)
}
end
respond_to
do
|
format
|
if
link
format
.
json
{
render
json:
{
link:
link
}
}
else
format
.
json
{
render
json:
"Invalid file."
,
status: :unprocessable_entity
}
end
end
end
...
...
app/uploaders/file_uploader.rb
View file @
8bec6b0b
...
...
@@ -25,7 +25,7 @@ class FileUploader < CarrierWave::Uploader::Base
end
def
store!
(
file
)
file
.
original_
filename
=
self
.
class
.
generate_filename
(
file
)
@
filename
=
self
.
class
.
generate_filename
(
file
)
super
end
...
...
spec/controllers/projects_controller_spec.rb
View file @
8bec6b0b
...
...
@@ -11,33 +11,34 @@ describe ProjectsController do
describe
"POST #upload_image"
do
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
end
context
"without params['markdown_img']"
do
it
"returns an error"
do
post
:upload_image
,
id:
project
.
to_param
expect
(
response
.
status
).
to
eq
(
4
04
)
post
:upload_image
,
id:
project
.
to_param
,
format: :json
expect
(
response
.
status
).
to
eq
(
4
22
)
end
end
context
"with invalid file"
do
before
do
post
:upload_image
,
id:
project
.
to_param
,
markdown_img:
@img
post
:upload_image
,
id:
project
.
to_param
,
markdown_img:
txt
,
format: :json
end
it
"returns an error"
do
expect
(
response
.
status
).
to
eq
(
4
04
)
expect
(
response
.
status
).
to
eq
(
4
22
)
end
end
context
"with valid file"
do
before
do
post
:upload_image
,
id:
project
.
to_param
,
markdown_img:
@img
post
:upload_image
,
id:
project
.
to_param
,
markdown_img:
jpg
,
format: :json
end
it
"returns a content with original filename and new link."
do
link
=
{
alt:
'rails_sample'
,
link:
''
}.
to_json
expect
(
response
.
body
).
to
have_content
link
expect
(
response
.
body
).
to
match
"
\"
alt
\"
:
\"
rails_sample
\"
"
expect
(
response
.
body
).
to
match
"
\"
url
\"
:
\"
http://test.host/uploads/
#{
project
.
path_with_namespace
}
"
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