2017-03-08 16:32:31 +08:00
|
|
|
# frozen_string_literal: true
|
2017-03-28 17:15:33 +08:00
|
|
|
|
2016-02-14 21:45:25 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Grape::Endpoint do
|
2017-01-16 06:46:22 +08:00
|
|
|
subject do
|
|
|
|
described_class.new(Grape::Util::InheritableSetting.new, path: '/', method: :get)
|
|
|
|
end
|
2016-06-16 19:35:29 +08:00
|
|
|
|
|
|
|
describe '#param_type_is_array?' do
|
|
|
|
it 'returns true if the value passed represents an array' do
|
|
|
|
expect(subject.send(:param_type_is_array?, 'Array')).to be_truthy
|
|
|
|
expect(subject.send(:param_type_is_array?, '[String]')).to be_truthy
|
|
|
|
expect(subject.send(:param_type_is_array?, 'Array[Integer]')).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the value passed does not represent an array' do
|
|
|
|
expect(subject.send(:param_type_is_array?, 'String')).to be_falsey
|
|
|
|
expect(subject.send(:param_type_is_array?, '[String, Integer]')).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2017-01-16 06:46:22 +08:00
|
|
|
|
|
|
|
describe '.content_types_for' do
|
|
|
|
describe 'defined on target_class' do
|
|
|
|
let(:own_json) { 'text/own-json' }
|
|
|
|
let(:own_xml) { 'text/own-xml' }
|
|
|
|
let(:content_types) do
|
|
|
|
{
|
|
|
|
own_json: own_json,
|
|
|
|
own_xml: own_xml
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:target_class) { OpenStruct.new(content_types: content_types) }
|
|
|
|
|
|
|
|
let(:object) { subject.content_types_for(target_class) }
|
|
|
|
specify do
|
|
|
|
expect(object).to eql [own_json, own_xml]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'not defined' do
|
|
|
|
describe 'format given' do
|
|
|
|
let(:format) { :json }
|
|
|
|
let(:target_class) { OpenStruct.new(format: format) }
|
|
|
|
let(:object) { subject.content_types_for(target_class) }
|
|
|
|
specify do
|
|
|
|
expect(object).to eql ['application/json']
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'format not given' do
|
|
|
|
let(:target_class) { OpenStruct.new }
|
|
|
|
let(:object) { subject.content_types_for(target_class) }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(object).to eql %w(application/xml application/json text/plain)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-14 21:45:25 +08:00
|
|
|
end
|