加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Ruby on Rails 4:使用rspec测试嵌套资源不起

发布时间:2020-12-17 02:46:34 所属栏目:百科 来源:网络整理
导读:我在rails应用程序上测试我的 ruby时遇到了一些麻烦.我有一个资源餐厅和一个嵌套的资源菜单. 路线文件: resources :restaurants do resources :menus 菜单型号: class Menuinclude Mongoid::Documentbelongs_to :restaurantaccepts_nested_attributes_for
我在rails应用程序上测试我的 ruby时遇到了一些麻烦.我有一个资源餐厅和一个嵌套的资源菜单.

路线文件:

resources :restaurants do
  resources :menus

菜单型号:

class Menu
include Mongoid::Document

belongs_to :restaurant
accepts_nested_attributes_for :restaurant

validates :name,presence: true
validates :description,presence: true
validates :restaurant,presence: true

field :name,type: String
field :description,type: String
end

餐厅模特:

class Restaurant
include Mongoid::Document

has_one :address,dependent: :destroy
has_many :menus,dependent: :destroy
accepts_nested_attributes_for :address,:menus

validates :name,presence: true
validates :address,type: String
field :thumbnail,type: String
field :banner,type: String
end

那么,我正在尝试这样的事情.它是来自rspec的默认测试,但我试图修改,因为我有一个嵌套资源..

describe MenusController do

before :each do
@restaurant = FactoryGirl.create(:random_restaurant)
@menu = FactoryGirl.create(:menu)
end

describe 'GET index' do
it 'assigns all menus as @menus' do
  get restaurant_menus_path(@restaurant)
  assigns(:menus).should eq([menu])
end
end

describe 'GET all restaurants menus' do
it 'responds with 200' do
  get :index,{ :id => @restaurant  }
  expect(response).to be_success
  expect(response.status).to eq(200)
  end
end

但错误是:

这是路线:


有趣的是,menu_spec.rb中的这个测试正在运行..


我真的不知道为什么这个测试不起作用..

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读