Skip to content

Instantly share code, notes, and snippets.

@elado
Created October 22, 2014 20:05
Show Gist options
  • Save elado/231fe6cfc26835304cdd to your computer and use it in GitHub Desktop.
Save elado/231fe6cfc26835304cdd to your computer and use it in GitHub Desktop.
Grape Encoding Test (currently fails)
# -*- encoding : utf-8 -*-
require 'spec_helper'
require 'shared/versioning_examples'
describe Grape::API do
module EncodingSpec
class API < Grape::API
params do
requires :a
requires :b
optional :file, type: Rack::Multipart::UploadedFile
end
post do
[params[:a].encoding, params[:b].encoding].map(&:to_s).join(",")
end
end
end
subject { EncodingSpec::API.new }
def app
subject
end
describe 'encoding' do
it 'should use UTF-8 encoding for UTF-8 strings' do
post '/', a: "aaa", b: "😈"
expect(last_response.body).to eq("UTF-8,UTF-8")
end
it 'should use UTF-8 encoding for UTF-8 strings also when sending a file' do
header 'Content-Type', 'multipart/form-data'
post '/', a: "aaa", b: "😈", file: Rack::Test::UploadedFile.new("grape.png", 'image/png', true)
expect(last_response.body).to eq("UTF-8,UTF-8")
end
it 'should use UTF-8 encoding for UTF-8 strings also when sending a file and charset=UTF-8 content type' do
header 'Content-Type', 'multipart/form-data; charset=UTF-8'
post '/', a: "aaa", b: "😈", file: Rack::Test::UploadedFile.new("grape.png", 'image/png', true)
expect(last_response.body).to eq("UTF-8,UTF-8")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment