Skip to content

Commit

Permalink
Update images_controller.rb with dataurl filename and test (#3804)
Browse files Browse the repository at this point in the history
* Update images_controller.rb

* Update images_controller_test.rb

* Update images_controller_test.rb

* Update images_controller_test.rb
  • Loading branch information
jywarren authored Oct 26, 2018
1 parent e3de62b commit 9724d9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def create
uid: current_user.uid)
flash[:error] = 'The image could not be saved.' unless @image.save!
elsif params[:data]
filetype = params[:data].split(';').first.split('/').last
@image = Image.new(uid: current_user.uid,
photo: params[:data],
photo_file_name: 'dataurl')
photo_file_name: 'dataurl.' + filetype)
@image.save!
else
@image = Image.new(uid: current_user.uid,
Expand Down
19 changes: 13 additions & 6 deletions test/functional/images_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require 'test_helper'

class ImagesControllerTest < ActionController::TestCase
# def create
# def new
# def update

def setup
activate_authlogic
Expand Down Expand Up @@ -35,13 +32,23 @@ def setup
test 'image creation success should render the details about the image in the form of json' do
user = UserSession.create(users(:jeff))
upload_photo = fixture_file_upload('rails.png', 'image/png')
post :create,
params: {
post :create,
params: {
image: {
photo: upload_photo,
title: 'Rails image',
},
}
}
assert_equal 'application/json', @response.content_type
end

test 'creation via daturl' do
user = UserSession.create(users(:jeff))
data = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z"
post :create,
params: {
data: data
}
assert "dataurl.jpeg", Image.last.filename
end
end

0 comments on commit 9724d9a

Please sign in to comment.