小编dam*_*mir的帖子

Ruby on Rails 4:使用rspec测试嵌套资源不起作用

我在rails应用程序上测试我的ruby时遇到了一些麻烦.我有一个资源餐厅和一个嵌套的资源菜单.

路线文件:

resources :restaurants do
  resources :menus
Run Code Online (Sandbox Code Playgroud)

菜单型号:

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
Run Code Online (Sandbox Code Playgroud)

餐厅模特:

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 :description, presence: true
validates :address, presence: true

field :name, type: String
field :description, type: String
field :thumbnail, type: String
field :banner, type: …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails mongoid

4
推荐指数
1
解决办法
4678
查看次数

RSpec路由测试嵌套资源中params的问题

我有一个奇怪的问题.. rspec在spec/routing中生成了一个名为menus_routing_spec.rb的类

测试失败,因为菜单是餐馆的嵌套资源.

这是我的测试:

    describe MenusController do

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

  describe 'routing' do
    it 'routes to #index' do
      params = {}
      params['restaurant_id'] = @restaurant


      #get('/restaurants/:restaurant_id/menus').should route_to('menus#index')
      #get(restaurant_menus_path(@restaurant)).should route_to('menus#index')
      #get(restaurant_menus_path, { :restaurant_id => @restaurant  }).should route_to('menus#index')

      get restaurant_menus_path, { :restaurant_id => @restaurant.to_param  }
      expect(response).should route_to('menus#index')
    end
Run Code Online (Sandbox Code Playgroud)

rake路由中的路径如下所示:

restaurant_menus_path    GET     (/:locale)/restaurants/:restaurant_id/menus(.:format)   menus#index
Run Code Online (Sandbox Code Playgroud)

我总是收到此错误消息:

Failure/Error: get restaurant_menus_path, @restaurant.to_param
     ActionController::UrlGenerationError:
       No route matches {:action=>"index", :controller=>"menus"} missing required keys: [:restaurant_id]
Run Code Online (Sandbox Code Playgroud)

我也尝试了其他的..但同样的错误..有谁能看到我在做错误的地方?

这是spec/controllers/menus_controller_spec.rb中的测试,它可以正常工作

it 'renders the index template' do …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails param nested-resources

4
推荐指数
1
解决办法
3118
查看次数

Ruby on Rails和Zurb Foundation Offcanvas无法正常工作

我刚刚将我的ui(Rails 4)从Bootstrap移动到了Foundation 5.我为大屏幕添加了一个普通的Nav,为小屏幕添加了一个Offcanvas Navigation.有关详细信息,请参阅此处:http://foundation.zurb.com/docs/components/offcanvas.html

当我点击菜单时,offcanvas导航显示所有链接,然后我可以点击内容,再次打开导航,但是,当我点击导航中的链接,然后,我无法打开offcan世界导航,它看起来就像它被阻止一样,我必须在浏览器中手动刷新我的视图.

这是我的代码:

<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title><%= content_for?(:title) ? yield(:title) : t('.siteTitle') %></title>

  <%= stylesheet_link_tag    'application'%>
  <%= javascript_include_tag 'vendor/modernizr' %>
  <%= csrf_meta_tags %>
</head>
<body>
    <!-- NAVIGATION Top Bar -->
    <!------------------------>
    <div class="off-canvas-wrap">
        <div class="inner-wrap">
            <div class="contain-to-grid sticky fixed">
                <nav class="top-bar hide-for-small" data-topbar data-options="is_hover: false">
                  <ul class="title-area">
                    <li class="name">
                      <h1><%= link_to t('.siteTitle'), root_path, :id => 'newolu' %></h1>
                    </li>
                  </ul>
                  <section class="top-bar-section">
                    <!-- Right Nav …
Run Code Online (Sandbox Code Playgroud)

html css jquery ruby-on-rails zurb-foundation

2
推荐指数
2
解决办法
1544
查看次数