Ruby on rails Rails 4.x在浏览器中工作,但在第二步失败

Ruby on rails Rails 4.x在浏览器中工作,但在第二步失败,ruby-on-rails,cucumber,Ruby On Rails,Cucumber,我正在开发一个小型企业客户管理应用程序 我的代码似乎运行良好,但我的cucumber测试遇到了以下消息 And I have created one business # features/step_definitions/owner_steps.rb:238 No route matches {:action=>"new", :business_id=>nil, :controller=>"customers"} missing required keys:

我正在开发一个小型企业客户管理应用程序

我的代码似乎运行良好,但我的cucumber测试遇到了以下消息

  And I have created one business      # features/step_definitions/owner_steps.rb:238
  No route matches {:action=>"new", :business_id=>nil, :controller=>"customers"} missing required keys: [:business_i
d] (ActionView::Template::Error)
  ./app/views/owners/show.html.erb:64:in `_app_views_owners_show_html_erb__1329160335005789747_57615300'
  ./features/step_definitions/owner_steps.rb:240:in `/^I have created one business$/'
  features/business_creates_customers.feature:9:in `And I have created one business'
再说一次,当我进入页面时,它工作正常。我相信我的怪癖在于我将如何走向新的商业、客户之路。我的“默认”页面是所有者显示页面。一个老板有很多生意。但是,这家公司有很多客户。为了进入customer页面并从owner show页面输入正确的业务id,我有一个方法在owner controller中找到正确的业务,并且它在浏览器中正确地传递了参数

无论如何,我的代码如下:

Owner(show.html.erb)——注意新的商业客户路径(@business)。当我放置@owner、@business时,它将owner id作为business\u id提供

<%= provide(:title, "#{@owner.name} Profile Page") %>
<div class="row">
    <div class="col-md-2">

    <div class="panel panel-default">
        <div class="panel-heading">
        <b>Personal Information</b><%= link_to "Edit", '/edit', class: 'pull-right' %>
      </div>
      <div class="panel-body">
        <b>Owner: </b>
        <%= link_to @owner.name, '/edit' %>
      <p>
        <b>Email: </b>
        <%= @owner.email %>
      </div>

      <% if @owner.businesses.count > 0 %>
      <div class="panel-heading">
        <b>Business Information</b><%= link_to "Add", new_owner_business_path(@owner), class: 'pull-right' %>
      </div>      
      <div class="panel-body">
        <% @owner.businesses.order("created_at asc").each do |business| %>
          <b>View:</b>
          <%= link_to business.name, owner_business_path(@owner, business) %><br>
        <% end %>
      </div>
      <% end %>

      </div>
  </div>

    <div class="col-md-10">
  <% if @owner.businesses.count == 0 %>
    <div class="panel panel-danger">
      <div class="panel-heading">
        <b>Business Information</b>
      </div>
      <div class="panel-body">
        <p>Thank you for signing up.   We will need information about your business for you to proceed.</p>
        <p>You have not yet provided us information about your business.</p>
        <p><%= link_to "Add your business now!", new_owner_business_path(@owner) %></p>
      </div>
    </div>
  <% else %>
    <div class="panel panel-danger">
      <div class="panel-heading">
        <b>Services Information</b>
      </div>
      <div class="panel-body">
      <p>
       Ok.  Your business is created.   We're about to add customers, which is kind of why you're here.  But, before we can do that, we need to know what types of services you provide them when they are with you.  You've already categorized your business when you created it.  Similar businesses who have already populated their services will be available options for you when you add here.  You can always add more, but we want you to start by adding at least one service now.  Please tell us what types of services your business provides.
       </p>
       <p><%= link_to "Add a service your business provides now!", '#' %></p>
      </div>
    </div>

    <div class="panel panel-danger">
      <div class="panel-heading">
        <b>Customer Information</b>
      </div>
      <div class="panel-body">
        <p>
          You have not yet added any customers.
        </p>
        <p><%= link_to "Add a customer for your business now!", new_business_customer_path(@business) %></p>
      </div>
    </div>
  <% end %>

  </div>

</div>
Customers\u controller.rb——此中的定义不会从上一页传递:business\u id,因为这是“所有者展示”页,我正在将@business推给所有者。我想这可能是我的问题。

Feature: Business creates customers
    In order to conduct business
    my business should be able to add customers
    I can create as an owner of the business

    Background: Logging in with a business
        Given I am logged in
      And I am at my owner profile page
      And I have created one business

      Scenario: Creating first customer
        Then I expect to see content "Customer Information"
        And I expect to see content "You have not yet added any customers."
        And I expect to see a link to "Add a customer for your business now!"
        When I click the "Add a customer for your business now!" link
        Then I am at the create new customer page
        And I expect to see a form to add customer information
        And I expect to see the title "Create a customer"
        When I fill in "First name" with "Kathy"
        And I fill in "Middle name" with ""
        And I fill in "Last name" with "Davis"
        And I fill in "Email" with "test@test.com"
        And I fill in "Phone number" with "651.555.1212"
        And I fill in "Referred by" with ""
        When I click the "Save Customer" button
        Then I expect to see content "This customer has been created."
        And I am at my owner profile page
        Then I expect to see content "Customer Information"
        But I expect to not see content "You have not yet added any customers."
        Then I expect to see a link to "Customers"
        And I expect to see a link to "Add"
        And I expect to see content "Customers = 1"
        And I expect to see a link to "Add customers"
class CustomersController < ApplicationController
    before_action :get_business_and_owner

    def new
        @customer = Customer.new
    end

    private

            def get_business_and_owner
                @business = Business.find(params[:business_id])
                @owner = @business.owner
            end

end
class OwnersController < ApplicationController
  before_action :set_owner, only: [:show, :edit, :update, :destroy]
  before_action :set_business, only: [:show, :edit, :update, :destroy]
  load_and_authorize_resource


    def show
    end



    private
    def owner_params
      params.require(:owner).permit(:first_name, :last_name, :middle_name, :email, :password, :password_confirmation)
    end

        def set_owner
            @owner = Owner.find(params[:id])
        end 

        def set_business
            @business = @owner.selected_business
        end

end

然后我访问根。我非常确定,我只需要找到一种方法,在这个测试中以某种方式识别所选的业务。但是,编写一个选定的业务方法在那里似乎不起作用。我快发疯了,希望能得到你的帮助。

正如我所怀疑的,问题是我是个笨蛋:)

在测试中,我没有实际测试应用程序的流程。我登录并进入了所有者配置文件页面,正如预期的那样。然后,我的创建步骤将业务写入数据库,这非常有效,但没有告诉应用程序任何信息,因此视图逻辑不会发生更改。因此,在测试中没有通过任何测试,尽管我可以在视图中看到它通过了

我试图通过期望当前页面为X页面来解决这个问题,但是,根据我编写测试的方式,这也试图为测试中不存在的业务强制使用@变量。有一次,我记得让应用程序完成预期的工作

我看到这被否决了好几次,所以如果这是一个太愚蠢的问题,我道歉。如果有人投票反对,我会非常感激,这样我就能学得更好。谢谢大家

def create_business
  @business = @owner.businesses.create(name: "My Great Business", description: "Cool business, huh?")
end