Table Refs

4 views
Skip to first unread message

Kevin Monk

unread,
Jan 14, 2011, 8:34:17 PM1/14/11
to pickle
It's 1.30 AM so apologies if the following is a little brief and
incoherent...

I'm trying to set up the following table so that I can use references
further into the scenario. If I have....

And the following active users exist:
| name | first_name | last_name |
| terry | Terry | Moore |
| david | David | Suchet |
| kevin | Kevin | Monk |
And the user: "kevin" logs in

Trouble is, I get undefined method `name=' for #<User:0x105967980>

That's not suprising because I don't have a method or attribute "name"
for my user model so how can I set up a reference against each table
row that I can use further down the scenario?

PS. I'm using FactoryGirl

This is my FacotryGirl....

require 'faker'
Factory.define :user do |f|
f.first_name Faker::Name.first_name
f.last_name Faker::Name.last_name
f.sequence(:employee_number) { |n| n }
f.password 'password'
f.password_confirmation {|u| u.password}
f.email {|u| "#{u.first_name}.#{u.last_name}@example.com".downcase }
f.role nil
end

Factory.define :active_user, :parent => :user do |f|
f.active true
end

Ian White

unread,
Jan 15, 2011, 10:08:36 AM1/15/11
to pickle-...@googlegroups.com
Hi there,

To use refs and tables, include a column that has the singularised name of the factory you are creating.

e.g.

And the following active users exist:

| active user | first_name | last_name |
| terry | Terry | Moore |

Hope that helps.

Cheers,
Ian

> --
> You received this message because you are subscribed to the Google Groups "pickle" group.
> To post to this group, send email to pickle-...@googlegroups.com.
> To unsubscribe from this group, send email to pickle-cucumb...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pickle-cucumber?hl=en.
>

Kevin Monk

unread,
Jan 15, 2011, 12:52:22 PM1/15/11
to pickle
THanks Ian.

After a long spate of head scratching the answer was obvious as
always. I was putting just "user" and not "active user".

A pretty obvious mistake now but hindsight is a great thing.

Hopefully this might help soemone else.
> >  f.email {|u| "#{u.first_name}.#{u.last_na...@example.com".downcase }
Reply all
Reply to author
Forward
0 new messages