代码之家  ›  专栏  ›  技术社区  ›  Joe

关于黄瓜/泡菜的问题

  •  1
  • Joe  · 技术社区  · 16 年前

    我想对Rails/ActiveRecord稍微熟悉一点。在尝试这样做时,我试图用黄瓜来帮助一些“发现”测试。

    Feature: Describing a task
      In order to work with tasks
      As a user
      I want to be able to know what makes up a task and to improve my understanding of ActiveRecord
    
    
    Scenario: A task has certain core fields
      Given the following tasks exist
      | id | name      |
      | 1  | some task |
      And the following estimates exist
      | task_id | hours | explanation                           |
      | 1       | 8     | initial estimate                      |
      | 1       | 6     | better undertsanding of task          |
      | 1       | 16    | no control over inputs to create task |
      | 2       | 22    | for other task |
    
    Then a task: "task" should exist with name: "some task" #this works
    Then the estimate "estimate" should exist with explanation: "initial estimate" #this works
    Then the estimate "estimate" should be one of task: "task"'s estimates #this works
    Then the task "task" should have 3 estimates  #this one fails
    

    编辑

    我没有定制的步骤-尝试使用从盒子里拿出的黄瓜和泡菜(只是为了限制我的困惑)。

    class Estimate < ActiveRecord::Base
    
      belongs_to :Task, :class_name => "Task", :foreign_key => "Task_id"
    
    end
    

    class Task < ActiveRecord::Base
      has_many :estimates
    end
    

    有人能告诉我正确的方向吗(或者如果我需要发布更多的代码的话)?

    1 回复  |  直到 16 年前
        1
  •  0
  •   jonnii    16 年前

    您的估算类可以如下所示:

    class Estimate ...
      belongs_to :task
    end 
    

    至于你的小步舞步,我从来没有用过泡菜,所以我不知道是怎么回事,但如果失败的一步是:

    Then the task "task" should have 3 estimates  #this one fails
    

    它可能与我在上面概述的更改有关(可能它在表名上做了一些奇怪的事情??)。

    推荐文章