views:

253

answers:

1

Hi,

I'm trying to get a little more familiarity with Rails / ActiveRecord. In trying to do so I am attempting to use Cucumber to help with some "discovery" tests.

I have the following

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

EDIT

I have no custom steps - trying to use use what comes out of the box with cucumber and pickle (just to limit my confusion).

The models are

class Estimate < ActiveRecord::Base

  belongs_to :Task, :class_name => "Task", :foreign_key => "Task_id"

end

and

class Task < ActiveRecord::Base
  has_many :estimates
end

Can anyone point me in the right direction (or if I need to post more code)?

Thanks,

Joe

A: 

Your estimate class can look like this:

class Estimate ...
  belongs_to :task
end 

It will infer the table name and the fk and assuming you've been following the rails database idioms it should all just work.

As for your cuke steps, I've never used pickle, so I'm not sure what's going on with that, but if the step that's failing is:

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

It might be to related to the change I've outlined above (maybe it's doing something weird with the table name??).

jonnii