associated models

48 views
Skip to first unread message

vladr

unread,
Jun 21, 2011, 8:14:54 AM6/21/11
to pickle-...@googlegroups.com
In models:
Corporation has_many :employees
Employee belongs_to :corporation

Feature
...
Given a corporation exists with name: "Test Corp Name"
And an employee exists with first_name: "First name", corporation_id: that corporation

These code creates objects which are not associated with each one.
So I have corporation_id which is not the same as id of "Test Corp Name" corporation

I have tried to use:
...
Given a corporation exists with name: "Test Corp Name"
And an employee exists with first_name: "Test", corporation: "Precision Door Service"

And got an error: "Corporation(#81549430) expected, got String(#67388660) (ActiveRecord::AssociationTypeMismatch)"

So what is the best way to create associated models using pickle?
I can create models from table but, I think, it is not the best way

Thanks for answers!

Gemfile:
...
gem 'rspec-rails', '~> 2.6'
gem 'machinist', '>= 2.0.0.beta2'
gem 'cucumber-rails', '~> 0.5'
gem 'database_cleaner', '~> 0.6'
gem 'pickle', '~> 0.4.7'
gem 'launchy'

Michael MacDonald

unread,
Jun 21, 2011, 11:25:29 AM6/21/11
to pickle-...@googlegroups.com
Have you tried using the association “corporation” instead of the key “corporation_id”?

Given a corporation exists with name: "Test Corp Name"
And an employee exists with first_name: "First name", corporation: the corporation

--
You received this message because you are subscribed to the Google Groups "pickle" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pickle-cucumber/-/tYVQ5Fz-bX8J.
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.

tomtt

unread,
Jun 21, 2011, 11:26:36 AM6/21/11
to pickle
> So what is the best way to create associated models using pickle?
> I can create models from table but, I think, it is not the best way

You can 'label' the models when you create them, so that you can refer
to them later on in your scenario. Like so:

Given a corporation "goo" exists with name: "Test Corp Name"
And an employee exists with first_name: "First name", corporation:
corporation "goo"

Tom.

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
 Tom ten Thij
 Unboxed Consulting, http://unboxedconsulting.com
 T: +44 20 3137 2943 F: +44 20 7183 4251
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Reply all
Reply to author
Forward
0 new messages