Skip to content

Commit

Permalink
Add tests for big/small gifs (but not big, yet) (#5433)
Browse files Browse the repository at this point in the history
* Add tests for big/small

* test gif

* small.gif

* small gif

* Add files via upload

* Fix string/integer conversion on gif size comparison

* Update images_controller_test.rb

* add login first

* Update images_controller_test.rb
  • Loading branch information
jywarren authored Apr 9, 2019
1 parent 05a2487 commit 3ebb453
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def is_image?
end

def skip_large_gifs
! (filetype == 'gif' && photo_file_size > 3.megabytes)
! (filetype == 'gif' && photo_file_size.to_i > 3.megabytes)
end

def filetype
Expand Down
Binary file added test/fixtures/small.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 29 additions & 1 deletion test/functional/images_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,35 @@ def setup
}
assert_equal 'application/json', @response.content_type
end


test 'upload a small gif' do
user = UserSession.create(users(:jeff))
upload_photo = fixture_file_upload('small.gif', 'image/gif')
post :create,
params: {
image: {
photo: upload_photo,
title: 'Rails image',
},
}
assert_response :success
end

# We'd like to do this but don't want to have to add a big gif to the repository...
# We need to synthesize a fake big gif locally? (it won't be processed anyways)
# test 'rejecting upload of a big gif' do
# user = UserSession.create(users(:jeff))
# upload_photo = fixture_file_upload('small.gif', 'image/gif')
# post :create,
# params: {
# image: {
# photo: upload_photo,
# title: 'Rails image',
# },
# }
# assert_response :failure
# 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"
Expand Down

0 comments on commit 3ebb453

Please sign in to comment.