RSPEC测试未能发布一个;创建;嵌套资源的操作

RSPEC测试未能发布一个;创建;嵌套资源的操作,rspec,ruby-on-rails,ruby,factory-bot,Rspec,Ruby On Rails,Ruby,Factory Bot,我有一个名为“参数”的资源,它嵌套在API中的“测试”下。其关系如下:“一个测试有许多参数”。我的路线安排如下 测试/:测试id/参数/:参数id 我的rake路由给出: test_参数GET/tests/:test_id/参数(:format)参数#索引{:format=>:json} POST/tests/:test_id/参数(:format)参数#创建{:format=>:json} new_test_参数GET/tests/:test_id/parameters/new(:format

我有一个名为“参数”的资源,它嵌套在API中的“测试”下。其关系如下:“一个测试有许多参数”。我的路线安排如下

测试/:测试id/参数/:参数id

我的
rake路由
给出:

test_参数GET/tests/:test_id/参数(:format)参数#索引{:format=>:json}
POST/tests/:test_id/参数(:format)参数#创建{:format=>:json}
new_test_参数GET/tests/:test_id/parameters/new(:format)参数35; new{:format=>:json}
edit_test_parameter GET/tests/:test_id/parameters/:id/edit(:format)参数35; edit{:format=>:json}
test_参数GET/tests/:test_id/parameters/:id(:format)参数35; show{:format=>:json}
补丁/测试/:测试id/参数/:id(:格式)参数#更新{:格式=>:json}
PUT/tests/:test_id/parameters/:id(:format)parameters#update{:format=>:json}
DELETE/tests/:test_id/parameters/:id(:format)parameters 35; destroy{:format=>:json}
我正在编写简单的测试来测试API的所有典型操作。现在,我的POST/CREATE给了我一个非常令人费解的错误

故障:
1) ParametersController使用名称和时间成功创建具有有效属性的新参数
失败/错误:post:create,:test\u id=>@test.id,参数:parameter.attributes,格式::json
命名错误:
未定义的方法“参数\ url”#
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u dispatch/routing/polymorphic\u routes.rb:220:in“polymorphic\u方法”
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u dispatch/routing/polymorphic\u routes.rb:114:in“polymorphic\u url”
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u dispatch/routing/url\u for.rb:163:in'url\u for'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/rendering.rb:95:在“进程选项”中
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/streaming.rb:200:在“进程选项”中
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/renders.rb:43:in`block in\u render\u to\u body\u with\u renderer'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/renders.rb:41:in`_render\u to_body\u with_renderer'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/renderers.rb:37:“渲染到主体”
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract\u controller/rendering.rb:25:在“render”中
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/rendering.rb:16:in'render'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/instrumentation.rb:44:in `渲染中的块(2层)'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active\u support/core\u ext/benchmark.rb:12:in`block in ms'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active\u support/core\u ext/benchmark.rb:12:in`ms'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/instrumentation.rb:44:在“渲染中的块”中
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/instrumentation.rb:87:在“清理”视图中
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activerecord-4.2.2/lib/active\u record/railties/controller\u runtime.rb:25:in“cleanup\u view\u runtime”
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/instrumentation.rb:43:in'render'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action\u controller/responder.rb:258:in“display”
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action\u controller/responder.rb:214:in'api\u behavior'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action\u controller/responder.rb:191:“救援格式”
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action\u controller/responder.rb:185:to\u格式
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action\u controller/responder.rb:163:in“respond”
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action\u controller/responder.rb:156:in'call'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action\u controller/respond\u with.rb:203:in“respond\u with”
#./app/controllers/parameters\u controller.rb:13:in'create'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/implicit\u render.rb:4:在“发送动作”中
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract\u controller/base.rb:198:in'process\u action'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action\u controller/metal/rendering.rb:10:in'process\u action'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract\u controller/callbacks.rb:20:in`block in process\u action'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active\u support/callbacks.rb:117:in'call'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active\u support/callbacks.rb:117:in'call'
#/Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active\u support/callbacks.rb:555:in `编译中的块(2个级别)'
#/Users/naseem.alnaji/.rvm/
    "spec/controllers/parameters_controller_spec.rb"
    require 'spec_helper'
    describe ParametersController do
      before :each do
        @test = FactoryGirl.create(:test, id: 1, name: 'Eccentric Tech')
        @test.save
      end

      # ...

      describe 'POST create a new parameter' do
        context 'with valid attributes' do
          it 'successfully with name and times' do
            parameter = FactoryGirl.build(:parameter)
            expect {
              post :create, :test_id => @test.id, parameter: parameter.attributes, format: :json
            }.to change(Parameter, :count).by(1)
          end
        end
        context 'with invalid attributes' do
          it 'fails without a name' do
            parameter = FactoryGirl.build(:no_name_parameter)
            expect {
              post :create, :test_id => @test.id, parameter: parameter.attributes, format: :json
            }.to change(Parameter, :count).by(0)
          end
          it 'fails without belonging to a test' do
            parameter = FactoryGirl.build(:no_test_parameter)
            expect {
              post :create, :test_id => @test.id, parameter: parameter.attributes, format: :json
            }.to change(Parameter, :count).by(0)
          end
        end
      end

      # ...

    end
"spec/factories/parameters.rb"
require 'faker'

FactoryGirl.define do
  factory :parameter do |f|
    f.name { "#{Faker::Hacker.noun}" }
    f.value { Faker::Number.number(2) }
    f.test_id { 1 }
  end

  factory :no_name_parameter, parent: :parameter do |f|
    f.name nil
    f.value { Faker::Number.number(2) }
    f.test_id { 1 }
  end

  factory :no_test_parameter, parent: :parameter do |f|
    f.name { "#{Faker::Hacker.noun}" }
    f.value { Faker::Number.number(2) }
    f.test_id nil
  end
end
class ParametersController < ApplicationController
  respond_to :json

  def index
    respond_with Parameter.all
  end

  def show
    respond_with Parameter.find(params[:id])
  end

  def create
      respond_with Parameter.create(parameter_params)
  end

  def update
    respond_with Parameter.update(params[:id], parameter_params)
  end

  def destroy
    respond_with Parameter.destroy(params[:id])
  end

  private
    def parameter_params
      params.require(:parameter).permit(:name, :value, :test_id)
    end
end
Rails.application.routes.draw do
  scope :defaults => { :format => :json } do
    resources :services do
      resources :tests
    end

    resources :tests do
      resources :parameters
      resources :singular_results
      resources :dataset_results
    end
  end
end
def create
  respond_with Parameter.create(parameter_params), location: nil
end