为什么此请求规范可以正常工作:
require "spec_helper"
describe "POST on a GET route" do
it "should not allow this" do
post "/applicants/new"
assert_response :missing
end
end
但是在这个控制器规范中,GET、POST、PUT 和 DELETE 在它们不应该的时候都一样工作:
require 'spec_helper'
describe ApplicantsController do
it "should not allow this" do
post :new
should respond_with :missing # but it responds with 200
end
end
更新:添加了申请人控制器代码和路由定义:
class ApplicantsController < InheritedResources::Base
respond_to :html
actions :index, :new, :create
def new
if current_user
redirect_to resume_application_path and return
end
@applicant = Applicant.new
@applicant.applications.build
@applicant.build_user_detail
new!
end
end
路线:
resources :applicants
更新:在对 API 进行大量研究和挖掘之后,我相信这是设计使然,因为控制器规范继承自 ActionController::TestCase,而请求规范继承自 ActionDispatch::IntegrationTest。在控制器规范的情况下,HTTP 动词变得仅仅是描述性的。
有人可以确认这是设计使然吗?还是我应该提交错误报告?
谢谢!