我有一个接受JSON的post方法:
post '/channel/create' do
content_type :json
@data = JSON.parse(env['rack.input'].gets)
if @data.nil? or !@data.has_key?('api_key')
status 400
body({ :error => "JSON corrupt" }.to_json)
else
status 200
body({ :error => "Channel created" }.to_json)
end
Run Code Online (Sandbox Code Playgroud)
作为rspec的新手,我很困惑,试图找出如何使用可接受的JSON有效负载编写针对该POST的测试.我最接近的是这是非常不准确但我似乎没有问谷歌上帝正确的问题,以帮助我在这里.
it "accepts create channel" do
h = {'Content-Type' => 'application/json'}
body = { :key => "abcdef" }.to_json
post '/channel/create', body, h
last_response.should be_ok
end
Run Code Online (Sandbox Code Playgroud)
在Sinatra中测试API的任何最佳实践指南也将非常受欢迎.
我们正在为所有媒体使用本地文件系统,并将其移至云文件(Rackspace).沮丧的是我们使用ImageManager插件,它似乎严重依赖于执行文件系统命令来生成文件列表等.
您是否有使用TinyMCE并从云存储服务插入图像和资产的经验?