没有路由匹配继承(创建)操作

时间:2016-05-03 13:51:29

标签: ruby-on-rails ruby rspec rspec-rails

我有2个版本的API(1& 2)api版本2的控制器继承自api版本1的控制器。问题是,版本1的规格运行正常,但是当我在版本2中运行规范时,它告诉我

  

ActionController :: UrlGenerationError:没有路由匹配{:action =>" create",:controller =>" api / mobile / v2 / samples"}

#version 1
class Api::Mobile::V1::SamplesController < ApplicationController
  def create
   #dummy
  end
end

#version 2
require "meta_data"
class Api::Mobile::V2::SamplesController < Api::Mobile::V1::SamplesController
  include MetaData
end


#spec for version 1
require 'rails_helper'
RSpec.describe Api::Mobile::V1::SamplesController, type: :controller do
  describe "POST #create" do
    it "performs a post" do
      post :create
    end
  end
end

#spec for version 2
require 'rails_helper'
RSpec.describe Api::Mobile::V2::SamplesController, type: :controller do
  describe "POST #create" do
    it "performs a post" do
      post :create
    end
  end
end

1 个答案:

答案 0 :(得分:0)

RSpec正在寻找SamplesController(复数)。如果这是你所拥有的,请确保使用单数resource指定路线。否则,请在初始值设定项中将复数形式的sample指定为sample

我会选择流程和用户复数形式。但是,显然公共API是一个真正令人头痛的问题。