【发布时间】:2014-11-28 19:09:51
【问题描述】:
所以我下面有一个api
#controllers/api/v4/...rb
this api render jbuilder json under:
#views/api/v4/....json.jbuilder
我有规格:
#spec/controllers/api/v4/..._spec.rb
require 'rails_helper'
RSpec.describe Api::V4::AlbumsController do
let(:user) { create(:user) }
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
sign_in(user)
end
describe "GET index" do
it "returns correct types" do
get :index, {:format => :json, :user_id => user.id}
puts @request.body
puts response.body
user_response = json_response
puts user_response
end
end
end
一切正常,直到我得到这个:
Failure/Error: get :index, {:format => :json, :user_id => user.id}
ActionView::MissingTemplate:
Missing template api/v4/albums/index, api/api/index with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007ff4721d9f20>"
有人有办法解决这个问题吗?
【问题讨论】:
-
你支持 html 和 json 响应吗?
-
我的 api 在他们自己的文件夹 api 中,我在 routes.rb -> 命名空间 :api 中将默认渲染设置为 json,默认值:{format: 'json'} 做。
标签: ruby-on-rails ruby json rspec