how can one make a paths.rb entry that picks up a pickle handle on a namespaced model?

50 views
Skip to first unread message

Erich

unread,
Feb 7, 2011, 5:04:33 PM2/7/11
to pickle
Everything worked until I moved my Contact model into a Roles
namepsace.

Factory.define :contact_start, :class => "Roles::Contact" do |f|...

The app is now working again, RSpec tests are fine, but I can't get
pickle/cucumber back in shape.

The following feature file runs up to the point of trying to get to
the edit page.

Scenario: Pickle reference to a Contact
Given the following contact_starts exist:
|contact_start |startfirstname | startlastname |
| Sally | Sally | Test |
Then 1 roles_contacts should exist
And a roles_contact "Sally" should exist with startfirstname:
"Sally"
And the roles_contact's startfirstname should be "Sally"
When I go to the roles_contact's edit page
Then I should see "Sally"

With the default paths.rb I get:

When I go to the roles_contact's edit
page # features/step_definitions/
web_steps.rb:23
Could not figure out a path for ["the roles_contact"]
{:extra=>"edit"} (RuntimeError)
./features/support/paths.rb:34:in `path_to'

Adding the namespace created the problem. Based on the issues others
reported with with controller namespaces and the advice they got, I
figure that the namespace will confuse path_to_pickle and I need to
add my own paths that use polymorphic_path. Pickle still seems to be
able to use a handle on a namespaced model--as shown by the previous
step. But I can't figure out how to refer to recognize a handle or
follow the handle reference when specifying paths.

I tried:

when /^#{capture_model}(?:'s)? (.+?) page$/
polymorphic_path [$2.to_sym, $1 ]

yielding

When I go to the roles_contact's edit
page # features/step_definitions/
web_steps.rb:23
undefined method `edit_the roles_contact_path' for
#<Cucumber::Rails::World:0x208f0a4> (NoMethodError)
./features/support/paths.rb:18:in `path_to'
./features/step_definitions/web_steps.rb:24:in `/^(?:|I )go to (.
+)$/'

Can anyone help, or offer any clues? Many thanks.

Erich

Erich

unread,
Feb 9, 2011, 8:25:02 PM2/9/11
to pickle
The answer appears to be:

when /^#{capture_model}(?:'s)? (.+?) page$/
polymorphic_path [$2, model($1) ]

I'm stabbing rather blindly here, but it seems to work. I got the
idea (eventually, amongst many that led nowhere) from noticing that
this part of pickle_steps.rb was working

# model.attribute.should eql(value)
# model.attribute.should_not eql(value)
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}
$/) do |name, attribute, expectation, expected|
actual_value = model(name).send(attribute)



Erich

unread,
Feb 10, 2011, 1:36:28 PM2/10/11
to pickle
It's still working, so I just thought I'd throw in some of the other
stuff I had to figure out in this situation in case it helps anyone
else.

Model: Roles::Contact
Factory: contact_start (there is of course a vanilla factory, this is
a special case)
Associaton: contacts

By that last row I mean:

class User < ActiveRecord::Base
has_many :contacts, :class_name => 'Roles::Contact', :through
=> :user_contacts

So to get cucumber/pickle working you need to make the right choice
between factory name, model name, or association name. Really--going
through the code it looked like factory or model were supposed to be
interchangeable, but that wasn't my experience.

Here's a working approach:

Scenario: Referring to Roles_Contacts, aka Contacts, aka
contact_starts
#note plural before tables even if only one row
#note column name for Bob (label assignment) is FACTORY name
Given the following contact_addeds exist:
|contact_added |firstname | lastname |
| Bob | Bob | Test |
And the following users exist:
| user | username |
| foo | foo |
#but here the column name is the ASSOCIATION name and prefix label for
"Bob" is the MODEL name
And the following user_contacts exist:
| user | contact |
| user: "foo" | roles_contact: "Bob" |
#here it's MODEL name again, and note the plural
Then 1 roles_contacts should exist
When I log in as "foo"
#loading up 'last used' pickle ref for Bob because that's the only
approach I've gotten to work with route finding
Then a roles_contact "Bob" should exist with firstname: "Bob"
When I go to the roles_contact's edit page
#form_for + namespace = maximum verbosity. Yay?
Then the "roles_contact_phone" field should contain "1234567890"
...

and for that penultimate line, going to the edit page, this was needed
in paths.rb:
Reply all
Reply to author
Forward
0 new messages