1

我正在尝试更熟悉 Rails / ActiveRecord。在尝试这样做时,我试图使用 Cucumber 来帮助进行一些“发现”测试。

我有以下

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

谁能指出我正确的方向(或者如果我需要发布更多代码)?

谢谢,

4

1 回答 1

0

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

class Estimate ...
  belongs_to :task
end 

它将推断表名和 fk 并假设您一直在遵循 rails 数据库习惯用法,它应该都可以正常工作。

至于你的 cuke 步骤,我从来没有使用过泡菜,所以我不确定这是怎么回事,但如果失败的步骤是:

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

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

于 2010-01-22T15:47:30.177 回答